Пример #1
0
        public void MsgLogin(Connection conn, ProtocolBase protocol)
        {
            ProtocolByte proto     = protocol as ProtocolByte;
            string       protoName = proto.Name;
            string       id        = proto.GetString(1);
            string       pw        = proto.GetString(2);

            //准备返回协议对象
            ProtocolByte protoRet = new ProtocolByte();

            protoRet.AddInfo <string>(NamesOfProtocol.Login);

            //从数据库判断
            bool isChecked = DataManager.GetSingleton().CheckPassword(id, pw);

            if (isChecked)
            {
                Console.WriteLine($"[Conected] User:{id},Info:{conn.RemoteAddress}.");
                protoRet.AddInfo <int>(1);
                conn.Send(protoRet);
                return;
            }
            else
            {
                protoRet.AddInfo <int>(0);
                conn.Send(protoRet);
                return;
            }
        }
        void OnReceivePlayerDataBack(ProtocolBase protocol)
        {
            ProtocolByte proto = protocol as ProtocolByte;
            string       id    = proto.GetString(1);

            if (id == Root.Account)
            {
                //初始化客户端的游戏数据
                int coin    = Convert.ToInt32(proto.GetString(2));
                int money   = Convert.ToInt32(proto.GetString(3));
                int star    = Convert.ToInt32(proto.GetString(4));
                int diamand = Convert.ToInt32(proto.GetString(5));

                if (DataManager.GetInstance().playerData != null)
                {
                    DataManager.GetInstance().playerData.Init(coin, money, star, diamand);
                }
            }
            else
            {
                Debug.Log("[Error]获取数据失败...");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "初始化数据失败,请退出,重新操作";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
        }
Пример #3
0
        public void MsgFindPassword(Connection conn, ProtocolBase protocol)
        {
            ProtocolByte proto     = protocol as ProtocolByte;
            string       protoName = proto.Name;
            string       id        = proto.GetString(1);
            string       code_str  = proto.GetString(2);
            string       password  = string.Empty;
            int          code_i    = Convert.ToInt32(code_str);

            //准备返回协议对象
            ProtocolByte protoRet = new ProtocolByte();

            protoRet.AddInfo <string>(NamesOfProtocol.FindPassword);

            //从数据库判断
            bool isChecked = DataManager.GetSingleton().FindoutPassword(id, code_i);

            if (isChecked)
            {
                Console.WriteLine($"[FindPassword] User:{id},Info:{conn.RemoteAddress}.");
                protoRet.AddInfo <int>(1);
                conn.Send(protoRet);
                return;
            }
            else
            {
                protoRet.AddInfo <int>(-1);
                conn.Send(protoRet);
                return;
            }
        }
Пример #4
0
        public void MsgRegister(Connection conn, ProtocolBase protocol)
        {
            ProtocolByte proto     = protocol as ProtocolByte;
            string       protoName = proto.Name;
            string       id        = proto.GetString(1);
            string       pw        = proto.GetString(2);
            int          code      = int.MinValue;

            //准备返回协议对象
            ProtocolByte protoRet = new ProtocolByte();

            protoRet.AddInfo <string>(NamesOfProtocol.Register);

            //从数据库判断
            bool isChecked = DataManager.GetSingleton().CanRegister(id);

            if (isChecked)
            {
                DataManager.GetSingleton().Register(id, pw, out code);
                Console.WriteLine($"[Register] User:{id},Info:{conn.RemoteAddress}.");
                protoRet.AddInfo <int>(1);
                protoRet.AddInfo <int>(code);
                conn.Send(protoRet);
                return;
            }
            else
            {
                protoRet.AddInfo <int>(-1);
                conn.Send(protoRet);
                return;
            }
        }
        private void OnRegisterBack(ProtocolBase protocol)
        {
            if (isRegster)
            {
                isRegster = false;
            }

            ProtocolByte proto = protocol as ProtocolByte;
            string       num   = proto.GetString(1);
            string       code  = proto.GetString(2);

            if (num == "1")
            {
                Debug.Log("注册成功--game start");
                code_txt.text = code;
                object[] obj = new object[2];
                obj[0] = "重要提示";
                obj[1] = string.Format("注册账号成功!你的口令是:[{0}]   请牢记你的密码,此口令用于修改密码操作。", code);
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
            else
            {
                Debug.Log("注册失败--password is error");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "您输入的账号已经注册,请返回到登录界面进行登录。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
        }
Пример #6
0
        private void OnChangePasswordBack(ProtocolBase protocol)
        {
            if (isChangePw)
            {
                isChangePw = false;
            }

            ProtocolByte proto = protocol as ProtocolByte;
            string       num   = proto.GetString(1);

            if (num == "1")
            {
                Debug.Log("修改密码成功");
                object[] obj = new object[2];
                obj[0] = "信息提示";
                obj[1] = "修改密码成功,请返回登录界面进行登录";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
            else
            {
                Debug.Log("修改密码失败");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "修改密码失败,请输入合法的新密码";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
        }
Пример #7
0
        private void OnFindPasswordBack(ProtocolBase protocol)
        {
            if (isFindout)
            {
                isFindout = false;
            }

            ProtocolByte proto = protocol as ProtocolByte;
            string       num   = proto.GetString(1);

            if (num == "1")
            {
                Debug.Log("验证成功");
                base.Close();
                PanelManager._instance.OpenPanel <ChangePWPanel>("", null);
            }
            else
            {
                Debug.Log("注册失败--password is error");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "您输入的账号不存在或者口令错误,请检查后重新操作。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
        }
Пример #8
0
        private void OnSendOriginPosBack(ProtocolBase protocol)
        {
            ProtocolByte proto     = protocol as ProtocolByte;
            string       protoName = proto.Name;

            //初始化服务器中已存在的对象数据
            string  id  = proto.GetString(1);
            string  x   = proto.GetString(2);
            string  y   = proto.GetString(3);
            string  z   = proto.GetString(4);
            float   x_f = Convert.ToSingle(x);
            float   y_f = Convert.ToSingle(y);
            float   z_f = Convert.ToSingle(z);
            Vector3 pos = new Vector3(x_f, y_f, z_f);

            CreateOtherPlayers(id, pos);
        }
Пример #9
0
        public void UpdateLocationBack(ProtocolBase protocol)
        {
            ProtocolByte proto = protocol as ProtocolByte;
            string       id    = proto.GetString(1);
            string       x     = proto.GetString(2);
            string       y     = proto.GetString(3);
            string       z     = proto.GetString(4);
            float        x_f   = Convert.ToSingle(x);
            float        y_f   = Convert.ToSingle(y);
            float        z_f   = Convert.ToSingle(z);

            Vector3 pos = new Vector3(x_f, y_f, z_f);

            if (players.ContainsKey(id))
            {
                playersModel[id].transform.position = pos;
            }
            else
            {
                CreateOtherPlayers(id, pos);
            }
        }
Пример #10
0
        void OnSendPlayerDataBack(ProtocolBase protocol)
        {
            ProtocolByte proto = protocol as ProtocolByte;
            string       num   = proto.GetString(1);

            if (num == "1")
            {
                Debug.Log("upload data is successful.");
            }
            else
            {
                Debug.Log("upload data is fail.");
            }
        }
Пример #11
0
        private void OnLoginBack(ProtocolBase protocol)
        {
            if (isLogin)
            {
                isLogin = !isLogin;
            }

            ProtocolByte proto = protocol as ProtocolByte;
            string       num   = proto.GetString(1);

            if (num == "1")
            {
                Debug.Log("登录成功--game start");
                Root.Account = acc_field.text;
                base.Close();
                object[] objs = new object[1];
                objs[0] = 1;
                PanelManager._instance.OpenPanel <LoadingPanel>("", objs);
                _msgDistri.DeleteListener(NamesOfProtocol.Login);
            }
            else if (num == "-1")
            {
                Debug.Log("登录失败--password is error");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "账号已登录,已踢出操作,请重新登录。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
            else
            {
                Debug.Log("登录失败--password is error");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "账号或密码错误,请检查信息后,再进行操作。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
            }
        }