Ejemplo n.º 1
0
 public void LeaveRoom()
 {
     playerState = NetPlayerState.InMainLobby;
     clientState = ClientTCPState.MainLobby;
     race        = null;
     room        = null;
 }
Ejemplo n.º 2
0
 public ClientTCP(Socket socket, IPEndPoint ip)
 {
     this.socket = socket;
     this.ip     = ip;
     _buffer     = new byte[Constants.TCP_BUFFER_SIZE];
     clientState = ClientTCPState.Entrance;
     Receive();
 }
Ejemplo n.º 3
0
 public void LogIn(string username)
 {
     accountData = Global.data.GetAccount(username);
     nickname    = accountData.Nickname;
     playerState = NetPlayerState.InMainLobby;
     clientState = ClientTCPState.MainLobby;
     foreach (string guideKey in accountData.Friends.ToArray())
     {
         foreach (ClientTCP friend in Global.clientList)
         {
             if (friend.accountData.GuideKey.Equals(guideKey))
             {
                 friends.Add(friend);
                 friend.friends.Add(this);
                 SendDataTCP.SendFriendInfo(friend, this);
                 break;
             }
         }
     }
     SendDataTCP.SendLoginOk(nickname, this);
 }
Ejemplo n.º 4
0
 public void Close()
 {
     if (clientState != ClientTCPState.Sleep)
     {
         if (clientState == ClientTCPState.Entrance)
         {
             clientState = ClientTCPState.Sleep;
             try
             {
                 socket.Dispose();
             }
             catch (Exception ex)
             {
                 Global.serverForm.Debug(ex + "");
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.clientList.Remove(this);
         }
         else if (clientState == ClientTCPState.MainLobby)
         {
             clientState = ClientTCPState.Sleep;
             try
             {
                 socket.Dispose();
             }
             catch (Exception ex)
             {
                 Global.serverForm.Debug(ex + "");
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.clientList.Remove(this);
             SendDataTCP.SendGlChatMsg("Server", $"Player { nickname } disconnected.");
         }
         else if (clientState == ClientTCPState.GameRoom)
         {
             clientState = ClientTCPState.Sleep;
             if (playerState == NetPlayerState.SearchingForMatch)
             {
                 room.DeletePlayer(this);
             }
             else if (playerState == NetPlayerState.Playing)
             {
                 room.AbortGameSession(this);
             }
             else if (playerState == NetPlayerState.EndPlaying)
             {
                 room.DeletePlayer(this);
             }
             foreach (ClientTCP friend in friends)
             {
                 SendDataTCP.SendFriendLeave(this, friend);
                 friend.friends.Remove(this);
             }
             Global.serverForm.Debug($"GamePlayer {nickname} lost connection");
             Global.clientList.Remove(this);
         }
         Global.serverForm.RemoveClient(this);
     }
 }