Beispiel #1
0
        static void OnUserPwdProtocol(C2SProtocol c2SProtocol, Socket socket)
        {
            UserPwdProtocol userPwdProtocol = c2SProtocol as UserPwdProtocol;

            if (userPwdProtocol == null)
            {
                return;
            }

            string user = userPwdProtocol.Username;
            string pwd  = userPwdProtocol.Password;

            //校验用户名和密码
            LOGINRESTYPE ret = Verify(user, pwd);

            //发送登录结果
            LoginResProtocol loginResProtocol = new LoginResProtocol(socket)
            {
                res = ret
            };

            loginResProtocol.SendData();
            Thread.Sleep(500);
            //发送sig
            if (ret == LOGINRESTYPE.SUCCESS)
            {
                GenerateSignature(user, out string sig);
                SignatureProtocol signatureProtocol = new SignatureProtocol(socket)
                {
                    signature = sig
                };
                signatureProtocol.SendData();
            }
        }
Beispiel #2
0
        static void Transmit(PROTOCOLTYPE type, byte[] buffer, Socket socket)
        {
            C2SProtocol c2SProtocol;

            switch (type)
            {
            case PROTOCOLTYPE.USERPWD:
                c2SProtocol = new UserPwdProtocol(buffer);
                c2SProtocol.UnMarshal();
                OnUserPwdProtocol(c2SProtocol, socket);
                break;

            case PROTOCOLTYPE.REGISTER:
                c2SProtocol = new RegisterProtocol(buffer);
                c2SProtocol.UnMarshal();
                OnRegisterProtocol(c2SProtocol, socket);
                break;
            }
        }