Timed Admin Console Messages

I put the following Python script together to send Rcon admin messages to the game at regular intervals, which appear as "console" messages. I'm using it with an Urban Terror server but it should work for any game using Rcon and can be easily adapted / expanded on.
import time
import socket
while(True):
if __name__ == "__main__":
time.sleep(21)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(("12.34.12.34", 29765))
sock.send("xFFxFFxFFxFFrcon %s %s %s" % ("P4s5wRD", "say", " ^5Welcome Message 1."))
sock.close()
time.sleep(60)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(("12.34.12.34", 29765))
sock.send("xFFxFFxFFxFFrcon %s %s %s" % ("P4s5wRD", "say", " ^5Detail Message 2."))
sock.close()
time.sleep(60)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(("12.34.12.34", 29765))
sock.send("xFFxFFxFFxFFrcon %s %s %s" % ("P4s5wRD", "say", " ^5Visit Message 3!"))
sock.close()
time.sleep(39)
That sends a rotating message every 60 seconds (21 seconds after start then every 60 seconds until stopped). To use, change the IP (12.34.12.34), the port (29765), and the password (P4s5wRD). Adjust the time and message(s) as needed. Save it as something like 'messages.py' in the same directory as your start and stop scripts.
I call it from my game server's start script, and end it the same way - so the message script starts and ends automatically with the game. Here's an example:
#!/bin/bash cd $(dirname $0) ./your game server start line... & echo $! > game.pid python messages.py & echo $! > messages.pid
start.sh
#!/bin/bash cd $(dirname $0) kill $(cat game.pid) kill $(cat messages.pid) rm game.pid rm messages.pid
stop.sh
Fairly basic, but you end up with automatic rotating admin announcements / rotating server advertisement messages, and it's easy to customize. Other Rcon commands can be substituted for "say" or added before the loop.
Comments
Be the first to comment.


Leave a comment?