/// <summary> /// Set player info. /// </summary> /// <param name="host">The host.</param> /// <param name="pclient">The client.</param> /// <param name="data">The data received from client.</param> public static void SetPlayerInfo(PirateHost host, PirateClient pclient, PirateMessage data) { Contract.Requires(host != null && pclient != null && data != null && data.Head == PirateMessageHead.Pnfo); var player = PirateMessage.GetPlayerName(data); if (player == null) return; if (!host.ContainsPlayer(player)) { if(host.Game.Contains(pclient)) host.Game.RemovePlayer(pclient); host.SetPlayerName(pclient, player); host.Game.ClearPlayers(); host.Game.AddPlayers(host.GetPlayers()); pclient.SetGame(host.Game); SendPlayerInfo(host); }else { var msg = new PirateMessage(PirateMessageHead.Erro, PirateError.NameAlreadyTaken.ToString()); host.SendMessage(pclient, msg); } }