Esempio n. 1
0
    void Start()
    {
        byte[] recv = new byte[16 * 1024];

        connector = new TcpConnector("192.168.31.236", 8888);
        connector.On(SocketEvents.Message, (d) =>
        {
            byte[] reData = d as byte[];
            Debug.LogError(reData.Length);
            unpacker.Input(reData);
            int length;
            ushort msgId;
            while (unpacker.MoveNext(recv, out length, out msgId))
            {
                LoginS2C lmsg = ProtobufTool.BytesToProtoBuf <LoginS2C>(recv, 0, length);
                Debug.LogError("recv msgID: " + msgId + " data:" + lmsg.playerId);
            }
        });
        var wait = connector.Connect();

        if (!Util.Wait(wait, 1000))
        {
            connector.Dispose();
        }
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        m_Socket = new TcpClient();
        m_Socket.Connect("192.168.31.236", 8888);
        m_Stream = m_Socket.GetStream();
        LoginC2S msg = new LoginC2S();

        msg.name = "huashao";
        byte[] dd  = ProtobufTool.ProtoBufToBytes <LoginC2S>(msg);
        int    len = dd.Length + 2;

        Debug.LogError(len);
        byte[] buf = new byte[len + 6];
        buf[0] = (byte)(len & 0xff);
        buf[1] = (byte)(len >> 8 & 0xff);
        buf[2] = (byte)(len >> 16 & 0xff);
        buf[3] = (byte)(len >> 24 & 0xff);
        buf[4] = 1;
        buf[5] = 0;
        Array.Copy(dd, 0, buf, 6, dd.Length);
        m_Stream.Write(buf, 0, buf.Length);
        byte[] recv = new byte[1024];
        int    c    = m_Stream.Read(recv, 0, 1024);
        int    rlen = (recv[0] | recv[1] << 8 | recv[2] << 16 | recv[3] << 24);
        int    rId  = (recv[4] | recv[5] << 8);

        Debug.LogError(string.Format("recv len:{0} id:{1}", rlen, rId));
        byte [] rbuf = new byte[rlen - 2];
        Array.Copy(recv, 6, rbuf, 0, rlen - 2);
        LoginS2C rmsg = ProtobufTool.BytesToProtoBuf <LoginS2C>(rbuf);

        Debug.LogError(rmsg.playerId);
        m_Stream.Close();
        m_Socket.Close();
    }
Esempio n. 3
0
    private void LoginResponse(byte[] bytes)
    {
        Debug.Log("收到登陆响应");
        LoginS2C package     = NetMgr.Instance.DeSerializes <LoginS2C>(bytes);
        int      loginStatus = package.status;

        if (loginStatus == 1)
        {
            Debug.Log("验证成功");
            int userID = package.userId;
            hallServerIP   = package.serverIp;
            hallServerPort = package.port;
            ((GameMgrProxy)Facade.RetrieveProxy(Proxys.GAMEMGR_PROXY)).systemTime = package.time;
            this.GetUserID(userID);
            NetMgr.Instance.StopTcpConnection(SocketType.LOGIN);
            NetMgr.Instance.CreateConnect(SocketType.HALL, hallServerIP, hallServerPort, HallConnectHandler);
        }
        else
        {
            DialogMsgVO dialogVO = new DialogMsgVO();
            dialogVO.dialogType = DialogType.ALERT;
            dialogVO.title      = "登录失败";
            dialogVO.content    = "登录失败,请重新连接";
            DialogView dialogView = UIManager.Instance.ShowUI(UIViewID.DIALOG_VIEW) as DialogView;
            dialogView.data = dialogVO;
        }
    }
        private void HandleLoginFeedback(byte[] data)
        {
            UILockManager.ResetGroupState(UIEventGroup.Middle);

            LoginS2C feedback = ProtobufUtils.Deserialize <LoginS2C>(data);

            if (feedback == null)
            {
                Utils.DebugUtils.LogError(Utils.DebugUtils.Type.Login, "HandleLoginFeedback - feedback is null");
                return;
            }

            if (feedback.result == 1)
            {
                Account account = datamanager.GetAccount();
                account.userID   = userID;
                account.password = password;
                datamanager.SetAccountId(feedback.accountId);
                ClientTcpMessage.sessionId = feedback.loginSessionId;

                if (feedback.playerId < 0)
                {
                    Utils.DebugUtils.Log(Utils.DebugUtils.Type.Login, "HandleLoginFeedback - need to chose avatar and username");
                    view.SetPlayerChoiceWindow(true);
                }
                else
                {
                    ClientTcpMessage.sessionId = feedback.loginSessionId;
                    datamanager.SetPlayerId(feedback.playerId);
                    datamanager.SetAccountId(feedback.accountId);
                    datamanager.SetGameServerIp(feedback.gameServerIp);
                    datamanager.SetGameServerPort(feedback.gameServerPort);
                    gameServerIP     = feedback.gameServerIp;
                    gameServerPort   = feedback.gameServerPort;
                    socialServerIP   = feedback.socialServerIp;
                    socialServerPort = feedback.socialServerPort;

                    PlayerPrefs.SetString("userID", userID);
                    PlayerPrefs.SetString("userPW", password);

                    Utils.DebugUtils.Log(Utils.DebugUtils.Type.Login, "HandleLoginFeedback");

                    DisconnectLoginServerAndConnectGameServer(feedback.gameServerIp, feedback.gameServerPort);
                    SwtichScene();
                }
            }
            else if (feedback.result == 2)
            {
                datamanager.SetAccountId(feedback.accountId);
                view.OpenPlayerChoiceWindow();
            }
            else
            {
                view.FailedLogin(feedback.tipType);
            }
        }
Esempio n. 5
0
    private void LoginResponse(byte[] bytes)
    {
        Debug.Log("收到登陆响应");
        LoginS2C package     = NetMgr.Instance.DeSerializes <LoginS2C>(bytes);
        int      loginStatus = package.status;

        if (loginStatus == 1)
        {
            Debug.Log("验证成功");
            int userID = package.userId;
            hallServerIP   = package.serverIp;
            hallServerPort = package.port;
            ((GameMgrProxy)Facade.RetrieveProxy(Proxys.GAMEMGR_PROXY)).systemTime = package.time;
            PlayerInfoProxy pip = Facade.RetrieveProxy(Proxys.PLAYER_PROXY) as PlayerInfoProxy;
            pip.userID = userID;
            NSocket.UpdateUserID(userID);
            NetMgr.Instance.StopTcpConnection(SocketType.LOGIN);
            NetMgr.Instance.CreateConnect(SocketType.HALL, hallServerIP, hallServerPort, HallConnectHandler);
        }
        else if (loginStatus == 2)
        {
            DialogMsgVO dialogVO = new DialogMsgVO();
            dialogVO.dialogType      = DialogType.ALERT;
            dialogVO.title           = "登录失败";
            dialogVO.content         = "版本过低,请点击确认下载最新版本";
            dialogVO.confirmCallBack = () =>
            {
                if (Application.platform == RuntimePlatform.Android)
                {
                    Application.OpenURL(package.androidUrl);
                }
                else if (Application.platform == RuntimePlatform.IPhonePlayer)
                {
                    Application.OpenURL(package.iosUrl);
                }
                else
                {
                    Application.OpenURL(package.androidUrl);
                }
            };
            DialogView dialogView = UIManager.Instance.ShowUI(UIViewID.DIALOG_VIEW) as DialogView;
            dialogView.data = dialogVO;
        }
        else
        {
            DialogMsgVO dialogVO = new DialogMsgVO();
            dialogVO.dialogType = DialogType.ALERT;
            dialogVO.title      = "登录失败";
            dialogVO.content    = "登录失败,请重新连接";
            DialogView dialogView = UIManager.Instance.ShowUI(UIViewID.DIALOG_VIEW) as DialogView;
            dialogView.data = dialogVO;
        }
    }