WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Addon Request - Lua Command Sending (https://www.wowinterface.com/forums/showthread.php?t=48372)

morpheusxeno 10-17-13 09:52 AM

Addon Request - Lua Command Sending
 
Is there any way for anyone to send a lua command to another wow client and have that client run the command.

I would like both clients to use the mod. Have some sort of approved list so that each client which sends commands are only able to send commands to trusted clients.

I would like the commands to be run automatically if on the approved list.

I have a seen a few mods capable of doing this. Like Elvui for example, you can send your entire elvui interface profile to another player.

Dridzt 10-17-13 12:27 PM

Telepathy does something along those lines with spells.

morpheusxeno 10-17-13 05:18 PM

Cool addon idea but nothing close to what I am looking for really.

I want to beable to push a lua command.
Even something simple like...
/run print("hi noob")

The idea is to beable to send a client LUA Commands that will run on next key press or just the instant they get the sent information from another client using the same mod.

Phanx 10-18-13 01:55 AM

Something like this on the sending end:

Code:

SendAddonMessage("CmdShare", [[print("hi noob")]], "WHISPER", "Otherplayer")
... and this on the receiving end:

Code:

RegisterAddonMessagePrefix("CmdShare")

local frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:SetScript("OnEvent", function(self, event, prefix, message, channel, sender)
    if prefix == "CmdShare" then
        local func, err = loadstring(message)
        if func then
            print("Running shared command:")
            print("  " .. message)
            func()
        else
            print("Error loading shared command:")
            print("  " .. message)
            print("  " .. err)
        end
    end
end)

Note that the above doesn't provide any security; it will send to anyone, and run commands from anyone. You'd want to check the sender before executing the command, and possibly add some kind of promt the receiver needs to accept before the command gets run.

Also, you should either:

(a) check the command against a list of secure/protected functions that require hardware events (or that can't be called by addons at all) and avoid sending it or execute it if it contains any;

or (b) set up a secure macrotext button for the receive to click (or activate with a keybind) to execute the command, though you'd still need to check for functions that can't be called by addons at all (eg. CastSpellByName) and either avoid trying to execute the command, or convert those function calls into secure button attributes (eg. type/spell, spell/Frostbolt).

morpheusxeno 10-18-13 09:56 AM

I thank you for the effort you have put forth.

I would be very honest to say, I know less lua than your pet hamster.

I would do an arena carry for you or something for you to create a mod however :D!

I was thinking of something similar like this

typing ! before what you type in chat tells the mod that this is a command to send then target or player name and then command. So I guess something like this?

! Morpheusxeno /run LeaveParty()

morpheusxeno 10-19-13 12:31 PM

shameless bump!

elcius 10-19-13 09:42 PM

Code:

local whitelist = {"NSA","FBI"};

CreateFrame("frame","RemoteScript"):RegisterEvent("CHAT_MSG_ADDON");
RemoteScript:SetScript("OnEvent",function(self,e,pre,msg,typ,src)
        return pre == "RS" and tContains(whitelist,src) and loadstring(msg)();
end)
RegisterAddonMessagePrefix("RS");

SLASH_REMOTESCRIPT1,SLASH_REMOTESCRIPT2 = "/rscript","/rrun";
SlashCmdList.REMOTESCRIPT = function(args)
        local tar,src = strsplit(" ",args,2);
        SendAddonMessage("RS",src,"WHISPER",tar);
end

Populate the whitelist table with character names to accept scripts from, then it would just be
/rrun Morpheusxeno LeaveParty()

Phanx 10-20-13 04:13 AM

Here is some better code (no unnecessary globals, unnecessary function calls, inconsistent formatting, etc.). If you need help turning it into an addon, copy and paste it into this page:
http://addon.bool.no/

Code:

----------------------------------------------------------------------------
-- RunTo
-- Allows you to send slash commands to other players to be run.
-- http://www.wowinterface.com/forums/showthread.php?t=48372
-- Usage examples:
--    /runto Player-Server print("Hello world!")
--    /runto Player-Server /dance
----------------------------------------------------------------------------
-- START OF CONFIGURATION

-- Set this to "false" to see only error messages,
-- or leave it set to "true" to see all notifications.

local SHOW_NOTIFICATIONS = true

-- Add players here in the "Name-Server" format:

local TRUSTED_SENDERS = {
        ["Somename-Theserver"] = true,
        ["Anothername-Otherserver"] = true,
}

-- END OF CONFIGURATION
----------------------------------------------------------------------------

RegisterAddonMessagePrefix("RUN")

local REALM_SUFFIX = "-" .. gsub(GetRealmName(), "%s", "")

local frame = CreateFrame("Frame", "RunTo", UIParent)
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:SetScript("OnEvent", function(self, event, prefix, command, _, sender)
        if prefix ~= "RUN" then return end
        if not strfind(sender, "%-") then
                -- Not actually sure if same-server senders
                -- are shown as just "Name" or not. If they are,
                -- then this line is necessary. If they aren't, then
                -- this line won't hurt anything.
                sender = sender .. REALM_SUFFIX
        end
        if not TRUSTED_SENDERS[sender] then
                return
        end
        if strsub(command, 1, 1) == "/" then
                ChatFrame1EditBox:SetText(command)
                ChatEdit_ParseText(ChatFrame1EditBox, 1)
        end
        local func, err = loadstring(command)
        if err then
                print("Error running command:")
                print("  -", command)
                print("  -", err)
                return
        end
        if SHOW_NOTIFICATIONS then
                print("Running command from", sender)
                print("  -", command)
        end
        securecall(func)
end)

SLASH_RUNTO1 = "/runto"
SlashCmdList.RUNTO = function(msg)
        local target, command = strsplit(" ", strtrim(msg), 1)
        if target and command then
                if SHOW_NOTIFICATIONS then
                        print("Sending command to", target)
                        print("  - " .. command)
                end
                if not strfind(sender, "%-") then
                        sender = sender .. REALM_SUFFIX
                end

                SendAddonMessage("RUN", command, "WHISPER", target)
        end
end


morpheusxeno 10-23-13 11:05 AM

Will test after work today. Thank you!
:banana:

morpheusxeno 10-23-13 09:27 PM

I created the addon , I dont get any errors when trying to run a command. But the command doesnt run either.

I think "Player-Server" has something to do with it.

Can it just be "Player"

Phanx 10-24-13 02:50 AM

I updated the code in my previous post to add your current server name if you don't include one in the command. The additional lines are highlighted in green, near the end.

morpheusxeno 10-24-13 08:31 AM

Getting this lua error after the interface loads before doing anything.

Code:

Message: Interface\FrameXML\ChatFrame.lua:3546: attempt to index field 'chatFrame' (a nil value)
Time: 10/24/13 08:35:37
Count: 1
Stack: Interface\FrameXML\ChatFrame.lua:3546: in function `ChatEdit_OnLoad'
[string "*:OnLoad"]:1: in function <[string "*:OnLoad"]:1>
[C]: in function `CreateFrame'
Interface\AddOns\MyFirstAddOn\code.lua:30: in main chunk

Locals: self = RunTo {
 0 = <userdata>
 header = RunToHeader {
 }
 focusLeft = RunToFocusLeft {
 }
 focusRight = RunToFocusRight {
 }
 headerSuffix = RunToHeaderSuffix {
 }
 focusMid = RunToFocusMid {
 }
}
(*temporary) = <function> defined =[C]:-1
(*temporary) = RunTo {
 0 = <userdata>
 header = RunToHeader {
 }
 focusLeft = RunToFocusLeft {
 }
 focusRight = RunToFocusRight {
 }
 headerSuffix = RunToHeaderSuffix {
 }
 focusMid = RunToFocusMid {
 }
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'chatFrame' (a nil value)"

Just for testing purposes I disabled all addons before testing it.

Nimhfree 10-24-13 10:50 AM

It appears you changed the code since Phanx posted it. Perhaps it would be better to paste the actual code you are using to see where you attempt to access "chatFrame" where it does not exist.

morpheusxeno 10-24-13 09:37 PM

Quote:

It appears you changed the code since Phanx posted it. Perhaps it would be better to paste the actual code you are using to see where you attempt to access "chatFrame" where it does not exist.
You are wrong. I didn't change the code in any way.

elcius 10-24-13 11:33 PM

My code still works, just saying...

morpheusxeno 10-25-13 08:54 AM

1 Attachment(s)
Should I need to prove to you via RDP that my code hasn't been changed. I don't really think that's necessary.

I use the US Client. Does this have anything to do with the reason it may not be working?

I posted a replica of the LUA file with the code you used, And a video for good measure. Both showing only the mod are running and the code is without change.
http://www.youtube.com/watch?v=7oOAnKjG8QE

Phanx 10-25-13 10:11 PM

You guys really don't need to spam the thread with [b]videos[/i] to "prove" that you did or didn't edit some code... :rolleyes:

Anyway, I've added another section of code (highlighted in blue). The problem is some (unsurprisingly) idiotic coding in Blizzard's template system that assumes you are using XML and is full of annoying interdependencies.

morpheusxeno 10-26-13 01:32 AM

New Lua error after the changes.

Code:

Message: Interface\FrameXML\ChatFrame.lua:3546: attempt to index field 'chatFrame' (a nil value)
Time: 10/26/13 01:30:32
Count: 1
Stack: Interface\FrameXML\ChatFrame.lua:3546: in function <Interface\FrameXML\ChatFrame.lua:3545>
Interface\AddOns\MyFirstAddOn\code.lua:36: in function `ChatEdit_OnLoad'
[string "*:OnLoad"]:1: in function <[string "*:OnLoad"]:1>
[C]: in function `CreateFrame'
Interface\AddOns\MyFirstAddOn\code.lua:39: in main chunk

Locals: self = RunTo {
 0 = <userdata>
 header = RunToHeader {
 }
 focusLeft = RunToFocusLeft {
 }
 focusRight = RunToFocusRight {
 }
 headerSuffix = RunToHeaderSuffix {
 }
 focusMid = RunToFocusMid {
 }
}
(*temporary) = <function> defined =[C]:-1
(*temporary) = RunTo {
 0 = <userdata>
 header = RunToHeader {
 }
 focusLeft = RunToFocusLeft {
 }
 focusRight = RunToFocusRight {
 }
 headerSuffix = RunToHeaderSuffix {
 }
 focusMid = RunToFocusMid {
 }
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'chatFrame' (a nil value)"


morpheusxeno 10-27-13 07:18 PM

Still looking for help to get the addon Phanx made for me working.

elcius 10-28-13 03:25 AM

I posted working code a week ago.


All times are GMT -6. The time now is 08:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI