// Use this for initialization void Start() { m_spinCount = 0; m_tigerNo = 888; m_seqNo = 666; m_gold = 0; m_net = new ProtoNet(); // 增加前台支持的网络包类型 m_net.Add(Constants.Tiger_QuickLoginInfo, TigerUserInfo.Parser); m_net.Add(Constants.Tiger_Spin, TigerResp.Parser); m_net.Add(Constants.Reconnect, null); m_net.Add(Constants.Error, null); m_net.Name = "SlotClerk"; m_login = false; m_lines = 1; m_win = 0; // 启动登录 RedirectResp rr = Lobby.getInstance().RedirectInfo; m_id = rr.UserId; m_key = rr.Key; if (false == m_net.Init(rr.Domain, rr.Port)) { DebugConsole.Log("Client init failed!"); } /* * m_id = 123456; * m_key = 123456; * // 启动登录 * if (false == m_net.Init("127.0.0.1", 1234)) * { * DebugConsole.Log("Client init failed!"); * } */ // 初始化Displays //m_displays = new SlotClientDisplays(); // MonoBehaviour不可以new m_displays = GameObject.Find("SlotDisplays").GetComponent <SlotDisplays>(); m_displays.User = this; // 初始化Requests m_requests = new SlotRequests(); m_requests.Net = m_net; m_requests.Clerk = this; // 发送快速登录 m_requests.QuickLogin(); }
// Update is called once per frame void Update() { if (DialogLogin.Actived()) { return; } if (!m_net.IsRunning()) { // 主动结束了 return; } // Step m_net.CheckReconnect(); //if (m_net.CheckReconnect()) //{ //DebugConsole.Log("Door:Reconnect successful."); //CheckLogin(); //DialogBase.Hide(); //} if (m_rcCount > 3) { DialogWarning.Show("No Network!", "Your internet seems to be down.\nPlease check your network settings.", "Retry", "Exit", OnOK, OnCancel, OnOK); return; } ProtoPacket packet = new ProtoPacket(); if (m_net.RecvTryDequeue(ref packet)) { DebugConsole.Log("Door:Reception handle cmdId:" + packet.cmdId); switch (packet.cmdId) { case Constants.Dog_Login: { LoginResp loginResp = (LoginResp)packet.proto; Lobby.getInstance().UId = loginResp.UserId; DebugConsole.Log("UId:" + loginResp.UserId); m_login = true; // 登录成功,重定向 if (packet.callback != null) { // 重定向 packet.callback(); } } break; case Constants.Dog_Redirect: { RedirectResp rdResp = (RedirectResp)packet.proto; Lobby lobby = Lobby.getInstance(); lobby.Domain = rdResp.Domain; lobby.Port = rdResp.Port; lobby.Key = rdResp.Key; m_net.Close(); // 重定向到大厅 DebugConsole.Log("Door:Redirect to lobby:" + lobby.Domain + ":" + lobby.Port); StartCoroutine(LoadingScene()); } break; case Constants.Reconnect: { // 展示重连对话框,直到重连成功 if (packet.msgId == 1) { ProtoNet.WriteLog("Door:Reconnecting..."); // 3s后Display中重连 m_net.CheckReconnect(5); //DialogBase.Show("RECONNECT", "reconnecting"); GameObject.Find("RcText").GetComponent <Text>().text = "Reconnecting..."; m_net.Ip = "182.92.74.240"; m_rcCount++; } else if (packet.msgId == 2) { DebugConsole.Log("Door:Reconnect successful."); //DialogBase.Hide(); GameObject.Find("RcText").GetComponent <Text>().text = "Connect successfully."; // 启动默认登录 if (m_auto) { Login(Redirect); } } } break; case Constants.Error: { // 这里一定是登录错误? Status stat = (Status)packet.proto; string err = "Error:" + stat.Code.ToString() + "-" + stat.Desc; GameObject.Find("RcText").GetComponent <Text>().text = err; // 打开登录对话框 DialogLogin.Show(LoginAsGuest, LoginWithFsID, null); } break; default: { DebugConsole.Log("Door:Invalid cmdId:" + packet.cmdId); } break; } } //process = (int)(async.progress * 100); }