public static void EventDisablePvP(NetUser netUser, string Command) { Class40 class2 = new Class40 { netUser_0 = netUser, string_0 = Command }; EventTimer timer = Timer.Find(new Predicate <EventTimer>(class2.method_0)); if (timer != null) { timer.Dispose(); if (class2.netUser_0 != null) { Users.SetFlags(class2.netUser_0.userID, UserFlags.nopvp, true); int num = Core.CommandNoPVPDuration + Core.CommandNoPVPCountdown; if (num > 0) { Users.CountdownAdd(class2.netUser_0.userID, new Countdown(class2.string_0, (double)num)); } TimeSpan span = TimeSpan.FromSeconds((double)Core.CommandNoPVPDuration); Broadcast.Notice(class2.netUser_0, "☢", Config.GetMessage("Command.PvP.Disabled", class2.netUser_0, null).Replace("%TIME%", string.Format("{0}:{1:D2}", span.Minutes, span.Seconds)), 5f); Broadcast.NoticeAll("☢", Config.GetMessage("Command.PvP.NoticeDisabled", class2.netUser_0, null), class2.netUser_0, 5f); } } }
protected void DoAnnounce() { if ((this.Announce.Count != 0) && this.Enabled) { foreach (string str in this.Announce) { Broadcast.NoticeAll("☢", Helper.ReplaceVariables(null, str, null, ""), null, 5f); } } }
public static void EventServerRestart(EventTimer sender, int ShutdownTime, ref int Timeleft) { if (Timeleft != 0) { if (Timeleft <= 5) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillRestart", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 1f); } else if (Timeleft == 10) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillRestart", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 5f); } else if (Timeleft == 30) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillRestart", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } else if (Timeleft == 60) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillRestart", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } else if (Timeleft == ShutdownTime) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.Restart", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } } if (Timeleft > 0) { Timeleft--; } else { try { if (sender != null) { sender.Stop(); } AvatarSaveProc.SaveAll(); ServerSaveManager.AutoSave(); string text = Environment.GetCommandLineArgs()[0]; string arguments = string.Join(" ", Environment.GetCommandLineArgs()).Replace(text, "").Trim(); Process.Start(text, arguments); Process.GetCurrentProcess().Kill(); } catch (Exception ex) { Helper.LogError(ex.ToString(), true); } } }
public static void EventServerShutdown(EventTimer sender, int ShutdownTime, ref int Timeleft) { if (Timeleft != 0) { if (Timeleft <= 5) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillShutdown", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 1f); } else if (Timeleft == 10) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillShutdown", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 5f); } else if (Timeleft == 30) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillShutdown", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } else if (Timeleft == 60) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.WillShutdown", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } else if (Timeleft == ShutdownTime) { Broadcast.NoticeAll("☢", Config.GetMessage("Server.Shutdown", null, null).Replace("%SECONDS%", Timeleft.ToString()), null, 10f); } } if (Timeleft > 0) { Timeleft--; } else { try { if (sender != null) { sender.Stop(); } AvatarSaveProc.SaveAll(); ServerSaveManager.AutoSave(); Process.GetCurrentProcess().Kill(); } catch (Exception ex) { Helper.LogError(ex.ToString(), true); } } }
public static void DoProcessUsers() { if (!Events.bool_1) { Events.bool_1 = true; foreach (UserData current in Users.All) { NetUser netUser = NetUser.FindByUserID(current.SteamID); if (netUser != null && !netUser.did_join) { netUser = null; } List <Countdown> list = new List <Countdown>(); foreach (Countdown current2 in Users.CountdownList(current.SteamID)) { if (current2.Expires) { if (current2.Expired) { list.Add(current2); } else if (current2.Command.Equals("pvp", StringComparison.OrdinalIgnoreCase) && current.HasFlag(UserFlags.nopvp) && Convert.ToInt32(current2.TimeLeft) < Core.CommandNoPVPCountdown) { current.SetFlag(UserFlags.nopvp, false); if (netUser != null) { Broadcast.Notice(netUser, "☢", Config.GetMessage("Command.PvP.Enabled", netUser, null), 5f); } Broadcast.NoticeAll("☢", Config.GetMessage("Command.PvP.NoticeEnabled", null, current.Username), netUser, 5f); } } } foreach (Countdown current3 in list) { Users.CountdownRemove(current.SteamID, current3); } if (current.PremiumDate.Millisecond != 0 && current.PremiumDate < DateTime.Now) { Users.SetFlags(current.SteamID, UserFlags.premium, false); Users.SetRank(current.SteamID, Users.DefaultRank); Users.SetPremiumDate(current.SteamID, default(DateTime)); Broadcast.Notice(netUser, "☢", Config.GetMessage("Player.Premium.Expired", null, null), 5f); } if (Core.OwnershipDestroyAutoDisable > 0 && Core.DestoryOwnership.ContainsKey(current.SteamID) && Core.DestoryOwnership[current.SteamID] < DateTime.Now) { Core.DestoryOwnership.Remove(current.SteamID); if (netUser != null) { Broadcast.Notice(netUser, "☢", Config.GetMessage("Command.Destroy.Disabled", null, null), 5f); } } Character character; if (netUser != null && netUser.did_join && netUser.admin && Character.FindByUser(netUser.userID, out character)) { Metabolism component = character.GetComponent <Metabolism>(); if (component.GetCalorieLevel() < 3000f) { component.AddCalories(3000f - component.GetCalorieLevel()); } if (component.GetRadLevel() > 0f) { component.AddAntiRad(component.GetRadLevel()); } } } Events.bool_1 = false; if (Core.DatabaseType.Equals("MYSQL") && !Events.bool_3 && DateTime.Now.Subtract(Events.dateTime_0).TotalMilliseconds > Core.MySQL_SyncInterval) { if (Core.MySQL_LogLevel > 2u) { Helper.LogSQL("Thread \"ProcessUsers\": Synchronizing server data from MySQL database", false); } SystemTimestamp restart = SystemTimestamp.Restart; Events.bool_3 = true; Core.SQL_UpdateServer(); if (Core.MySQL_Synchronize) { Users.SQL_SynchronizeUsers(); } if (Core.MySQL_Synchronize) { Clans.SQL_SynchronizeClans(); } Events.dateTime_0 = DateTime.Now; Events.bool_3 = false; restart.Stop(); if (Core.MySQL_LogLevel > 2u) { Helper.LogSQL("Thread \"ProcessUsers\": Synchronized, is took " + restart.ElapsedSeconds.ToString("0.0000") + " second(s).", false); } } } }
public static void DoServerEvents() { if (!Events.bool_0) { Events.bool_0 = true; try { Core.GetSpawnersSpawns(); if (Core.GenerateSource.Length > 0 && Core.GenerateOutput.Length > 0 && Core.GenerateSource.Length == Core.GenerateOutput.Length) { for (int i = 0; i < Core.GenerateSource.Length; i++) { Helper.GenerateFile(Core.GenerateSource[i], Core.GenerateOutput[i]); } } if (Truth.RustProtectChangeKey && Time.time - Truth.ProtectionUpdateTime > Truth.RustProtectChangeKeyInterval) { Truth.ProtectionUpdateTime = Time.time + 1f; int newSerial = (int)Helper.NewSerial; Truth.ProtectionKey ^= newSerial; Truth.ProtectionHash ^= newSerial; if (server.log > 2) { ConsoleSystem.Print("Protection Key Changed To=" + string.Format("0x{0:X8}", Truth.ProtectionKey) + ", New Hash=" + string.Format("0x{0:X8}", Truth.ProtectionHash), false); } foreach (PlayerClient current in PlayerClient.All) { Users.GetBySteamID(current.userID).ProtectTick = 0; Users.GetBySteamID(current.userID).ProtectTime = 0f; } } if (Core.CyclePvP) { if (server.pvp && (int)EnvironmentControlCenter.Singleton.GetTime() == Core.CyclePvPOff) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.PvP.Disabled", null, null), null, 5f); server.pvp = false; } else if (!server.pvp && (int)EnvironmentControlCenter.Singleton.GetTime() == Core.CyclePvPOn) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.PvP.Enabled", null, null), null, 5f); server.pvp = true; } } if (Core.CycleInstantCraft) { if (crafting.instant && (int)EnvironmentControlCenter.Singleton.GetTime() == Core.CycleInstantCraftOff) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.InstantCraft.Disabled", null, null), null, 5f); crafting.instant = false; } else if (!crafting.instant && (int)EnvironmentControlCenter.Singleton.GetTime() == Core.CycleInstantCraftOn) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.InstantCraft.Enabled", null, null), null, 5f); crafting.instant = true; } } if (Clans.Database != null) { uint[] array = Clans.Database.Keys.ToArray <uint>(); uint[] array2 = array; for (int j = 0; j < array2.Length; j++) { uint key = array2[j]; if (Clans.Database.ContainsKey(key)) { ClanData clanData = Clans.Database[key]; uint[] array3 = clanData.Hostile.Keys.ToArray <uint>(); if (array3.Length > 0) { uint[] array4 = array3; for (int k = 0; k < array4.Length; k++) { uint key2 = array4[k]; if (Clans.Database.ContainsKey(key2) && DateTime.Now > clanData.Hostile[key2]) { ClanData clanData2 = Clans.Database[key2]; string[] messagesClan = Config.GetMessagesClan("Command.Clan.Hostile.Ended", clanData, null, null); for (int l = 0; l < messagesClan.Length; l++) { string text = messagesClan[l]; clanData.Message(text.Replace("%HOSTILE.CLAN.NAME%", clanData2.Name)); } string[] messagesClan2 = Config.GetMessagesClan("Command.Clan.Hostile.Ended", clanData2, null, null); for (int m = 0; m < messagesClan2.Length; m++) { string text2 = messagesClan2[m]; clanData2.Message(text2.Replace("%HOSTILE.CLAN.NAME%", clanData.Name)); } clanData.Hostile.Remove(clanData2.ID); clanData.Penalty = Helper.StringToTime(Clans.ClanWarEndedPenalty, DateTime.Now); clanData2.Hostile.Remove(clanData.ID); clanData2.Penalty = Helper.StringToTime(Clans.ClanWarEndedPenalty, DateTime.Now); if (Core.DatabaseType.Equals("MYSQL")) { MySQL.Update(string.Format(Clans.SQL_DELETE_CLAN_HOSTILE, clanData.ID)); MySQL.Update(string.Format(Clans.SQL_DELETE_CLAN_HOSTILE, clanData2.ID)); } } } } } } } } catch (Exception) { Helper.LogWarning("WARNING: Server DoEvents restarted by exception.", true); } Events.bool_0 = false; } }
public static void DoServerEvents() { if (!bool_0) { bool_0 = true; try { Core.GetSpawnersSpawns(); if (((Core.GenerateSource.Length > 0) && (Core.GenerateOutput.Length > 0)) && (Core.GenerateSource.Length == Core.GenerateOutput.Length)) { for (int i = 0; i < Core.GenerateSource.Length; i++) { Helper.GenerateFile(Core.GenerateSource[i], Core.GenerateOutput[i]); } } if (Truth.RustProtectChangeKey && ((Time.time - Truth.ProtectionUpdateTime) > Truth.RustProtectChangeKeyInterval)) { Truth.ProtectionUpdateTime = Time.time + 1f; int newSerial = (int)Helper.NewSerial; Truth.ProtectionKey ^= newSerial; Truth.ProtectionHash ^= newSerial; if (server.log > 2) { ConsoleSystem.Print("Protection Key Changed To=" + string.Format("0x{0:X8}", Truth.ProtectionKey) + ", New Hash=" + string.Format("0x{0:X8}", Truth.ProtectionHash), false); } foreach (PlayerClient client in PlayerClient.All) { Users.GetBySteamID(client.userID).ProtectTick = 0; Users.GetBySteamID(client.userID).ProtectTime = 0f; } } if (Core.CyclePvP) { if (server.pvp && (((int)EnvironmentControlCenter.Singleton.GetTime()) == Core.CyclePvPOff)) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.PvP.Disabled", null, null), null, 5f); server.pvp = false; } else if (!server.pvp && (((int)EnvironmentControlCenter.Singleton.GetTime()) == Core.CyclePvPOn)) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.PvP.Enabled", null, null), null, 5f); server.pvp = true; } } if (Core.CycleInstantCraft) { if (crafting.instant && (((int)EnvironmentControlCenter.Singleton.GetTime()) == Core.CycleInstantCraftOff)) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.InstantCraft.Disabled", null, null), null, 5f); crafting.instant = false; } else if (!crafting.instant && (((int)EnvironmentControlCenter.Singleton.GetTime()) == Core.CycleInstantCraftOn)) { Broadcast.NoticeAll("☢", Config.GetMessage("Cycle.InstantCraft.Enabled", null, null), null, 5f); crafting.instant = true; } } if (Clans.Database != null) { foreach (uint num3 in ((ICollection <uint>)Clans.Database.Keys).ToArray <uint>()) { if (Clans.Database.ContainsKey(num3)) { ClanData clan = Clans.Database[num3]; uint[] numArray2 = ((ICollection <uint>)clan.Hostile.Keys).ToArray <uint>(); if (numArray2.Length > 0) { foreach (uint num4 in numArray2) { if (Clans.Database.ContainsKey(num4) && (DateTime.Now > clan.Hostile[num4])) { ClanData data2 = Clans.Database[num4]; foreach (string str in Config.GetMessagesClan("Command.Clan.Hostile.Ended", clan, null, null)) { clan.Message(str.Replace("%HOSTILE.CLAN.NAME%", data2.Name)); } foreach (string str2 in Config.GetMessagesClan("Command.Clan.Hostile.Ended", data2, null, null)) { data2.Message(str2.Replace("%HOSTILE.CLAN.NAME%", clan.Name)); } clan.Hostile.Remove(data2.ID); clan.Penalty = Helper.StringToTime(Clans.ClanWarEndedPenalty, DateTime.Now); data2.Hostile.Remove(clan.ID); data2.Penalty = Helper.StringToTime(Clans.ClanWarEndedPenalty, DateTime.Now); if (Core.DatabaseType.Equals("MYSQL")) { MySQL.Update(string.Format(Clans.SQL_DELETE_CLAN_HOSTILE, clan.ID)); MySQL.Update(string.Format(Clans.SQL_DELETE_CLAN_HOSTILE, data2.ID)); } } } } } } } } catch (Exception) { Helper.LogWarning("WARNING: Server DoEvents restarted by exception.", true); } bool_0 = false; } }
public static void DoProcessUsers() { if (!bool_1) { bool_1 = true; foreach (UserData data in Users.All) { Character character; NetUser player = NetUser.FindByUserID(data.SteamID); if ((player != null) && !player.did_join) { player = null; } System.Collections.Generic.List <Countdown> list = new System.Collections.Generic.List <Countdown>(); foreach (Countdown countdown in Users.CountdownList(data.SteamID)) { if (countdown.Expires) { if (countdown.Expired) { list.Add(countdown); } else if ((countdown.Command.Equals("pvp", StringComparison.OrdinalIgnoreCase) && data.HasFlag(UserFlags.nopvp)) && (Convert.ToInt32(countdown.TimeLeft) < Core.CommandNoPVPCountdown)) { data.SetFlag(UserFlags.nopvp, false); if (player != null) { Broadcast.Notice(player, "☢", Config.GetMessage("Command.PvP.Enabled", player, null), 5f); } Broadcast.NoticeAll("☢", Config.GetMessage("Command.PvP.NoticeEnabled", null, data.Username), player, 5f); } } } foreach (Countdown countdown2 in list) { Users.CountdownRemove(data.SteamID, countdown2); } if ((data.PremiumDate.Millisecond != 0) && (data.PremiumDate < DateTime.Now)) { Users.SetFlags(data.SteamID, UserFlags.premium, false); Users.SetRank(data.SteamID, Users.DefaultRank); DateTime date = new DateTime(); Users.SetPremiumDate(data.SteamID, date); Broadcast.Notice(player, "☢", Config.GetMessage("Player.Premium.Expired", null, null), 5f); } if (((Core.OwnershipDestroyAutoDisable > 0) && Core.DestoryOwnership.ContainsKey(data.SteamID)) && (Core.DestoryOwnership[data.SteamID] < DateTime.Now)) { Core.DestoryOwnership.Remove(data.SteamID); if (player != null) { Broadcast.Notice(player, "☢", Config.GetMessage("Command.Destroy.Disabled", null, null), 5f); } } if (((player != null) && player.did_join) && (player.admin && Character.FindByUser(player.userID, out character))) { Metabolism component = character.GetComponent <Metabolism>(); if (component.GetCalorieLevel() < 3000f) { component.AddCalories(3000f - component.GetCalorieLevel()); } if (component.GetRadLevel() > 0f) { component.AddAntiRad(component.GetRadLevel()); } } } bool_1 = false; if ((Core.DatabaseType.Equals("MYSQL") && !bool_3) && (DateTime.Now.Subtract(dateTime_0).TotalMilliseconds > Core.MySQL_SyncInterval)) { if (Core.MySQL_LogLevel > 2) { Helper.LogSQL("Thread \"ProcessUsers\": Synchronizing server data from MySQL database", false); } SystemTimestamp restart = SystemTimestamp.Restart; bool_3 = true; Core.SQL_UpdateServer(); if (Core.MySQL_Synchronize) { Users.SQL_SynchronizeUsers(); } if (Core.MySQL_Synchronize) { Clans.SQL_SynchronizeClans(); } dateTime_0 = DateTime.Now; bool_3 = false; restart.Stop(); if (Core.MySQL_LogLevel > 2) { Helper.LogSQL("Thread \"ProcessUsers\": Synchronized, is took " + restart.ElapsedSeconds.ToString("0.0000") + " second(s).", false); } } } }