Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
 private void end_handshake(object sender, UdpPacket packet)
 {
     lock(packet)
     {
         packet.Send(Encoding.ASCII.GetBytes("HNDF"), packet.Destination);
     }
     //packet.Reset();
 }
Exemplo n.º 3
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.
         }
     }
 }