private void OnPlayerTeamUpdate(ushort id, ServerPlayerTeamUpdatePacket packet) { if (!_playerData.TryGetValue(id, out _)) { Logger.Warn(this, $"Received PlayerTeamUpdate packet, but player with ID {id} is not in mapping"); return; } Logger.Info(this, $"Received PlayerTeamUpdate packet from ID: {id}, new team: {packet.Team}"); // Get the player data associated with this ID var playerData = _playerData[id]; // Update the team in the player data playerData.Team = packet.Team; // Create the team update packet var teamUpdatePacket = new ClientPlayerTeamUpdatePacket { Id = id, Username = playerData.Username, Team = packet.Team }; // Broadcast the packet to all players except the player we received the update from foreach (var playerId in _playerData.GetCopy().Keys) { if (id == playerId) { continue; } _netServer.SendTcp(playerId, teamUpdatePacket.CreatePacket()); } }
public void ChangeTeam(Team team) { if (!_netClient.IsConnected) { return; } _playerManager.OnLocalPlayerTeamUpdate(team); var teamUpdatePacket = new ServerPlayerTeamUpdatePacket { Team = team }; _netClient.SendTcp(teamUpdatePacket.CreatePacket()); UI.UIManager.InfoBox.AddMessage($"You are now in Team {team}"); }