/// <summary>
        ///     This method is invoked when the client has been approved of connecting to the server. The client should
        ///     be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        ///     sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState state)
        {
            // Create the client for the asynchronous state:
            User client = new User(this, state.Socket, null);

            state.Client = client;
        }
Beispiel #2
0
        /// <summary>
        /// This method is invoked when the client has been approved of connecting to the server. The client should
        /// be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        /// sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState state)
        {
            var client = new Client(this, state.Socket, new NetDragonAuthenticationCipher());

            state.Client = client;
            client.Send(new MsgEncryptCode(client.IpAddress.GetHashCode()));
        }
        /// <summary>
        /// This method is invoked when the client is exchanging keys with the server to generate a common key for
        /// cipher encryptions and decryptions. This method is only implemented in the message server after
        /// patch 5017 (when Blowfish and the DH Key Exchange was implemented).
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public unsafe void Exchange(AsynchronousState state)
        {
            // Retrieve client information from the asynchronous state:
            Client client = state.Client as Client;

            if (client != null && client.Packet != null)
                fixed(byte *packet = client.Packet)
                {
                    // Process the client's packet:
                    int position     = 7;
                    int packetLength = *(int *)(packet + position); position += 4;

                    if (packetLength + 7 == client.Packet.Length)
                    {
                        // The exchange is valid. Process it:
                        int    junkLength = *(int *)(packet + position); position += 4 + junkLength;
                        int    keyLength  = *(int *)(packet + position); position += 4;
                        string key        = new string((sbyte *)packet, position, keyLength);

                        // Process the key and configure Blowfish:
                        client.Cipher = client.Exchange.Respond(key, client.Cipher as BlowfishCipher);
                    }
                    else
                    {
                        client.Disconnect();
                    }
                }
        }
        /// <summary>
        /// This method is invoked when the client has been approved of connecting to the server. The client should
        /// be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        /// sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState state)
        {
            // Create the client for the asynchronous state:
            Client client = new Client(this, state.Socket, new BlowfishCipher());

            state.Client = client;
            client.Send(client.Exchange.Request());
        }
Beispiel #5
0
        /// <summary>
        ///     This method is invoked when the client has data ready to be processed by the server. The server will
        ///     switch between the packet type to find an appropriate function for processing the packet. If the
        ///     packet was not found, the packet will be outputted to the console as an error.
        /// </summary>
        /// <param name="pState">Represents the status of an asynchronous operation.</param>
        public void Receive(AsynchronousState pState)
        {
            if (pState.Client is PatchServer pServer && pServer.Packet != null)
            {
                var type = (PacketType)BitConverter.ToUInt16(pServer.Packet, 2);
                Action <PatchServer, byte[]> action = m_pProcessor[type];

                // Process the client's packet:
                if (action != null)
                {
                    action(pServer, pServer.Packet);
                }
                else
                {
                    PatcherPacketHandler.Report(pServer.Packet);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        ///     This method is invoked when the client has been approved of connecting to the server. The client should
        ///     be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        ///     sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="pState">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState pState)
        {
            var pServer = new PatchServer(this, pState.Socket);

            pState.Client = pServer;

            Program.FrmMain.Edit(Program.FrmMain.lblCenterStatus, LabelAsyncOperation.Text, LanguageManager.GetString("StrCheckingPrivacyTerms"));

            MsgClientInfo msg = new MsgClientInfo();

            msg.MacAddress = Program.FrmMain.GetMacAddress();
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.OPERATING_SYSTEM, MsgClientInfo.OperatingSystem).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.BASE_BOARD, MsgClientInfo.BaseBoard).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PROCESSOR, MsgClientInfo.Processor).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.PHYSICAL_MEMORY, MsgClientInfo.PhysicalMemory).Values.ToArray());
            msg.Append(SystemProperties.GetObjects(MsgClientInfo.VIDEO_CONTROLLER, MsgClientInfo.VideoController).Values.ToArray());
            pServer.Send(msg);
        }
        public void Receive(AsynchronousState pState)
        {
            var pServer = pState.Client as GameServer;

            if (pServer != null && pServer.Packet != null)
            {
                var type = (PacketType)BitConverter.ToUInt16(pServer.Packet, 2);
                Action <GameServer, byte[]> action = m_packetProcessor[type];

                // Process the client's packet:
                if (action != null)
                {
                    action(pServer, pServer.Packet);
                }
                else
                {
                    MsgPacketHandler.Report(pServer.Packet);
                }
            }
        }
        /// <summary>
        ///     This method is invoked when the client has data ready to be processed by the server. The server will
        ///     switch between the packet type to find an appropriate function for processing the packet. If the
        ///     packet was not found, the packet will be outputted to the console as an error.
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public void Receive(AsynchronousState state)
        {
            User client = state.Client as User;

            if (client?.Packet != null)
            {
                // Get the packet handler from the packet processor:
                PacketType            type   = (PacketType)BitConverter.ToUInt16(client.Packet, 2);
                Action <User, byte[]> action = m_processor[type];

                // Process the client's packet:
                if (action != null)
                {
                    action(client, client.Packet);
                }
                else
                {
                    UpdaterPacketHandler.Report(client.Packet);
                }
            }
        }
        public void Connect(AsynchronousState pState)
        {
            var pClient = new GameServer(this, pState.Socket, null);

            pState.Client = pClient;
        }
Beispiel #10
0
        /// <summary>
        /// This method is invoked when the client has data ready to be processed by the server. The server will
        /// switch between the packet type to find an appropriate function for processing the packet. If the
        /// packet was not found, the packet will be outputted to the console as an error.
        /// </summary>
        /// <param name="state">Represents the status of an asynchronous operation.</param>
        public void Receive(AsynchronousState state)
        {
            // Retrieve client information from the asynchronous state:
            var pClient = state.Client as Client;

            if (pClient != null && pClient.Packet != null) // check if it's alright
            {
                var type = (PacketType)BitConverter.ToUInt16(pClient.Packet, 2);
                Action <Client, byte[]> action = m_pProcessor[type];

                // Process the client's packet:
                if (action != null)
                {
                    action(pClient, pClient.Packet);
                }
                else
                {
                    LoginPacketHandler.Report(pClient.Packet);
                }

                #region Moved
                //byte[] pPacket = pClient.Packet;
                //var pType = (PacketType)BitConverter.ToInt16(pPacket, 2);

                //if (BitConverter.ToUInt16(pPacket, 0) == 276 &&
                //    (pType == PacketType.AUTHENTICATION_REQUEST))
                //{
                //    var pRequest = new AuthenticationRequest(pPacket, pClient.IpAddress.GetHashCode());

                //    // tells the console that the user x is trying to login on server y
                //    ServerKernel.Log.SaveLog(string.Format("User [{0}] is trying to login on server [{1}].",
                //        pClient.Account, pRequest.Server));

                //    // let's check if user is spamming login requests
                //    LoginAttemptRecord pLogin = null;
                //    if (!ServerKernel.LoginAttemptRecords.TryGetValue(pClient.IpAddress, out pLogin))
                //    {
                //        pLogin = new LoginAttemptRecord(pClient.IpAddress);
                //        ServerKernel.LoginAttemptRecords.TryAdd(pLogin.IpAddress, pLogin);
                //    }

                //    if (!pLogin.Enabled) // user spamming login?
                //    {
                //        pClient.Send(new AuthenticationResponse(RejectionType.MAXIMUM_LOGIN_ATTEMPTS));
                //        ServerKernel.Log.SaveLog(
                //            string.Format("User [{0}] has passport denied due to exceeding login limit on IP [{1}].",
                //                pRequest.Account, pClient.IpAddress), true, "LoginServer");
                //        pClient.Disconnect();
                //        return;
                //    }

                //    DbAccount pUser = Database.Accounts.SearchByName(pRequest.Account); // fetch user information
                //    if (pUser != null) // user exists?
                //    {
                //        // yes
                //        pClient.Account = pUser;

                //        // check uncommon characters
                //        var szPw = string.Empty;
                //        foreach (var c in pRequest.Password)
                //        {
                //            switch (c)
                //            {
                //                case '-':
                //                    szPw += '0';
                //                    break;
                //                case '#':
                //                    szPw += '1';
                //                    break;
                //                case '(':
                //                    szPw += '2';
                //                    break;
                //                case '"':
                //                    szPw += '3';
                //                    break;
                //                case '%':
                //                    szPw += '4';
                //                    break;
                //                case '\f':
                //                    szPw += '5';
                //                    break;
                //                case '\'':
                //                    szPw += '6';
                //                    break;
                //                case '$':
                //                    szPw += '7';
                //                    break;
                //                case '&':
                //                    szPw += '8';
                //                    break;
                //                case '!':
                //                    szPw += '9';
                //                    break;
                //                default:
                //                    szPw += c;
                //                    break;
                //            }
                //        }

                //        bool bSuccess = true;
                //        // check if user has input the right password
                //        if (pUser.Password != szPw)
                //        {
                //            // invalid pw
                //            pClient.Send(new AuthenticationResponse(RejectionType.INVALID_PASSWORD));
                //            ServerKernel.Log.SaveLog(
                //                string.Format("User [{0}] entered an invalid password [{1}].", pUser.Username,
                //                    pClient.IpAddress), true, "LoginServer");
                //            pClient.Disconnect();
                //            return;
                //        }

                //        if (pUser.Status == 1) // user is banned?
                //        {
                //            // banned
                //            pClient.Send(new AuthenticationResponse(RejectionType.ACCOUNT_BANNED));
                //            ServerKernel.Log.SaveLog(
                //                string.Format("User [{0}] has passport denied due to account lock status.",
                //                    pUser.Username), true, "LoginServer");
                //            pClient.Disconnect();
                //            return;
                //        }

                //        if (pUser.Status == -1) // user has activated account?
                //        {
                //            pClient.Send(new AuthenticationResponse(RejectionType.ACCOUNT_NOT_ACTIVATED));
                //            ServerKernel.Log.SaveLog(
                //                string.Format("User [{0}] has passport denied due to account inactive status.",
                //                    pUser.Username), true, "LoginServer");

                //            pClient.Disconnect();
                //            return;
                //        }

                //        GameServer pServer;
                //        if (!ServerKernel.OnlineServers.TryGetValue(pRequest.Server, out pServer))
                //        // server is not online
                //        {
                //            pClient.Send(new AuthenticationResponse(RejectionType.SERVER_MAINTENANCE));
                //            ServerKernel.Log.SaveLog(
                //                string.Format("User [{0}] tried to login on a invalid server [{1}].", pUser.Username,
                //                    pRequest.Server), true, "LoginServer");

                //            pClient.Disconnect();
                //            return;
                //        }

                //        uint dwHash = (uint)ThreadSafeRandom.RandGet(1000, int.MaxValue);

                //        var pTransferCipher = new TransferCipher(ServerKernel.LoginTransferKey,
                //            ServerKernel.LoginTransferSalt, pClient.IpAddress);
                //        var pCrypto = pTransferCipher.Encrypt(new[] { pUser.Identity, dwHash });

                //        string szAddress = "135.12.15.139"; // random ip just to connect
                //        if (!pServer.IpAddress.StartsWith("127") && pServer.IpAddress != "localhost")
                //            szAddress = pServer.IpAddress;

                //        pServer.Send(new MsgUsrLogin(pUser.Identity, dwHash) { IpAddress = pClient.IpAddress });

                //        pClient.Send(new AuthenticationResponse(pCrypto[0], pCrypto[1], szAddress, 5816));
                //        ServerKernel.Log.SaveLog(string.Format("User [{0}] has successfully logged into {1}.",
                //            pUser.Username, pRequest.Server), true, LogType.MESSAGE);
                //        return;
                //    }
                //    else
                //    {
                //        // no
                //        pClient.Send(new AuthenticationResponse(RejectionType.INVALID_ACCOUNT));
                //        ServerKernel.Log.SaveLog(
                //            string.Format("User [{0}] doesn't exist. Connection [{1}].", pRequest.Account,
                //                pClient.IpAddress), true, "LoginServer");
                //    }
                //}
                //else
                //{
                //    pClient.Send(new AuthenticationResponse(RejectionType.INVALID_AUTHENTICATION_PROTOCOL));
                //    ServerKernel.Log.SaveLog(string.Format("User has tried to connect with an invalid protocol at {0}.", pClient.IpAddress));
                //}

                //pClient.Disconnect();
                #endregion
            }
        }
Beispiel #11
0
        /// <summary>
        /// This method is invoked when the client has been approved of connecting to the server. The client should
        /// be constructed in this method, and cipher algorithms should be initialized. If any packets need to be
        /// sent in the connection state, they should be sent here.
        /// </summary>
        /// <param name="pState">Represents the status of an asynchronous operation.</param>
        public void Connect(AsynchronousState pState)
        {
            var pServer = new LoginClient(this, pState.Socket, null);

            pState.Client = pServer;
        }