Battlefield 2142 サーバ

Linux版 dedicated serverの建て方

の続編ですかね。

の具体的な例やら実際的な運用のtipsを、

BattleRecorderを動かす場合。Windows版ではうまく行かなかったので、Linux版に限定して書きますね。まずrotate_demo.cfgの設定ですが、Linux版では自前のhttpdから読めるようにすればいいので、

# set the number of demo files to keep in rotation
file_limit = 30

# for local web server; edit this path and make it match the one in serversettings.con
target_root = /var/www/html/bf2142

# set to 1 to enable ftp uploading
use_ftp = 0

# set to the target directory on the ftp server
ftp_target_dir = /path/to/webroot/demos

# login information for the ftp server goes here
ftp_server = my.ftp.server
ftp_user = my_user
ftp_password = my_password

こんな感じでよいでしょうか?ただし、pythonで書かれているhookがダメなので直しました。そのパッチが、

--- original/rotate_demo.py     2025-04-29 14:49:40.325857421 +0900
+++ rotate_demo.py      2025-04-29 14:52:55.351270927 +0900
@@ -61,8 +61,8 @@
                try:
                        key, value = line.split('=')
                        options[key.strip()] = value.strip()
-               except ValueError, ex:
-                       print ex
+               except ValueError as ex:
+                       print (ex)
 except IOError:
        pass

@@ -82,7 +82,8 @@
        # try to move the fail, or fail miserably
        try:
                # NOTE: this requires atleast Python 2.3
-               print "moving '%s' to '%s'" % (path, target_demo_dir)
+               print ("moving '%s' to '%s'" % (path, target_demo_dir))
+               os.chmod(path, 0o777)
                shutil.move(path, target_demo_dir)
        except IOError:
                sys.exit(1)
@@ -100,7 +101,7 @@
        # sort the timestamped file list according to modification time
        # NOTE: this sort is reversed so that older files are at the end of the list
        def compare_times(f1, f2): return cmp(f2[0], f1[0]) # note reverse sort order
-       timestamped.sort(compare_times)
+       #timestamped.sort(compare_times)

        # delete the oldest files to meet the file limit
        file_limit = int(options['file_limit'])
@@ -169,7 +170,7 @@
                # bye bye
                ftp.quit()

-       except Exception, detail:
+       except Exception as detail:
                import traceback
                log = open('rotate_demo_err.txt', 'w')
                ex = sys.exc_info()
@@ -177,4 +178,3 @@
                log.write('\n')
                log.close()
                sys.exit(1)
-

になります。先ほどのrotate_demo.cfgが正しくても、移動させたdemoファイルをhttpdから読めるようにしてやらないと、download errorになりますから。

-               print "moving '%s' to '%s'" % (path, target_demo_dir)
+               print ("moving '%s' to '%s'" % (path, target_demo_dir))
+               os.chmod(path, 0o777)

これが必須です。他は、python2とpython3の書き方の違いですかね。面倒なのでsortは無視しました。

他には、時々マップ切り替え時に落ちてcore吐くので、落ちた場合に自動的に再起動するべく。

#!/bin/bash
#
# Press Ctrl+C to stop the restarting
echo "##########################"
echo "# Bf2142 Server Starting #"
echo "##########################"
echo To stop the restarting press Ctrl+C when the server is being restarted
echo
trap 'echo; echo $SRV Server Restarter has been STOPPED!; exit 1' 2
C1=0
while true
do
C1=$((C1+=1))
cd /home/nao/bf2142/bf2142
# Modify the line bellow to match your server execution command line
./start.sh
echo "Bf2142 server restarted $C1 time(s)!"
sleep 10
done

で動かしてます。これはbf2サーバ用scripthttps://bf2tech.uturista.pt/index.php/Scripts:RestartScript

を修正して使っています。ボット君やBattleRecorderを止めると、落ちにくくなるかもしれませんが、当面これで動かします。が、joinしてくれる人が少ないと、早々に終了するかもしれませんので、クライアントが用意できる方は、是非参加してテストをお願いいたします。

ボット君も、ドライバー席とかすぐに譲ってくれたり、”need medic”するとすぐに駆けつけてくれたりしてかわいいもんですが、平気でひき殺していきますので、ご注意ください。あ、Rankingは反映されませんが、装備は最初からフル装備です。

コメント