예제 #1
0
 public void Send(byte[] _data, IPEndPoint destination, bool ndata)
 {
     //data = RSATools.RSAEncrypt(data, Core.RSACryptoTools.ExportParameters(false), false);
     //_base.Send(data, data.Length, destination);
     UdpPacket upc = new UdpPacket(_data, destination, _base, ndata);
     payload pp = new payload() { packet = upc, ip = destination, data = _data };
     pendingHandshakes.Add(upc.HandshakeID);
     Thread t = new Thread(start_sending);
     t.IsBackground = true;
     t.Start(pp);
 }
예제 #2
0
 private void end_handshake(object sender, UdpPacket packet)
 {
     lock(packet)
     {
         packet.Send(Encoding.ASCII.GetBytes("HNDF"), packet.Destination);
     }
     //packet.Reset();
 }
예제 #3
0
        private void authorize_Req(object sender, UdpPacket packet)
        {
            NetworkPacketHeader header = (NetworkPacketHeader)packet.Reader.ReadInt16();
            if(header == NetworkPacketHeader.LobbyAuthorize)
            {
                long guid = packet.Reader.ReadInt64();
                string username = packet.Reader.ReadString();

                string layerName = packet.Reader.ReadString();
                NetworkLayerStatus sts = (NetworkLayerStatus)packet.Reader.ReadInt16();
                IPAddress ip = new IPAddress(packet.Reader.ReadBytes(16));
                int port = packet.Reader.ReadInt32();

                //
                // Perform a check if the player can be connected.
                //
                if (Clients.Count < Clients.Capacity)
                {
                    LobbyPlayer pl = new LobbyPlayer(username, guid, new IPEndPoint(ip, port));
                    Clients.Add(pl);
                    Log.Info(string.Format("{0}: Player with GUID {1}; \"{2}\" has been connected.", new object[] { GUID, guid, username }));

                    // Send the ack back to the user..
                    packet.Writer.Write((short)NetworkPacketHeader.LobbyAuthorizeResponse);
                    packet.Writer.Write((short)NetworkResult.Success);
                }
                else
                {
                    packet.Writer.Write((short)NetworkPacketHeader.LobbyAuthorizeResponse);
                    packet.Writer.Write((short)NetworkResult.LobbyFull);
                }
                packet.Writer.Flush();
                packet.Send();
            }
            packet.Reset();
        }
예제 #4
0
 public void udpPacket_Received(object sender, UdpPacket packet)
 {
     packet.Reset();
         NetworkPacketHeader header = (NetworkPacketHeader)packet.Reader.ReadInt16();
         switch (header)
         {
             case NetworkPacketHeader.MasterAuthorizeResponse:
                 NetworkResult res = (NetworkResult)packet.Reader.ReadInt16();
                 switch (res)
                 {
                     case NetworkResult.ConnectionError:
                         Log.Error("Connection Error. #1");
                         break;
                     case NetworkResult.ConnectionTimedOut:
                         Log.Error("Connection Timed Out. #1");
                         break;
                     case NetworkResult.PlayerBanned:
                         Log.Error("Player has been banned.");
                         break;
                     case NetworkResult.Success:
                         InGame = false;
                         UpdateStatus(NetworkPlayerStatus.Online, Username);  // Once done tell the server to update our status.
                         break;
                     case NetworkResult.Fail:
                         Log.Error("Unknown error. #1");
                         break;
                     default:
                         Log.Info("Invalid result from server.");
                         break;
                 }
                 break;
             case NetworkPacketHeader.LobbyAuthorizeResponse:
                 Log.Debug("This feature is yet to be implemented. [LobbyAuthorizeResponse]");
                 break;
             default:
                 Log.Info("Invalid packet received.");
                 return;
         }
         Status = NetworkPlayerStatus.Online;
 }
예제 #5
0
 private void connect_Request(object sender, UdpPacket packet)
 {
     lock(packet)
     {
         NetworkPacketHeader header = (NetworkPacketHeader)packet.Reader.ReadInt16();
         if (header == NetworkPacketHeader.MasterAuthorize)
         {
             long guid = packet.Reader.ReadInt64();
             packet.Writer.Write((short)NetworkPacketHeader.MasterAuthorizeResponse);
             if (IsBanned(guid))
             {
                 packet.Writer.Write((short)NetworkResult.PlayerBanned);
             }
             else
                 packet.Writer.Write((short)NetworkResult.Success);
             packet.Writer.Flush();
             packet.Send();  // Send it back to the client.
         }
     }
 }