public override void Load() { TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(Name, typeof(ServerConfig)); var text = reader.ReadToEnd(); reader.Close(); if (!string.IsNullOrEmpty(text)) { try { ChatMessages = MyAPIGateway.Utilities.SerializeFromXML <List <ChatMessage> >(text); } catch (Exception ex) { var exception = new Exception(string.Format("An error occuring loading the file '{0}'. Begining with the text \"{1}\".", Name, text.Substring(0, Math.Min(text.Length, 100))), ex); AdminNotificator.StoreExceptionAndNotify(exception); } } if (ChatMessages == null) { ChatMessages = new List <ChatMessage>(); } }
public override void Load() { Config = new ServerConfigurationStruct(); TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(Name, typeof(ServerConfig)); var xmlText = reader.ReadToEnd(); reader.Close(); if (string.IsNullOrWhiteSpace(xmlText)) { return; } try { Config = MyAPIGateway.Utilities.SerializeFromXML <ServerConfigurationStruct>(xmlText); } catch (Exception ex) { AdminNotification notification = new AdminNotification() { Date = DateTime.Now, Content = string.Format(@"There is an error in the config file. It couldn't be read. The server was started with default settings. Message: {0} If you can't find the error, simply delete the file. The server will create a new one with default settings on restart.", ex.Message) }; AdminNotificator.StoreAndNotify(notification); } if (Config == null) { Config = new ServerConfigurationStruct(); } var sendLogPms = Config.LogPrivateMessages != CommandPrivateMessage.LogPrivateMessages; CommandPrivateMessage.LogPrivateMessages = Config.LogPrivateMessages; if (sendLogPms) { ConnectionHelper.SendMessageToAllPlayers(new MessageConfig() { Config = new ServerConfigurationStruct() { LogPrivateMessages = CommandPrivateMessage.LogPrivateMessages }, Action = ConfigAction.LogPrivateMessages }); } Config.MotdFileSuffix = Config.MotdFileSuffix.ReplaceForbiddenChars(); }
private void InvokeServerProcessing() { Logger.Debug("START - Processing [Server] {0}", this.GetType().Name); try { ProcessServer(); } catch (Exception ex) { AdminNotificator.StoreExceptionAndNotify(ex); } Logger.Debug("END - Processing [Server] {0}", this.GetType().Name); }
public override void Load() { TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(Name, typeof(ServerConfig)); var text = reader.ReadToEnd(); reader.Close(); try { PrivateConversations = MyAPIGateway.Utilities.SerializeFromXML <List <PrivateConversation> >(text); } catch (Exception ex) { var exception = new Exception(string.Format("An error occuring loading the file '{0}'. Begining with the text \"{1}\".", Name, text.Substring(0, Math.Min(text.Length, 100))), ex); AdminNotificator.StoreExceptionAndNotify(exception); throw exception; } }
public override void ProcessServer() { if (ServerConfig.IsServerAdmin(SenderSteamId)) { AdminNotificator.SendEnqueuedNotifications(SenderSteamId); } if (!ServerConfig.IsServerAdmin(SenderSteamId) && ChatCommandLogic.Instance.ServerCfg.Config.ForceBannedPlayers.Any(p => p.SteamId == SenderSteamId)) { ConnectionHelper.SendMessageToPlayer(SenderSteamId, new MessageForceDisconnect() { SteamId = SenderSteamId }); } ConnectionHelper.SendMessageToPlayer(SenderSteamId, new MessageConfig() { Config = new ServerConfigurationStruct() { LogPrivateMessages = CommandPrivateMessage.LogPrivateMessages }, Action = ConfigAction.LogPrivateMessages }); ChatCommandLogic.Instance.ServerCfg.SendPermissions(SenderSteamId); ConnectionHelper.SendMessageToPlayer(SenderSteamId, new MessageSyncProtection() { Config = ProtectionHandler.Config }); if (!ServerConfig.ServerIsClient) { var motdMessage = new MessageOfTheDayMessage() { Content = CommandMessageOfTheDay.Content, HeadLine = CommandMessageOfTheDay.HeadLine, ShowInChat = CommandMessageOfTheDay.ShowInChat, FieldsToUpdate = MessageOfTheDayMessage.ChangedFields.Content | MessageOfTheDayMessage.ChangedFields.HeadLine | MessageOfTheDayMessage.ChangedFields.ShowInChat }; ConnectionHelper.SendMessageToPlayer(SenderSteamId, motdMessage); } }
public override void Load() { TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(Name, typeof(ServerConfig)); var text = reader.ReadToEnd(); reader.Close(); Permissions = new Permissions { Commands = new List <CommandStruct>(), Groups = new List <PermissionGroup>(), Players = new List <PlayerPermission>() }; if (!string.IsNullOrEmpty(text)) { try { Permissions = MyAPIGateway.Utilities.SerializeFromXML <Permissions>(text); } catch (Exception ex) { AdminNotification notification = new AdminNotification() { Date = DateTime.Now, Content = string.Format(@"There is an error in the _permissions file. It couldn't be read. The server was started with default _permissions. Message: {0} If you can't find the error, simply delete the file. The server will create a new one with default settings on restart.", ex.Message) }; AdminNotificator.StoreAndNotify(notification); } } //create a copy of the commands in the file var invalidCommands = new List <CommandStruct>(Permissions.Commands); foreach (ChatCommand command in _chatCommands) { if (!Permissions.Commands.Any(c => c.Name.Equals(command.Name))) { //add a command if it does not exist Permissions.Commands.Add(new CommandStruct() { Name = command.Name, NeededLevel = command.Security }); } else { //remove all commands from the list, that are valid invalidCommands.Remove(Permissions.Commands.First(c => c.Name.Equals(command.Name))); } } foreach (CommandStruct cmdStruct in invalidCommands) { // remove all invalid commands Permissions.Commands.Remove(cmdStruct); // clean up the player permissions var extentions = new List <PlayerPermission>(Permissions.Players.Where(p => p.Extensions.Any(c => c.Equals(cmdStruct.Name)))); var restrictions = new List <PlayerPermission>(Permissions.Players.Where(p => p.Restrictions.Any(c => c.Equals(cmdStruct.Name)))); foreach (PlayerPermission playerPermission in extentions) { var i = Permissions.Players.IndexOf(playerPermission); var player = Permissions.Players[i]; Permissions.Players.RemoveAt(i); player.Extensions.Remove(cmdStruct.Name); Permissions.Players.Insert(i, playerPermission); } foreach (PlayerPermission playerPermission in restrictions) { var i = Permissions.Players.IndexOf(playerPermission); var player = Permissions.Players[i]; Permissions.Players.RemoveAt(i); player.Restrictions.Remove(cmdStruct.Name); Permissions.Players.Insert(i, player); } // if the struct used an alias, we add it again properly while keeping the previous level // this might be because we changed the name of an command and keep the old as an alias to not confuse the users if (_chatCommands.Any(c => c.Commands.Any(s => s.Substring(1).Equals(cmdStruct.Name)))) { var command = _chatCommands.First(c => c.Commands.Any(s => s.Substring(1).Equals(cmdStruct.Name))); // remove all commands with the same name as we might have added it already asuming it is new Permissions.Commands.RemoveAll(c => c.Name.Equals(command.Name)); Permissions.Commands.Add(new CommandStruct() { Name = command.Name, NeededLevel = cmdStruct.NeededLevel }); foreach (PlayerPermission playerPermission in extentions) { var i = Permissions.Players.IndexOf(Permissions.Players.First(p => p.Player.SteamId == playerPermission.Player.SteamId)); var player = Permissions.Players[i]; Permissions.Players.RemoveAt(i); player.Extensions.Add(command.Name); Permissions.Players.Insert(i, player); } foreach (PlayerPermission playerPermission in restrictions) { var i = Permissions.Players.IndexOf(Permissions.Players.First(p => p.Player.SteamId == playerPermission.Player.SteamId)); var player = Permissions.Players[i]; Permissions.Players.RemoveAt(i); player.Restrictions.Add(command.Name); Permissions.Players.Insert(i, player); } } } Logger.Debug("Permission File loaded {0} commands.", Permissions.Commands.Count); // for better readability we sort it, first by level then by name Permissions.Commands = new List <CommandStruct>(Permissions.Commands.OrderByDescending(c => c.NeededLevel).ThenBy(c => c.Name)); }