// get the trusted player IDs from the commandline private static void GetTrustedPlayerIds() { if (trustedPlayers != null) { return; // already set } trustedPlayers = new List <MPBanEntry>(); string idstring = null; if (!GameMod.Core.GameMod.FindArgVal("-trustedPlayerIds", out idstring) || String.IsNullOrEmpty(idstring)) { return; // no trustedPlayerIds specified; } string[] ids = idstring.Split(',', ';', ':', '|'); foreach (string id in ids) { MPBanEntry entry = new MPBanEntry(null, null, id); if (entry.IsValid()) { bool doAdd = true; foreach (MPBanEntry e in trustedPlayers) { if (e.matches(entry, "TRUSTED PLAYER: ")) { doAdd = false; } } if (doAdd) { Debug.LogFormat("MPChatCommands: adding trusted player {0}", entry.Describe()); trustedPlayers.Add(entry); } } } }
// Check if a player is an authenticated player on this server public static bool IsAuthenticatedPlayer(MPBanEntry playerEntry) { if (playerEntry == null || !playerEntry.IsValid()) { Debug.LogFormat("IsAuthenticatedPlayer without valid player"); return(false); } foreach (MPBanEntry e in authenticatedPlayers) { if (e.matches(playerEntry, "AUTHENTICATED PLAYER: ")) { return(true); } } return(false); }
// Add a player to the Ban List public static bool Ban(MPBanEntry candidate, MPBanMode mode = MPBanMode.Ban, bool permanent = false) { if (!candidate.IsValid()) { return(false); } candidate.permanent = permanent; var banList = GetList(mode); foreach (var entry in banList) { if (entry.matches(candidate, "BAN already matched: ")) { // Update it entry.Set(candidate); OnUpdate(mode, true); return(false); } } banList.Add(candidate); Debug.LogFormat("BAN: player {0} is NOW banned in mode: {1}", candidate.Describe(), mode); OnUpdate(mode, true); return(true); }
// set authentication status of player by id private static bool SetAuth(bool allowed, MPBanEntry playerEntry) { if (playerEntry == null || !playerEntry.IsValid()) { Debug.LogFormat("SETAUTH called without valid player"); return(false); } if (allowed) { Debug.LogFormat("AUTH: player {0} is authenticated", playerEntry.name); bool doAdd = true; foreach (MPBanEntry entry in authenticatedPlayers) { if (entry.matches(playerEntry, "AUTHENTICATED PLAYER: ")) { entry.Set(playerEntry); doAdd = false; } } if (doAdd) { authenticatedPlayers.Add(playerEntry); } } else { // de-auth Debug.LogFormat("AUTH: player {0} is NOT authenticated any more", playerEntry.name); if (authenticatedPlayers.RemoveAll(entry => entry.matches(playerEntry, "AUTHENTICATED PLAYER: ")) < 1) { return(false); } } return(true); }