Redefined functions, in particular Send, Send to World and the command line

Posted by Cino on Mon 16 Jan 2006 12:56 AM — 3 posts, 15,965 views.

Australia #0
I have made an idle counter, as you appear to the MUD (so based on the last command sent) as opposed to the last command entered clientside.


I have a somewhat functioning implementation, using a redefined version of Send,


OldSend=Send
function NewSend(...)
	for i,v in ipairs(arg) do
		OldSend(v)
	end
	option.idle=os.time()
end
Send=NewSend

as inspired from http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5434

and an alias,

<aliases>
  <alias
   match="^((?&lt;!/)|(?&lt;!#)).*$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="999"
  >
  <send>Send("%0")</send>
  </alias>
</aliases>

This catches everything that does not begin with '/' (for script command), '#' (the chat plugin) or is another alias as it has the latest sequence in my list.


Between them, they appear to catch every sent command (be it from the command line or a macro), except when something uses the 'Send to World' option.


Of course, a work around for the 'Send to World' is to instead 'Send to Script' or 'Send to Execute', and just use Send...



I was wondering if there was a way to redefine the send from command line and 'Send to World' to use this new Send, without having to go through the extra alias or sending to script or execute.



Just so you know where I end up with all this, here is my status bar

function StatusBar()
	local sb
	sb="Idle: "..TimeSince(option.idle)
	--sb=sb..whatever_else_I_deem_useful_to_display
	--sb=sb..etc
	SetStatus(sb)
end

which is called from a timer to update every second.
Australia Forum Administrator #1
My first reaction is that it would be simpler to make a small plugin which uses OnPluginSend callback.

This detects *all* text sent to the MUD, including timers, triggers etc.

Thus, this is the logical place to capture the time from the MUD's point of view.


See:

http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks


Your other problem is this:


for i,v in ipairs(arg) do
		OldSend(v)
	end


Send actually appends a newline to the text, as it assumes you want to send something with a newline at the end. The documentation doesn't mention this (yet), but it does say multiple arguments are concatenated together.

Unfortunately your approach of doing multiple OldSend calls would actually break up the command being sent and put a newline after each piece of it.

If you are going to stick to your function you should concatenate the "arg" arguments together and then do a single OldSend.
Australia #2
Quote:

Unfortunately your approach of doing multiple OldSend calls would actually break up the command being sent and put a newline after each piece of it.

Ah yes, I hadn't noticed that. I had been concatenating the components and only sending one argument anyways thus far.

But OnPluginSend is perfect for this case.

Thank you.