public ClientUpdatePacket(Packet packet) : base(packet) { DataPacketIds = new HashSet <ClientPacketId>(); PlayerConnect = new PacketDataCollection <PlayerConnect>(); PlayerDisconnect = new PacketDataCollection <ClientPlayerDisconnect>(); PlayerEnterScene = new PacketDataCollection <ClientPlayerEnterScene>(); PlayerAlreadyInScene = new ClientPlayerAlreadyInScene(); PlayerLeaveScene = new PacketDataCollection <GenericClientData>(); PlayerUpdates = new PacketDataCollection <PlayerUpdate>(); EntityUpdates = new PacketDataCollection <EntityUpdate>(); PlayerDeath = new PacketDataCollection <GenericClientData>(); PlayerTeamUpdate = new PacketDataCollection <ClientPlayerTeamUpdate>(); PlayerSkinUpdate = new PacketDataCollection <ClientPlayerSkinUpdate>(); PlayerEmoteUpdate = new PacketDataCollection <ClientPlayerEmoteUpdate>(); GameSettingsUpdate = new GameSettingsUpdate(); }
// TODO: make sure that resent data does not overwrite newer instance of later sent reliable data public void SetLostReliableData(ClientUpdatePacket lostPacket) { if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerConnect)) { Logger.Get().Info(this, " Resending PlayerConnect data"); DataPacketIds.Add(ClientPacketId.PlayerConnect); PlayerConnect.DataInstances.AddRange(lostPacket.PlayerConnect.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerDisconnect)) { Logger.Get().Info(this, " Resending PlayerDisconnect data"); DataPacketIds.Add(ClientPacketId.PlayerDisconnect); PlayerDisconnect.DataInstances.AddRange(lostPacket.PlayerDisconnect.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerEnterScene)) { Logger.Get().Info(this, " Resending PlayerEnterScene data"); DataPacketIds.Add(ClientPacketId.PlayerEnterScene); PlayerEnterScene.DataInstances.AddRange(lostPacket.PlayerEnterScene.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerAlreadyInScene)) { Logger.Get().Info(this, " Resending PlayerAlreadyInScene data"); DataPacketIds.Add(ClientPacketId.PlayerAlreadyInScene); PlayerAlreadyInScene.PlayerEnterSceneList.AddRange(lostPacket.PlayerAlreadyInScene .PlayerEnterSceneList); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerLeaveScene)) { Logger.Get().Info(this, " Resending PlayerLeaveScene data"); DataPacketIds.Add(ClientPacketId.PlayerLeaveScene); PlayerLeaveScene.DataInstances.AddRange(lostPacket.PlayerLeaveScene.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerDeath)) { Logger.Get().Info(this, " Resending PlayerDeath data"); DataPacketIds.Add(ClientPacketId.PlayerDeath); PlayerDeath.DataInstances.AddRange(lostPacket.PlayerDeath.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerTeamUpdate)) { Logger.Get().Info(this, " Resending PlayerTeamUpdate data"); DataPacketIds.Add(ClientPacketId.PlayerTeamUpdate); PlayerTeamUpdate.DataInstances.AddRange(lostPacket.PlayerTeamUpdate.DataInstances); } if (lostPacket.DataPacketIds.Contains(ClientPacketId.PlayerSkinUpdate)) { // Only update if the current packet does not already contain another skin update // since we want the latest update to arrive if (!DataPacketIds.Contains(ClientPacketId.PlayerSkinUpdate)) { Logger.Get().Info(this, " Resending PlayerSkinUpdate data"); DataPacketIds.Add(ClientPacketId.PlayerSkinUpdate); PlayerSkinUpdate.DataInstances.AddRange(lostPacket.PlayerSkinUpdate.DataInstances); } } if (lostPacket.DataPacketIds.Contains(ClientPacketId.GameSettingsUpdated)) { // Only update if the current packet does not already contain another settings update // since we want the latest update to arrive if (!DataPacketIds.Contains(ClientPacketId.GameSettingsUpdated)) { Logger.Get().Info(this, " Resending GameSettingsUpdated data"); DataPacketIds.Add(ClientPacketId.GameSettingsUpdated); GameSettingsUpdate = lostPacket.GameSettingsUpdate; } } }
private void OnGameSettingsUpdated(GameSettingsUpdate update) { var pvpChanged = false; var bodyDamageChanged = false; var displayNamesChanged = false; var alwaysShowMapChanged = false; var onlyCompassChanged = false; var teamsChanged = false; var allowSkinsChanged = false; // Check whether the PvP state changed if (_gameSettings.IsPvpEnabled != update.GameSettings.IsPvpEnabled) { pvpChanged = true; var message = $"PvP is now {(update.GameSettings.IsPvpEnabled ? "enabled" : "disabled")}"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether the body damage state changed if (_gameSettings.IsBodyDamageEnabled != update.GameSettings.IsBodyDamageEnabled) { bodyDamageChanged = true; var message = $"Body damage is now {(update.GameSettings.IsBodyDamageEnabled ? "enabled" : "disabled")}"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether the always show map icons state changed if (_gameSettings.AlwaysShowMapIcons != update.GameSettings.AlwaysShowMapIcons) { alwaysShowMapChanged = true; var message = $"Map icons are now{(update.GameSettings.AlwaysShowMapIcons ? "" : " not")} always visible"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether the wayward compass broadcast state changed if (_gameSettings.OnlyBroadcastMapIconWithWaywardCompass != update.GameSettings.OnlyBroadcastMapIconWithWaywardCompass) { onlyCompassChanged = true; var message = $"Map icons are {(update.GameSettings.OnlyBroadcastMapIconWithWaywardCompass ? "now only" : "not")} broadcast when wearing the Wayward Compass charm"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether the display names setting changed if (_gameSettings.DisplayNames != update.GameSettings.DisplayNames) { displayNamesChanged = true; var message = $"Names are {(update.GameSettings.DisplayNames ? "now" : "no longer")} displayed"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether the teams enabled setting changed if (_gameSettings.TeamsEnabled != update.GameSettings.TeamsEnabled) { teamsChanged = true; var message = $"Teams are {(update.GameSettings.TeamsEnabled ? "now" : "no longer")} enabled"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Check whether allow skins setting changed if (_gameSettings.AllowSkins != update.GameSettings.AllowSkins) { allowSkinsChanged = true; var message = $"Skins are {(update.GameSettings.AllowSkins ? "now" : "no longer")} enabled"; UI.UIManager.InfoBox.AddMessage(message); Logger.Get().Info(this, message); } // Update the settings so callbacks can read updated values _gameSettings.SetAllProperties(update.GameSettings); // Only update the player manager if the either PvP or body damage have been changed if (pvpChanged || bodyDamageChanged || displayNamesChanged) { _playerManager.OnGameSettingsUpdated(pvpChanged || bodyDamageChanged, displayNamesChanged); } if (alwaysShowMapChanged || onlyCompassChanged) { if (!_gameSettings.AlwaysShowMapIcons && !_gameSettings.OnlyBroadcastMapIconWithWaywardCompass) { _mapManager.RemoveAllIcons(); } } // If the teams setting changed, we invoke the registered event handler if they exist if (teamsChanged) { // If the team setting was disabled, we reset all teams if (!_gameSettings.TeamsEnabled) { _playerManager.ResetAllTeams(); } TeamSettingChangeEvent?.Invoke(); } // If the allow skins setting changed and it is no longer allowed, we reset all existing skins if (allowSkinsChanged && !_gameSettings.AllowSkins) { _playerManager.ResetAllPlayerSkins(); } }