internal void ConnectIfNotOpen() { if (!IsConnected) { m_LastHeartbeatTime = 0; m_LastReceiveHeartbeatTime = 0; m_LastQueueingTime = 0; m_LastShowQueueingTime = 0; m_LastConnectTime = TimeUtility.GetLocalMilliseconds(); TimeUtility.LobbyLastResponseTime = 0; LogSystem.Info("ConnectIfNotOpen at time:{0} ServerAddress:{1}", m_LastConnectTime, m_Url); m_IsLogining = true; m_IsQueueing = false; try { m_WebSocket.Open(); } catch (Exception ex) { LogSystem.Warn("m_WebSocket.Open throw exception {0}\n{1}", ex.Message, ex.StackTrace); BuildWebSocket(); //下次tick立即重连 m_LastConnectTime = 0; } } }
internal void Init() { m_LastTickTime = TimeUtility.GetLocalMilliseconds(); m_SaveDataToDBInterval = DataCacheConfig.PersistentInterval; m_TablePieceCapacity = DataCacheConfig.TablePieceCapacity; LogSys.Log(LOG_TYPE.INFO, "PersistentSystem initialized"); }
internal static SkillInfo NpcFindCanUseSkill(EntityInfo npc) { SkillStateInfo skStateInfo = npc.GetSkillStateInfo(); int priority = -1; SkillInfo skInfo = null; long curTime = TimeUtility.GetLocalMilliseconds(); if (npc.AutoSkillIds.Count <= 0) { return(null); } int randIndex = Helper.Random.Next(0, npc.AutoSkillIds.Count); skInfo = skStateInfo.GetSkillInfoById(npc.AutoSkillIds[randIndex]); SkillInfo selectSkill = null; if (null != skInfo && !skInfo.IsInCd(curTime)) { selectSkill = skInfo; } else { for (int i = 0; i < npc.AutoSkillIds.Count; i++) { skInfo = skStateInfo.GetSkillInfoById(npc.AutoSkillIds[i]); if (null != skInfo && !skInfo.IsInCd(curTime) && skInfo.ConfigData.skillData.autoCast > priority) { selectSkill = skInfo; priority = skInfo.ConfigData.skillData.autoCast; } } } return(selectSkill); }
internal bool CheckOperation(ulong guid) { bool ret = true; long curTime = TimeUtility.GetLocalMilliseconds(); OperationInfo opInfo; if (m_OperationInfos.TryGetValue(guid, out opInfo)) { if (opInfo.m_LastTime + c_MonitorInterval < curTime) { opInfo.m_Count = 0; opInfo.m_LastTime = curTime; } else { ++opInfo.m_Count; if (opInfo.m_Count > c_MaxOperationCount) { ret = false; } } } else { opInfo = new OperationInfo(); opInfo.m_LastTime = curTime; m_OperationInfos.Add(guid, opInfo); } return(ret); }
internal void Tick() { try { if (m_NetClient == null) { return; } long curTime = TimeUtility.GetLocalMilliseconds(); if (m_IsConnected && m_CanSendMessage) { if (curTime - m_LastPingTime >= m_PingInterval) { InternalPing(); } } ProcessMsg(); if (m_WaitDisconnect && m_WaitDisconnectTime + 5000 < curTime) { m_WaitDisconnect = false; WorldSystem.Instance.PromptExceptionAndGotoMainCity(); } } catch (Exception e) { string err = "Exception:" + e.Message + "\n" + e.StackTrace + "\n"; LogSystem.Error("Exception:{0}\n{1}", e.Message, e.StackTrace); } }
public void Tick() { if (GlobalVariables.Instance.IsFullClient) { return; } if (!m_IsWaitStart) { long curTime = TimeUtility.GetLocalMilliseconds(); if (!IsConnected) { if (m_LastConnectTime + 10000 < curTime) { ConnectIfNotOpen(); } } else { if (m_IsLogged && m_LastHeartbeatTime + 60000 < curTime) { m_LastHeartbeatTime = curTime; SendHeartbeat(); } } } }
public void Evaluate(StoryInstance instance, object iterator, object[] args) { m_HaveValue = false; m_Value = (int)TimeUtility.GetLocalMilliseconds(); m_HaveValue = true; }
public void Evaluate(StoryInstance instance, StoryMessageHandler handler, BoxedValue iterator, BoxedValueList args) { m_HaveValue = false; m_Value = (int)TimeUtility.GetLocalMilliseconds(); m_HaveValue = true; }
private void OnCommand(int src, int dest, string command) { const string c_QuitLobby = "QuitLobby"; const string c_ReloadConfig = "ReloadConfig"; try { if (0 == command.CompareTo(c_QuitLobby)) { LogSys.Log(LOG_TYPE.MONITOR, "receive {0} command, save data and then quitting ...", command); if (!m_WaitQuit) { m_UserProcessScheduler.DispatchAction(m_UserProcessScheduler.DoCloseServers); m_LastWaitQuitTime = TimeUtility.GetLocalMilliseconds(); m_WaitQuit = true; } } else if (0 == command.CompareTo(c_ReloadConfig)) { CenterClientApi.ReloadConfigScript(); LobbyConfig.Init(); LogSys.Log(LOG_TYPE.WARN, "receive {0} command.", command); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal void ConnectIfNotOpen() { if (!IsConnected) { m_LastReceiveHeartbeatTime = 0; m_LastQueueingTime = 0; m_LastShowQueueingNum = 0; m_LastConnectTime = TimeUtility.GetLocalMilliseconds(); LogSystem.Debug("ConnectIfNotOpen at time:{0} ServerAddress:{1}", m_LastConnectTime, m_Url); WorldSystem.Instance.WaitMatchSceneId = -1; m_IsLogining = true; m_IsQueueing = false; #if !PLATFORM_WEBGL m_WebSocket = new WebSocket4Net.WebSocket(m_Url); #else m_WebSocket = WebSocketWrapper.Instance; m_WebSocket.SetUrl(m_Url); #endif m_WebSocket.AllowUnstrustedCertificate = true; m_WebSocket.EnableAutoSendPing = true; m_WebSocket.AutoSendPingInterval = 10; m_WebSocket.Opened += OnWsOpened; m_WebSocket.MessageReceived += OnWsMessageReceived; m_WebSocket.DataReceived += OnWsDataReceived; m_WebSocket.Error += OnWsError; m_WebSocket.Closed += OnWsClosed; m_WebSocket.Open(); } }
internal void Tick() { try { if (m_NetClient == null) { return; } long curTime = TimeUtility.GetLocalMilliseconds(); if (m_IsConnected && m_CanSendMessage) { if (curTime - m_LastPingTime >= m_PingInterval) { InternalPing(); } } ProcessMsg(); if (m_WaitDisconnect && m_WaitDisconnectTime + 5000 < curTime) { m_WaitDisconnect = false; LogSystem.Debug("{0} auth failed, restart match !!! {1}", Robot.LobbyNetworkSystem.User, LobbyRobot.Robot.GetDateTime()); QuitBattle(true); Robot.LobbyNetworkSystem.QuitRoom(); Robot.StorySystem.SendMessage("missionfailed"); } } catch (Exception e) { LogSystem.Error("{0} Exception:{1}\n{2}", Robot.LobbyNetworkSystem.User, e.Message, e.StackTrace); } }
internal void Disconnect() { if (null != m_Connection && NetConnectionStatus.Connected == m_Connection.Status) { m_Connection.Disconnect("disconnect"); SetLastPingTime(TimeUtility.GetLocalMilliseconds() - m_ConnectionOverTime); } }
private void InternalPing() { Msg_Ping builder = new Msg_Ping(); m_LastPingTime = TimeUtility.GetLocalMilliseconds(); builder.send_ping_time = (int)m_LastPingTime; SendMessage(builder); }
internal void WaitDisconnect() { if (!m_WaitDisconnect) { m_WaitDisconnect = true; m_WaitDisconnectTime = TimeUtility.GetLocalMilliseconds(); } }
public override void Tick() { long now = TimeUtility.GetLocalMilliseconds(); if (now - LastGCTime > GCInterval) { Env_.Tick(); LastGCTime = now; } }
private void TryUpdateValue(StoryInstance instance) { Scene scene = instance.Context as Scene; if (null != scene) { m_HaveValue = true; m_Value = TimeUtility.GetLocalMilliseconds(); } }
private void InternalPing() { if (m_CanSendMessage) { Msg_Ping builder = new Msg_Ping(); m_LastPingTime = TimeUtility.GetLocalMilliseconds(); builder.send_ping_time = (int)m_LastPingTime; SendMessage(RoomMessageDefine.Msg_Ping, builder); } }
internal long GetElapsedDroppedTime() { long time = 0; if (IsTimeout()) { long current_time = TimeUtility.GetLocalMilliseconds(); time = current_time - m_LastPingTime - m_ConnectionOverTime; } return(time); }
internal static void Execute(object msg, NetConnection conn) { Msg_Pong pong_msg = msg as Msg_Pong; if (pong_msg == null) { return; } long time = TimeUtility.GetLocalMilliseconds(); NetworkSystem.Instance.OnPong(time, pong_msg.send_ping_time, pong_msg.send_pong_time); }
internal void AddKickUser(string accountId, long time) { long unlockTime = TimeUtility.GetLocalMilliseconds() + time; if (m_KickedUsers.ContainsKey(accountId)) { m_KickedUsers[accountId] = unlockTime; } else { m_KickedUsers.Add(accountId, unlockTime); } }
internal void Tick() { if (!m_IsWaitStart) { long curTime = TimeUtility.GetLocalMilliseconds(); if (!IsConnected) { if (m_LastConnectTime + 10000 < curTime) { ConnectIfNotOpen(); } } else { if (m_IsQueueing) { if (m_LastQueueingTime + 5000 < curTime) { m_LastQueueingTime = curTime; SendGetQueueingCount(); } } if (m_HasLoggedOn && !m_IsLogining && m_LastConnectTime + 5000 < curTime) { if (m_LastHeartbeatTime + 5000 < curTime) { m_LastHeartbeatTime = curTime; if (m_LastReceiveHeartbeatTime == 0) { m_LastReceiveHeartbeatTime = curTime; } SendHeartbeat(); } if (m_LastReceiveHeartbeatTime > 0 && m_LastReceiveHeartbeatTime + 30000 < curTime) { //断开连接 if (IsConnected) { m_WebSocket.Close(); m_LastReceiveHeartbeatTime = 0; } //触发重连 m_LastConnectTime = curTime - 10000; } } } } }
private void OnConnected(NetConnection conn) { m_Connection = conn; m_IsConnected = true; m_ReconnectCount = 0; Msg_CR_ShakeHands bd = new Msg_CR_ShakeHands(); bd.auth_key = Key; SendMessage(RoomMessageDefine.Msg_CR_ShakeHands, bd); m_LastShakeHandsTime = TimeUtility.GetLocalMilliseconds(); m_WaitShakeHands = true; }
internal bool IsTimeout() { long current_time = TimeUtility.GetLocalMilliseconds(); if (current_time <= m_EnterRoomTime + m_FirstEnterWaitTime) { return(false); } if (current_time - m_LastPingTime > m_ConnectionOverTime) { return(true); } return(false); }
private void Loop() { try { while (CenterClientApi.IsRun()) { long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastTickTime != 0) { long elapsedTickTime = curTime - m_LastTickTime; if (elapsedTickTime > c_WarningTickTime) { LogSys.Log(LOG_TYPE.MONITOR, "DataCache Network Tick:{0}", curTime - m_LastTickTime); } } m_LastTickTime = curTime; CenterClientApi.Tick(); Thread.Sleep(10); if (m_WaitQuit) { if (PersistentSystem.Instance.StartLastSaveResult == PersistentSystem.SaveState.Failed) { //发起存盘操作失败,重置m_WaitQuit m_WaitQuit = false; } if (PersistentSystem.Instance.LastSaveState == PersistentSystem.SaveState.Success) { LogSys.Log(LOG_TYPE.MONITOR, "DataCache LastSave Success. DataCache quit ..."); Thread.Sleep(10000); CenterClientApi.Quit(); } else if (PersistentSystem.Instance.LastSaveState == PersistentSystem.SaveState.Failed) { LogSys.Log(LOG_TYPE.MONITOR, "DataCache LastSave Failed. DataCache NOT quit ..."); PersistentSystem.Instance.LastSaveState = PersistentSystem.SaveState.Initial; m_WaitQuit = false; } } if (m_LastEchoTime + 5000 < curTime) { m_LastEchoTime = curTime; CenterClientApi.SendCommandByName("DataCache", "Echo"); } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "DataCache.Loop throw exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
internal void Tick() { long time = TimeUtility.GetLocalMilliseconds(); int ct = m_StoryLogicInfos.Count; for (int ix = ct - 1; ix >= 0; --ix) { StoryInstance info = m_StoryLogicInfos[ix]; info.Tick(time); if (info.IsTerminated) { m_StoryLogicInfos.RemoveAt(ix); } } }
internal void UpdateUserServerInfo(int worldId, int userCount) { UserServerInfo info; if (!m_LobbyInfo.UserServerInfos.TryGetValue(worldId, out info)) { info = new UserServerInfo(); m_LobbyInfo.UserServerInfos.Add(worldId, info); } info.LastUpdateTime = TimeUtility.GetLocalMilliseconds(); info.WorldId = worldId; info.UserCount = userCount; LogSys.Log(LOG_TYPE.MONITOR, "UpdateLobbyServerInfo, world id:{0}, user count:{1}", worldId, userCount); }
public void Tick() { if (!m_IsWaitStart) { long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastConnectTime + 10000 < curTime) { ConnectIfNotOpen(); } if (m_LastHeartbeatTime + USERINTERVAL * 1000 < curTime) { m_LastHeartbeatTime = curTime; SendHeartbeat(); } } }
private void SendRoomServerUpdateInfo() { long curTime = TimeUtility.GetLocalMilliseconds(); int ts = (int)(curTime - m_LastSendRoomInfoTime); if (ts >= c_SendIntervalMs) { m_LastSendRoomInfoTime = curTime; Msg_RL_RoomServerUpdateInfo msgBuilder = new Msg_RL_RoomServerUpdateInfo(); msgBuilder.ServerName = m_RoomServerName; msgBuilder.IdleRoomNum = m_RoomMgr.GetIdleRoomCount(); msgBuilder.UserNum = m_RoomMgr.GetUserCount(); m_Channel.Send(msgBuilder); //LogSys.Log(LOG_TYPE.DEBUGI, "send room info to Lobby, Name:{0} IdleRoomNum:{1} UserNum:{2}.", room_server_name_, room_mgr_.GetIdleRoomCount(), room_mgr_.GetUserCount()); } }
private void ConnectIfNotOpen() { if (!IsConnected) { m_IsLogged = false; m_LastConnectTime = TimeUtility.GetLocalMilliseconds(); GfxSystem.GfxLog("ConnectIfNotOpen at time {0}", m_LastConnectTime); m_WebSocket = new SocketIOClient.Client(m_Url); m_WebSocket.Opened += OnOpened; m_WebSocket.Error += OnError; m_WebSocket.SocketConnectionClosed += OnClosed; m_WebSocket.Message += OnMessageReceived; m_WebSocket.Connect(); } }
private void SendRoomServerUpdateInfo() { long curTime = TimeUtility.GetLocalMilliseconds(); int ts = (int)(curTime - last_send_roominfo_time_); if (ts >= c_send_interval_ms) { last_send_roominfo_time_ = curTime; Msg_RL_RoomServerUpdateInfo msgBuilder = new Msg_RL_RoomServerUpdateInfo(); msgBuilder.ServerName = room_server_name_; msgBuilder.IdleRoomNum = room_mgr_.GetIdleRoomCount(); msgBuilder.UserNum = room_mgr_.GetUserCount(); channel_.Send(msgBuilder); //LogSys.Log(LOG_TYPE.DEBUGI, "send room info to Lobby, Name:{0} IdleRoomNum:{1} UserNum:{2}.", room_server_name_, room_mgr_.GetIdleRoomCount(), room_mgr_.GetUserCount()); } }