This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

HELP on eggping.tcl ping-reply modification

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
V
VinceDalnet
Voice
Posts: 17
Joined: Thu Mar 05, 2009 1:57 pm

HELP on eggping.tcl ping-reply modification

Post by VinceDalnet »

.
.
.
.
.
.
.
Can anyone help me edit eggping.tcl so it will reply in channel and NOT via notice. thanks in advance.



here's eggping.tcl


Code: Select all

### eggping.tcl v1.0.6, 27 December 2003
### by Graeme Donaldson
### (Souperman @ #eggdrop @ Undernet)
### Visit http://www.eggdrop.za.net/ for updates and other Tcl scripts.
###
### Lets your eggdrop listen for ping requests on channel or /msg
### Not the world's best script, but somebody asked for it. =)
###
### To use:
###  - Extract the files to your eggdrop scripts dir.
###  - Add a 'source scripts/eggping.tcl' to your eggdrop's config file.
###  - Edit the settings below if necessary, then .rehash your eggdrop.
### Anyone can now type request a ping from the bot using (defaults):
###  - !ping or !pingme on a channel, or
###  - /msg bot ping or /msg bot pingme
###
### Multiple triggers can be configured for public and /msg requests.
### Can accept ping requests only from users with specific flags.
### Can reply to ping requests only from specific channels.
### Can ignore ping requests made on certain channels.
### Can calculate the ping reply in milliseconds (requires Tcl 8.3 or higher)
### Can tell the user what server the bot is currently on.
###
### History:
###
### 1.0.0 29-Mar-2002 First release.both 
### 1.0.1 01-Apr-2002 Removed a small bit of code which I'd used for debugging.
###                   Show website address when the script loads.
### 1.0.2 11-May-2003 Fixed calculation bug on some systems with Tcl 8.3+.
### 1.0.3 21-May-2003 Modified wording of bot's reply to make it clearer.
### 1.0.4 19-Nov-2003 Fixed another calculation bug.
###                   Added option to specify whether you want to show ping
###                    time in milliseconds (if Tcl version allows this).
###                   Made telling the user the bot's current server an option.
### 1.0.5 23-Nov-2003 Added an option to specify which channels to respond to
###                    ping requests on.
###                   Added an option to specify that ping requests only be
###                    accepted by users with certain flags.
###                   Removed a debugging message I had left behind from the
###                    previous version.
### 1.0.6 27-Dec-2003 Fixed a bug caused by come clients refusing to reply
###                    to a CTCP PING with a negative number.
################################################################################

### You can change these settings if you want ###

# Public triggers, seperated by spaces.
set pingpubwords "!ping !pingme"

# /msg triggers, seperated by spaces.
set pingmsgwords "ping pingme"

# If you want to restrict ping requests to users with certain flags, change this.
set pingreqdflags "-|-"

# If you only want the bot to respond to requests from specific channels,
# set them here, separated by spaces, e.g. "#foo #bar #baz".  Setting one
# or more channels here makes the bot ignore the disabled chans setting.
set pingenabledchans ""

# If there are channels where you don't want the bot to listen for !ping
# requests, set them here, seperated by spaces, e.g. "#lame #lamer #lamest".
# This setting is meaningless if a specific list of channels have been given
# in the enabled chans setting.
set pingdisabledchans ""

# Do you want to calculate ping replies in milliseconds (1) or not (0)?
# Millisecond calculation only works on Tcl 8.3 and above, but you can safely
# leave this enabled, the script will detect your Tcl version and disable this
# if necessary.
set pingmilli 1

# Do you want the bot to tell the user what server it is currently on (1)
# or not (0)?
set pingtellserver 1


### YOU SHOULDN'T NEED TO EDIT ANYTHING BEYOND THIS POINT! ###
# Misc. stuff
set pingver "1.0.6"
set pingnver "100006"
putlog "Loading eggping.tcl $pingver by Souperman..."
if { ([info tclversion] < 8.3) && ($pingmilli == 1) } {
	set pingmilli 0
	putlog " eggping.tcl: warning: cannot calculate PINGs in milliseconds (requires Tcl 8.3 or higher). PINGs will be calculated in seconds."
}

# binds
foreach trigger [split $pingpubwords] { bind pub $pingreqdflags $trigger pingnickpub }
foreach trigger [split $pingmsgwords] { bind msg $pingreqdflags $trigger pingnickmsg }
bind ctcr $pingreqdflags PING pingreply

# triggered by ping command on channel
proc pingnickpub {nick uhost hand chan text} {
	if {$::pingenabledchans != ""} {
		foreach channel [split $::pingenabledchans] {
			if {[string tolower $channel] == [string tolower $chan]} {
				pingnick $nick
				return 1
			}
		}
		return 0
	} else {
		foreach channel [split $::pingdisabledchans] {
			if {[string tolower $channel] == [string tolower $chan]} {
				return 0
			}
		}
		pingnick $nick
		return 1
	}
}

# triggered by ping command via msg
proc pingnickmsg {nick uhost hand text} {
	pingnick $nick
	return 1
}

# called by pingnickpub or pingnickmsg, sends a CTCP PING to $nick.
proc pingnick {nick} {
	if {$::pingmilli} {
		putquick "PRIVMSG $nick :\001PING [expr {abs([clock clicks -milliseconds])}]\001"
	} else {
		putquick "PRIVMSG $nick :\001PING [unixtime]\001"
	}
}

# processes a CTCP PING reply.
proc pingreply {nick uhost hand dest key args} {
	set pingnum [lindex $args 0]
	set pingserver [lindex [split $::server :] 0]
	# sanity check -- only processes the CTCP PING reply if it's value is a number
	if {[regexp -- {^-?[0-9]+$} $pingnum]} {
		if {$::pingmilli} {
			puthelp "NOTICE $nick :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr {abs([expr [expr {abs([clock clicks -milliseconds])} - $pingnum] / 1000.000])}] seconds"
		} else {
			puthelp "NOTICE $nick :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr [unixtime] - $pingnum] seconds"
		}
	}
}
putlog " Visit http://www.eggdrop.za.net/ for updates and other Tcl scripts."
putlog "Successfully loaded eggping.tcl $pingver by Souperman!"
[i][/i]
Last edited by VinceDalnet on Fri Mar 06, 2009 3:10 am, edited 1 time in total.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Change

Code: Select all

puthelp "NOTICE $nick :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr {abs([expr [expr {abs([clock clicks -milliseconds])} - $pingnum] / 1000.000])}] seconds"
to

Code: Select all

puthelp "PRIVMSG $chan :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr {abs([expr [expr {abs([clock clicks -milliseconds])} - $pingnum] / 1000.000])}] seconds"
and

Code: Select all

puthelp "NOTICE $nick :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr [unixtime] - $pingnum] seconds" 
to

Code: Select all

puthelp "PRIVMSG $chan :Ping reply from $::botnick[expr $::pingtellserver?\" (currently on $pingserver) \":\" \"]to $nick: [expr [unixtime] - $pingnum] seconds"
And don`t forget to use

Code: Select all

 tag when posting your code.
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Was thinking of that easy-fix myself, but then remembered that pingreply is called upon ctcr (ctcp reply), and thus $chan is not available (as most likely, <target> would be the bot's nickname).

This would instead have to be stored when the user first makes the request in a channel, and then recalled within pingreply.
NML_375
V
VinceDalnet
Voice
Posts: 17
Joined: Thu Mar 05, 2009 1:57 pm

Post by VinceDalnet »

username: it doesnt work :cry:
it's only pinging a user but no replies are being shown in the channel.... i can see ctcp in dcc partyline though.


nml375: pls help me how to correct this error.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Lets bring a little colour into our lives. Requires Tcl 8.4+ and text embellishments allowed in the command channel. Needs a utf-8 compliant client too, like mIRC or XChat.

Syntax !ping ?target?

Code: Select all

bind CTCR - PING pPingCtcrReceive
bind PUB - !ping pPingPubCommand
bind RAW - 401 pPingRawOffline

proc pPingTimeout {} {
  global vPingOperation
  set schan [lindex $vPingOperation 0]
  set snick [lindex $vPingOperation 1]
  set tnick [lindex $vPingOperation 2]
  putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) operation timed out attempting to ping \00307$tnick\003"
  unset vPingOperation
  return 0
}

proc pPingCtcrReceive {nick uhost hand dest keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {[string equal -nocase $nick $tnick]} {
      set reply [lindex [split $txt] 0]
      set seconds [expr {([clock clicks -milliseconds] - $reply) / 1000.0}]
      set char [encoding convertto utf-8 \u258C]
      if {[expr {round($seconds / 0.5)}] > 10} {set red 10} else {set red [expr {round($seconds / 0.5)}]}
      set green [expr {10 - $red}]
      set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
      putserv "PRIVMSG $schan :\00310Compliance\003 (\00314$snick\003) $output $seconds seconds from \00307$tnick\003"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}

proc pPingKillutimer {} {
  foreach item [utimers] {
    if {[string equal pPingTimeout [lindex $item 1]]} {
      killutimer [lindex $item 2]
    }
  }
  return 0
}

proc pPingPubCommand {nick uhost hand channel txt} {
  global vPingOperation
  switch -- [llength [split [string trim $txt]]] {
    0 {set tnick $nick}
    1 {set tnick [string trim $txt]}
    default {
      putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) correct syntax is \00307!ping ?target?\003"
      return 0
    }
  }
  if {![info exists vPingOperation]} {
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $tnick]} {
      set vPingOperation [list $channel $nick $tnick]
      putserv "PRIVMSG $tnick :\001PING [clock clicks -milliseconds]\001"
      utimer 10 pPingTimeout
    } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) \00307$tnick\003 is not a valid nick"}
  } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) a ping operation is still pending, please wait"}
  return 0
}

proc pPingRawOffline {from keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {[string equal -nocase $tnick [lindex [split $txt] 1]]} {
      putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) \00307$tnick\003 is not online"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}
I must have had nothing to do
V
VinceDalnet
Voice
Posts: 17
Joined: Thu Mar 05, 2009 1:57 pm

Post by VinceDalnet »

arfer wrote:Lets bring a little colour into our lives. Requires Tcl 8.4+ and text embellishments allowed in the command channel. Needs a utf-8 compliant client too, like mIRC or XChat.

Syntax !ping ?target?

Code: Select all

bind CTCR - PING pPingCtcrReceive
bind PUB - !ping pPingPubCommand
bind RAW - 401 pPingRawOffline

proc pPingTimeout {} {
  global vPingOperation
  set schan [lindex $vPingOperation 0]
  set snick [lindex $vPingOperation 1]
  set tnick [lindex $vPingOperation 2]
  putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) operation timed out attempting to ping \00307$tnick\003"
  unset vPingOperation
  return 0
}

proc pPingCtcrReceive {nick uhost hand dest keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {[string equal -nocase $nick $tnick]} {
      set reply [lindex [split $txt] 0]
      set seconds [expr {([clock clicks -milliseconds] - $reply) / 1000.0}]
      set char [encoding convertto utf-8 \u258C]
      if {[expr {round($seconds / 0.5)}] > 10} {set red 10} else {set red [expr {round($seconds / 0.5)}]}
      set green [expr {10 - $red}]
      set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
      putserv "PRIVMSG $schan :\00310Compliance\003 (\00314$snick\003) $output $seconds seconds from \00307$tnick\003"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}

proc pPingKillutimer {} {
  foreach item [utimers] {
    if {[string equal pPingTimeout [lindex $item 1]]} {
      killutimer [lindex $item 2]
    }
  }
  return 0
}

proc pPingPubCommand {nick uhost hand channel txt} {
  global vPingOperation
  switch -- [llength [split [string trim $txt]]] {
    0 {set tnick $nick}
    1 {set tnick [string trim $txt]}
    default {
      putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) correct syntax is \00307!ping ?target?\003"
      return 0
    }
  }
  if {![info exists vPingOperation]} {
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $tnick]} {
      set vPingOperation [list $channel $nick $tnick]
      putserv "PRIVMSG $tnick :\001PING [clock clicks -milliseconds]\001"
      utimer 10 pPingTimeout
    } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) \00307$tnick\003 is not a valid nick"}
  } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) a ping operation is still pending, please wait"}
  return 0
}

proc pPingRawOffline {from keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {[string equal -nocase $tnick [lindex [split $txt] 1]]} {
      putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) \00307$tnick\003 is not online"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}




arfer: it doesnt work perfectly :cry:


it produces alot of these...

07:17:26] <@Vince> !ping Vince

[07:17:37] 14<4@ Bodybuilder14> 04Error (14Vince) operation timed out attempting to ping 07Vince

:cry: :cry: :cry:
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I must admit I do often get that every time I try to script a ping command. In some cases I know its interference from routers not forwarding the ping request. For example, I can't use the eggdrop to ping myself because I'm behind a router.

Perhaps somebody could take a look at the code and advise. I would dearly like to know the problem. The strange thing is that other people can successfully ping me from their IRC client, which does make me suspicious that something is wrong with my code. Unfortunately, I can't see any problem. I do know from observing the partyline that the bot does not receive the ping reply on the occasions it fails.
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Actually, this script solely uses plain simple CTCP pings. And it's entirely up to the remote client to decide whether to reply or not.
The timeout error message simply means that your eggdrop did not get a reply within 10 seconds, and the remote client most likely ignored your ping request.

Arfer, routers and other network devices should not interfere with CTCP ping's. They can, of course, interfere with ICMP/IP-pings, but that's on a completely different level of communication (not related to irc at all).
Some "intelligent" NAT-routers might try to parse irc messages, especially CTCP-requests in order to translate addresses and setup port forwarding dynamically to allow transparent support for DCC CHAT. They're pretty rare these days though, and shouldn't mangle non-DCC CTCP's.
NML_375
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thanks for your input nml375

The most annoying thing about this whole business is why somebody can ping me directly from their IRC client and get a response, yet the same user cannot ping me via my eggdrop Tcl ping script (though I do receive the ping request). My client does not in this case respond (or at least the eggdrop does not receive the response).

It suggests that whilst my IRC client (mIRC) receives the ping request from my eggdrop Tcl script, it is not understood and my IRC client cannot format a reply.

I do have one clue. I am unable to verify if it is 100% consistent but the evidence so far suggests that users with XChat clients do successfully respond to the script.
I must have had nothing to do
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

The evidence. Same computer, router, connection etc. Different IRC client.

Image

Image
I must have had nothing to do
V
VinceDalnet
Voice
Posts: 17
Joined: Thu Mar 05, 2009 1:57 pm

Post by VinceDalnet »

I guess i have to stick with eggping.tcl even if its NOTICE on REPLY :cry:


thanks guys for your inputs here. ciao!
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

OK fixed.

I should have read the script you originally posted.

mIRC will not reply to a negative integer as the ping argument.

I also changed the command trigger from ! (exclamation) to . (period) so the syntax is .ping ?target? ... this was because my script was setting off other mIRC based ping scripts which took precedence and my script failed to respond.

I also increased the timeout to 20secs

I am not completely satisfied. There are still users that respond to a manual ctcp ping (in effect mIRC to mIRC) yet do not respond to the script. Nonetheless, this should work as well as the script you originally posted. I need to understand better the mechanism of a manual ping and reply from mIRC to improve it.

Code: Select all

bind CTCR - PING pPingCtcrReceive
bind PUB - .ping pPingPubCommand
bind RAW - 401 pPingRawOffline

proc pPingTimeout {} {
  global vPingOperation
  set schan [lindex $vPingOperation 0]
  set snick [lindex $vPingOperation 1]
  set tnick [lindex $vPingOperation 2]
  putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) operation timed out attempting to ping \00307$tnick\003"
  unset vPingOperation
  return 0
}

proc pPingCtcrReceive {nick uhost hand dest keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {([string equal -nocase $nick $tnick]) && ([regexp -- {^[0-9]+$} $txt])} {
      set seconds [expr {abs((abs([clock clicks -milliseconds]) - $txt) / 1000.0)}]
      set char [encoding convertto utf-8 \u258C]
      if {[expr {round($seconds / 0.5)}] > 10} {set red 10} else {set red [expr {round($seconds / 0.5)}]}
      set green [expr {10 - $red}]
      set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
      putserv "PRIVMSG $schan :\00310Compliance\003 (\00314$snick\003) $output $seconds seconds from \00307$tnick\003"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}

proc pPingKillutimer {} {
  foreach item [utimers] {
    if {[string equal pPingTimeout [lindex $item 1]]} {
      killutimer [lindex $item 2]
    }
  }
  return 0
}

proc pPingPubCommand {nick uhost hand channel txt} {
  global vPingOperation
  switch -- [llength [split [string trim $txt]]] {
    0 {set tnick $nick}
    1 {set tnick [string trim $txt]}
    default {
      putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) correct syntax is \00307!ping ?target?\003"
      return 0
    }
  }
  if {![info exists vPingOperation]} {
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $tnick]} {
      set vPingOperation [list $channel $nick $tnick]
      putserv "PRIVMSG $tnick :\001PING [expr {abs([clock clicks -milliseconds])}]\001"
      utimer 20 pPingTimeout
    } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) \00307$tnick\003 is not a valid nick"}
  } else {putserv "PRIVMSG $channel :\00304Error\003 (\00314$nick\003) a ping operation is still pending, please wait"}
  return 0
}

proc pPingRawOffline {from keyword txt} {
  global vPingOperation
  if {[info exists vPingOperation]} {
    set schan [lindex $vPingOperation 0]
    set snick [lindex $vPingOperation 1]
    set tnick [lindex $vPingOperation 2]
    if {[string equal -nocase $tnick [lindex [split $txt] 1]]} {
      putserv "PRIVMSG $schan :\00304Error\003 (\00314$snick\003) \00307$tnick\003 is not online"
      unset vPingOperation
      pPingKillutimer
    }
  }
  return 0
}
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'm not so sure your fix with absolute values is proper at a first glance, although I'll need to bring forth paper and pencil to verify this.

One workaround could be to try and use the CTCP ECHO request, which is supported by most clients, and takes no consideration as to the content being a string, integer, etc.

Another approach, since you already store information between pinging and reacting to the reply, is simply storing the timestamp in that list, and simply sending some kind of numeric id as ping-value (possibly a unixtime timestamp). Should satisfy the kinkiest of clients (such as mIRC).

As for the "specs" of CTCP and PING:
CTCP (Client To Client Protocol) is a psuedo-standard to pass instructions between clients on a network. A transaction constitutes a request, and a possible response. Extended details can be found at http://www.irchelp.org/irchelp/rfc/ctcpspec.html, but I'll do a short summary that simly covers what is related to this thread:

The request:
The request is done using PRIVMSG's to the target (either nickname or channel), and is embedded with the Ctrl-A (\001) control character. The first word will become the command, and any subsequent words arguments. One PRIVMSG may contain several CTCP requests, and may also be embedded in normal messages.

The response:
The response is done using NOTICE's to the initiator (always nickname), and is embedded with the Ctrl-A (\001) control character. The first word will become the command, and should match that of the request. Any subsequent words will be arguments. One notice should only contain one CTCR (Client To Client Response), and should not be embedded in a normal notice.

The PING request:
Ping is used to measure the time delay between clients on the IRC network. It takes one argument, being a timestamp:

Code: Select all

\001PING timestamp\001
`timestamp' is the current time encoded in any form the querying
client finds convenient. The replying client should reply with a CTCR PING having the same timestamp.


Unfortunately, CTCP/CTCR is a psuedo-standard, which means it is entirely up to each irc client developer to decide how well they wish to support it, if at all. Some clients get kinky with the case of the request, some don't like stacked or embedded requests. Some add additional constraints to requests like PING, making the assumption it should be a unixtime timestamp.

As to mIRC, as I recall, it does not like stacked requests, although it handles embedded ones. It has a very strict interpretation of ping (and other requests), and assumes anything not resembling a unixtime timestamp being some kind of bogus/flood request.
NML_375
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thanks very much for that.

The 'quick fix' seems to be largely working but I do like your idea of storing the start [clock clicks -milliseconds] within the script and simply sending a dummy [unixtime] timestamp with the ping request. Such a timestamp is more widely accepted by various clients. As confirmation, a manual ping from mIRC client to mIRC client only has an accuracy to the nearest second.
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

After thinking it through, your quickfix is indeed flawed in the case where the "timestamp" and "current-time" have opposite signs, in that it will yield a far lower value than the actual delay. If they are both positive or negative, you will however get accurate delay.

Considder we get the numeric timestamp of -3, and as the ping reply comes back, current-time has reached 2.
With no conversions, the equation turns into 2 - (-3) = 5, which is good.
However, in your code, we'll first get the absolute value of the timestamp; 3.
Next, we'll get the absolute value of current-time; 2.
So, now we do the maths:
abs(2 - 3) => abs(-1) => 1.

It won't cause your script to crash or break your eggdrop, but it will return bogus "ping-time" values.
NML_375
Post Reply