[cod] tdm fails to rotate map on occasion

Joe Brown joe at overdrivepc.com
Fri Dec 12 16:32:55 EST 2003


Okay, if you have a server that uses timelimits on Linux, this can work 
nice.
I have a server w/15 min timelimit, so no map should last much longer.

Quick install:
# su -l cod1
$ mkdir monitor
$ cd monitor
$ cat > map_rotate.buff
<paste rotate.buff here>
ctrl-d
$ cat > monitor.py
<paste monitor.py here>
ctrl-d
$ python2 monitor.py &
$ screen -r
ctrl-a ctrl-H  (start logging to screenlog.0)

This will issues map_rotate via screen's cut/paste buffer, if monitor 
hasn't seen one in the screenlog.0 file for X amount of time.  You'll 
probably have to adjust the log= line in monitor.py to point to your 
actual screenlog.0 file, but this works pretty good to keep a server 
running, w/out baby sitting.

I'm posting this in hopes that the patch that fixes this freeze at end 
of map bug will be out, and this whole post will be pointless...  
Although, necessity is the mother of invention... This is a nifty means 
to automate console operations, when rcon doesn't work.  So if you have 
some imagination, you can do a lot more than this, with screen and a 
script like this.

Don't set the timer for monitor too close to the actual timelimit.  
Buffered disk writes can throw off timing, especially on low activity 
servers...  developer 1 can be of some assistance, to cause more 
frequent disk writes...

----begin ~/monitor/rotate.buff
map_rotate
----end ~/monitor/rotate.buff
----begin ~/monitor/monitor.py----
#!python2
# paste this in your cod user directory
import status, os, os.path, time, sys
log='/usr/games/cod/servers/cod1/screenlog.0'
timelimit=20
# I chose 20 min timer to force a rotate
# since 15 min is the actual map timelimit
# this should avoid interrupting a game.

def map_rotate():
    os.system('/usr/bin/screen -X bufferfile monitor/rotate.buff')
    os.system('/usr/bin/screen -X readbuf')
    os.system('/usr/bin/screen -X paste .')


def main():
    last_rotate = time.time()
    pos = os.path.getsize(log)
    file = open(log)
    #pos = file.tell()
    while(1):
        file.seek(pos)
        pos = file.tell()
        line = file.readline()
        while(line):
            if line.find("----- Server Shutdown -----") != -1:
                map_rotate()
                print line[:len(line)-1]
            elif line.find('map_rotate') != -1:
                last_rotate = time.time()
                print last_rotate, time.strftime('%H:%M:%S')
            elif line[len(line)-1] == "\n":
                pos = file.tell()
            line = file.readline()
        if time.time() > last_rotate + (60 * timelimit):
            print "time exceeded: ", time.time() - last_rotate
            map_rotate()
            time.sleep(30)
        time.sleep(1)
---end ~/monitor/monitor.py


if __name__ == "__main__":
    main()




More information about the Cod mailing list