private static void GameThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long balance = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long start = TickHelper.GetTickCount(); int gameCount = 0; try { gameCount = GameMgr.UpdateGames(start); if (GameMgr.m_clearGamesTimer <= start) { GameMgr.m_clearGamesTimer += (long)GameMgr.CLEAR_GAME_INTERVAL; ArrayList temp = new ArrayList(); foreach (BaseGame g in GameMgr.m_games) { if (g.GameState == eGameState.Stopped) { temp.Add(g); } } foreach (BaseGame g in temp) { GameMgr.m_games.Remove(g); } ThreadPool.QueueUserWorkItem(new WaitCallback(GameMgr.ClearStoppedGames), temp); } } catch (Exception ex) { GameMgr.log.Error("Game Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += GameMgr.THREAD_INTERVAL - (end - start); if (end - start > GameMgr.THREAD_INTERVAL * 2L) { GameMgr.log.WarnFormat("Game Mgr spent too much times: {0} ms, count:{1}", end - start, gameCount); } if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { balance += 1000L; } } if (GameMgr.DELAY_TIME > 0) { GameMgr.log.ErrorFormat("Delay for {0} ms!", GameMgr.DELAY_TIME); Thread.Sleep(GameMgr.DELAY_TIME); } } }
private static void GameThread() { long num = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long tickCount = TickHelper.GetTickCount(); try { GameMgr.UpdateGames(tickCount); GameMgr.ClearStoppedGames(tickCount); } catch (Exception exception) { GameMgr.log.Error("Room Mgr Thread Error:", exception); } long tickCount2 = TickHelper.GetTickCount(); num += GameMgr.THREAD_INTERVAL - (tickCount2 - tickCount); if (num > 0L) { Thread.Sleep((int)num); num = 0L; } else { if (num < -1000L) { GameMgr.log.WarnFormat("Room Mgr is delay {0} ms!", num); num += 1000L; } } } }
private static void GameThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long num = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long tickCount = TickHelper.GetTickCount(); int num2 = 0; try { num2 = GameMgr.UpdateGames(tickCount); if (GameMgr.m_clearGamesTimer <= tickCount) { GameMgr.m_clearGamesTimer += (long)GameMgr.CLEAR_GAME_INTERVAL; ArrayList arrayList = new ArrayList(); foreach (BaseGame current in GameMgr.m_games) { if (current.GameState == eGameState.Stopped) { arrayList.Add(current); } } foreach (BaseGame item in arrayList) { GameMgr.m_games.Remove(item); } ThreadPool.QueueUserWorkItem(new WaitCallback(GameMgr.ClearStoppedGames), arrayList); } } catch (Exception exception) { GameMgr.log.Error("Game Mgr Thread Error:", exception); } long tickCount2 = TickHelper.GetTickCount(); num += GameMgr.THREAD_INTERVAL - (tickCount2 - tickCount); if (tickCount2 - tickCount > GameMgr.THREAD_INTERVAL * 2L) { GameMgr.log.WarnFormat("Game Mgr spent too much times: {0} ms, count:{1}", tickCount2 - tickCount, num2); } if (num > 0L) { Thread.Sleep((int)num); num = 0L; } else { if (num < -1000L) { num += 1000L; } } } }
private static void RoomThread() { long balance = 0; m_nextClearTick = TickHelper.GetTickCount(); m_nextPickTick = TickHelper.GetTickCount(); while (m_running) { long start = TickHelper.GetTickCount(); try { ExecuteActions(); if (m_nextPickTick <= start) { m_nextPickTick += PICK_UP_INTERVAL; PickUpRooms(start); } if (m_nextClearTick <= start) { m_nextClearTick += CLEAR_ROOM_INTERVAL; ClearRooms(start); } } catch (Exception ex) { log.Error("Room Mgr Thread Error:", ex); } //时间补偿 long end = TickHelper.GetTickCount(); balance += THREAD_INTERVAL - (end - start); if (balance > 0) { Thread.Sleep((int)balance); balance = 0; } else { if (balance < -1000) { log.WarnFormat("Room Mgr is delay {0} ms!", balance); balance += 1000; } } } }
private static int ExecuteActions() { IAction[] actions = null; Queue <IAction> actionQueue; Monitor.Enter(actionQueue = RoomMgr.m_actionQueue); try { if (RoomMgr.m_actionQueue.Count > 0) { actions = new IAction[RoomMgr.m_actionQueue.Count]; RoomMgr.m_actionQueue.CopyTo(actions, 0); RoomMgr.m_actionQueue.Clear(); } } finally { Monitor.Exit(actionQueue); } int result; if (actions != null) { IAction[] array = actions; for (int i = 0; i < array.Length; i++) { IAction ac = array[i]; try { long begin = TickHelper.GetTickCount(); ac.Execute(); long end = TickHelper.GetTickCount(); if (end - begin > 40L) { RoomMgr.log.WarnFormat("RoomMgr action spent too much times:{0},{1}ms!", ac.GetType(), end - begin); } } catch (Exception ex) { RoomMgr.log.Error("RoomMgr execute action error:", ex); } } result = actions.Length; } else { result = 0; } return(result); }
private static void RoomThread() { long balance = 0L; ProxyRoomMgr.m_nextClearTick = TickHelper.GetTickCount(); ProxyRoomMgr.m_nextPickTick = TickHelper.GetTickCount(); while (ProxyRoomMgr.m_running) { long start = TickHelper.GetTickCount(); try { ProxyRoomMgr.ExecuteActions(); if (ProxyRoomMgr.m_nextPickTick <= start) { ProxyRoomMgr.m_nextPickTick += (long)ProxyRoomMgr.PICK_UP_INTERVAL; ProxyRoomMgr.PickUpRooms(start); } if (ProxyRoomMgr.m_nextClearTick <= start) { ProxyRoomMgr.m_nextClearTick += (long)ProxyRoomMgr.CLEAR_ROOM_INTERVAL; ProxyRoomMgr.ClearRooms(start); } } catch (Exception ex) { ProxyRoomMgr.log.Error("Room Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += (long)ProxyRoomMgr.THREAD_INTERVAL - (end - start); if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { ProxyRoomMgr.log.WarnFormat("Room Mgr is delay {0} ms!", balance); balance += 1000L; } } if (ProxyRoomMgr.DELAY_TIME > 0) { ProxyRoomMgr.log.ErrorFormat("Delay for {0} ms!", ProxyRoomMgr.DELAY_TIME); Thread.Sleep(ProxyRoomMgr.DELAY_TIME); } } }
private static void RoomThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long balance = 0L; RoomMgr.m_clearTick = TickHelper.GetTickCount(); while (RoomMgr.m_running) { long start = TickHelper.GetTickCount(); int count = 0; try { count = RoomMgr.ExecuteActions(); if (RoomMgr.m_clearTick <= start) { RoomMgr.m_clearTick += (long)RoomMgr.CLEAR_ROOM_INTERVAL; RoomMgr.ClearRooms(start); } } catch (Exception ex) { RoomMgr.log.Error("Room Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += (long)RoomMgr.THREAD_INTERVAL - (end - start); if (end - start > (long)(RoomMgr.THREAD_INTERVAL * 2)) { RoomMgr.log.WarnFormat("Room Mgr is spent too much times: {0} ms,count:{1}", end - start, count); } if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { balance += 1000L; } } if (RoomMgr.DELAY_TIME > 0) { RoomMgr.log.ErrorFormat("Delay for {0} ms!", RoomMgr.DELAY_TIME); Thread.Sleep(RoomMgr.DELAY_TIME); } } }
private static void RoomThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long balance = 0; m_clearTick = TickHelper.GetTickCount(); while (m_running) { long start = TickHelper.GetTickCount(); int count = 0; try { count = ExecuteActions(); if (m_clearTick <= start) { m_clearTick += CLEAR_ROOM_INTERVAL; ClearRooms(start); } } catch (Exception ex) { log.Error("Room Mgr Thread Error:", ex); } //时间补偿 long end = TickHelper.GetTickCount(); balance += THREAD_INTERVAL - (end - start); if (end - start > THREAD_INTERVAL * 2) { log.WarnFormat("Room Mgr is spent too much times: {0} ms,count:{1}", end - start, count); } if (balance > 0) { Thread.Sleep((int)balance); balance = 0; } else { if (balance < -1000) { balance += 1000; } } } }
private static int ExecuteActions() { IAction[] array = null; Queue <IAction> actionQueue; Monitor.Enter(actionQueue = RoomMgr.m_actionQueue); try { if (RoomMgr.m_actionQueue.Count > 0) { array = new IAction[RoomMgr.m_actionQueue.Count]; RoomMgr.m_actionQueue.CopyTo(array, 0); RoomMgr.m_actionQueue.Clear(); } } finally { Monitor.Exit(actionQueue); } if (array != null) { IAction[] array2 = array; for (int i = 0; i < array2.Length; i++) { IAction action = array2[i]; try { long tickCount = TickHelper.GetTickCount(); action.Execute(); long tickCount2 = TickHelper.GetTickCount(); if (tickCount2 - tickCount > 40L) { RoomMgr.log.WarnFormat("RoomMgr action spent too much times:{0},{1}ms!", action.GetType(), tickCount2 - tickCount); } } catch (Exception exception) { RoomMgr.log.Error("RoomMgr execute action error:", exception); } } return(array.Length); } return(0); }
private static void RoomThread() { long num = 0L; ProxyRoomMgr.m_nextClearTick = TickHelper.GetTickCount(); ProxyRoomMgr.m_nextPickTick = TickHelper.GetTickCount(); while (ProxyRoomMgr.m_running) { long tickCount = TickHelper.GetTickCount(); try { ProxyRoomMgr.ExecuteActions(); if (ProxyRoomMgr.m_nextPickTick <= tickCount) { ProxyRoomMgr.m_nextPickTick += (long)ProxyRoomMgr.PICK_UP_INTERVAL; ProxyRoomMgr.PickUpRooms(tickCount); } if (ProxyRoomMgr.m_nextClearTick <= tickCount) { ProxyRoomMgr.m_nextClearTick += (long)ProxyRoomMgr.CLEAR_ROOM_INTERVAL; ProxyRoomMgr.ClearRooms(tickCount); } } catch (Exception exception) { ProxyRoomMgr.log.Error("Room Mgr Thread Error:", exception); } long tickCount2 = TickHelper.GetTickCount(); num += (long)ProxyRoomMgr.THREAD_INTERVAL - (tickCount2 - tickCount); if (num > 0L) { Thread.Sleep((int)num); num = 0L; } else { if (num < -1000L) { ProxyRoomMgr.log.WarnFormat("Room Mgr is delay {0} ms!", num); num += 1000L; } } } }
private static void RoomThread() { Thread.CurrentThread.Priority = ThreadPriority.Highest; long num = 0L; RoomMgr.m_clearTick = TickHelper.GetTickCount(); while (RoomMgr.m_running) { long tickCount = TickHelper.GetTickCount(); int num2 = 0; try { num2 = RoomMgr.ExecuteActions(); if (RoomMgr.m_clearTick <= tickCount) { RoomMgr.m_clearTick += (long)RoomMgr.CLEAR_ROOM_INTERVAL; RoomMgr.ClearRooms(tickCount); } } catch (Exception exception) { RoomMgr.log.Error("Room Mgr Thread Error:", exception); } long tickCount2 = TickHelper.GetTickCount(); num += (long)RoomMgr.THREAD_INTERVAL - (tickCount2 - tickCount); if (tickCount2 - tickCount > (long)(RoomMgr.THREAD_INTERVAL * 2)) { RoomMgr.log.WarnFormat("Room Mgr is spent too much times: {0} ms,count:{1}", tickCount2 - tickCount, num2); } if (num > 0L) { Thread.Sleep((int)num); num = 0L; } else { if (num < -1000L) { num += 1000L; } } } }
public override void SendTCP(GSPacketIn pkg) { Debug.Log("Sending pkg code " + ((ePackageType)pkg.Code).ToString() + " para1: " + pkg.Parameter1.ToString() + "para2: " + pkg.Parameter2.ToString()); GameController.LogToScreen("Sending pkg code " + ((ePackageType)pkg.Code).ToString() + " para1: " + pkg.Parameter1.ToString() + "para2: " + pkg.Parameter2.ToString()); base.SendTCP(pkg); Debug.Log("SEND " + ((ePackageType)pkg.Code).ToString() + " SUCCEED"); this.m_sentCount++; this.m_lastSent = pkg.Code; this.m_lastSentTime = DateTime.Now; this.m_actionInterval = TickHelper.GetTickCount() - this.m_lastSentTick; this.m_lastSentTick = TickHelper.GetTickCount(); /*if (this.m_log != null) * { * this.m_log.WriteLine(Marshal.ToHexDump(string.Format("player [{0}]:{1} sent:", this.m_account, DateTime.Now), pkg.Buffer, 0, pkg.Length)); * }*/ }
public ClientConnector(string account, string password, int interval, string ip, int port, ConnectorManager cManager) : base(ip, port, false, new byte[0x2000], new byte[0x2000]) { this.m_account = account; this.Password = password; this.m_isHost = false; this.m_timer = new System.Timers.Timer((double)interval); this.m_timer.Elapsed += new ElapsedEventHandler(this.m_timer_Elapsed); this.m_queue = new Queue <PlayerExecutable>(); this.m_state = ePlayerState.Init; this.m_lastSentTick = TickHelper.GetTickCount(); this.m_actionInterval = 0L; this.m_recvCount = 0; this.m_sentCount = 0; base.Strict = true; base.Encryted = true; this.connectorManager = cManager; this.SetHostIp(ip); this.lastErr = eErrorCode.DONE; //this.m_log = new StreamWriter(System.IO.File.Create(string.Format("./logs/{0}.log", account))); }
private static void GameThread() { long balance = 0L; GameMgr.m_clearGamesTimer = TickHelper.GetTickCount(); while (GameMgr.m_running) { long start = TickHelper.GetTickCount(); try { GameMgr.UpdateGames(start); GameMgr.ClearStoppedGames(start); } catch (Exception ex) { GameMgr.log.Error("Room Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += GameMgr.THREAD_INTERVAL - (end - start); if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { GameMgr.log.WarnFormat("Room Mgr is delay {0} ms!", balance); balance += 1000L; } } if (GameMgr.DELAY_TIME > 0) { GameMgr.log.ErrorFormat("Delay for {0} ms!", GameMgr.DELAY_TIME); Thread.Sleep(GameMgr.DELAY_TIME); } } }
private static void GameThread() { long balance = 0; m_clearGamesTimer = TickHelper.GetTickCount(); while (m_running) { long start = TickHelper.GetTickCount(); try { UpdateGames(start); ClearStoppedGames(start); } catch (Exception ex) { log.Error("Room Mgr Thread Error:", ex); } //时间补偿 long end = TickHelper.GetTickCount(); balance += THREAD_INTERVAL - (end - start); if (balance > 0) { Thread.Sleep((int)balance); balance = 0; } else { if (balance < -1000) { log.WarnFormat("Room Mgr is delay {0} ms!", balance); balance += 1000; } } } }
private static int ExecuteActions() { IAction[] actions = null; lock (m_actionQueue) { if (m_actionQueue.Count > 0) { actions = new IAction[m_actionQueue.Count]; m_actionQueue.CopyTo(actions, 0); m_actionQueue.Clear(); } } if (actions != null) { foreach (IAction ac in actions) { try { long begin = TickHelper.GetTickCount(); ac.Execute(); long end = TickHelper.GetTickCount(); if (end - begin > 40) { log.WarnFormat("RoomMgr action spent too much times:{0},{1}ms!", ac.GetType(), end - begin); } } catch (Exception ex) { log.Error("RoomMgr execute action error:", ex); } } return(actions.Length); } return(0); }
public BaseAction(int delay, int finishDelay) { this.m_tick = TickHelper.GetTickCount() + (long)delay; this.m_finishDelay = (long)finishDelay; this.m_finishTick = 9223372036854775807L; }
private static void PickUpRooms(long tick) { List <ProxyRoom> rooms = ProxyRoomMgr.GetWaitMatchRoomUnsafe(); rooms.Sort(); int pairs = 0; long begin = TickHelper.GetTickCount(); if (ProxyRoomMgr.ShowTick) { log.DebugFormat("-----begin pickup----tick:{0}-----rooms:{1}", begin, rooms.Count); } foreach (ProxyRoom red in rooms) { red.PickUpCount++; int maxScore = -2147483648; ProxyRoom matchRoom = null; if (!red.IsPlaying) { if (red.GameType == eGameType.ALL) { foreach (ProxyRoom blue in rooms) { //判断是不是同一个公会或不是同一个区 if (blue.GuildId != red.GuildId || blue.AreaID != red.AreaID) { if (blue != red && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score > maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } else { if (red.GameType == eGameType.Guild) { foreach (ProxyRoom blue in rooms) { if (blue.GuildId == 0 || blue.AreaID != red.AreaID || blue.GuildId != red.GuildId) { if (blue != red && blue.GameType != eGameType.Free && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score >= maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } else { foreach (ProxyRoom blue in rooms) { if (blue.GuildId == 0 || blue.GuildId != red.GuildId || blue.AreaID != red.AreaID) { if (blue != red && blue.GameType != eGameType.Guild && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score >= maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } } if (matchRoom != null) { if (red.PickUpCount >= 2) { pairs++; ProxyRoomMgr.StartMatchGame(red, matchRoom); } } } } ProxyRoomMgr.SendInfoToAllGameServer(); if (ProxyRoomMgr.ShowTick) { long end = TickHelper.GetTickCount(); Console.WriteLine("-----end pickup----tick:{0}-----spends:{1} --- pairs:{2}", end, end - begin, pairs); } }
public CheckPVEGameStateAction(int delay) { this.m_time = TickHelper.GetTickCount() + (long)delay; this.m_isFinished = false; }
public WaitPlayerLoadingAction(BaseGame game, int maxTime) { m_time = TickHelper.GetTickCount() + maxTime; game.GameStarted += new GameEventHandle(game_GameStarted); }
public CheckPVEGameStateAction(int delay) { m_time = TickHelper.GetTickCount() + delay; m_isFinished = false; }
public BaseAction(int delay, int finishDelay) { m_tick = TickHelper.GetTickCount() + delay; m_finishDelay = finishDelay; m_finishTick = long.MaxValue; }
void player_EndAttacking(Living player) { player.EndAttacking -= player_EndAttacking; Finish(TickHelper.GetTickCount()); }
private void player_EndAttacking(Living player) { player.EndAttacking -= new LivingEventHandle(this.player_EndAttacking); base.Finish(TickHelper.GetTickCount()); }