Example #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();
            }
        }
Example #2
0
        static void OnRegisterProtocol(C2SProtocol c2SProtocol, Socket socket)
        {
            RegisterProtocol registerProtocol = c2SProtocol as RegisterProtocol;

            if (registerProtocol == null)
            {
                return;
            }
            DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SQLite.EF6");

            using (var conn = dbProviderFactory.CreateConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlite"].ConnectionString;
                conn.Open();
                DbCommand command = conn.CreateCommand();

                // 判断是否已有该用户名
                command.CommandText = string.Format(@"SELECT * FROM account where user = ""{0}"" ", registerProtocol.Username);
                command.CommandType = CommandType.Text;
                command.Prepare();
                bool isExist = false;
                using (IDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        isExist = true;
                    }
                }
                if (isExist)
                {
                    RegisterRetProtocol prc = new RegisterRetProtocol(socket)
                    {
                        Res = REGISTERTYPE.EXIST
                    };
                    prc.SendData();
                    return;
                }
                // 插入该用户名
                command.CommandText = string.Format(@"
                    INSERT INTO account (user, pwd) VALUES (""{0}"", ""{1}"")", registerProtocol.Username, registerProtocol.Password);
                Console.WriteLine(command.CommandText);
                //command.CommandText = @"select * from account";

                command.CommandType = CommandType.Text;
                command.Prepare();
                int col = command.ExecuteNonQuery();
                if (col > 0)
                {
                    RegisterRetProtocol prc = new RegisterRetProtocol(socket)
                    {
                        Res = REGISTERTYPE.SUCCESS
                    };
                    prc.SendData();
                }
            }
        }
Example #3
0
    public void registerProtocol(C2SProtocol protocol, BumProtocolType type, string url, DispatchProtocolDelegate dispatchCallBack)
    {
        BumProtocolInfo newProtocolInfo = new BumProtocolInfo();

        newProtocolInfo.protocol         = protocol;
        newProtocolInfo.url              = url;
        newProtocolInfo.protocolType     = type;
        newProtocolInfo.dispatchProtocol = dispatchCallBack;

        protocolCluster.Add((int)protocol, newProtocolInfo);
    }
Example #4
0
 public void callHttpServerMethod(C2SProtocol protocol, WWWForm postForm)
 {
     send(protocol, postForm);
 }
Example #5
0
 public BumProtocolInfo getProtocolInfo(C2SProtocol protocol)
 {
     return(protocolCluster[(int)protocol]);
 }
Example #6
0
    public void send(C2SProtocol protocol, WWWForm postForm)
    {
        BumProtocolInfo pi = getProtocolInfo(protocol);

        doSend(pi, postForm);
    }