public void Analysis(Client pClient) { int Count = pClient.bufferCount; try { pClient.msgLength = pClient.readBuffer.Length; object cmdmsgs = ProtocolByt.ByteToStruct(pClient.readBuffer, typeof(MsgHead)); MsgHead head = (MsgHead)cmdmsgs; pClient.bufferCount -= Marshal.SizeOf(head); string msg = ""; if (pClient.bufferCount > 0) { msg = System.Text.Encoding.UTF8.GetString(pClient.readBuffer, Count - pClient.bufferCount, head.len); bufferCount = 0; } EDebug.LogFormat("Analysis {0} {1}", head.cmd_id, msg); ServerMsgObj serverMsgPair = new ServerMsgObj { MsgId = (int)head.cmd_id, SubId = (int)head.sub_id, Msg = msg }; _msgReceived.AddLast(serverMsgPair); } catch (Exception e) { EDebug.Log(e.ToString()); OnDisconnect(); //throw; } }
public void OnLogin(ServerMsgObj msg) { LoginResponse loginResponse = JsonUtility.FromJson <LoginResponse>(msg.Msg); Debug.LogFormat("OnLogin", msg.Msg); if (loginResponse == null) { return; } Role.Instance.RoleName = loginResponse.nickname; Role.Instance.RoleId = uint.Parse(loginResponse.user_id); Role.Instance.HeadId = loginResponse.base_data.face_id; Role.Instance.Level = loginResponse.levels; Role.Instance.Cash = loginResponse.coins; Role.Instance.Gold = loginResponse.golds; Role.Instance.LockedGold = loginResponse.bind_golds; Role.Instance.Sex = loginResponse.base_data.sex; var stubdata = Role.Instance.GetStubData(StubType.PVE); stubdata.Clear(); if (loginResponse.formation != null) { Role.Instance.InitStubData(loginResponse.formation); } OnMailData(msg); //测试邮箱 ZEventSystem.Dispatch(EventConst.OnMsgLogin, msg); }
public void OnMain(ServerMsgObj msgObj) { Role.Instance.RoleName = this.mView.Import_input.text; Role.Instance.Sex = this.mView.isMan; Role.Instance.HeadId = (int)this.mView.role; SceneMgr.Instance.LoadScene("Main"); }
public virtual bool OnMsg(ServerMsgObj msg) { if (ModuleEvents.ContainsKey(msg.MsgId)) { ModuleEvents[msg.MsgId](msg); return(true); } return(false); }
public void OnLoadTotemData(ServerMsgObj msg) { string server = msg.Msg; TotemMsgCollect tc = JsonUtility.FromJson <TotemMsgCollect>(server); TotemData[] data = new TotemData[tc.totems.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new TotemData(tc.totems[i]); TotemMgr.GetSingleton().AddTotem(data[i]); } }
public void OnLoadEquipData(ServerMsgObj msg) { string server = msg.Msg; EquipMsgCollect em = JsonUtility.FromJson <EquipMsgCollect>(server); EquipData[] data = new EquipData[em.equips.Length]; for (int i = 0; i < data.Length; i++) { data[i] = new EquipData(em.equips[i]); EquipMgr.GetSingleton().AddEquip(data[i]); } }
public void OnLoadHeroData(ServerMsgObj msg) { string server = msg.Msg; HeroMsgCollect hm = JsonUtility.FromJson <HeroMsgCollect>(server); HeroData[] dataArray = new HeroData[hm.heros.Length]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = new HeroData(hm.heros[i]); HeroMgr.GetSingleton().AddHeroData(dataArray[i]); } HeroMgr.GetSingleton().HeroDataLoaded(); }
public void OnLogin(ServerMsgObj msgObj) { if (Role.Instance.RoleName == "") { UIFace.GetSingleton().Close(UIID.Login); UIFace.GetSingleton().Open(UIID.CreateRole); } else { PlayerPrefs.SetString("username", mView.account_input.text); PlayerPrefs.SetString("passwd", mView.password_input.text); SceneMgr.Instance.LoadScene("Main"); } }
public void OnRegMain(ServerMsgObj msg) { if (msg.SubId == 0) { Debug.Log("未知错误"); } else if (msg.SubId == 1) { Debug.Log("用户名重复"); } else if (msg.SubId == 2) { Debug.Log("服务器异常"); } }
public void OnShopFailed(ServerMsgObj msg) { switch (msg.SubId) { case 0: Debug.LogFormat("OnShopFailed" + ":" + "未知错误"); break; case 1: Debug.LogFormat("OnShopFailed" + ":" + "生成列表错误"); break; default: Debug.LogFormat("OnShopFailed" + ":" + "未知错误" + msg.SubId); break; } }
public void OnRecvMsg(ServerMsgObj serverMsg) { int msgId = serverMsg.MsgId; bool msgHandled = false; for (int idx = 0; idx < _modules.Count; ++idx) { if (_modules[idx].OnMsg(serverMsg) && !msgHandled) { msgHandled = true; } } if (!msgHandled) { EDebug.LogWarningFormat("MsgFactory处理消息失败,未处理的消息id:{0} sub_id:{1} msg:\"{2}\"", serverMsg.MsgId, serverMsg.SubId, serverMsg.Msg); } }
public void OnShop(ServerMsgObj msg) { ShopsData shopRes = JsonUtility.FromJson <ShopsData>(msg.Msg); ShopItem[] shop = null; int type = 0; if (shopRes.shop_1.Length > 0) { type = 1; shop = shopRes.shop_1; } else if (shopRes.shop_2.Length > 0) { type = 2; shop = shopRes.shop_2; } else if (shopRes.shop_3.Length > 0) { type = 3; shop = shopRes.shop_3; } else if (shopRes.shop_4.Length > 0) { type = 4; shop = shopRes.shop_4; } else if (shopRes.shop_5.Length > 0) { type = 5; shop = shopRes.shop_5; } Debug.Log(shop.Length); if (shop.Length > 0) { ShopMgr.Instance.ServerGoods(type, shop); ZEventSystem.Dispatch(EventConst.ShowUnitShop, type); } }
public void OnStubSaveFailed(ServerMsgObj msg) { EDebug.LogErrorFormat("Stub Save failed"); }
public void OnStubSaveOver(ServerMsgObj msg) { Debug.LogFormat("OnStubSaveOver {0}", msg.Msg); ZEventSystem.Dispatch(EventConst.OnStubSaveOver); }
public void OnMailData(ServerMsgObj msg) { // MailData maildate = JsonUtility.FromJson<MailData>(msg.Msg); for (int i = 0; i < 5; i++) { MailDatas Mail = new MailDatas(); Item item = new Item(); System.Collections.Generic.List <Item> itemlist = new System.Collections.Generic.List <Item>(); switch (i) { case 0: item.itemId = 30001; item.itemNum = 10 + i; itemlist.Add(item); break; case 1: item.itemId = 30006; item.itemNum = 10 + i; itemlist.Add(item); break; case 2: item.itemId = 30011; item.itemNum = 10 + i; itemlist.Add(item); break; case 3: item.itemId = 30016; item.itemNum = 10 + i; itemlist.Add(item); break; case 4: item.itemId = 30021; item.itemNum = 10 + i; itemlist.Add(item); break; } Mail.mail_id = 1000 + i; Mail.ico_id = 20110; Mail.addresser = "卫东" + i; Mail.content = "是人,都有一颗心,有血有肉。是心,难免会生情,有牵有挂。人与人一旦有了感情,就会关心,就会惦记;心与心一旦有了相吸,就会眷恋,就会难舍。其实,人心都是肉长的,每一份惦记,都关着情;每一份感动,都连着心;每一声问候,都藏着真;每一份守望,都是用情至深!人与人之间,全凭一颗坦诚的心;心与心之间,全凭一份挚热的情。人心是肉长,是真情,女人也会流泪,男人也会动容;人心是肉长,是真情,小孩也会感动,老人也会触动;人心是肉长,是真情,我们都要铭记,都要珍惜,都要感恩心中!" + "是人,都有一颗心,有血有肉。是心,难免会生情,有牵有挂。人与人一旦有了感情,就会关心,就会惦记;心与心一旦有了相吸,就会眷恋,就会难舍。其实,人心都是肉长的,每一份惦记,都关着情;每一份感动,都连着心;每一声问候,都藏着真;每一份守望,都是用情至深!人与人之间,全凭一颗坦诚的心;心与心之间,全凭一份挚热的情。人心是肉长,是真情,女人也会流泪,男人也会动容;人心是肉长,是真情,小孩也会感动,老人也会触动;人心是肉长,是真情,我们都要铭记,都要珍惜,都要感恩心中!"; Mail.date = Util.Utc2DateTime(long.Parse(((int)ConvertDateTimeInt(DateTime.Now) + i).ToString())); Mail.mailname = "卫东置信" + i; Mail.isRead = 0; if (i % 2 == 0) { } switch (i) { case 0: Mail.type = 1; break; case 1: Mail.type = 2; Mail.mailitem = itemlist; break; case 2: Mail.type = 3; break; case 3: Mail.type = 1; break; case 4: Mail.type = 2; Mail.mailitem = itemlist; break; } bool idcon = false; if (PostBoxMgr.Instance.MailData.Count > 0) { for (int idx = 0; idx < PostBoxMgr.Instance.MailData.Count; idx++) { if (PostBoxMgr.Instance.MailData[idx].mail_id == Mail.mail_id) { idcon = true; } } } if (false == idcon) { PostBoxMgr.Instance.MailData.Add(Mail); } } PostBoxMgr.Instance.isUpd = true; }
public void OnBattleStart(ServerMsgObj msgObj) { Debug.LogFormat("OnBattleStart {0}", msgObj.Msg); }
public void OnLoginFailed(ServerMsgObj msg) { Debug.Log("OnLoginFailed" + msg.Msg); CanvasView.Instance.AddNotice("用户名或密码错误"); }
public void OnBattleEnd(ServerMsgObj msgObj) { Debug.LogFormat("OnBattleEnd {0}", msgObj.Msg); }
public void Update() { if (_openDisconnect) { CanvasView.Instance.OpenConnect(true); _openDisconnect = false; } if (Application.internetReachability == NetworkReachability.NotReachable) { return; } if (client.Connected == true) { if (_login) { if (lastKeepAliveReceive > 0 && Time.time - lastKeepAliveReceive > KeepAliveTimeOut) { OnDisconnect(); return; } if (Time.time - lastKeepAliveSend >= KeepAliveInterval) { try { client.BeginSend(keepalive, 0, 16, SocketFlags.None, OnSendCallback, client); lastKeepAliveSend = Time.time; } catch (SocketException se) { EDebug.LogErrorFormat("Client KeepAlive Socket Exception {0}", se.Message); OnDisconnect(); return; } } if (_msgSend.Count > 0) { byte[] buffer = _msgSend.First.Value; try { client.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, OnSendCallback, client); Debug.Log("Send Data Over"); _msgSend.RemoveFirst(); } catch (Exception e) { EDebug.LogErrorFormat("Client Socket Exception {0}", e.ToString()); OnDisconnect(); } } } if (_msgReceived.Count > 0) { ServerMsgObj serverMsgPair = _msgReceived.First.Value; //如果是登录消息,截获一下 if (serverMsgPair.MsgId == (int)ServerMsgId.DCMD_AUTH_SUCCEEDED) { OnLoginResult(true); } else if (serverMsgPair.MsgId == (int)ServerMsgId.ECMD_AUTH_FAILED) { OnLoginResult(false); } else if (serverMsgPair.MsgId == (int)ServerMsgId.CCMD_KEEP_ALIVE) { //收到心跳 lastKeepAliveReceive = Time.time; } try { MsgFactory.Instance.OnRecvMsg(serverMsgPair); } catch (Exception e) { throw new Exception(string.Format("Client->MsgFactory.Instance.OnRecvMsg error, {0}", e.ToString())); } finally { if (_msgReceived != null && _msgReceived.Count > 0) { _msgReceived.RemoveFirst(); } } } } }
public void OnRegFailed(ServerMsgObj msgObj) { Debug.Log("OnRegFailed " + msgObj.Msg); }
public void OnMain(ServerMsgObj msg) { ZEventSystem.Dispatch(EventConst.OnMsgOnMain, msg); }