Advertisement
Kylroi

TC admin script to send a worldserver command - 1/27 #2

Jan 24th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # 1/27 update - quotes around command when calling script are no longer needed
  4.  
  5. use Net::Telnet;
  6.  
  7. # adjust these variables for your server
  8. my $host = "127.0.0.1";
  9. my $username = "user";
  10. my $password = "password";
  11. my $command = "";
  12.  
  13. if ($#ARGV == -1) {
  14.   print "worldserver command not provided\n";
  15.   exit;
  16. }
  17.  
  18. if ($#ARGV == 0) {
  19.   $command = $ARGV[0];
  20. } else {
  21.   for (my $l=0; $l <= $#ARGV; $l++) {
  22.     $command .= $ARGV[$l];
  23.     if ($l != $#ARGV) {
  24.       $command .= " ";
  25.     }
  26.   }
  27. }
  28.  
  29. $telnet = new Net::Telnet ( Port=>3443, Prompt=>'/TC\> $/' );
  30. $telnet->open($host);
  31. my $stat = $telnet->login($username, $password);
  32. if ($stat == 1) {
  33.   my @results = $telnet->cmd($command);
  34.   print @results if scalar(@results);
  35. } else {
  36.   print "login error for user: $username\n";
  37. }
  38. $telnet->close;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement