/// <summary> /// 请求连接 /// </summary> public void SendConnect(string _server, int _port, XLua.LuaFunction function, int timeoutMS = 3000) { Util.Log($"{_server}:{_port} Connecting.... {DateTime.Now.ToString()}"); this.Connect(_server, _port, (ex) => { if (function != null) { function.Action(ex); } if (ex != null) { Util.LogError($"{_server}:{_port} connecting error: {ex.Message}"); return; } Util.Log($"{_server}:{_port} connecting: {ex == null} {ex}"); //test // 设置元数据 // SetValue("player", "10086"); // SetValue("session", "1111111"); //NetworkManager.AddEvent(Protocal.Connect, new ByteNetCommand()); // var login = new logic.proto.CS_Player_Login { token = "11010", }; // this.SendMessage(login, (cmd) => // { // //var sc_login = cmd as logic.proto.SC_Player_Login; // //Util.Log($"login reslut --> {sc_login} id:{sc_login.id} "); // NetworkManager.AddEvent(Protocal.Message, cmd as ByteNetCommand); // }); }, timeoutMS); }
private void ProgressSwitchSceneMessage(float progress) { if (progressLoadActon != null) { progressLoadActon.Action <float>(progress); } }
void Update() { watch.Reset(); watch.Start(); while (queue != null && queue.Count > 0) { // 处理包之后重置ping gate的计时器 剔除事件Packet //if (packet.Type < 0 || packet.Type > 6) { pingGateCurTime = Time.time; pingGateWaitCurTime = Time.time; isStartPingGate = false; } Packet packet = (Packet)queue[0]; queue.RemoveAt(0); if (luaNetHandler == null) { luaNetHandler = Hugula.EnterLua.luaenv.Global.GetInPath <XLua.LuaFunction>("Net.net_handler"); } if (luaNetHandler != null) { try { #if HUGULA_PROFILER_DEBUG Profiler.BeginSample("WarNet.Type=" + packet.Type); #endif if (isSync && packet.Type != NetEventPacketType.DISCONNECT && packet.Type != NetEventPacketType.CONNECT_ERROR) { syncWaitQueue.Add(packet); if (packet.Type == 159043482)//sync { isSync = false; while (syncWaitQueue.Count > 0) { Packet tpacket = (Packet)syncWaitQueue[0]; syncWaitQueue.RemoveAt(0); // LuaPacket luaPacket = new LuaPacket(tpacket); // luaNetHandler.call(luaPacket); luaNetHandler.Action <int, byte[]>(tpacket.Type, tpacket.GetBytes()); } } } else if (packet.Type != 12)// Ping gate的包不走Lua Rpc逻辑 { // LuaPacket luaPacket = new LuaPacket(packet); // luaNetHandler.call(luaPacket); luaNetHandler.Action <int, byte[]>(packet.Type, packet.GetBytes()); } else { // this.NetLog("Ping received.."); } #if HUGULA_PROFILER_DEBUG Profiler.EndSample(); #endif //this.NetLogFormat("<color=#409021> netHandler end type({0}) , count ={1},time{2} </color>", packet.Type,queue.Count,Hugula.Utils.CUtils.ConvertDateTimeInt(System.DateTime.Now)); } catch (Exception e) { SendErro(e.Message, e.StackTrace); Debug.Log(e.ToString()); } } if (watch.ElapsedMilliseconds >= netHandlerTimeoutMilliSeconds && queue.Count > 0) { #if UNITY_EDITOR Debug.LogWarningFormat("<color=yellow> netHandler Timeout type({0}) , wait.count ={1},timeline{2} cost={3}ms </color>", packet.Type, queue.Count, System.DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"), watch.ElapsedMilliseconds); #endif break; } } if (isbegin) { // this.NetLog(" Connected "+this.client.Connected); bool connted = IsConnected; if (!connted && isConnectioned == false) { TimeSpan ts = DateTime.Now - begin; //this.NetLogFormat("TotalMilliseconds {0} timeoutMilliSeconds {1}.", ts.TotalMilliseconds, this.timeoutMilliSeconds); if (ts.TotalMilliseconds > this.timeoutMilliSeconds) { isbegin = false; NetEvent(NetEventPacketType.CONNECT_ERROR); return; } } else if (!connted && isConnectioned) { isbegin = false; NetEvent(NetEventPacketType.DISCONNECT); return; } if (connted && isConnectioned) { float dt = Time.time - lastSeconds; if (dt > pingDelay) { // onIntervalFn.call(this); lastSeconds = Time.time; } float waitDt = Time.time - pingGateWaitCurTime; if (isStartPingGate && waitDt > pingGateWaitMaxTime) { #if !HUGULA_NO_LOG Debug.LogFormat("ping gate timeout pingGateWaitCurTime={0} waitDt={1}", pingGateWaitCurTime, waitDt); #endif //Debug.Log(": Update ping gate timeout..."); this.Close(); isStartPingGate = false; } } } }
public static void ResponseClickEmojiTextHref(string origText) { if (origText.Contains("goodsOid")) { string idStr = origText.Replace("goodsOid=", ""); var matchs = Regex.Matches(idStr, @"\{(\d+),(\d+)\}"); foreach (Match _match in matchs) { if (_match.Success) { uint sendId = (DBTextResource.ParseUI(_match.Groups[1].Value)); ulong goodsOid = DBTextResource.ParseUL_s(_match.Groups[2].Value, 0); Net.C2STalkGoods pack = new Net.C2STalkGoods(); pack.uuid = sendId; pack.oid = goodsOid; //GameDebug.LogError("=============== OnClickHref test"); Net.NetClient.GetBaseClient().SendData <Net.C2STalkGoods>(xc.protocol.NetMsg.MSG_TALK_GOODS, pack); } } //兼容3个参数和2个参数 matchs = Regex.Matches(idStr, @"\{(\d+),(\d+),(\d+)\}"); foreach (Match _match in matchs) { if (_match.Success) { uint sendId = (DBTextResource.ParseUI(_match.Groups[1].Value)); ulong goodsOid = DBTextResource.ParseUL_s(_match.Groups[2].Value, 0); ulong goodsGid = DBTextResource.ParseUL_s(_match.Groups[3].Value, 0); Net.C2STalkGoods pack = new Net.C2STalkGoods(); pack.uuid = sendId; pack.oid = goodsOid; pack.gid = (uint)goodsGid; Net.NetClient.GetBaseClient().SendData <Net.C2STalkGoods>(xc.protocol.NetMsg.MSG_TALK_GOODS, pack); } } } else if (origText.Contains("teamId")) { var idStr = origText.Replace("teamId=", ""); var teamId = uint.Parse(idStr); TeamManager.Instance.Apply(teamId); } else if (origText.Contains("playerId")) {//查看玩家 var idStr = origText.Replace("playerId=", ""); List <string> param_list = DBTextResource.ParseArrayString(idStr, ";"); if (param_list.Count >= 5) { // 不能查看玩家自己的信息 if (param_list[0].Equals(LocalPlayerManager.Instance.LocalActorAttribute.UnitId.obj_idx.ToString()) == false) { Dictionary <string, string> playerInfo = new Dictionary <string, string>(); playerInfo.Clear(); playerInfo.Add("uuid", param_list[0]); xc.ui.ugui.UIManager.Instance.ShowWindow("UIWatchPlayerWindow", playerInfo); } } else { GameDebug.LogError("playerId param is error! idStr = " + idStr); } } else if (origText.Contains("jumpSysId=")) {//跳转系统ID var idStr = origText.Replace("jumpSysId=", ""); List <string> param_list = DBTextResource.ParseArrayString(idStr, ";"); if (param_list.Count >= 1) { uint sys_id = 0; if (uint.TryParse(param_list[0], out sys_id)) { if (LuaScriptMgr.Instance != null) { XLua.LuaFunction func = LuaScriptMgr.Instance.GetLuaFunction(LuaScriptMgr.Instance.Lua.Global, "GotoSysRouter_chatItem"); if (func != null) { func.Action(param_list); } } } } else { GameDebug.LogError("jumpSysId param is error! idStr = " + idStr); } } else if (origText.Contains("clientGoodsTips")) {//客户端拼凑的物品TIPS string idStr = origText; //var idStr = origText.Replace("clientGoodsTips=", ""); var matchs = Regex.Matches(origText, @"clientGoodsTips=\{(.+)\}"); foreach (Match _match in matchs) { if (_match.Success) { idStr = _match.Groups[1].Value; } } Goods item_info = xc.GoodsHelper.ParseClientGoodsStr(idStr); if (item_info != null) { GoodsHelper.ShowGoodsTips(item_info, null, null, "GuildWarehouseNormal"); } else { GameDebug.LogError("playerId param is error! idStr = " + idStr); } } else if (origText.Contains("enter_guild_manor")) {//进入帮派领地 if (SysConfigManager.GetInstance().CheckSysHasOpened(GameConst.SYS_OPEN_GUILD, true)) { if (LocalPlayerManager.Instance.GuildID > 0) { InstanceHelper.EnterGuildManor(); } else { xc.UINotice.Instance.ShowMessage(xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_77")); xc.ui.ugui.UIManager.GetInstance().ShowSysWindow("UIGuildWindow"); } } } else if (origText.Contains("goodsTips")) {//查看物品 string idStr = origText.Replace("goodsTips=", ""); var matchs = Regex.Matches(idStr, @"\{(\d+),(\d+)\}"); foreach (Match _match in matchs) { if (_match.Success) { uint sendId = (DBTextResource.ParseUI(_match.Groups[1].Value)); ulong goodsOid = DBTextResource.ParseUL_s(_match.Groups[2].Value, 0); Net.C2STalkGoods pack = new Net.C2STalkGoods(); pack.uuid = sendId; pack.oid = goodsOid; //GameDebug.LogError("=============== OnClickHref test"); Net.NetClient.GetBaseClient().SendData <Net.C2STalkGoods>(xc.protocol.NetMsg.MSG_TALK_GOODS, pack); } } } else if (origText.Contains("goodsGid")) { var matchs = Regex.Matches(origText, @"goodsGid=\{(\d+),(\d+)\}"); foreach (Match _match in matchs) { if (_match.Success) { //uint playerId = (DBTextResource.ParseUI(_match.Groups[1].Value)); uint goodsGid = DBTextResource.ParseUI(_match.Groups[2].Value); var goods = GoodsHelper.CreateGoodsByTypeId(goodsGid); if (goods != null) { GoodsHelper.ShowGoodsTips(goods); } } } } else if (origText.Contains("position=")) { var matchs = Regex.Matches(origText, @"position=\{(\d+),(\d+),(\d+\.?\d*),(\d+\.?\d*)\}"); foreach (Match _match in matchs) { if (_match.Success) { uint instanceId = DBTextResource.ParseUI(_match.Groups[1].Value); uint line = DBTextResource.ParseUI(_match.Groups[2].Value); float x = DBTextResource.ParseF(_match.Groups[3].Value); float z = DBTextResource.ParseF(_match.Groups[4].Value); ClientEventMgr.GetInstance().FireEvent( (int)ClientEvent.CE_CHAT_JUMP_TO_CONST_POSITION, new CEventEventParamArgs(instanceId, line, x, z)); } } } else if (origText.Contains("marketGoodsTips")) { var matchs = Regex.Matches(origText, @"marketGoodsTips=\{(\d+)\}"); foreach (Match _match in matchs) { if (_match.Success) { uint goodsOid = DBTextResource.ParseUI(_match.Groups[1].Value); Net.C2SMarketDetail pack = new Net.C2SMarketDetail(); pack.oid = goodsOid; Net.NetClient.GetBaseClient().SendData <Net.C2SMarketDetail>(xc.protocol.NetMsg.MSG_MARKET_DETAIL, pack); } } } else { ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_CHAT_RESPONSE_CLICK_TEXT_HREF, new CEventEventParamArgs(origText)); } }