1. 程式人生 > 實用技巧 >摸魚伺服器

摸魚伺服器

網課摸魚摸出來的伺服器

伺服器簡介

是個災厄開荒,中世界。

歡迎各位來玩。務必自覺開荒,拜託了。(我甚至提前搭了傳送網已經夠不肝了

IP: \(39.97.220.53\)

埠:\(7777\)

現在想的是每天下午 7:00~23:30 開著。

密碼的話請 \(Q\) 我,順便把Mod包發給你(其實本來想寫防熊的但是……沒看懂 \(Tshock\) 程式碼,所以就用這種劣質方法了

伺服器資訊

版本 : \(tmodloader\) \(11.7.5\)

Mods:

主mod :Calamity1.4.4.005 (俺也知道大山豬今天發了1.4.5,但是沒漢化也沒辦法啊qaq)

輔助mod:

Fargo,鍊金npc(非新版),自動連點,無限buff欄位,luaifk,自動連點,bosschecklist,額外翅膀欄位,合成表查詢。(大概就這些吧……

問題

1.有的mod顯示版本太舊。

​ 卸掉重灌tmod。

2.to be continued

​ 現在還在測試中,後面的鍋慢慢修

搭建過程記錄

環境

阿里雲 輕量應用伺服器:1C2G,Ubuntu 18.04 映象

最好建個新使用者

adduser steam

安裝 steamcmd

cd ~/steamcmd

wget http://media.steampowered.com/installer/steamcmd_linux.tar.gz

tar -xvzf steamcmd_linux.tar.gz

./steamcmd.sh

登入下載terraria

login USERNAME

app_update 105600 

執行terraria資料夾下自帶的Server

./TerrariaServer

按照指示新建world

在管理臺開啟埠7777的TCP和UDP

檢驗一下是否能連結伺服器

然後下載 tModLoader

最好新建個資料夾 出了鍋好除錯

https://www.jxtxzzw.com/archives/3629

https://zerol.me/2020/02/08/Terraria-Server-With-Mods/

之後執行 tmodloaderserver ,首次執行後會自己生成mod資料夾,位置在:

~/.local/share/Terraria

可能是1.4版本適配問題 直接使用 \(11.7.5\)\(tmod\)

會使這些未更新的 \(mod\) 不適配 似乎先使用\(11.7.4\) 然後再用 \(11.7.5\) 就行了。(鬼知道什麼原理

然後發現 \(Magicstore\) 出了bug,一直是 \(0\) 儲存,退出去回來後還會炸掉周圍物塊。

找了半天發現有人發了錯誤報告,原來是 \(Magicstore\) 在linux上沒有合適執行環境,安裝mono後把缺失的連結複製到tr裡即可(捧讀)。

apt install mono-runtime
cp /usr/lib/libMonoPosixHelper.so [tr的目錄]

雖然仍然一使用儲存模組就會報錯,但是實際上可以用了。(草這些bug鬼知道我試了多久

然後照著大佬的指令碼自己糊了一份(基本就是看了遍加註釋,幾處試圖修改只有一點點成功了)。

功能大概是:報時,自動儲存,自動備份,顯示歡迎資訊,遊戲內調時間。

import subprocess
from threading import Thread
from queue import Queue, Empty
import psutil
from datetime import datetime
import time
import traceback
import sys
import os

world_name = sys.argv[1]

server_path = "/home/steam/steamcmd/steamapps/common/Terraria/tModLoader11.7.5"
world_path = "/home/steam/.local/share/Terraria/ModLoader/Worlds"
backup_path = "/home/steam/tModLoaderServerBackups"

cmd = ("%s/tModLoaderServer.bin.x86_64 -world %s/%s.wld" % (server_path,
                                                            world_path,
                                                            world_name)).split() + sys.argv[2:]

p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)


def enqueue_output(out, queue):
    for line in iter(out.readline, b''):
        queue.put(line)
    out.close()


q = Queue()
t = Thread(target=enqueue_output, args=(p.stdout, q), daemon=True)
t.start()


pid = p.pid

def gfs(Filepath,size=0):
    for root,dirs,files in os.walk(Filepath):
        for f in files :
            sizi += os.path.getsize(os.path.join(root,f))
    return size


def monitor():
    print(pid)
    ready = False

    while psutil.pid_exists(pid):
        def write(s):
            s += '\n'
            p.stdin.write(s.encode())
            p.stdin.flush()
        try:
            line = q.get_nowait().decode()
            print(line[:-1]) #將server裡的輸出列印到螢幕上
            if not ready and "Type 'help' for a list of commands." in line:
                ready = True
            if ready:
                if "\exit" in line:
                    write("say Closing in 60s...")
                    time.sleep(60)
                    write("say Now closing...")
                    write("exit")
                if "\dawn" in line:
                    write("say Switch game time 4:30AM.")
                    write("dawn")
                if "\dusk" in line:
                    write("say Switch game time 7:30PM.")
                    write("dusk")
                if "has joined." in line:
                    write("say Welcome to %s!" % (world_name))
        except Empty:
            if ready:
                now = datetime.now()
                if now.second < 5:
                    if now.minute % 15 == 0: #自動備份 自動報時
                        write("say Current time: %02d:%02d." % (now.hour, now.minute))
                        if gfs(backup_path) >= 1073741824 :
                            os.system("cd backup_path")
                            os.system("rm -rf *")
                        for ext in [".wld", ".twld"]:
                            os.system("cp %s %s" % (world_path + '/' + world_name + ext,
                                                    backup_path + '/' + world_name + datetime.now().strftime("-%Y-%M-%d-%H-%M") + ext))

                    if now.minute % 3 == 1: #自動儲存
                        write("say Now saving...")
                        write("save")
            time.sleep(5)


try:
    monitor()
except Exception as e:  #錯誤處理
    p.stdin.write(b'exit')
    traceback.print_exc() #輸出錯誤資訊

本來想著每天最後一節晚自習摸會魚,結果最後每天基本只能有半個小時時間,然後就折騰了四天……

最後終於摸出來了 不容易

$\frak by ; thorn_ $