Esempio n. 1
0
    void Start()
    {
        connect.onClick.AddListener(() => {
            if ("" == host.text)
            {
                session.Connect(host_name, 20000, 60000);
            }
            else
            {
                session.Connect(host.text, 20000, 60000);
            }
        });
        pause.onClick.AddListener(() => {
            if (false == pause_toggle)
            {
                pause.transform.Find("Text").GetComponent <Text>().text = "Play";
                pause_toggle = true;

                if (null != coroutine)
                {
                    StopCoroutine(coroutine);
                }
                coroutine = null;
                session.Pause();
            }
            else
            {
                pause.transform.Find("Text").GetComponent <Text>().text = "Pause";
                pause_toggle = false;
                coroutine    = StartCoroutine(SendHeartBeat());
            }
        });
        close.onClick.AddListener(() => {
            session.Close();
        });

        session.onConnect += () => {
            msg_seq = 1;
            MsgCliSvr_Login_Req req = new MsgCliSvr_Login_Req();
            req.user_id = SystemInfo.deviceUniqueIdentifier;

            Log("MsgCliSvr_Login_Req(user_id:" + req.user_id + ")");
            session.SendMsg(req);
            session.Pause();
        };
        session.onResume += () => {
            Log("UnityClient.onResume");
            Debug.Log("UnityClient.onResume");
        };
        session.onClose += () => {
            Log("UnityClient.onClose");
            Debug.Log("UnityClient.onClose");
        };
        session.onError += (Gamnet.Exception e) => {
            Log(e.ToString());
            if (TimeoutError == e.ErrorCode)
            {
                return;
            }
            if (null != coroutine)
            {
                StopCoroutine(coroutine);
            }
            coroutine = null;
        };

        session.RegisterHandler <MsgSvrCli_Login_Ans> ((MsgSvrCli_Login_Ans ans) => {
            user_data = ans.user_data;
            Log("MsgSvrCli_Login_Ans(user_seq:" + user_data.user_seq + ", error_code:" + ans.error_code.ToString() + ")");
            if (ErrorCode.Success != ans.error_code)
            {
                session.Close();
                return;
            }
            if (null != coroutine)
            {
                StopCoroutine(coroutine);
            }
            coroutine = StartCoroutine(SendHeartBeat());
        });
        session.RegisterHandler <MsgSvrCli_HeartBeat_Ntf>((MsgSvrCli_HeartBeat_Ntf ntf) => {
            Log("MsgSvrCli_HeartBeat_Ntf(msg_seq:" + ntf.msg_seq.ToString() + ")");
        });
        session.RegisterHandler <MsgSvrCli_Kickout_Ntf>((MsgSvrCli_Kickout_Ntf ntf) => {
            Log("MsgSvrCli_Kickout_Ntf(error_code:" + ntf.error_code.ToString() + ")");
            session.Close();
            if (null != coroutine)
            {
                StopCoroutine(coroutine);
            }
            coroutine = null;
        });
    }
Esempio n. 2
0
 public static int Size(MsgCliSvr_Login_Req obj)
 {
     return(obj.Size());
 }
Esempio n. 3
0
 public static bool Store(MemoryStream _buf_, MsgCliSvr_Login_Req obj)
 {
     return(obj.Store(_buf_));
 }
Esempio n. 4
0
 public static bool Load(ref MsgCliSvr_Login_Req obj, MemoryStream _buf_)
 {
     return(obj.Load(_buf_));
 }
Esempio n. 5
0
    void Start()
    {
        connect.onClick.AddListener(() => {
            //session.msg_seq = 0;
            if ("" == host.text)
            {
                session.Connect("52.78.185.159", 20000, 60000);
            }
            else
            {
                session.Connect(host.text, 20000, 60000);
            }
        });
        pause.onClick.AddListener(() => {
            if (false == pause_toggle)
            {
                pause.transform.Find("Text").GetComponent <Text>().text = "Play";
                pause_toggle = true;

                if (null != coroutine)
                {
                    StopCoroutine(coroutine);
                }
                coroutine = null;
            }
            else
            {
                pause.transform.Find("Text").GetComponent <Text>().text = "Pause";
                pause_toggle = false;
                coroutine    = StartCoroutine(SendHeartBeat());
            }
        });
        close.onClick.AddListener(() => {
            session.Close();
        });

        session.onConnect += () => {
            msg_seq = 1;
            MsgCliSvr_Login_Req req = new MsgCliSvr_Login_Req();
            req.user_id = SystemInfo.deviceUniqueIdentifier;

            Log("MsgCliSvr_Login_Req(user_id:" + req.user_id + ")");
            session.SendMsg(req);
        };
        session.onReconnect += () => {
        };
        session.onClose     += () => {
            Log("session close");
        };
        session.onError += (Gamnet.Exception e) => {
            Log(e.ToString());
            if (TimeoutError == e.ErrorCode)
            {
                return;
            }
            if (null != coroutine)
            {
                StopCoroutine(coroutine);
            }
            coroutine = null;
        };
        session.RegisterHandler(MsgSvrCli_Login_Ans.MSG_ID, Recv_Login_Ans);

        session.RegisterHandler(MsgSvrCli_HeartBeat_Ntf.MSG_ID, (System.IO.MemoryStream buffer) => {
            MsgSvrCli_HeartBeat_Ntf ntf = new MsgSvrCli_HeartBeat_Ntf();
            if (false == ntf.Load(buffer))
            {
                Log("MessageFormatError(MsgSvrCli_HeartBeat_Ntf)");
                return;
            }
            Log("MsgSvrCli_HeartBeat_Ntf(msg_seq:" + ntf.msg_seq.ToString() + ")");
        });
        session.RegisterHandler(MsgSvrCli_Kickout_Ntf.MSG_ID, (System.IO.MemoryStream buffer) => {
            MsgSvrCli_Kickout_Ntf ntf = new MsgSvrCli_Kickout_Ntf();
            if (false == ntf.Load(buffer))
            {
                Log("MessageFormatError(MsgSvrCli_Kickout_Ntf)");
                return;
            }

            Log("MsgSvrCli_Kickout_Ntf(error_code:" + ntf.error_code.ToString() + ")");
            session.Close();
            if (null != coroutine)
            {
                StopCoroutine(coroutine);
            }
            coroutine = null;
        });
    }