checkversion.pl 2.1 KB

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