Пример #1
0
    public void OnRegisterOKPress()
    {
        PageManager.Instance.ShowDialog(LoginDialog.Instance, PageManager.AnimationType.MiddleZoomOut);

        if (m_registerPassword.text != m_registerPassword2.text)
        {
            LoginDialog.Instance.SetTips("两次密码输入不一致");
            return;
        }

        //到后台注册用户
        NETWORK_DATA_PROTOCOL.Protocol protocol = new NETWORK_DATA_PROTOCOL.Protocol();
        protocol.seq     = TcpManager.Instance.GetConnectSeq();
        protocol.command = (UInt16)NETWORK_DATA_PROTOCOL.CMD.REGISTER;

        NETWORK_DATA_PROTOCOL.DoRegisterReq request
            = new NETWORK_DATA_PROTOCOL.DoRegisterReq();

        request          = new NETWORK_DATA_PROTOCOL.DoRegisterReq();
        request.name     = m_registerUserName.text;
        request.password = m_registerPassword.text;

        protocol.request = JsonConvert.SerializeObject(request);

        SignalModule.FuncWithParam1 <string> callback = OnRegisterCallBack;
        TcpManager.Instance.SendAndRecieve(JsonConvert.SerializeObject(protocol), callback);
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        //拉取房间列表
        NETWORK_DATA_PROTOCOL.Protocol protocol = new NETWORK_DATA_PROTOCOL.Protocol();
        protocol.seq     = TcpManager.Instance.GetConnectSeq();
        protocol.command = (UInt16)NETWORK_DATA_PROTOCOL.CMD.GET_ROOM_LIST;

        SignalModule.FuncWithParam1 <string> callback = ShowRoomList;
        TcpManager.Instance.SendAndRecieve(JsonConvert.SerializeObject(protocol), callback);
    }
Пример #3
0
    public void send(string request, Delegate callback)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(request);

        //注册回调
        SignalModule.SignalMgr.instance.Subscribe(get_signal((ulong)protocol.seq), callback, true);
        send(request);

        Debug.Log("send data." + request);
    }
Пример #4
0
    public void OnGameStart(string data)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol> (data);

        NETWORK_DATA_PROTOCOL.DoStart request
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.DoStart> (protocol.request);

        WorldPage.Instance.UpdatePlayerStatus(request.status);
        WorldPage.Instance.survive = request.survive;
        PageManager.Instance.ShowPage(WorldPage.Instance);
    }
Пример #5
0
    public void OnRegisterCallBack(string respone)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(respone);

        if (protocol.ret == 0)
        {
            LoginDialog.Instance.SetTips("注册成功");
        }
        else
        {
            LoginDialog.Instance.SetTips(protocol.msg);
        }
    }
Пример #6
0
    public void EnterSence(string respone)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(respone);

        if (protocol.ret == 0)
        {
            //加载下一个场景
            SceneManager.LoadScene("game", LoadSceneMode.Single);
        }
        else
        {
            Debug.LogError(protocol.msg);
        }
    }
Пример #7
0
    public void recieve()
    {
        string returnData = client.GetRecvStr();

        if (returnData != null)
        {
            foreach (char ch in returnData)
            {
                switch (ch)
                {
                case protocol_begin:
                    buf_temp = "";
                    break;

                case protocol_end:
//					Debug.Log (buf_temp);
                    recieve_data.Enqueue(buf_temp);
                    break;

                default:
                    buf_temp += ch;
                    break;
                }
            }

            while (recieve_data.Count > 0)
            {
                string respone = recieve_data.Dequeue();

                Debug.Log("recieve data." + respone);

                NETWORK_DATA_PROTOCOL.Protocol protocol
                    = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(respone);

                if (protocol.respone)
                {
                    //事件分发
                    SignalModule.SignalMgr.instance.Raise(get_signal((ulong)protocol.seq), respone);
                }
                else
                {
                    SignalModule.SignalMgr.instance.Raise((ulong)SignalModule.GAME_EVT.DATA_SYNC, respone);
                }
            }
        }
    }
Пример #8
0
    public void ShowRoomList(string data)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(data);

        NETWORK_DATA_PROTOCOL.GetRoomListRsp respone
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.GetRoomListRsp>(protocol.request);

        if (protocol.ret == 0)
        {
            foreach (var room in respone.roomlist)
            {
                GameObject newRoom = MonoBehaviour.Instantiate(m_room, GameObject.Find("Content").transform);
                newRoom.transform.GetComponent <RoomInfo> ().id   = room.id;
                newRoom.transform.GetComponent <RoomInfo> ().name = room.name;
            }
        }
    }
Пример #9
0
    public void OnOpenRoom()
    {
        //获取房间号
        int iRoomID = int.Parse(id);

        //保存数据
        PlayerPrefs.SetInt("roomid", iRoomID);
        //请求加入场景
        NETWORK_DATA_PROTOCOL.Protocol protocol = new NETWORK_DATA_PROTOCOL.Protocol();
        protocol.seq     = TcpManager.Instance.GetConnectSeq();
        protocol.command = (UInt16)NETWORK_DATA_PROTOCOL.CMD.ENTER_ROOM;

        NETWORK_DATA_PROTOCOL.DoEnterRoomReq request = new NETWORK_DATA_PROTOCOL.DoEnterRoomReq();
        request.name     = Player.instance.UserName;
        request.room     = iRoomID.ToString();
        protocol.request = JsonConvert.SerializeObject(request);

        SignalModule.FuncWithParam1 <string> callback = EnterSence;
        TcpManager.Instance.SendAndRecieve(JsonConvert.SerializeObject(protocol), callback, "sence");
    }
Пример #10
0
    public void OnLoginCallBack(string data)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(data);

        NETWORK_DATA_PROTOCOL.DoLoginRsp respone
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.DoLoginRsp> (protocol.request);

        if (protocol.ret == 0)
        {
            //保存用户信息
            Player.instance.AccountToken = respone.key;
            Player.instance.UserName     = m_loginUserName.text;
            //加载下一个场景
            SceneManager.LoadScene("main", LoadSceneMode.Single);
        }
        else
        {
            m_loginTips.text = protocol.msg;
        }
    }
Пример #11
0
    public void OnGameOver(string data)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol> (data);

        if (protocol.command == (UInt16)NETWORK_DATA_PROTOCOL.CMD.END_ROOM)
        {
            NETWORK_DATA_PROTOCOL.DoEnd request
                = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.DoEnd> (protocol.request);

            string end_text = "winer:";
            foreach (var status in request.status)
            {
                end_text += status.Key;
                break;
            }

            PageManager.Instance.ShowPage(EndPage.Instance);
            EndPage.Instance.SetResult(end_text);
        }
    }
Пример #12
0
    public void UpdatePlayerStatus(string data)
    {
        NETWORK_DATA_PROTOCOL.Protocol protocol
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.Protocol>(data);

        time = protocol.time;

        NETWORK_DATA_PROTOCOL.DoSynchronize request
            = JsonConvert.DeserializeObject <NETWORK_DATA_PROTOCOL.DoSynchronize> (protocol.request);

        if (protocol.time < time)
        {
            return;
        }

        UpdatePlayerStatus(request.status);

        if (request.expired != null)
        {
            foreach (var playerid in request.expired)
            {
                if (m_players.ContainsKey(playerid))
                {
                    if (playerid == Player.instance.UserName)
                    {
                        //玩家死亡,游戏结束
                        isdead = true;
                    }
                    m_players [playerid].gameObject.SetActive(false);
                }
                else
                {
                    Debug.Log("not found:" + playerid);
                }
            }
        }

        //幸存人数
        survive = request.survive;
    }
Пример #13
0
    // Update is called once per frame
    void Update()
    {
        if (isdead)
        {
            //玩家死亡不允许控制角色
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            isMouseDown = true;
        }
        if (Input.GetMouseButtonUp(0))
        {
            isMouseDown = false;
        }

        if (isMouseDown)
        {
            //请求移动
            NETWORK_DATA_PROTOCOL.Protocol protocol = new NETWORK_DATA_PROTOCOL.Protocol();
            protocol.seq     = TcpManager.Instance.GetConnectSeq();
            protocol.command = (UInt16)NETWORK_DATA_PROTOCOL.CMD.MOVE;
            protocol.time    = m_time + 1;
            protocol.key     = Player.instance.AccountToken;

            var request = new NETWORK_DATA_PROTOCOL.DoMove();
            request.name = Player.instance.UserName;

            var position_world = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Debug.Log("mouse point:" + position_world.ToString());
            var dest = transform.InverseTransformPoint(position_world);
            Debug.Log("mouse point relative:" + dest.ToString());
            request.destination = new NETWORK_DATA_PROTOCOL.Vector3();
            request.destination.CloneVector3(dest);

            TcpManager.Instance.Send(protocol.PackProtocol(request), "sence");
        }
    }
Пример #14
0
    public void OnLoginPress()
    {
        bool bIsRegisted = false;

        string userName = m_loginUserName.text;
        string password = m_loginUserPassword.text;

        //到后台验证用户名和密码
        NETWORK_DATA_PROTOCOL.Protocol protocol = new NETWORK_DATA_PROTOCOL.Protocol();
        protocol.seq     = TcpManager.Instance.GetConnectSeq();
        protocol.command = (UInt16)NETWORK_DATA_PROTOCOL.CMD.LOGIN;

        NETWORK_DATA_PROTOCOL.DoLoginReq request
            = new NETWORK_DATA_PROTOCOL.DoLoginReq();

        request          = new NETWORK_DATA_PROTOCOL.DoLoginReq();
        request.name     = userName;
        request.password = password;
        protocol.request = JsonConvert.SerializeObject(request);

        SignalModule.FuncWithParam1 <string> callback = OnLoginCallBack;
        TcpManager.Instance.SendAndRecieve(JsonConvert.SerializeObject(protocol), callback);
    }