public void ServerRead(IReadMessage incMsg, Client c) { if (!c.HasPermission(Networking.ClientPermissions.ManageSettings)) { return; } NetFlags flags = (NetFlags)incMsg.ReadByte(); bool changed = false; if (flags.HasFlag(NetFlags.Name)) { string serverName = incMsg.ReadString(); if (ServerName != serverName) { changed = true; } ServerName = serverName; } if (flags.HasFlag(NetFlags.Message)) { string serverMessageText = incMsg.ReadString(); if (ServerMessageText != serverMessageText) { changed = true; } ServerMessageText = serverMessageText; } if (flags.HasFlag(NetFlags.Properties)) { changed |= ReadExtraCargo(incMsg); UInt32 count = incMsg.ReadUInt32(); for (int i = 0; i < count; i++) { UInt32 key = incMsg.ReadUInt32(); if (netProperties.ContainsKey(key)) { object prevValue = netProperties[key].Value; netProperties[key].Read(incMsg); if (!netProperties[key].PropEquals(prevValue, netProperties[key])) { GameServer.Log(GameServer.ClientLogName(c) + " changed " + netProperties[key].Name + " to " + netProperties[key].Value.ToString(), ServerLog.MessageType.ServerMessage); } changed = true; } else { UInt32 size = incMsg.ReadVariableUInt32(); incMsg.BitPosition += (int)(8 * size); } } bool changedMonsterSettings = incMsg.ReadBoolean(); incMsg.ReadPadBits(); changed |= changedMonsterSettings; if (changedMonsterSettings) { ReadMonsterEnabled(incMsg); } changed |= BanList.ServerAdminRead(incMsg, c); changed |= Whitelist.ServerAdminRead(incMsg, c); } if (flags.HasFlag(NetFlags.Misc)) { int orBits = incMsg.ReadRangedInteger(0, (int)Barotrauma.MissionType.All) & (int)Barotrauma.MissionType.All; int andBits = incMsg.ReadRangedInteger(0, (int)Barotrauma.MissionType.All) & (int)Barotrauma.MissionType.All; GameMain.NetLobbyScreen.MissionType = (Barotrauma.MissionType)(((int)GameMain.NetLobbyScreen.MissionType | orBits) & andBits); int traitorSetting = (int)TraitorsEnabled + incMsg.ReadByte() - 1; if (traitorSetting < 0) { traitorSetting = 2; } if (traitorSetting > 2) { traitorSetting = 0; } TraitorsEnabled = (YesNoMaybe)traitorSetting; int botCount = BotCount + incMsg.ReadByte() - 1; if (botCount < 0) { botCount = MaxBotCount; } if (botCount > MaxBotCount) { botCount = 0; } BotCount = botCount; int botSpawnMode = (int)BotSpawnMode + incMsg.ReadByte() - 1; if (botSpawnMode < 0) { botSpawnMode = 1; } if (botSpawnMode > 1) { botSpawnMode = 0; } BotSpawnMode = (BotSpawnMode)botSpawnMode; float levelDifficulty = incMsg.ReadSingle(); if (levelDifficulty >= 0.0f) { SelectedLevelDifficulty = levelDifficulty; } UseRespawnShuttle = incMsg.ReadBoolean(); bool changedAutoRestart = incMsg.ReadBoolean(); bool autoRestart = incMsg.ReadBoolean(); if (changedAutoRestart) { AutoRestart = autoRestart; } changed |= true; } if (flags.HasFlag(NetFlags.LevelSeed)) { GameMain.NetLobbyScreen.LevelSeed = incMsg.ReadString(); changed |= true; } if (changed) { if (KarmaPreset == "custom") { GameMain.NetworkMember?.KarmaManager?.SaveCustomPreset(); GameMain.NetworkMember?.KarmaManager?.Save(); } SaveSettings(); GameMain.NetLobbyScreen.LastUpdateID++; } }
public void ServerRead(NetIncomingMessage incMsg, Client c) { if (!c.HasPermission(Networking.ClientPermissions.ManageSettings)) { return; } NetFlags flags = (NetFlags)incMsg.ReadByte(); bool changed = false; if (flags.HasFlag(NetFlags.Name)) { string serverName = incMsg.ReadString(); if (ServerName != serverName) { changed = true; } ServerName = serverName; } if (flags.HasFlag(NetFlags.Message)) { string serverMessageText = incMsg.ReadString(); if (ServerMessageText != serverMessageText) { changed = true; } ServerMessageText = serverMessageText; } if (flags.HasFlag(NetFlags.Properties)) { changed |= ReadExtraCargo(incMsg); UInt32 count = incMsg.ReadUInt32(); for (int i = 0; i < count; i++) { UInt32 key = incMsg.ReadUInt32(); if (netProperties.ContainsKey(key)) { netProperties[key].Read(incMsg); GameServer.Log(c.Name + " changed " + netProperties[key].Name + " to " + netProperties[key].Value.ToString(), ServerLog.MessageType.ServerMessage); changed = true; } else { UInt32 size = incMsg.ReadVariableUInt32(); incMsg.Position += 8 * size; } } bool changedMonsterSettings = incMsg.ReadBoolean(); incMsg.ReadPadBits(); changed |= changedMonsterSettings; if (changedMonsterSettings) { ReadMonsterEnabled(incMsg); } changed |= BanList.ServerAdminRead(incMsg, c); changed |= Whitelist.ServerAdminRead(incMsg, c); } if (flags.HasFlag(NetFlags.Misc)) { int missionType = GameMain.NetLobbyScreen.MissionTypeIndex + incMsg.ReadByte() - 1; while (missionType < 0) { missionType += Enum.GetValues(typeof(MissionType)).Length; } while (missionType >= Enum.GetValues(typeof(MissionType)).Length) { missionType -= Enum.GetValues(typeof(MissionType)).Length; } GameMain.NetLobbyScreen.MissionTypeIndex = missionType; int traitorSetting = (int)TraitorsEnabled + incMsg.ReadByte() - 1; if (traitorSetting < 0) { traitorSetting = 2; } if (traitorSetting > 2) { traitorSetting = 0; } TraitorsEnabled = (YesNoMaybe)traitorSetting; int botCount = BotCount + incMsg.ReadByte() - 1; if (botCount < 0) { botCount = MaxBotCount; } if (botCount > MaxBotCount) { botCount = 0; } BotCount = botCount; int botSpawnMode = (int)BotSpawnMode + incMsg.ReadByte() - 1; if (botSpawnMode < 0) { botSpawnMode = 1; } if (botSpawnMode > 1) { botSpawnMode = 0; } BotSpawnMode = (BotSpawnMode)botSpawnMode; float levelDifficulty = incMsg.ReadFloat(); if (levelDifficulty >= 0.0f) { SelectedLevelDifficulty = levelDifficulty; } UseRespawnShuttle = incMsg.ReadBoolean(); bool changedAutoRestart = incMsg.ReadBoolean(); bool autoRestart = incMsg.ReadBoolean(); if (changedAutoRestart) { AutoRestart = autoRestart; } changed |= true; } if (flags.HasFlag(NetFlags.LevelSeed)) { GameMain.NetLobbyScreen.LevelSeed = incMsg.ReadString(); changed |= true; } if (changed) { GameMain.NetLobbyScreen.LastUpdateID++; } }
public void ClientAdminWrite(NetFlags dataToSend, int missionType = 0, float?levelDifficulty = null, bool?autoRestart = null, int traitorSetting = 0, int botCount = 0, int botSpawnMode = 0, bool?useRespawnShuttle = null) { if (!GameMain.Client.HasPermission(Networking.ClientPermissions.ManageSettings)) { return; } IWriteMessage outMsg = new WriteOnlyMessage(); outMsg.Write((byte)ClientPacketHeader.SERVER_SETTINGS); outMsg.Write((byte)dataToSend); if (dataToSend.HasFlag(NetFlags.Name)) { if (GameMain.NetLobbyScreen.ServerName.Text != ServerName) { ServerName = GameMain.NetLobbyScreen.ServerName.Text; } outMsg.Write(ServerName); } if (dataToSend.HasFlag(NetFlags.Message)) { if (GameMain.NetLobbyScreen.ServerMessage.Text != ServerMessageText) { ServerMessageText = GameMain.NetLobbyScreen.ServerMessage.Text; } outMsg.Write(ServerMessageText); } if (dataToSend.HasFlag(NetFlags.Properties)) { //TODO: split this up? WriteExtraCargo(outMsg); IEnumerable <KeyValuePair <UInt32, NetPropertyData> > changedProperties = netProperties.Where(kvp => kvp.Value.ChangedLocally); UInt32 count = (UInt32)changedProperties.Count(); bool changedMonsterSettings = tempMonsterEnabled != null && tempMonsterEnabled.Any(p => p.Value != MonsterEnabled[p.Key]); outMsg.Write(count); foreach (KeyValuePair <UInt32, NetPropertyData> prop in changedProperties) { DebugConsole.NewMessage(prop.Value.Name, Color.Lime); outMsg.Write(prop.Key); prop.Value.Write(outMsg, prop.Value.GUIComponentValue); } outMsg.Write(changedMonsterSettings); outMsg.WritePadBits(); if (changedMonsterSettings) { WriteMonsterEnabled(outMsg, tempMonsterEnabled); } BanList.ClientAdminWrite(outMsg); Whitelist.ClientAdminWrite(outMsg); } if (dataToSend.HasFlag(NetFlags.Misc)) { outMsg.Write((byte)(missionType + 1)); outMsg.Write((byte)(traitorSetting + 1)); outMsg.Write((byte)(botCount + 1)); outMsg.Write((byte)(botSpawnMode + 1)); outMsg.Write(levelDifficulty ?? -1000.0f); outMsg.Write(useRespawnShuttle ?? UseRespawnShuttle); outMsg.Write(autoRestart != null); outMsg.Write(autoRestart ?? false); outMsg.WritePadBits(); } if (dataToSend.HasFlag(NetFlags.LevelSeed)) { outMsg.Write(GameMain.NetLobbyScreen.SeedBox.Text); } GameMain.Client.ClientPeer.Send(outMsg, DeliveryMethod.Reliable); }