Beispiel #1
0
        private void OnFindPasswordClick()
        {
            if (string.IsNullOrEmpty(newpw_field.text) || string.IsNullOrEmpty(acc_field.text))
            {
                Debug.Log("[Warn] input nothing.");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "账号或密码为空,请输入您的信息。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
                return;
            }

            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                string host = Root.IP;
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }

            if (!isChangePw)
            {
                isChangePw = true;
            }

            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.ChangePassword);
            proto.AddInfo <string>(acc_field.text);
            proto.AddInfo <string>(newpw_field.text);
            NetworkManager.ConnClient.Send(proto);
        }
Beispiel #2
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;
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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;
            }
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        private void OnLoginClick()
        {
            if (!isLogin)
            {
                isLogin = !isLogin;
            }

#if NETWORK
            if (string.IsNullOrEmpty(acc_field.text) || string.IsNullOrEmpty(pw_field.text))
            {
                Debug.Log("[Warn] input nothing.");
                return;
            }

            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                string host = Root.IP;
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }

            ProtocolByte proto = new ProtocolByte();
            proto.AddInfo <string>(NamesOfProtocol.Login);
            proto.AddInfo <string>(acc_field.text);
            proto.AddInfo <string>(pw_field.text);
            NetworkManager.ConnClient.Send(proto);
#elif DEBUG
            Debug.Log("登录成功--game start");
            base.Close();
            object[] objs = new object[1];
            objs[0] = 1;
            PanelManager._instance.OpenPanel <LoadingPanel>("", objs);
#endif
        }
        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);
            }
        }
        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);
            }
        }
        public void Logout()
        {
            ProtocolByte protoRet = new ProtocolByte();

            protoRet.AddInfo <string>(NamesOfProtocol.Logout);
            protoRet.AddInfo <string>(Root.Account);

            NetworkManager.ConnClient.Send(protoRet);
        }
Beispiel #11
0
        public void UpdateLocation(Vector3 postion)
        {
            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.UpdatePosition);
            proto.AddInfo <string>(Root.Account);
            proto.AddInfo <float>(postion.x);
            proto.AddInfo <float>(postion.y);
            proto.AddInfo <float>(postion.z);

            NetworkManager.ConnClient.Send(proto);
        }
        public void RemoteSaveData(object sender, EventArgs args)
        {
            ProtocolByte protoRet = new ProtocolByte();

            protoRet.AddInfo <string>(NamesOfProtocol.SendPlayerData);
            protoRet.AddInfo <string>(Root.Account);
            protoRet.AddInfo <int>(this.playerData.Coin);
            protoRet.AddInfo <int>(this.playerData.Money);
            protoRet.AddInfo <int>(this.playerData.Star);
            protoRet.AddInfo <int>(this.playerData.Diamand);

            NetworkManager.ConnClient.Send(protoRet);
        }
Beispiel #13
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.");
            }
        }
Beispiel #14
0
        public void MsgLogout(Connection conn, ProtocolBase protocol)
        {
            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.Logout);
            proto.AddInfo <int>(1);
            if (conn.Player == null)
            {
                conn.Send(proto);
                conn.Close();
            }
            else
            {
                conn.Send(proto);
                conn.Player.Logout();
            }
        }
Beispiel #15
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);
        }
        IEnumerator ReceivePlayerData()
        {
            yield return(null);

            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                //string host = "127.0.0.1";
                string host = "192.168.1.105";
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }
            ProtocolByte proto = new ProtocolByte();

            proto.Expression = "";
            proto.AddInfo <string>(NamesOfProtocol.ReceivePlayerData);
            proto.AddInfo <string>(Root.Account);
            NetworkManager.ConnClient.Send(proto);
        }
Beispiel #17
0
        public void SendOriginPos()
        {
            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                //string host = "127.0.0.1";
                string host = Root.IP;
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }

            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.SendOriginPos);
            proto.AddInfo <string>(Root.Account);
            proto.AddInfo <float>(originPos.x);
            proto.AddInfo <float>(originPos.y);
            proto.AddInfo <float>(originPos.z);

            NetworkManager.ConnClient.Send(proto);
        }
        private void OnRegisterClick()
        {
            if (string.IsNullOrEmpty(acc_field.text) || string.IsNullOrEmpty(pw_field.text) || string.IsNullOrEmpty(pwtwin_field.text))
            {
                Debug.Log("[Warn] input nothing.");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "账号或密码空,请输入您的信息。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
                return;
            }
            if (pw_field.text != pwtwin_field.text)
            {
                Debug.Log("[Warn] twice password is not the same.");
                object[] obj = new object[2];
                obj[0] = "错误提示";
                obj[1] = "你输入的两次密码不符合,请检查后重试。";
                PanelManager._instance.OpenPanel <MentionPanel>("", obj);
                return;
            }

            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                string host = Root.IP;
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }

            if (!isRegster)
            {
                isRegster = true;
            }

            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.Register);
            proto.AddInfo <string>(acc_field.text);
            proto.AddInfo <string>(pw_field.text);
            NetworkManager.ConnClient.Send(proto);
        }
Beispiel #19
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);
            }
        }
Beispiel #20
0
        IEnumerator SendPlayerData()
        {
            yield return(null);

            if (NetworkManager.ConnClient.status != NetworkStatus.Connected)
            {
                //string host = "127.0.0.1";
                string host = "192.168.1.105";
                int    port = 1234;
                NetworkManager.ConnClient.Connect(host, port);
            }
            ProtocolByte proto = new ProtocolByte();

            proto.AddInfo <string>(NamesOfProtocol.SendPlayerData);
            proto.AddInfo <string>(Root.Account);
            proto.AddInfo <int>(DataManager.GetInstance().playerData.Coin);
            proto.AddInfo <int>(DataManager.GetInstance().playerData.Money);
            proto.AddInfo <int>(DataManager.GetInstance().playerData.Star);
            proto.AddInfo <int>(DataManager.GetInstance().playerData.Diamand);

            NetworkManager.ConnClient.Send(proto);
        }
Beispiel #21
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);
            }
        }
 public static ProtocolBase GetHeartBeatProtocol()
 {
     ProtocolByte protocol = new ProtocolByte();
     protocol.AddInfo<string>("HeartBeat");
     return protocol;
 }