public void TickPlayer(Player p, AdminCore core) { //reset triggers bool rs = false; switch (Reset) { case ResetCondition.OnScore: rs = p.HasScored; break; case ResetCondition.OnKill: rs = p.HasKilled; break; case ResetCondition.OnDeath: rs = p.HasDied; break; } if (p.HasSlotReset) { rs = true; } if (rs) { p.MessageStates[this] = false; } //exit if triggered but not reset yet if (p.MessageStates[this]) { return; } bool tr = false; switch (Trigger) { case TriggerCondition.ScoreSinceLastKillGreaterThan: tr = (p.ScoreSinceLastKill > Threshold); break; case TriggerCondition.ScoreSinceLastDeathGreaterThan: tr = (p.ScoreSinceLastDeath > Threshold); break; case TriggerCondition.KillsSinceLastScoreGreaterThan: tr = (p.KillsSinceLastScore > Threshold); break; case TriggerCondition.KillsSinceLastDeathGreaterThan: tr = (p.KillsSinceLastDeath > Threshold); break; case TriggerCondition.DeathsSinceLastKillGreaterThan: tr = (p.DeathsSinceLastKill > Threshold); break; case TriggerCondition.DeathsSinceLastScoreGreaterThan: tr = (p.DeathsSinceLastScore > Threshold); break; case TriggerCondition.TotalKillsGreatherThan: tr = (p.Kills > Threshold); break; case TriggerCondition.TotalScoreGreaterThan: tr = (p.Score > Threshold); break; case TriggerCondition.TotalDeathsGreaterThan: tr = (p.Deaths > Threshold); break; } if (tr) { core.Rcon.Say(Util.FormatString(SelectMessage(), "{player}", p.Name, "{value}", (Threshold - 1).ToString() )); p.MessageStates[this] = true; } }
public static void SaveMapRotation(AdminCore core, List <string> maps) { string sr = string.Empty; foreach (string m in maps) { sr += string.Format("/addmap {0} ", m); } core.Files.WriteFileText(core.Config.ServerPath + "/settings/ServerRotation.cfg", sr); }
public void WriteToFile(AdminCore core) { string file = ""; string fileName = core.Server.ServerPath + FILE_NAME; PropertyInfo[] props = typeof(ServerSettings).GetProperties(); foreach (PropertyInfo p in props) { if (p.PropertyType.IsEquivalentTo(typeof(bool))) { ConfigSection[] attr = (ConfigSection[])p.GetCustomAttributes(typeof(ConfigSection), false); if (attr.Length > 0 && attr[0].YesNoBool) { file += ((bool)p.GetValue(this) ? "/" : "/no") + p.Name.ToLower(); } else { file += "/" + p.Name.ToLower() + " "; file += (((bool)p.GetValue(this)) ? "1" : "0"); } } else { file += "/" + p.Name.ToLower() + " "; } if (p.PropertyType.IsEquivalentTo(typeof(ushort))) { file += ((ushort)p.GetValue(this)).ToString(); } else if (p.PropertyType.IsEquivalentTo(typeof(int))) { file += ((int)p.GetValue(this)).ToString(); } else if (p.PropertyType.IsEquivalentTo(typeof(string))) { file += "\"" + (string)p.GetValue(this) + "\""; } file += "\r\n"; } try { core.Files.WriteFileText(fileName, file); Logger.Log(LogLevel.Verbose, "Server settings saved."); } catch (Exception e) { Logger.Log(LogLevel.Error, "Failed to write to file {0} ({1})", fileName, e.ToString()); } }
public string ParseMessage(AdminCore core) { if (!EnableParser) { return(Message); } else { return(Util.ParseVars(Message, core)); } }
public static List <string> ReadMapRotation(AdminCore core) { string sr = core.Files.ReadFileText(core.Config.ServerPath + "/settings/ServerRotation.cfg"); string[] cs = sr.Split('/'); List <string> res = new List <string>(); foreach (string c in cs) { if (c.ToLower().StartsWith("addmap")) { string[] cp = c.Split(' '); if (cp.Length < 2) { Logger.Log(LogLevel.Warning, "Skipping invalid SeverRotation-Command '{0}'", cp); } else { res.Add(cp[1]); } } } return(res); }
public void Init(AdminCore core, DirectoryInfo dir) { Core = core; api = new LuaApi(core, this); name = dir.Name; try { string lua = Core.Files.ReadFileText($"{dir.FullName}/{dir.Name}.lua"); script.DoString(lua); script.Globals[LuaApi.GLOBALS_API] = api; CallFunction(LuaApi.FUNC_INIT); } catch (Exception e) { Logger.Log(LogLevel.Warning, "Failed to load {0}.lua : {1}. Disabling {0}.", dir.Name, e.Message); Enabled = false; } if (PermissionName == null) { Logger.Log(LogLevel.Warning, "{0} has no valid PermissionName definition: disabling it.", name); Enabled = false; } }
public ResourcesPage(AdminCore core) : base(core, "/res") { }
public BansPage(AdminCore core) : base(core, "/db/bans", "bans.htm") { }
public DiscordPlugin(AdminCore core) : base(core, "DiscordPlugin", "1.0") { Logger.Log(LogLevel.Info, "[DISCORD] Loaded {0} v{1}", Name, Version); Initialize(); }
public GameHandler(AdminCore core) : base(core) { }
public MapSettingsPage(AdminCore core) : base(core, "/settings/maps", "maps.htm") { }
public PluginManager(AdminCore core) : base(core) { pluginAssemblies = new List <Assembly>(); pluginObjects = new List <SWBF2AdminPlugin>(); }
public ChatPage(AdminCore core) : base(core, "/live/chat", "chat.htm") { Core.Rcon.ChatInput += new EventHandler(Rcon_Chat); Core.Rcon.ChatOutput += new EventHandler(Rcon_Chat); }
public AnnounceHandler(AdminCore core) : base(core) { }
public SQLHandler(AdminCore core) : base(core) { }
public SWBF2AdminPlugin(AdminCore core, string name, string version) { this.core = core; Name = name; Version = version; }
public GameSettingsPage(AdminCore core) : base(core, "/settings/game", "game.htm") { }
public RconClient(AdminCore core) : base(core) { }
public StatisticsPage(AdminCore core) : base(core, "/db/statistics", "statistics.htm") { }
public LvlWriter(AdminCore core) : base(core) { }
public PlayersPage(AdminCore core) : base(core, "/live/players", "players.htm") { }
public DefaultPage(AdminCore core) : base(core, "/", "frame.htm") { }
public static string ParseVars(string s, AdminCore core) { //time, using .NET DateTime formatters int idx1, idx2; if ((idx1 = s.IndexOf("{t:")) > 0) { if ((idx2 = s.IndexOf("}", idx1 + 3)) > 0) { string fmt = s.Substring(idx1 + 3, idx2 - (idx1 + 3)); s = s.Substring(0, idx1) + DateTime.Now.ToString(fmt) + s.Substring(++idx2); } else { Logger.Log(LogLevel.Error, "String format error: missing } (parsing \"{0}\")", s); } } //server status ServerInfo info = core.Game.LatestInfo; if (info != null) { s = FormatString(s, "{s:map}", info.CurrentMap, "{s:ff}", info.FFEnabled, "{s:gm}", info.GameMode, "{s:heroes}", info.Heroes, "{s:maxplayers}", info.MaxPlayers, "{s:nextmap}", info.NextMap, "{s:password}", info.Password, "{s:players}", info.Players, "{s:ip}", info.ServerIP, "{s:name}", info.ServerName, "{s:t1score}", info.Team1Score.ToString(), "{s:t2score}", info.Team2Score.ToString(), "{s:t1tickets}", info.Team1Tickets.ToString(), "{s:t2tickets}", info.Team1Score.ToString(), "{s:version}", info.Version); } //game nr GameInfo game = core.Game.LatestGame; if (game != null) { s = FormatString(s, "{g:nr}", game.DatabaseId.ToString()); } //these db queries can be quite expensive -> only query if we really have to //TODO: figure something out to cache total points/kills/deaths if (s.Contains("{stats:totalpoints}")) { s = FormatString(s, "{stats:totalpoints}", core.Database.GetTotalPoints().ToString()); } if (s.Contains("{stats:totalkills}")) { s = FormatString(s, "{stats:totalkills}", core.Database.GetTotalKills().ToString()); } if (s.Contains("{stats:totaldeaths}")) { s = FormatString(s, "{stats:totaldeaths}", core.Database.GetTotalDeaths().ToString()); } if (s.Contains("{stats:totalplayers}")) { s = FormatString(s, "{stats:totalplayers}", core.Database.GetTotalPlayers().ToString()); } if (s.Contains("{stats:totalmatches}")) { s = FormatString(s, "{stats:totalmatches}", core.Database.GetTotalMatches().ToString()); } //banner for generous folks s = FormatString(s, "{banner}", $"{GetProductName()} v{GetProductVersion()} ({GetProductAuthor()})"); return(s); }
public IngameServerController(AdminCore core) : base(core) { }
public WebServer(AdminCore core) : base(core) { }
public WebPage(AdminCore core, string url) { Core = core; Url = url; }
//Attention: messy code ahead public static List <ServerMap> ReadServerMapConfig(AdminCore core) { Logger.Log(LogLevel.Info, "Starting map import..."); string mapCfg = core.Files.ReadFileText(core.Config.ServerPath + "/settings/Maps.cfg"); mapCfg = mapCfg.Replace("\r", ""); string[] rows = mapCfg.Split('\n'); int cnt = 0; List <ServerMap> maps = new List <ServerMap>(); foreach (string r in rows) { //Read mapfile string mapName = r.Split(',')[0]; if (mapName.Length < 9) { Logger.Log(LogLevel.Warning, "Invalid map: '{0}' - skipping row", mapName); break; } //Parse era char era = mapName[4]; string mode = mapName.Substring(6); if (era != 'c' && era != 'g') { Logger.Log(LogLevel.Warning, "Invalid era: '{0}' - skipping row", era.ToString()); break; } //Find map string name = mapName.Substring(0, 4); ServerMap m = null; foreach (ServerMap mp in maps) { if (mp.Name.Equals(name)) { m = mp; break; } } if (m == null) { m = new ServerMap(); m.Name = name; maps.Add(m); } //Parse mode bool gcw = (era == 'g'); switch (mode) { case "con": if (gcw) { m.HasGCWCon = true; } else { m.HasCWCon = true; } break; case "ctf": if (gcw) { m.HasGCWCTF = true; } else { m.HasCWCTF = true; } break; case "1flag": if (gcw) { m.HasGCW1Flag = true; } else { m.HasCW1Flag = true; } break; case "hunt": if (gcw) { m.HasGCWHunt = true; } else { m.HasCWHunt = true; } break; case "eli": if (gcw) { m.HasGCWEli = true; } else { m.HasCWEli = true; } break; case "ass": if (gcw) { m.HasGCWAss = true; } else { m.HasCWAss = true; } break; } cnt++; } return(maps); }
public PlayerHandler(AdminCore core) : base(core) { }
public DashboardPage(AdminCore core) : base(core, "/live/dashboard", "dashboard.htm") { }
public WebUsersPage(AdminCore core) : base(core, "/web/users", "users.htm") { }