root/tools/checkversion @ 13

Revision 1, 2.2 kB (checked in by jinshiro, 17 years ago)
Line 
1#!/usr/bin/perl -w
2
3##########################################################################
4# INFORMATION TOOL ABOUT THE SERVERS VERSION OF ATHENA
5#
6# By connection on a server, this software display the version of the
7# designed server.
8#-------------------------------------------------------------------------
9# Usages:
10#   ./checkversion IP:port
11#   ./checkversion IP port
12#   perl checkversion IP:port
13#   perl checkversion IP port
14#
15# note: default port: 6900
16#
17# When successfull, the software return the value 0.
18#
19##########################################################################
20
21#------------------------- start of configuration ------------------------
22
23$connecttimeout = 10;   # Connection Timeout (in seconds)
24
25#-------------------------- End of configuration -------------------------
26
27use IO::Socket;
28
29unless($ARGV[0]) {
30        print "USAGE: $0 server_ip:port\n";
31        exit(1);
32}
33
34$server = $ARGV[0];
35$port = $ARGV[1];
36$port = $1 if ($server =~ s/:(\d+)//);
37$port ||= 6900;
38
39# Connection to the server
40my($so,$er) = ();
41eval{
42        $so = IO::Socket::INET->new(
43                PeerAddr=> $server,
44                PeerPort=> $port,
45                Proto   => "tcp",
46                Timeout => $connecttimeout) or $er = 1;
47};
48
49if($er || $@) {
50        print "Can't not connect to server [$server:$port] !\n";
51        exit(2);
52}
53
54# Request for the server version
55print $so pack("v",30000); # 0x7530
56$so->flush();
57
58# Receiving of the answer of the server
59if (read($so,$buf,10) < 10) {
60        print "Invalid answer. It isn't an athena server or it is a too old version.\n";
61        exit(5);
62}
63
64# Sending end of connection to the server
65print $so pack("v",30002); # 0x7532
66$so->flush();
67
68# Analyse of the answer
69my($ret,$maver,$miver,$rev,$dev,$mod,$type,$mdver) = unpack("v c6 v",$buf);
70
71if ($ret != 30001) { # 0x7531
72        print "Invalid answer. It isn't an athena server or it is a too old version.\n";
73        exit(6);
74}
75
76my(@stype) = ();
77foreach $i(0..3) {
78        push @stype,(("login","char","inter","map")[$i]) if( $type & (1<<$i) );
79}
80print "  ".join("/",@stype)." server [$server:$port].\n";
81printf "  Athena version %s-%d.%d", ("stable","dev")[$dev], $maver,$miver;
82printf " revision %d",$rev if $rev;
83printf "%s%d\n",("","-mod")[$mod],$mdver;
84
85exit(0);
Note: See TracBrowser for help on using the browser.