perl script to send commands to worldserver

While the worldserver does respond to signals, it didn’t seem to have a signal to shutdown in so many minutes. I would prefer to give any players online a chance to wrap up what they were doing before just shutting down the server. So, rather than require someone to be at the console, I wanted a script or program to use the remote access (telnet) interface. I didn’t find one in my searches, so I wrote one. This script could be used in a crontab or some other scheduling system.

#!/usr/bin/perl

1/27 update - quotes around command when calling script are no longer needed

use Net::Telnet;

adjust these variables for your server

my $host = “127.0.0.1”;
my $username = “user”;
my $password = “password”;
my $command = “”;

if ($#ARGV == -1) {
print “worldserver command not providedn”;
exit;
}

if ($#ARGV == 0) {
$command = $ARGV[0];
} else {
for (my $l=0; $l <= $#ARGV; $l++) {
$command .= $ARGV[$l];
if ($l != $#ARGV) {
$command .= " ";
}
}
}

$telnet = new Net::Telnet ( Port=>3443, Prompt=>‘/TC> $/’ );
$telnet->open($host);
my $stat = $telnet->login($username, $password);
if ($stat == 1) {
my @results = $telnet->cmd($command);
print @results if scalar(@results);
} else {
print “login error for user: $usernamen”;
}
$telnet->close;

It has a simple usage (script.pl can be whatever you wish to call the script): script.pl

Example (15 minute delayed shutdown): script.pl “server shutdown 900”

Syntax: .server shutdown #delay [#exit_code]

Shut the server down after #delay seconds. Use #exit_code or 0 as program exit code.

huh?

Either you can’t do math (15*60=900) or you missed how the point of the script is to allow a separate scheduling program to tell the server to shutdown, with a delay, without requiring someone to manually issue the console command. If no delay is desire, a “kill -INT ” could be used, but that wouldn’t exactly be nice to anyone that was playing and not paying attention to the time. Thus, my desire to create this script. If nobody else wants it, that’s fine. I simply thought I’d share what I had.

FYI: On the 4.3.4 core (if not on the 3.3.5a core, too), commands given on the console or via RA do not require the period on them. If that was the cause of your pointless post, you just learned something.

no, the cause of my “pointless” post was, if you were using SOAP or RA, this wouldn’t be necessary.

Also, I wrote and rewrote many, if not most of the console commands in my years working on TC, so, how about you try to be a bit less condescending when you don’t know who you are talking to.

I’ll treat you as dumb when you blatantly ignore what I said (the bold, italicized, and underlined portion of my quote). Go back and actually READ the very first paragraph of the first post. For that matter, re-read the 3rd post, too. For such a “know it all”, you sure ignore what is said an awful lot. The script is specifically for situations when an admin is NOT at a console or, necessarily, even at a computer.

If you choose to be a better than everyone else, you’d best never jump to a conclusion before you actually read what someone said. What you specifically wrote in the core is irrelevant. With all of the scheduling in the core, there is no “exit for maintenance” setting that can be defined. Also, your quoting of the command syntax for the example I gave was POINTLESS. The example command, as I wrote it, already followed that syntax. All you did with that quote was show everyone that you can’t read and only quoted something that I clearly knew.

NOTE: If a ban comes from attacking a moron “know it all”, so be it. I’ll get a laugh, and other users might be entertained, too. I don’t really need this site, anyway. I certainly don’t need abuse from someone that CANNOT READ. Besides, as I recall, the only question I actually had, NOBODY helped. No wonder there’s so little community contribution for this project. Those that do get treated VERY badly. Not by all moderators/devs, but certainly by the self-proclaimed “know it all” that can’t read or keep his stupid comments to himself.

here we go with the imaginary attacks again, did you get banned from the forum under another name for doing this exact thing before? You sure sound a lot like that “genius”.

I will admit, I did misread the post, but, that doesn’t deserve such a moronic rage against me. Have fun with your court ordered anger classes one day.

The “moronic rage” was in response to your invalid claim of me being condescending towards you. You admit that you misread my post. That’s good. That means you can also see that your quote of syntax that I obviously knew was suggesting that I had done something wrong. Since I knew I hadn’t, ANYONE should see your initial response as being condescending to me, first. As such, you bet you got treated as the idiot involved. This is especially true when you have the “Know it all” title and blatantly responded in a way that showed you didn’t know it all.

No, I have never been banned on this site. I did get banned on Curse for merely pointing out that one of their staff was being rude to users during a period of known and documented connection issues with their service. I wasn’t mean about it. I simply pointed out that what they said, and when they said it, was doing exactly the same thing they were attacking users for. In fact, they also quoted something that happened to be already on the exact same page as their comment, but was invalid due to the (at the time) connection issues that the users were commenting about. That was also something that I pointed out and suggested that they may wish to actually research the users complaints before being rude in the future. That moderator has a history of being very rude to users, but I was as polite as I could be. The result was banning my account on their forums and placing an IP address block on a couple of their other sites. Absolute power corrupts absolutely (just look at U.S. politicians for proof of that). In essence, the people behind Curse make you seem like a saint, and you’re not even close (nor am I, but I don’t ever claim to be).

As for “court ordered anger classes”, I’ll assume that you have already been through that. My “anger” is always provoked. If you don’t see it, you need to take a sensitivity class to start thinking about what and how you say things so that you don’t upset others (seemingly on a fairly regular basis). You are KNOWN to be a jerk, and that’s being polite. With me, I give what I get. Don’t like to get mistreated? Don’t ever mistreat me. I tend to amplify whatever I get. If I’m treated nice, I treat the other person better. If I’m treated badly, the other person will be treated worse. Even with your admitting that you misread me, you still attacked me, immediately after admitting fault, with the whole “anger classes” remark. Which one of us has the real problem? Look in the mirror before you even consider saying it’s me.

—back to original topic—

Another use for this script is placing it in a shell script to execute a common command. I imported SQL updates earlier today. Instead of issuing a reload command to scan in the changes, I sent a “server restart 300” command. Rather than type that command every time I intend to use it, I simply made a shell script called “restart” that calls this perl script with that command. I will probably enhance that shell script to default to 5 minutes, but allow a parameter to adjust the delay.

While there were shell scripts available, none of them covered all of the functionality that I desired. So, I wrote my own. This perl script and 3 (bash) shell scripts are on my pastebin. A single crontab entry can be set to send a maintenance shutdown command (I default to an exit code of 3 for that, but that can be changed). The crontab entry is the primary reason behind my desire for this perl script. If the core had a setting to exit for maintenance, the crontab entry wouldn’t be needed, but I’d still use the perl script as a convenience. Why log in every time (via ssh/telnet to the server, RA, or SOAP) you need to issue a single command when a perl script can do the login for you? The beauty of this perl script is that it can be run from a totally different machine than the one running server. In my case, I run my server on a Linux computer, but can use this script from my Mac. Click a dock icon and type a simple command (aka “restart”) or click that same icon, issue an ssh command, type in my remote password (or use a programmed F-key to make it easier) and THEN issue the same command. Honestly, which is easier?

Updated the script to display the results of the command. This update is not likely to be used by myself, but it may allow the script to be more useful for others.