示例#1
0
 public bool Login()
 {
     //IPlayer not yet implemented
     if (Handshake(player.GetUserUUID(), player.GetUsername(), handler.GetSessionID(), handler.GetServerHost(), handler.GetServerPort()))
     {
         Send(new byte[] { 0xCD, 0 });
         try
         {
             byte[] pid = new byte[1];
             try
             {
                 if (c.Connected)
                 {
                     Receive(pid, 0, 1, SocketFlags.None);
                     while (pid[0] >= 0xC0 && pid[0] != 0xFF) //Skip some early packets or plugin messages
                     {
                         processPacket(pid[0]);
                         Receive(pid, 0, 1, SocketFlags.None);
                     }
                     if (pid[0] == (byte)1)
                     {
                         readData(4); readNextString(); readData(5);
                         StartUpdating();
                         return(true); //The Server accepted the request
                     }
                     else if (pid[0] == (byte)0xFF)
                     {
                         string reason = readNextString();
                         handler.OnConnectionLost(DisconnectReason.LoginRejected, reason);
                         return(false);
                     }
                 }
             }
             catch
             {
                 //Connection failed
                 return(false);
             }
         }
         catch
         {
             handler.OnConnectionLost(DisconnectReason.ConnectionLost, "");
             return(false);
         }
         return(false); //Login was unsuccessful (received a kick...)
     }
     else
     {
         return(false);
     }
 }