serverpermadeath

版本 v1.0.0·更新於 2023-06-22

Server side only. Records deaths and bans characters when they die.

模組介紹 作者原文

serverpermadeath

this mod runs on the server only. The goal of this mod is to give server authority / no client mod solution to permadeath. We don't want to use the originally bannedlist.txt because that will ban a player all together. We want players to continue playing, they just can't use a character that has died.

new server textfile permadeath.txt

Server checks for dead players. if a player dies:

  • adds steamid|charactername to permadeath.txt
  • shout that player has died
  • start a 30 sec timer giving them time to say goodbye
  • kicks them, shows Banned popup

Server checks permadeath.txt and all players connected. if player|charactername is on list:

  • kicks them, shows Banned popup

Combine this with servercharacters to have a hardcore server

install

prerequisite: have bepinex installed on server

drag serverpermadeath.dll into bepinex/plugins folder

restart server

code

public static SyncedList characterbans;

public static Dictionary timers = new Dictionary();

//initialize the synced list used for tracking bans

[HarmonyPatch(typeof(ZNet), "Awake")]

public static class awakepatch{

private static void Postfix()

{

characterbans = new SyncedList(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/permadeath.txt",

"List of dead players by steamid|charname - ONE per line - serverpermadeath mod");

}

}

[HarmonyPatch(typeof(ZNet), "CheckWhiteList")]

public static class CheckCharWhitelist

{

private static bool Prefix(ZNet __instance)

{

//runs every 5s

//check whitelist

if (__instance.m_peers!= null)

{

if (__instance.m_peers.Count > 0)

{

foreach (ZNetPeer znetPeer in __instance.m_peers.ToList())

{

if (znetPeer.IsReady() &&!znetPeer.m_characterID.IsNone())

{

string charName = znetPeer.m_playerName;

string id = znetPeer.m_socket.GetHostName();

string idandname = id + "|" + charName;

bool bannedalready = characterbans.Contains(idandname);

//they are banned, gtfo

if (bannedalready)

{

ZNet.instance.InternalKick(znetPeer);

}

else

{

//check if they're dead

ZDO zdo = __instance.m_zdoMan.GetZDO(znetPeer.m_characterID);

if (zdo!= null)

{

bool dead = zdo.GetBool("dead", false);

if (dead &&!TrippingPatches.timers.ContainsKey(idandname))

{

//tell everyone they are dead

ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ChatMessage", new object

{

znetPeer.m_refPos,

2,

znetPeer.m_playerName,

znetPeer.m_playerName + " has been slain"

});

ZLog.Log(znetPeer.m_playerName + " DIED " + znetPeer.m_refPos.ToString());

//start a timer to kick them

TrippingPatches.timers.Add(idandname, 5);

}

}

}

}

}

}

}

//clean up the timers

foreach (string key in TrippingPatches.timers.Keys.ToList())

{

TrippingPatches.timers[key] = TrippingPatches.timers[key] - 1;

if (TrippingPatches.timers[key] < 0)

{

//add them to the banned list

characterbans.Add(key);

//remove the timer

TrippingPatches.timers.Remove(key);

}

}

return true;

}

}

安裝與使用 安裝:BepInEx 外掛

  1. 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
  2. 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
  3. 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
  4. 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。

帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。 多人連線時,主機與所有用戶端需要安裝一致的模組。

前置依賴

下面這些內容需要先安裝,否則該模組不會生效:

denikson-BepInExPack_Valheim

檔案與校驗

檔案名稱
serverpermadeath-1.0.0.zip
檔案大小
17.9 KiB