Thread Tools Display Modes
10-29-13, 01:54 AM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
@morpheusxeno:

You really don't need to bump the thread every 12 hours. I'm not glued to the forums. When I visit, I'll see your post on my "new posts since last visit" list, whether it's been 20 seconds or 20 years since you posted. Bumping doesn't magically summon me, or alert me in any way that you're posting.

Anyway, I've edited my code again. Since I don't have time to look through thousands of lines of crappy Blizzard UI code to figure out why their template is so bad, I've just switched it to using the existing editbox for ChatFrame1. This may cause taint, so let me know if you get any "action blocked" errors as a result.

@elcius:

As I already said in my first code post, your code may "work" but it has a lot of issues -- global leakage, unnecessary calls to useless functions, and (most problematic) no error checking.
__________________
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-29-13, 04:16 AM   #22
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
I'm not as familiar with the environment as most people, but the only 'leak' I see would maybe be the function generated by loadscript, which i assumed the garbage collector handles seeing as it has no reference.
"unnecessary calls to useless functions", - pray tell, and outside of wow's lua error handler, what else is needed?, he only asked for it to work and have a whitelist.
  Reply With Quote
10-29-13, 06:57 AM   #23
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Originally Posted by elcius View Post
I'm not as familiar with the environment as most people, but the only 'leak' I see would maybe be the function generated by loadscript, which i assumed the garbage collector handles seeing as it has no reference.
"unnecessary calls to useless functions", - pray tell, and outside of wow's lua error handler, what else is needed?, he only asked for it to work and have a whitelist.
Phanx is probably talking about the frame you put in the global environment "RemoteScript".
This is really not such a big deal although you could name it something a little more unique to avoid collisions or even better create an unnamed frame and work with a local reference.
It's also not using the returns from loadstring() so if the user makes a typo in the Lua snippet you won't catch that. You're also using the -relatively speaking - costly tContains() where a small change to your whitelist table would get rid of it.
Code:
local whitelist = {["FBI"]=true,["NSA"]=true}
local RemoteScript = CreateFrame("Frame")
RemoteScript:OnEvent = function(event,...)
  local pre,msg,typ,src = ...
  if pre=="RS" and whitelist[src] then
    local func,err = loadstring(msg)
    if err then
      print(err)
    else
      func()
    end
  end
end
RemoteScript:SetScript("OnEvent",RemoteScript.OnEvent)
RemoteScript:RegisterEvent("CHAT_MSG_ADDON")
This is a little more verbose alternative of the relevant code that illustrates those differences.
All in all it's mostly nitpicking and far less dramatic than it sounded
From the user perspective, working code that doesn't follow best practices always wins over polished code that doesn't work.

Last edited by Dridzt : 10-29-13 at 07:02 AM.
  Reply With Quote
10-29-13, 10:06 PM   #24
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
Error fixed, But issued commands do not work.

I do not get any feedback or any confirmation that the command went through.

Sorry for bumping the thread every so often. Most of the forum boards that I post on. Youre not seen unless you bump. I realize now that's different here. I will wait patiently for responses. I am most thankful for the work put forth thus far.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 10-29-13 at 10:56 PM.
  Reply With Quote
10-30-13, 05:13 AM   #25
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
#1 - Did you forget to update the TRUSTED_SENDERS table with your (or your friend's) character name(s)? Any commands received from names not in the table will be ignored. This sounds like what's happening now...

#2 - ...but in case it's not, I added some extra debug prints to show you what's happening at each step. Once you verify that it's working with the names in the table, you can remove all the lines with "-- #DEBUG" at the end of them. If you did add the names to the table (and reloaded the UI on both characters) and it's still not working, let me know. Also, it would probably be helpful to know what command(s) you're trying to send that aren't working.

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 PLAYER_NAME = UnitName("player") .. REALM_SUFFIX

local frame = CreateFrame("Frame", "RunTo", UIParent)
frame:RegisterEvent("CHAT_MSG_ADDON")
frame:SetScript("OnEvent", function(self, event, prefix, command, _, sender)
	if sender == PLAYER_NAME or 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
	print(strjoin(" / ", event, prefix, sender, command)) -- #DEBUG
	if not TRUSTED_SENDERS[sender] then
		print("Sender not trusted!") -- #DEBUG
		return
	end
	if strsub(command, 1, 1) == "/" then
		print("Running slash command...") -- #DEBUG
		ChatFrame1EditBox:SetText(command)
		ChatEdit_ParseText(ChatFrame1EditBox, 1)
		return
	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
	print("Running securecall...") -- #DEBUG
	securecall(func)
end)

SLASH_RUNTO1 = "/runto"
SlashCmdList.RUNTO = function(msg)
	local target, command = strsplit(" ", strtrim(msg), 2)
	print(strjoin(" / ", "/runto", target or "NO TARGET", command or "NO COMMAND")) -- #DEBUG
	if target and command then
		if SHOW_NOTIFICATIONS then
			print("Sending command to", target)
			print("  - " .. command)
		end
		if not strfind(target, "%-") then
			target = target .. REALM_SUFFIX
		end
		SendAddonMessage("RUN", command, "WHISPER", target)
		print(strjoin(" / ", "SendAddonMessage", "RUN", command, "WHISPER", target)) -- #DEBUG
	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 : 11-03-13 at 08:56 PM. Reason: Fixed missing parenthesis. Fixed strsplit parameters. Ignore self messages.
  Reply With Quote
10-30-13, 10:48 PM   #26
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
Code:
Message: Interface\AddOns\MyFirstAddOn\code.lua:79: ')' expected near 'RUN'
Time: 10/30/13 22:46:25
Count: 1
Stack: 
Locals:
This is prolly something really simple that I dont understand

I am simply trying out command

/dance for now

"/runto devoutlight /dance"
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-30-13, 11:58 PM   #27
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Fixed. There was a missing parenthesis on the indicated line.
__________________
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-31-13, 01:27 AM   #28
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
So now with the DEBUG that you have added

I do the following

Type : /runto devoutlight /dance
Debug returns : /runto / devoutlight /dance / NO COMMAND

Still nothing happens :P
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
10-31-13, 05:44 PM   #29
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Should be fixed now. Was an issue with the count parameter passed to strsplit.
__________________
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-31-13, 11:41 PM   #30
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
We are definitely making progress.

At least now we getting a different error. Regardless of how I put the character names in the top. Its always saying that the sender is not trusted.

CHAT_MSG_ADDON / RUN / Dêvoutlight / /dance
Sender not trusted!
:: /runto / devoutlight / /dance
Sending command to devoutlight
- /dance
SendAddonMessage / RUN / /dance / WHISPER / devoutlight-Tichondrius
CHAT_MSG_ADDON / RUN / Devoutlight / /dance
Sender not trusted

Edit ::::::

When commenting the code
Code:
	--if not TRUSTED_SENDERS[sender] then
	--	print("Sender not trusted!") -- #DEBUG
	--	return
	--end
But its really important that I dont have other people sending commands to the other client. It could be very dangerous.

When testing a few commands I sometimes get errors like...

Command Doesnt Work

CHAT_MSG_ADDON / RUN / Devoutlight / /say test 123
Running slash command...
Error running command:
- /say test 123
- [string "/say test 123"]:1: unexpected symbol near '/'

Command Worked

CHAT_MSG_ADDON / RUN / Devoutlight / /follow Devoutlight
Running slash command...
Error running command:
- /follow Devoutlight
- [string "/follow Devoutlight"]:1: unexpected symbol near '/'

When using the follow command I get an error, but It still follows.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 11-01-13 at 12:08 AM.
  Reply With Quote
11-01-13, 07:56 PM   #31
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by morpheusxeno View Post
CHAT_MSG_ADDON / RUN / Dêvoutlight / /dance
Sender not trusted!
:: /runto / devoutlight / /dance
Those names do not match; ê and e are not the same letter, and neither are D and d as far as Lua (and pretty much any other programming language) is concerned.

Make sure you use proper capitalization and accent marks in the trusted senders list. You can use whatever capitalization you like when typing the command in-game, since WoW will automatically fix the capitalization for you, but when you receive a message, the sender's name is always capitalized correctly.
__________________
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
11-01-13, 09:10 PM   #32
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
I have 25 Disc Priest that I multi box, Some of them are using ascii Letters, Im only testing between 2 clients right now.

I made the other D capital letter...

I doubt that is the cause of the issue though.

EDIT ::

The capital D and lower case d made no difference.
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 11-01-13 at 09:58 PM.
  Reply With Quote
11-01-13, 10:12 PM   #33
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
I think there is a missing return statement (in bold):
Code:
    if strsub(command, 1, 1) == "/" then
        print("Running slash command...") -- #DEBUG
        ChatFrame1EditBox:SetText(command)
        ChatEdit_ParseText(ChatFrame1EditBox, 1)
        return
    end
  Reply With Quote
11-03-13, 01:53 PM   #34
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
After changes made on 11/2/2013 at 01:09 AM


Code:
local TRUSTED_SENDERS = {
	["Devoutlight-Tichondrius"] = true,
	["Dêvoutlight-Tichondrius"] = true,
}
What was sent in chat :

/runto Devoutlight /yell OMG

What was sent back in debug :

/runto / devoutlight / /yell OMG
Sending command to devoutlight
- /yell OMG
SendAddonMessage / RUN / /yell OMG / WHISPER / devoutlight-Tichondrius
CHAT_MSG_ADDON / RUN / Devoutlight / /yell OMG
Running slash command...

The command was net sent. All other issues have been resolved however.
I also noted this...

In order for me to get the character to say something. I have to use something like...

/runto Devoutlight /script SendChatMessage("CheckReady", "SAY", "Common");
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...

Last edited by morpheusxeno : 11-03-13 at 02:37 PM.
  Reply With Quote
11-03-13, 06:27 PM   #35
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
/say /yell etc are not slash commands, they are short cuts for switching message channels in the chat window.
  Reply With Quote
11-03-13, 06:29 PM   #36
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Right, because that's the Lua function for chat. What is your issue exactly?

Edit @elcius: they are slash commands. They're just not Lua functions.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-03-13, 06:37 PM   #37
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
hash_SlashCmdList["/SAY"] = nil
hash_SlashCmdList["/YELL"] = nil
  Reply With Quote
11-03-13, 07:56 PM   #38
morpheusxeno
A Flamescale Wyrmkin
 
morpheusxeno's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 126
How can I make the mod refer to /say as

/script SendChatMessage(" ", "SAY", "Common");
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked...
  Reply With Quote
11-03-13, 08:06 PM   #39
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You have to set up a filter for your addon to catch /say as it goes through and change it to /script... before being sent to the other user.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-03-13, 09:06 PM   #40
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
New code:
http://pastebin.com/jsYH7ncd

I forgot that CHAT_MSG_ADDON also receives the messages you send; I've added a check so you won't try to handle your own messages. Also added the missing return as pointed out by Vrul, and fixed another minor issue related to handling slash commands vs scripts. If you want to send a script, you don't need to include "/script" or "/run" in front of it.

@elucius:
You are correct that "/say" is not a "real" slash command, but in this case that's completely irrelevant, since the code is calling the same function that the default UI calls when you press enter with "/say X" in the chat input box.
__________________
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

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


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