Thread Tools Display Modes
10-17-13, 09:52 AM   #1
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-17-13, 12:27 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Telepathy does something along those lines with spells.
  Reply With Quote
10-17-13, 05:18 PM   #3
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-18-13, 01:55 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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).
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-18-13 at 01:57 AM.
  Reply With Quote
10-18-13, 09:56 AM   #5
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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 !

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()
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 10-18-13 at 09:59 AM.
  Reply With Quote
10-19-13, 12:31 PM   #6
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
shameless bump!
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-19-13, 09:42 PM   #7
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
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()

Last edited by elcius : 10-20-13 at 05:43 AM.
  Reply With Quote
10-20-13, 04:13 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-29-13 at 01:55 AM.
  Reply With Quote
10-23-13, 11:05 AM   #9
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
Will test after work today. Thank you!
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-23-13, 09:27 PM   #10
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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"
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-24-13, 02:50 AM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-24-13, 08:31 AM   #12
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 10-24-13 at 08:40 AM.
  Reply With Quote
10-24-13, 10:50 AM   #13
Nimhfree
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 267
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.
  Reply With Quote
10-24-13, 09:37 PM   #14
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-24-13, 11:33 PM   #15
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
My code still works, just saying...
  Reply With Quote
10-25-13, 08:54 AM   #16
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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
Attached Files
File Type: lua code.lua (2.2 KB, 173 views)
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 10-25-13 at 10:15 AM.
  Reply With Quote
10-25-13, 10:11 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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...

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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-26-13, 01:32 AM   #18
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
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)"
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-27-13, 07:18 PM   #19
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
Still looking for help to get the addon Phanx made for me working.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-28-13, 03:25 AM   #20
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
I posted working code a week ago.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Addon Request - Lua Command Sending

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off