Example #1
0
        private static void CheckNameExistance(Client.AuthClient client, AuthPackets.Packet packet)
        {
            string Name = Encoding.ASCII.GetString(packet.buffer, 6, 12).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");

            client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_CheckNameExsitance, new byte[4] {
                (byte)(Database.EntityTable.NameExists(Name) ? 0x2 : 0x0), 0x0, 0x0, 0x0
            }));
        }
Example #2
0
 private static void TryEnterServer(Client.AuthClient client)
 {
     System.Threading.Thread thread = new System.Threading.Thread(delegate()
     {
         System.Threading.Thread.Sleep(Constants.timeToAutomaticallyEnterServer * 1000);
         client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_TryEnter, new byte[0]));
     });
     thread.Start();
 }
Example #3
0
        private static void CreateAccount(Client.AuthClient client, AuthPackets.Packet packet)
        {
            string Name = Encoding.ASCII.GetString(packet.buffer, 6, 12).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");

            if (!Database.EntityTable.NameExists(Name) && Database.EntityTable.CreateEntity(client, Name))
            {
                client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_CreateAccount, new byte[4]));
            }
        }
Example #4
0
File: Mains.cs Project: iodz37/Iodz
 static void AuthServer_OnClientConnect(ClientWrapper obj)
 {
     Client.AuthClient authState;
     obj.Connector           = (authState = new Client.AuthClient(obj));
     authState.Cryptographer = new Network.Cryptography.AuthCryptography();
     Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
     pcs.Seed = Kernel.Random.Next();
     authState.PasswordSeed = pcs.Seed;
     authState.Send(pcs);
 }
Example #5
0
 private static void Login(Enums.LoginTypes type, Client.AuthClient client)
 {
     if (type == Enums.LoginTypes.NoError)
     {
         byte[] Buffer = new byte[800];
         var    packet = new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_ValidAccount, Buffer);
         packet.buffer[8] = 2; packet.buffer[406] = 1;
         client.Send(packet);
         SendServers(client);
     }
     else
     {
         byte[] buff = new byte[1452];
         Writer.Write((byte)type, 2, buff);
         if (type == Enums.LoginTypes.Player_Already_Logged_In)
         {
             Writer.Write(client.Account.EntityID, 26, buff);
         }
         client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_DisplayError, buff));
     }
 }
Example #6
0
 private static void SendServers(Client.AuthClient client)
 {
     System.IO.MemoryStream memory = new System.IO.MemoryStream();
     System.IO.BinaryWriter writer = new System.IO.BinaryWriter(memory);
     #region Character Info
     writer.Write(client.Account.EntityID > 0 ? 0 : 6);
     if (client.Account.EntityID > 0)
     {
         writer.Write(Encoding.ASCII.GetBytes(client.Account.Name));
         writer.Write(new byte[16 - client.Account.Name.Length]);
     }
     else
     {
         memory.Position += 16;
     }
     writer.Write(client.Account.EntityID);
     writer.Write((ushort)0);
     writer.Write(client.Account.Rank);
     writer.Write(client.Account.TotalKills);
     writer.Write(client.Account.TotalDeaths);
     writer.Write(0u);
     writer.Write(StringToBytes("2D 3E F7 D5 CF 18 F7 3F"));
     writer.Write((ulong)Program.Servers.Length);
     #endregion
     #region Servers
     for (int i = 0; i < Program.Servers.Length; i++)
     {
         var Server = Program.Servers[i];
         writer.Write((ushort)(Server.serverType));
         writer.Write(Server.NoLimit);
         writer.Write(Server.MinRank);
         writer.Write(Server.MaxRank);
         memory.Position += 16;
         writer.Write((ushort)(i + 1));
         writer.Write(Encoding.ASCII.GetBytes(Server.Name));
         writer.Write(new byte[34 - Server.Name.Length]);
         writer.Write(Server.Port);
         writer.Write(Server.IPBytes);
         writer.Write(100u);
         writer.Write((ulong)((double)Kernel.GamePool.Values.Where(x => x.Account.Server == Server).Count() / (double)Server.MaxPlayers * 100d));//FF FF FF FF Should be Maintanance
     }
     #endregion
     memory.Position = 0;
     byte[] answer = new byte[memory.Length];
     memory.Read(answer, 0, answer.Length);
     writer.Close();
     memory.Close();
     client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_GetServers, answer));
     TryEnterServer(client);
 }
Example #7
0
 private static void SendNewGUID(Client.AuthClient client)
 {
     byte[] buffer = new byte[208];
     Writer.Write(45138, 14 - 6, buffer);
     Writer.Write("pY20", 16 - 6, buffer);
     Writer.Write(44431, 22 - 6, buffer);
     Writer.Write("lY", 24 - 6, buffer);
     Writer.Write(DateTime.Now.ToString("yyyymmddhhmmss"), 26 - 6, buffer);
     Writer.Write(client.Account.Rank, 94 - 6, buffer);
     Writer.Write(client.Account.TotalKills, 98 - 6, buffer);
     Writer.Write(client.Account.TotalDeaths, 102 - 6, buffer);
     // client.Account.Identifer = Kernel.RandomString(32);
     Writer.Write(client.Account.Identifer, 106 - 6, buffer);
     client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_LoginToGameServer_Step1, buffer));
 }
Example #8
0
 /// <summary>
 /// Handling all connections.
 /// </summary>
 /// <param name="socketClient">The socket client.</param>
 public static bool Handle_Connection(SocketClient socketClient)
 {
     try
     {
         Client.AuthClient client = new Client.AuthClient(socketClient);
         using (var packet = new Packets.PasswordSeedPacket())
         {
             packet.Seed = 90011337;
             client.Send(packet);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     return true;
 }
Example #9
0
 /// <summary>
 /// Handling all connections.
 /// </summary>
 /// <param name="socketClient">The socket client.</param>
 public static bool Handle_Connection(SocketClient socketClient)
 {
     try
     {
         Client.AuthClient client = new Client.AuthClient(socketClient);
         using (var packet = new Packets.PasswordSeedPacket())
         {
             packet.Seed = 90011337;
             client.Send(packet);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     return(true);
 }
Example #10
0
        private static void ReturnToServers(Client.AuthClient client, AuthPackets.Packet packet)
        {
            System.IO.MemoryStream memory = new System.IO.MemoryStream();
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(memory);
            string Username = Encoding.ASCII.GetString(packet.buffer, 10, 20).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
            uint   UID      = BitConverter.ToUInt32(packet.buffer, 6);

            client.Account = Kernel.GamePool.Values.Where(i => i.Entity.UID == UID && i.Account.Username == Username).FirstOrDefault().Account;
            Kernel.AwaitingPool[client.Account.Identifer] = client.Account;
            #region Character Info
            memory.Position += 20;
            writer.Write(client.Account.EntityID);
            writer.Write((ushort)0);
            writer.Write(client.Account.Rank);
            writer.Write(client.Account.TotalKills);
            writer.Write(client.Account.TotalDeaths);
            writer.Write(0u);
            writer.Write(StringToBytes("2D 3E F7 D5 CF 18 F7 3F"));
            writer.Write((ulong)Program.Servers.Length);
            #endregion
            #region Servers
            for (int i = 0; i < Program.Servers.Length; i++)
            {
                var Server = Program.Servers[i];
                writer.Write((ushort)(Server.serverType));
                writer.Write(Server.NoLimit);
                writer.Write(Server.MinRank);
                writer.Write(Server.MaxRank);
                memory.Position += 16;
                writer.Write((ushort)(i + 1));
                writer.Write(Encoding.ASCII.GetBytes(Server.Name));
                writer.Write(new byte[34 - Server.Name.Length]);
                writer.Write(Server.Port);
                writer.Write(Server.IPBytes);
                writer.Write(100u);
                writer.Write((ulong)((double)Kernel.GamePool.Values.Where(x => x.Account.Server == Server).Count() / (double)Server.MaxPlayers * 100d));//FF FF FF FF Should be Maintanance
            }
            #endregion
            memory.Position = 0;
            byte[] answer = new byte[memory.Length];
            memory.Read(answer, 0, answer.Length);
            writer.Close();
            memory.Close();
            client.Send(new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_GoBackForServers, answer));
        }
Example #11
0
        public static void Process(Client.AuthClient client, AuthPackets.Packet packet)
        {
            if (packet.CorrectPacket)
            {
                switch (packet.packetType)
                {
                case AuthPackets.Packet.PacketType.C2S_Login:
                    var Username    = Encoding.ASCII.GetString(packet.buffer, 16, 20).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    var Password    = Encoding.ASCII.GetString(packet.buffer, 37, 20).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    var CFArugments = Encoding.ASCII.GetString(packet.buffer, 145, 12).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    var MacAddress  = Encoding.ASCII.GetString(packet.buffer, 407, 12).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    client.Account = new Database.AccountTable(Username)
                    {
                        IP = client.Socket.IP
                    };
                    client.Account.Identifer = Encoding.ASCII.GetString(packet.buffer, 77, 32).Replace(Encoding.ASCII.GetString(new byte[] { 0x0 }), "");
                    if (client.Account.exists && client.Account.Password == Password && !Kernel.GamePool.ContainsKey(client.Account.EntityID))
                    {
                        Kernel.AwaitingPool[client.Account.Identifer] = client.Account;
                        Login(Enums.LoginTypes.NoError, client);
                    }
                    else if (client.Account.exists && client.Account.Password == Password && Kernel.GamePool.ContainsKey(client.Account.EntityID))
                    {
                        Login(Enums.LoginTypes.Player_Already_Logged_In, client);
                    }
                    else
                    {
                        Login(Enums.LoginTypes.Unknown_Username_Or_Password, client);
                    }
                    break;

                case AuthPackets.Packet.PacketType.C2S_AccountAlreadyLoggedOn:
                    if (client.Account != null)
                    {
                        var player = Kernel.GamePool.Values.Where(i => i.Account.EntityID == client.Account.EntityID).FirstOrDefault();
                        player.Disconnect();
                        packet = new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_PlayerHasBeenLoggedOut, new byte[0]);
                        client.Send(packet);
                    }
                    break;

                case AuthPackets.Packet.PacketType.C2S_LoginToGameServer_Step1:
                    byte ServerNumber = packet.buffer[6];
                    client.Account.Server = Program.Servers[ServerNumber - 1];
                    SendNewGUID(client);
                    break;

                case AuthPackets.Packet.PacketType.C2S_LoginToGameServer_Step2:
                    while (true)
                    {
                        if (Kernel.GamePool.ContainsKey(client.Account.EntityID) && Kernel.GamePool[client.Account.EntityID].Entity.FullyLoaded)
                        {
                            var ans = new AuthPackets.Packet(AuthPackets.Packet.PacketType.S2C_LoginToGameServer_Step2, new byte[4] {
                                1, 0, 0, 0
                            });
                            client.Send(ans);
                            break;
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(10);
                        }
                    }
                    break;

                case AuthPackets.Packet.PacketType.C2S_GoBackForServers:
                    ReturnToServers(client, packet);
                    break;

                case AuthPackets.Packet.PacketType.C2S_CheckNameExsitance:
                    CheckNameExistance(client, packet);
                    break;

                case AuthPackets.Packet.PacketType.C2S_CreateAccount:
                    CreateAccount(client, packet);
                    break;

                case AuthPackets.Packet.PacketType.C2S_Exit:
                    //Send a Packet To Confirm Exit
                    packet.buffer[4] = 12;
                    client.Send(packet);
                    client.Disconnect();
                    break;

                case AuthPackets.Packet.PacketType.Unknown:
                    if (Program.CaptureUnknownPackets)
                    {
                        Console.WriteLine("Unknown Packet! =>  (" + packet.buffer[3] + "-" + packet.buffer[4] + "-" + packet.buffer[5] + ")");
                    }
                    break;
                }
            }
            else
            {
                Console.WriteLine("Incorrent Packet Structure! =>  (" + packet.buffer[3] + "-" + packet.buffer[4] + "-" + packet.buffer[5] + ")");
            }
        }
Example #12
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");
            }
        }