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.

Need help.. Creting tcl for check opened ports

Old posts that have not been replied to for several years.
Locked
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Need help.. Creting tcl for check opened ports

Post by zfitri »

i'm newbie is scripting.. i want to make a tcl to check my raganarok server status.. in mIRC their make that such script by checking ragnarok server opened ports such 6901 for login server ports,

are the any idea to help me creating such tcl for eggdrop..

thanxs
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Non-blocking

Code: Select all

# usage: tcpProbe <ip> <port> <callback>
#
# Two arguments are appended to the callback command:
# * A status code (1/0 for success/failure) 
# * A message (hostname/reason depending on the status code)
proc tcpProbe {ip port callback} {
	set sock [socket -async $ip $port]
	fileevent $sock writable [list tcpProbed $sock $callback]
	set sock
}
proc tcpProbed {sock callback} {
	if {[set msg [fconfigure $sock -error]]==""} {
		set ok 1
		set msg [lindex [fconfigure $sock -peername] 1]
	} else {
		set ok 0
	}
	close $sock
	eval [lappend callback $ok $msg]
}

# example:
proc showResult {what ok msg} {
	if {$ok} {
		putlog "connected to $what ($msg)"
	} else {
		putlog "failed connecting to $what ($msg)"
	}
}
tcpProbe 127.0.0.1 1234 [list showResult "the thing"]
Blocking

Code: Select all

if {[catch {socket $ip $port} re]} {
	# connection failed - $re is the reason
} else {
	# connected - $re is the socket id
	close $re
}
Have you ever read "The Manual"?
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Post by zfitri »

ok thanxs for the quick reply :-
for your info i want to make this example mIRC script for my eggdrop,
can u confirm the tcl u post is what i'm need here..
thank you...

alias checkstatus { .sockclose loginsock | .sockclose mapsock | .sockclose charsock | .sockclose patchsock
.sockopen loginsock 192.168.0.2 6900
.sockopen charsock 192.168.0.2 6121
.sockopen mapsock 192.168.0.2 5121
.sockopen patchsock 192.168.0.2 21
}

on *:sockopen:patchsock: {
if ($sockerr) { set %chropatch 4TERMINATED }
else { set %chropatch 3ONLINE }
}

on *:sockopen:loginsock: {
if ($sockerr) { set %chrologin 4TERMINATED }
else { set %chrologin 3ONLINE }
}
on *:sockopen:mapsock: {
if ($sockerr) { set %chromap 4TERMINATED }
else { set %chromap 3ONLINE }
}
on *:sockopen:charsock: {
if ($sockerr) { set %chrocharacter 4TERMINATED }
else { set %chrocharacter 3ONLINE }
}

on *:text:*:#aJRo,#myradio,#xxx: {
if (!status isin $1-) {
.inc -u50 %status 1
if (%status > 2) { .ignore -u20 $nick }
else { goto status }
:status
.checkstatus
.timer 1 4 msg $chan - Server Status [- Login Server [ %chrologin ] - Character Server [ %chrocharacter ] - Map Server [ %chromap ] - Register [ ajspeedi.ath.cx/ro/login.php ] - Server Name [ aJRo ] - Service Type ( eAthena ) Domain Host ( aJRo Team ) -
}
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Are you talking to me? I don't know that "language". Try to describe in plain english what you're trying to create :)
Have you ever read "The Manual"?
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Post by zfitri »

ok sorry...
actually me from malaysia.. so my english is poor..

what i need is a tcl for eggdrop... i'm running a private server of ragnarok on my linux slackware box. I'm thinking to make an eggdrop and put it on my irc channel for status of my server..

when my user enter my irc room they type

!status

then i want my bot to answer something like this

<ajRo> - Server Status [- Login Server [ ONLINE ] - Character Server [ ONLINE ] - Map Server [ ONLINE ] - Register [ ajspeedi.ath.cx/ro/login.php ] - Server Name [ aJRo ] - Service Type ( eAthena ) Domain Host ( aJRo Team ) -

ok, my irc script check the socket 6901 for character server on my lan ip slackware 192.168.0.2.. and so on.. mapserver socket 5121, charserver 6121

hope u understand what i post here

thank you very much
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Try this

Post by user »

Add the two probe procs from my first post...

Code: Select all

bind pub - !status sstat:pub
proc sstat:pub {n u h c a} {
	global sstat
	if {[info exists sstat(pending)]&&$sstat(pending)>0} {
		# add channel to target list and wait for pending request
		set sstat(target,$c) $n
		return
	}
	if {[info exists sstat(next)]&&$sstat(next)>[clock sec]} {
		# use result of previous check
		set sstat(target,$c) $n
		sstat:msg
	} else {
		# (re)check servers
		set sstat(target,$c) $n
		set sstat(pending) 0
		# 90 seconds delay before re-checking to prevent flooding
		set sstat(next) [expr {[clock sec]+90}]
		foreach {name ip port} {
			login 192.168.0.2 6900 
			char 192.168.0.2 6121 
			map 192.168.0.2 5121 
		} {
			if {[catch {tcpProbe $ip $port [list sstat:sock $name]} err]} {
				set sstat(status,$name) "OFFLINE"
				putlog "sstat Warning: $err"
			} {
				incr sstat(pending)
			}
		}
		if {$sstat(pending)==0} {
			puthelp "PRIVMSG $c :$n - failed miserably...contact my admin."
		}
	}
}
proc sstat:sock {name ok x} {
	global sstat
	if {$ok} {
		set sstat(re,$name) "ONLINE"
	} {
		set sstat(re,$name) "OFFLINE"
	}
	if {[incr sstat(pending) -1]==0} {
		set sstat(msg) "- Server Status \[- Login Server \[ $sstat(re,login) \] - Character Server \[ $sstat(re,char) \] - Map Server \[ $sstat(re,map) \] - Register \[ ajspeedi.ath.cx/ro/login.php \] - Server Name \[ aJRo \] - Service Type ( eAthena ) Domain Host ( aJRo Team ) -"
		sstat:msg
	}
}
proc sstat:msg {} {
	global sstat
	foreach name [array names sstat target,*] {
		unset sstat($name)
		scan $name target,%s chan
		puthelp "PRIVMSG $chan :$sstat(msg)"
	}
}
...I leave the testing to you...because I dislike testing stuff :P
Make sure you don't mess up the code by adding linebreaks etc (the best way to copy the code unaltered is to press the "quote" button and copy from the texarea on the posting page)
Have you ever read "The Manual"?
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Post by zfitri »

after i make some adjustment these error found when i run the eggdrop

Eggdrop v1.6.17 (C) 1997 Robey Pointer (C) 2004 Eggheads
[10:07] --- Loading eggdrop v1.6.17 (Wed Dec 8 2004)
[10:07] Tcl error in file 'ajro.tcl':
[10:07] wrong # args: should be "tcpProbed sock callback"
while executing
"tcpProbed 127.0.0.1 1234 [list showResult "the thing"]"
(file "ajro.tcl" line 31)
[10:07] * MSG534

just for note,
# 1st level
# usage: tcpProbe <ip> <port> <callback>
#
# Two arguments are appended to the callback command:
# * A status code (1/0 for success/failure)
# * A message (hostname/reason depending on the status code)
proc tcpProbed {ip port callback} {
set sock [socket -async $ip $port]
fileevent $sock writable [list tcpProbed $sock $callback]
set sock
}
proc tcpProbed {sock callback} {
if {[set msg [fconfigure $sock -error]]==""} {
set ok 1
set msg [lindex [fconfigure $sock -peername] 1]
} else {
set ok 0
}
close $sock
eval [lappend callback $ok $msg]
}

# example:
proc showResult {what ok msg} {
if {$ok} {
putlog "connected to $what ($msg)"
} else {
putlog "failed connecting to $what ($msg)"
}
}
tcpProbed 127.0.0.1 1234 [list showResult "the thing"]

# 2nd level
if {[catch {socket $ip $port} re]} {
# connection failed - $re is the reason
} else {
# connected - $re is the socket id
close $re
}

# 3rd level
bind pub - !status sstat:pub
proc sstat:pub {n u h c a} {
global sstat
if {[info exists sstat(pending)]&&$sstat(pending)>0} {
# add channel to target list and wait for pending request
set sstat(target,$c) $n
return
}
if {[info exists sstat(next)]&&$sstat(next)>[clock sec]} {
# use result of previous check
set sstat(target,$c) $n
sstat:msg
} else {
# (re)check servers
set sstat(target,$c) $n
set sstat(pending) 0
# 90 seconds delay before re-checking to prevent flooding
set sstat(next) [expr {[clock sec]+90}]
foreach {name ip port} {
login 192.168.0.2 6900
char 192.168.0.2 6121
map 192.168.0.2 5121
} {
if {[catch {tcpProbe $ip $port [list sstat:sock $name]} err]} {
set sstat(status,$name) "OFFLINE"
putlog "sstat Warning: $err"
} {
incr sstat(pending)
}
}
if {$sstat(pending)==0} {
puthelp "PRIVMSG $c :$n - failed miserably...contact my admin."
}
}
}
proc sstat:sock {name ok x} {
global sstat
if {$ok} {
set sstat(re,$name) "ONLINE"
} {
set sstat(re,$name) "OFFLINE"
}
if {[incr sstat(pending) -1]==0} {
set sstat(msg) "- Server Status \[- Login Server \[ $sstat(re,login) \] - Character Server \[ $sstat(re,char) \] - Map Server \[ $sstat(re,map) \] - R$
sstat:msg
}
}
proc sstat:msg {} {
global sstat
foreach name [array names sstat target,*] {
unset sstat($name)
scan $name target,%s chan
puthelp "PRIVMSG $chan :$sstat(msg)"
}
}
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Try this

Post by user »

user wrote:Add the two probe procs from my first post...
You didn't just add the two procs...you added my usage example too and the non-blocking example ...AND you somehow got the brilliant idea of renaming one of the procs :P

Here's what you should have done (the order of the procs doesn't matter)

Code: Select all

bind pub - !status sstat:pub
proc sstat:pub {n u h c a} {
	global sstat
	if {[info exists sstat(pending)]&&$sstat(pending)>0} {
		# add channel to target list and wait for pending request
		set sstat(target,$c) $n
		return
	}
	if {[info exists sstat(next)]&&$sstat(next)>[clock sec]} {
		# use result of previous check
		set sstat(target,$c) $n
		sstat:msg
	} else {
		# (re)check servers
		set sstat(target,$c) $n
		set sstat(pending) 0
		# 90 seconds delay before re-checking to prevent flooding
		set sstat(next) [expr {[clock sec]+90}]
		foreach {name ip port} {
			login 192.168.0.2 6900 
			char 192.168.0.2 6121 
			map 192.168.0.2 5121 
		} {
			if {[catch {tcpProbe $ip $port [list sstat:sock $name]} err]} {
				set sstat(status,$name) "OFFLINE"
				putlog "sstat Warning: $err"
			} {
				incr sstat(pending)
			}
		}
		if {$sstat(pending)==0} {
			puthelp "PRIVMSG $c :$n - failed miserably...contact my admin."
		}
	}
}
proc sstat:sock {name ok x} {
	global sstat
	if {$ok} {
		set sstat(re,$name) "ONLINE"
	} {
		set sstat(re,$name) "OFFLINE"
	}
	if {[incr sstat(pending) -1]==0} {
		set sstat(msg) "- Server Status \[- Login Server \[ $sstat(re,login) \] - Character Server \[ $sstat(re,char) \] - Map Server \[ $sstat(re,map) \] - Register \[ ajspeedi.ath.cx/ro/login.php \] - Server Name \[ aJRo \] - Service Type ( eAthena ) Domain Host ( aJRo Team ) -"
		sstat:msg
	}
}
proc sstat:msg {} {
	global sstat
	foreach name [array names sstat target,*] {
		unset sstat($name)
		scan $name target,%s chan
		puthelp "PRIVMSG $chan :$sstat(msg)"
	}
}

# the two procs from my first post:
proc tcpProbe {ip port callback} {
	set sock [socket -async $ip $port]
	fileevent $sock writable [list tcpProbed $sock $callback]
	set sock
}
proc tcpProbed {sock callback} {
	if {[set msg [fconfigure $sock -error]]==""} {
		set ok 1
		set msg [lindex [fconfigure $sock -peername] 1]
	} else {
		set ok 0
	}
	close $sock
	eval [lappend callback $ok $msg]
}
Have you ever read "The Manual"?
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Post by zfitri »

ok thanxs for replying.. sorry i made the mistakes.. :P

now the tcl work.. but the result is not what i want.. i mean.. when the server offline it still reply online... any idea.?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

zfitri wrote:ok thanxs for replying.. sorry i made the mistakes.. :P

now the tcl work.. but the result is not what i want.. i mean.. when the server offline it still reply online... any idea.?
# 90 seconds delay before re-checking to prevent flooding
After doing a check, the script will not perform another check for 90 seconds, but instead use the result of the previous check. If you think 90 seconds is too long, change the line below that comment to suit your needs. :)
Have you ever read "The Manual"?
z
zfitri
Voice
Posts: 6
Joined: Mon Dec 06, 2004 10:15 pm

Post by zfitri »

the tcl works great now.. thank you for your help and support..

now.. i want make some additional function to the tcl.. telling the online player in my server...

is there possible that i can make the tcl to look parameter on my online website because.. in my website there is status of server an online players...

http://ajspeedi.ath.cx/ro/login.php

the server status for login, char and map server now runnning great.. just wann add the status of how many user online..

thank you.. hope answer for this post
Locked