Exemple #1
0
        /*
         * Unknown_7D6 Packet
         * -------------------------
         * Client2Server Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * int      : padding
         * ushort   : opcode
         *
         * int      : unk1
         * byte[]   : encrypted data    #array size depends on RSA keylength, see PublicKey packet
         * -------------------------
         * Server2Client Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * ushort   : opcode
         *
         * int      : unk1              #is set to 1 upon successful login; otherwise 0
         * int      : unk2
         * byte     : unk3
         * int      : status            #account status
         * -------------------------
         * If login was successful, server sends another Unknown_7D6 packet:
         * Server2Client Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * ushort   : opcode
         *
         * int      : unk1              #is set to 1 upon successful login; otherwise 0
         * int      : unk2
         * byte     : unk3
         * int      : status            #account status
         * int      : unk4
         * byte     : unk5
         * int      : unk6
         * long     : unk7
         * byte     : unk8
         * int      : unk9
         * byte     : unk10
         * int      : unk11
         * int      : unk12
         * int      : unk13
         * char[32] : auth key          #possibly used for cash shop
         * short    : unk14
         * byte     : server count
         *
         * foreach server
         *      byte     : server id
         *      byte     : character count
         *
         * byte[]   : unk15             #array length is 248
         */
        #endregion

        public static void Unknown_7D6(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            packet.Skip(4);

            var rsa = client.Metadata["rsa"] as RSA;

            if (rsa == null)
            {
                Log.Error("Unable to decrypt RSA data!");
                client.Disconnect();
                client = null;
                return;
            }

            byte[] encrypted = packet.ReadBytes(rsa.KeyLength / 8); // keylength is in bits
            byte[] details   = rsa.Decrypt(encrypted);
            byte[] tmpdata   = new byte[16];

            if (details == null)
            {
                Log.Error("Unable to decrypt RSA data!");
                client.Disconnect();
                client = null;
                return;
            }

            Array.Copy(details, tmpdata, 16);
            string name = Encoding.UTF8.GetString(tmpdata).Trim('\0');

            Array.Copy(details, 65, tmpdata, 0, 16);
            string pass = Encoding.UTF8.GetString(tmpdata).Trim('\0');

            Log.Notice("Login authentication: " + name);

            string ip         = client.RemoteEndPoint.ToString().Split(':')[0];
            var    syncServer = client.Metadata["syncServer"] as SyncReceiver;
            var    data       = Authentication.FetchAccount(syncServer, name, pass);
            bool   kick       = false;

            if (data == null || data.id == -1)
            {
                builder.New(0x7D6);
                {
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.OutOfService;
                }

                events.FailedLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, LoginResult.OutOfService));
                client.Send(builder, "Unknown_7D6");
                return;
            }

            builder.New(0x7D6);
            {
                switch (data.status)
                {
                case AuthStatus.Unverified:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Unverified;
                    break;

                case AuthStatus.Banned:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Banned;
                    break;

                case AuthStatus.IncorrectName:
                case AuthStatus.IncorrectPass:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Incorrect;
                    var tmp = data.status == AuthStatus.IncorrectName ? LoginResult.UnknownUsername : LoginResult.WrongPassword;
                    events.FailedLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, tmp));
                    break;

                case AuthStatus.Verified:
                    client.AccountID = data.id;
                    Authentication.UpdateIPDate(syncServer, client.AccountID, ip, DateTime.Now);
                    Authentication.UpdateOnline(syncServer, client.AccountID, true);
                    builder += 1;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Normal;
                    events.SuccessfulLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, LoginResult.Success, client.AccountID));
                    break;

                default:
                    kick = true;
                    break;
                }
            }

            client.Send(builder, "Unknown_7D6");

            if (kick)
            {
                client.Disconnect();
            }

            if (data.id > 0 && data.status == AuthStatus.Verified)
            {
                builder.New(0x7D6);
                {
                    builder += 1;
                    builder += 0x0900;
                    builder += (byte)0;

                    builder += (int)AccountStatus.Normal;
                    builder += 0x4B6359;
                    builder += (byte)1;
                    builder += 0x67;
                    builder += (long)0;
                    builder += (byte)0;
                    builder += 0x43A56B60;
                    builder += (byte)0;
                    builder += 1;
                    builder += 0;
                    builder += 0;
                    builder += "0A47130EA1D04A4D99D58F094B7E88C3";           // AuthKey
                    builder += (short)0;
                    builder += (byte)1;                                      // Char Num of all servers
                    builder += (byte)1;                                      // Server ID
                    builder += (byte)1;                                      // CharNum
                }

                client.Send(builder, "Unknown_7D6");

                URLToClient(packet, builder, client, events);
                SystemMessg(packet, builder, client, events);

                SendChannels.SendChannelList(client);

                var timer = new System.Timers.Timer(5000);
                timer.AutoReset = true;
                timer.Elapsed  += (sender, e) => { SendChannels.SendChannelList(client); };

                timer.Start();
                client.Metadata["timer"] = timer;
            }
        }
Exemple #2
0
        public static void Unknown_7D6(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            packet.Skip(4);
            var details = RSA.Decrypt(packet.ReadBytes(256));
            var tmpdata = new byte[16];

            Array.Copy(details, tmpdata, 16);
            var name = Encoding.UTF8.GetString(tmpdata).Trim('\0');

            Array.Copy(details, 65, tmpdata, 0, 16);
            var pass = Encoding.UTF8.GetString(tmpdata).Trim('\0');

            Log.Notice("Login authentication with name: " + name);

            var ip         = client.RemoteEndPoint.ToString().Split(':')[0];
            var syncServer = client.Metadata["syncServer"] as SyncReceiver;
            var data       = Authentication.FetchAccount(syncServer, name, pass);
            var kick       = false;

            if (data == null || data.id == -1)
            {
                builder.New(0x7D6);
                {
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.OutOfService;
                }

                events.FailedLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, LoginResult.OutOfService));
                client.Send(builder, "Unknown_7D6");
                return;
            }

            builder.New(0x7D6);
            {
                switch (data.status)
                {
                case AuthStatus.Unverified:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Unverified;
                    break;

                case AuthStatus.Banned:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Banned;
                    break;

                case AuthStatus.IncorrectName:
                case AuthStatus.IncorrectPass:
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Incorrect;
                    var tmp = data.status == AuthStatus.IncorrectName ? LoginResult.UnknownUsername : LoginResult.WrongPassword;
                    events.FailedLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, tmp));
                    break;

                case AuthStatus.Verified:
                    client.AccountID = data.id;
                    Authentication.UpdateIPDate(syncServer, client.AccountID, ip, DateTime.Now);
                    builder += 1;
                    builder += 0;
                    builder += (byte)0;
                    builder += (int)AccountStatus.Normal;
                    events.SuccessfulLogin("login.AuthAccount", new LoginEventArgs(name, pass, ip, LoginResult.Success, client.AccountID));
                    break;

                default: kick = true; break;
                }
            }

            client.Send(builder, "Unknown_7D6");

            if (kick)
            {
                client.Disconnect();
            }

            if (data.id > 0 && data.status == AuthStatus.Verified)
            {
                builder.New(0x7D6);
                {
                    builder += 1;
                    builder += 0x0700;
                    builder += (byte)0;

                    builder += (int)AccountStatus.Normal;
                    builder += 0x2FD49F;
                    builder += (byte)1;
                    builder += 0x67;
                    builder += (long)0;
                    builder += (byte)0;
                    builder += 0x55746A01;
                    builder += (byte)0;
                    builder += 1;
                    builder += 0;
                    builder += 0x02;
                    builder += "A6318A0A7D294CE2A7019511FEDB7AD7";           // AuthKey
                    builder += (short)0;
                    builder += (byte)1;                                      // Char Num of all servers
                    builder += (byte)1;                                      // Server ID
                    builder += (byte)1;                                      // CharNum
                }

                client.Send(builder, "Unknown_7D6");

                URLToClient(packet, builder, client, events);
                SystemMessg(packet, builder, client, events);

                SendChannels.SendChannelList(client);

                var timer = new System.Timers.Timer(5000);
                timer.AutoReset = true;
                timer.Elapsed  += (sender, e) => { SendChannels.SendChannelList(client); };

                timer.Start();
                client.Metadata["timer"] = timer;
            }
        }
Exemple #3
0
        public static void CheckVersion(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var version = packet.ReadInt();

            var ip            = client.RemoteEndPoint.ToString().Split(':')[0];
            var kick          = false;
            var ver           = client.Metadata["version"] as int[];
            var clientVersion = ver[0];
            var ignore        = ver[2];

            if (version != clientVersion && ignore == 0)
            {
                Log.Notice(string.Format("Failed ClientAuth IP: {0} Client ver: {1} Server ver: {2}", ip, version, clientVersion));

                if (version > clientVersion)
                {
                    events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, VersionCheckResult.NewerClient));
                }
                else
                {
                    events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, VersionCheckResult.OlderClient));
                }

                kick = true;
            }

            if (ignore == 0)
            {
                version = clientVersion;
            }

            events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, VersionCheckResult.Match));

            builder.New(0x7A);
            {
                builder += version;     // Client Version
                builder += 0x0059077C;  // Debug
                builder += 0;           // Reserved
                builder += 0;           // Reserved
            }

            client.Send(builder, "CheckVersion");

            if (kick)
            {
                events.ClientDisconnected(client, client);
                return;
            }

            var id = -2;

            var sleep = new Timer(500);

            sleep.Elapsed += (s, _e) =>
            {
                if (id == -2)
                {
                    var syncServer = client.Metadata["syncServer"] as SyncReceiver;
                    id = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);
                }

                if (id > 0)
                {
                    client.AccountID = id;
                    SendChannels.SendChannelList(client);

                    var timer = new Timer(5000);
                    timer.AutoReset = true;
                    timer.Elapsed  += (sender, e) => { SendChannels.SendChannelList(client); };

                    timer.Start();
                    client.Metadata["timer"] = timer;
                }

                sleep.Stop();
            };

            sleep.Start();
        }
Exemple #4
0
        /*
         * CheckVersion Packet
         * -------------------------
         * Client2Server Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * int      : padding
         * ushort   : opcode
         *
         * int      : version1         #client version
         * int      : version2         #debug
         * int      : version3         #reserved
         * int      : version4         #reserved
         * -------------------------
         * Server2Client Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * ushort   : opcode
         *
         * int      : version1         #client version
         * int      : version2         #debug
         * int      : version3         #reserved
         * int      : version4         #reserved
         */
        #endregion

        public static void CheckVersion(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            int version = packet.ReadInt();

            var conf = client.Metadata["conf"] as Configuration;

            if (conf == null)
            {
                return;
            }

            int clientVersion = conf.ClientVersion;

            // i dont like this one, should be way better: client.GetIpAddress();
            string ip   = client.RemoteEndPoint.ToString().Split(':')[0];
            bool   kick = false;

            if (conf.Debug)
            {
                // skipping on debug mode

                builder.New(0x7A);
                {
                    builder += version;     // Client Version
                    builder += 0;           // Debug
                    builder += 0;           // Reserved
                    builder += 0;           // Reserved
                }

                events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, VersionCheckResult.Match));

                client.Send(builder, "CheckVersion");
                return;
            }

            var result = VersionCheckResult.None;

            if (version != clientVersion)
            {
                result = version > clientVersion ? VersionCheckResult.NewerClient : VersionCheckResult.OlderClient;
                kick   = true;
                Log.Notice(string.Format("Failed CheckVersion Ip: {0} Client: {1}; Server: {2}", ip, version, clientVersion));
            }
            else
            {
                result = VersionCheckResult.Match;
            }

            events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, result));

            builder.New(0x7A);
            {
                builder += clientVersion;   // Client Version
                builder += 0;               // Debug
                builder += 0;               // Reserved
                builder += 0;               // Reserved
            }

            client.Send(builder, "CheckVersion");

            if (kick)
            {
                // we have to be sure that client will be disconnected
                // if client didnt closed it's connection, server will close after 800ms
                var waitKick = new Timer(800);
                waitKick.Elapsed += (s, _e) =>
                {
                    client.Disconnect();
                    waitKick.Stop();
                };

                waitKick.Start();
                return;
            }

            int id = -2;

            var sleep = new Timer(500);

            sleep.Elapsed += (s, _e) =>
            {
                if (id == -2)
                {
                    var syncServer = client.Metadata["syncServer"] as SyncReceiver;
                    id = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);
                }

                if (id > 0)
                {
                    client.AccountID = id;
                    SendChannels.SendChannelList(client);

                    var timer = new Timer(5000);
                    timer.AutoReset = true;
                    timer.Elapsed  += (sender, e) => { SendChannels.SendChannelList(client); };

                    timer.Start();
                    client.Metadata["timer"] = timer;
                }

                sleep.Stop();
            };

            sleep.Start();
        }