Пример #1
0
    void RecvCallback(byte[] buf)
    {
        ushort buflen = 0;
        ushort appid  = 0;
        uint   numid  = 0;
        uint   xyid   = 0;

        if (ProtocolBase.getProtolHand(buf, out buflen, out appid, out numid, out xyid))
        {
            if (xyid == (uint)HANDTYPE.XYID_SRS_RESP_CONNECT)
            {
                RespConnect resp = new RespConnect();
                resp.make(buf);
                Debug.Log("连接回复:connid=" + resp.connid);

                ReqLogin req    = new ReqLogin(resp.connid, "test3003", "123456");
                byte[]   reqbuf = req.pack();
                m_socket.sendBuf(reqbuf);
            }
            else if (xyid == (uint)HANDTYPE.XYID_SRS_RESP_LOGIN)
            {
                RespLogin resp = new RespLogin();
                resp.make(buf);
                Debug.Log("登录回复:flag=" + resp.flag + ",numid=" + resp.numid);
            }
        }
        else
        {
            Debug.Log("解析协议头失败");
        }
    }
Пример #2
0
    private void OnLoginResp(SocketModel model)
    {
        RespLogin resp = SerializeUtil.Deserialize <RespLogin>(model.message);

        if (resp.msgtips == (uint)MsgTips.LoginSuccess)
        {
            // 请求获取角色信息
            ReqCharactersInfo req = new ReqCharactersInfo();
            req.characterid = 0;
            Net.instance.Send((int)MsgID.CHAR_INFO_CREQ, req);
        }
        else
        {
            MessageBox.Show(((MsgTips)resp.msgtips).ToString());
        }
    }
Пример #3
0
    private void OnLogin(UserToken token, SocketModel model)
    {
        ReqLogin req = SerializeUtil.Deserialize <ReqLogin>(model.message);

        RespLogin resp = new RespLogin();

        string             sql      = string.Format("select * from account where account = '{0}'", req.account);
        List <AccountData> accDatas = MysqlManager.instance.ExecQuery <AccountData>(sql);

        if (accDatas.Count <= 0)         // 没有这个账号
        {
            resp.msgtips = (uint)MsgTips.NoAccount;
        }
        else                            // 有这个账号
        {
            AccountData acc = accDatas[0];

            if (CacheManager.instance.IsAccountOnline(acc.id))     // 账号已经在线,就不让再登录了
            {
                resp.msgtips = (uint)MsgTips.AccountHasOnline;
            }
            else
            {
                if (acc.password == req.password)
                {
                    resp.msgtips = (uint)MsgTips.LoginSuccess;

                    CacheManager.instance.AccountOnline(acc.id, acc.account, acc.password);

                    token.accountid = acc.id;
                }
                else
                {
                    resp.msgtips = (uint)MsgTips.PasswordError;
                }
            }
        }

        NetworkManager.Send(token, (int)MsgID.ACC_LOGIN_SRES, resp);
    }
Пример #4
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtUserName.Text == "" || txtUserName.Text == null)
            {
                txtUserName.Text = "";
                txtUserName.Text = "";
                //Label1.Text = "Please Enter User Name";
                //Label1.Visible = true;
                add = " Kindly enter username ! ";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Warning('" + add + "');", true);
                return;
            }
            if (txtPassword.Text == "" || txtPassword.Text == null)
            {
                txtUserName.Text = "";
                txtPassword.Text = "";
                //Label1.Text = "Please Enter Password";
                //Label1.Visible = true;
                add = " Kindly enter Password ! ";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Warning('" + add + "');", true);
                return;
            }
            var    decodedString1 = Base64.Decode(txtUserName.Text);
            string Uname          = TrimString(System.Text.Encoding.UTF8.GetString(decodedString1), '&');

            var    decodedString2 = Base64.Decode(txtPassword.Text);
            string Pwd            = TrimString(System.Text.Encoding.UTF8.GetString(decodedString2), '*');

            ReqLogin objReqLogin = new ReqLogin();
            objReqLogin.UserName   = Uname;
            objReqLogin.Password   = Pwd;
            objReqLogin.TerminalID = cmbTerminalID.Text;

            WebClient objWC = new WebClient();
            objWC.Headers[HttpRequestHeader.ContentType] = "text/json";

            DataContractJsonSerializer objJsonSerSend = new DataContractJsonSerializer(typeof(ReqLogin));
            MemoryStream memStrToSend = new MemoryStream();
            objJsonSerSend.WriteObject(memStrToSend, objReqLogin);

            string data = Encoding.Default.GetString(memStrToSend.ToArray());

            string result = objWC.UploadString(URL + "/Login", "POST", data);

            MemoryStream memstrToReceive = new MemoryStream(Encoding.UTF8.GetBytes(result));
            DataContractJsonSerializer objJsonSerRecv = new DataContractJsonSerializer(typeof(RespLogin));
            RespLogin objRespLogin = (RespLogin)objJsonSerRecv.ReadObject(memstrToReceive);

            if (objRespLogin.Result)
            {
                if (objRespLogin.OtherData == "success")
                {
                    Session["Username"]   = Uname;
                    Session["Role"]       = Uname;
                    Session["Location"]   = null;
                    Session["TerminalID"] = cmbTerminalID.Text;
                    Session["Privileges"] = objRespLogin.Privileges;
                    Response.Redirect("Dashboard//DashboardUser.aspx", false);
                }
                else if (objRespLogin.OtherData == "location")
                {
                    Session["Username"] = Uname;
                    //Session["Role"] = response[1];
                    //Session["Location"] = response[2];
                    Response.Redirect("Dashboard//DashboardUser.aspx", false);
                }
                else if (objRespLogin.OtherData.Contains("redirect"))
                {
                    string[] uid = objRespLogin.OtherData.Split('#');
                    Session["Username"]   = Uname;
                    Session["Role"]       = Uname;
                    Session["TerminalID"] = cmbTerminalID.Text;
                    Response.Redirect("Dashboard/ResetPassword.aspx?Username="******"&UID=" + Convert.ToBase64String(Encoding.ASCII.GetBytes(uid[1])), false);
                }
            }
            else
            {
                txtUserName.Text = "";
                txtPassword.Text = "";
                add = " Enter User Name & Password  Wrong ! ";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "Failed('" + add + "');", true);
                return;
            }
        }
        catch (Exception ex)
        {
            //  Session["Username"] = null;
            txtUserName.Text = "";
            txtPassword.Text = "";
        }
    }
Пример #5
0
        protected override void Initialize()
        {
            // 로그인
            procedurePool.AddProcedure <ReqLogin, RespLogin>("ReqLogin", "RespLogin", UserType.Guest, (recv, send) =>
            {
                var id   = recv.param.userid;
                var pass = recv.param.password;

                sqlHelper.RunSqlSession((sql) =>
                {
                    var sendParam = new RespLogin();

                    var cmd         = sql.CreateCommand();
                    cmd.CommandText = "select iduser, password, is_admin, is_blinded from user where iduser = @id";
                    cmd.Parameters.AddWithValue("@id", id);

                    var reader = cmd.ExecuteReader();
                    if (!reader.HasRows)                                                                                                        // 맞는 유저가 없는 경우
                    {
                        send.header.code = Packet.Header.Code.ClientSideError;
                        sendParam.status = RespLogin.Status.WrongPassword;
                    }
                    else
                    {
                        reader.Read();

                        if (reader.GetString("password") != pass)                                                               // 패스워드 틀린 경우
                        {
                            send.header.code = Packet.Header.Code.ClientSideError;
                            sendParam.status = RespLogin.Status.WrongPassword;
                        }
                        else if (reader.GetBoolean("is_blinded"))                                                               // 유저 차단된 경우
                        {
                            send.header.code = Packet.Header.Code.ClientSideError;
                            sendParam.status = RespLogin.Status.BlindedUser;
                        }
                        else
                        {                                                                                                                                               // 다 통과했으면 로그인시켜준다...
                            var isadmin = reader.GetBoolean("is_admin");
                            var utype   = isadmin? UserType.Administrator : UserType.Registered;
                            var newkey  = authServer.SetupNewAuthKey(id, utype);                                                        // 새 authkey 생성해서 설정

                            send.header.code   = Packet.Header.Code.OK;
                            sendParam.status   = RespLogin.Status.OK;
                            sendParam.authKey  = newkey;
                            sendParam.userType = utype;
                        }

                        reader.Close();
                    }

                    send.SetParameter(sendParam);
                });
            });

            // 현재 Auth 유효한지 체크
            procedurePool.AddProcedure <EmptyParam, EmptyParam>("ReqCheckAuth", "RespCheckAuth", UserType.Guest, (recv, send) =>
            {
                var validkey     = authServer.GetUserIDFromAuthKey(recv.header.authKey) != null;
                send.header.code = validkey ? Packet.Header.Code.OK : Packet.Header.Code.AuthNeeded;
            });
        }