Esempio n. 1
0
 protected async void HandshakeHandler(NeutronPlayer player, double clientTime, Authentication authentication)
 {
     if (authentication.Pass.Decrypt(out string phrase))
     {
         authentication = new Authentication(authentication.User, phrase, false);
         try
         {
             if (await OnAuthentication.Invoke(player, authentication))             //* First packet
             {
                 using (NeutronStream stream = Neutron.PooledNetworkStreams.Pull()) //* Second First packet
                 {
                     NeutronStream.IWriter writer = stream.Writer;
                     writer.WritePacket((byte)Packet.Handshake);
                     writer.Write(LocalTime);
                     writer.Write(clientTime);
                     writer.Write(player.StateObject.UdpLocalEndPoint.Port);
                     writer.WriteWithInteger(player);
                     player.Write(writer);
                 }
                 OnPlayerConnected?.Invoke(player); //* Three packet
             }
         }
         catch (Exception ex) // Tasks manual catch exception.
         {
             LogHelper.Stacktrace(ex);
         }
     }
     else if (!LogHelper.Error("Auth decrypt failed!"))
     {
         DisconnectHandler(player);
     }
 }