예제 #1
0
        /// <summary>
        /// Sends a packet to the client.
        /// </summary>
        /// <param name="Packet">The packet to send.</param>
        public void Send(DataPacket Packet)
        {
            if (IsAIBot)
                return;

            // TODO: rewrite the sockets to actually handle this proper ...
            if (Packet.ReadString(Packet.BufferLength - 8, 8) == "TQClient") // this is actually never used, not removing it though just to be sure
            {
                using (var sendPacket = new DataPacket(Packet))
                {
                    sendPacket.WriteBytes(Packet.Copy(), 0);
                    sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8);
                    NetworkClient.Send(sendPacket);
                }
            }
            else
            {
                using (var sendPacket = new DataPacket(new byte[Packet.BufferLength + 8]))
                {
                    sendPacket.WriteBytes(Packet.Copy(), 0);
                    sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8);
                    NetworkClient.Send(sendPacket);
                }
            }
        }
 public void Append(DataPacket buffer, int offset, out int nextoffset)
 {
     nextoffset = offset;
     buffer.WriteString(Name, offset);
     buffer.WriteUInt32(Unknown16, offset + 16);
     buffer.WriteUInt32(Unknown20, offset + 20);
     buffer.WriteUInt32(Level, offset + 24);
     buffer.WriteUInt16((ushort)Rank, offset + 28);
     buffer.WriteUInt16(Unknown30, offset + 30);
     buffer.WriteUInt32(Unknown32, offset + 32);
     buffer.WriteInt32(Donation, offset + 36);
     buffer.WriteBool(IsOnline, offset + 40);
     buffer.WriteUInt32(Unknown44, offset + 44);
     nextoffset += 48;
 }
예제 #3
0
        /// <summary>
        /// Handles the auth request packet.
        /// </summary>
        /// <param name="client">The auth client.</param>
        /// <param name="Packet">The packet.</param>
        public static void Handle(Client.AuthClient client, DataPacket Packet)
        {
            using (var auth = new AuthRequestPacket(Packet))
            {
                Enums.AccountStatus status = Database.ServerDatabase.Authenticate(client, auth.Account, auth.Password);
                client.EntityUID = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(1000000, 699999999);

                if (status == Enums.AccountStatus.Ready)
                {
                    try
                    {
                        Database.ServerDatabase.UpdateAuthentication(client);
                        Socket quicksock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                        quicksock.Connect(new IPEndPoint(IPAddress.Parse(Program.Config.ReadString("GameIP")), Program.Config.ReadInt32("GameAuthPort")));

                        using (DataPacket packet = new DataPacket(44, 9001))
                        {
                            packet.WriteString(Program.Config.ReadString("ServerPassword"), 4);
                            packet.WriteString(client.Account, 20);
                            packet.WriteInt32(client.DatabaseUID, 36);
                            packet.WriteUInt32(client.EntityUID, 40);
                            quicksock.BeginSend(packet.Copy(), 0, 44, SocketFlags.None,
                                                new AsyncCallback((ia) =>
                                                                  {
                                                                  	int send = quicksock.EndSend(ia);
                                                                  	if (send != 44)
                                                                  	{
                                                                  		status = Enums.AccountStatus.Datebase_Error;
                                                                  		client.EntityUID = 0;
                                                                  	}
                                                                  	Console.WriteLine("Database Notified: [Account: {0}] [DUID: {1}] [EUID: {2}]", client.Account, client.DatabaseUID, client.EntityUID);
                                                                  }), null);

                        }
                        System.Threading.Thread.Sleep(2000);
                    }
                    catch
                    {
                        status = Enums.AccountStatus.Datebase_Error;
                    }
                }

                using (var resp = new AuthResponsePacket())
                {
                    if (status == Enums.AccountStatus.Ready)
                    {
                        Console.WriteLine("Incoming login. [Account: {0}] [Password: {1}]", client.Account, client.Password);

                        resp.EntityUID = client.EntityUID;
                        resp.Port = Program.Config.ReadUInt32("GamePort");
                        resp.IPAddress = Program.Config.ReadString("GameIP");
                    }
                    else
                    {
                        resp.EntityUID = 0;
                    }
                    resp.AccountStatus = status;
                    client.Send(resp);
                }
                System.Threading.Thread.Sleep(5000);
                client.NetworkClient.Disconnect("TIME_OUT");
            }
        }