public bool Delay() { if (m_tDelay == null) { m_tDelay = new TimeOutMS(0); SetDelay(); } return(m_tDelay.ToNextTime()); }
/// <summary> /// Starts the server common threading, like checking if a client is online, /// updating the window title and such things. /// </summary> public static void ServerTasks() { _tTitle.Update(); _tAnalytic.Update(); _tCheckBan.Update(); var remove = new List <BannedAddress>(); while (true) { if (_tTitle.ToNextTime()) { Program.UpdateWindowTitle(); } if (_tAnalytic.ToNextTime()) { Program.WriteAnalytic(); } if (ServerKernel.BannedAddresses.Count > 0 && _tCheckBan.ToNextTime()) { remove = ServerKernel.BannedAddresses.Values.Where(banned => !banned.Banned).ToList(); } if (remove.Count > 0) { BannedAddress trash; foreach (var get in remove) { ServerKernel.BannedAddresses.TryRemove(get.Address, out trash); } } Thread.Sleep(500); } }
public static void ServerTasks() { m_pLoginMs.Update(); m_pLogin.Update(); m_t_1Second.Startup(1); m_tPlayer.Startup(1); m_tItem.Startup(5); while (true) { try { // handle socket connection if (ServerKernel.LoginServer == null && m_pLoginMs.ToNextTime()) { ServerKernel.Log.SaveLog("Connect to the account server...", true, LogType.MESSAGE); try { var pSocket = new LoginSocket(); pSocket.ConnectTo(ServerKernel.LoginServerAddress, ServerKernel.LoginServerPort); ServerKernel.LoginServer = new LoginClient(pSocket, pSocket, null); try { ServerKernel.Log.SaveLog("Connected to the account server!", true, LogType.MESSAGE); ServerKernel.Log.SaveLog("Server will attempt a connection after 1 second...", true, LogType.MESSAGE); Thread.Sleep(1000); var pMsg = new MsgLoginSvAuthRequest(ServerKernel.HelloSendString); ServerKernel.LoginServer.Send(pMsg); } catch (SocketException ex) { ServerKernel.LoginServer = null; pSocket.Dispose(); pSocket = null; } } catch (SocketException ex) { if (ex.ErrorCode != 10061 && ex.ErrorCode != 10057) { ServerKernel.Log.SaveLog("Exception thrown while trying to connect to login server", true, LogType.ERROR); ServerKernel.Log.SaveLog(ex.ToString(), false, LogType.EXCEPTION); } } } // clean the login request list if (ServerKernel.LoginServer != null) { if (m_pLogin.ToNextTime() && ServerKernel.LoginQueue.Count > 0) { List <LoginRequest> temp = ServerKernel.LoginQueue.Values.Where(x => x.IsExpired()).ToList(); LoginRequest trash; foreach (var pReq in temp) { ServerKernel.LoginQueue.TryRemove(pReq.AccountIdentity, out trash); } } } if (m_t_1Second.ToNextTime()) { Program.UpdateTitle(); } if (!m_tItem.ToNextTime()) { continue; } foreach (Client user in ServerKernel.Players.Values.ToList()) { if (user.Character == null) { continue; } if (!user.Character.LoginComplete || user.Character.Inventory == null || user.Character.Equipment == null) { continue; } foreach (Item item in user.Character.Inventory.Items.Values) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { user.Character.Inventory.Remove(item.Identity); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } item.TryUnlockItem(); } foreach (Item item in user.Character.Equipment.Items.Values) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { user.Character.Equipment.Remove(item.Position, Equipment.ItemRemoveMethod.DELETE); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } item.TryUnlockItem(); } try { foreach (Warehouse wh in user.Character.Warehouses.Values.ToList()) { foreach (Item item in wh.Items.Values.ToList()) { if (!item.ArtifactIsActive() || !item.RefineryIsActive()) { item.CheckForPurificationExpired(); } if (item.ItemExpired()) { wh.Delete(item.Identity); ServerKernel.Log.GmLog("item_expire", string.Format("Item[{0}] type[{1}] owner[{2}] expired-at[{3}]", item.Identity, item.Type, item.PlayerIdentity, UnixTimestamp.Timestamp())); } } } } catch { } } foreach (var detained in ServerKernel.DetainedObjects.Values.Where(x => x.IsItem())) { detained.OnTimer(); } foreach (Map map in ServerKernel.Maps.Values) { foreach (IScreenObject _object in map.GameObjects.Values) { if (_object is MapItem) { var item = _object as MapItem; if (item.IsDisappear()) { map.RemoveItem(item); item.SelfDelete(); } } } } if (m_tRestart.IsActive() && m_tRestart.ToNextTime(30)) { m_nRestartAlert++; if (MaintenanceRemainingSeconds() <= 0) { ServerKernel.SendMessageToAll("Server is being brought down to maintenance.", ChatTone.TALK); Program.SaveAll(); Environment.Exit(0); break; } //string msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY, // MaintenanceRemainingSeconds()); int remainSecs = MaintenanceRemainingSeconds(); string msg = ""; if (remainSecs == 60) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MINUTE, remainSecs / 60); } else if (remainSecs > 60 && remainSecs % 60 == 0) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MINUTES, remainSecs / 60); } else if (remainSecs % 60 > 0) { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_MIN_AND_SECS, remainSecs / 60, remainSecs % 60); } else { msg = string.Format(ServerString.STR_SHUTDOWN_NOTIFY_SECONDS, remainSecs); } ServerKernel.SendMessageToAll(msg, ChatTone.CENTER); ServerKernel.Log.SaveLog(msg, true, LogType.DEBUG); } } catch (Exception ex) { ServerKernel.Log.SaveLog(ex.ToString(), true, LogType.EXCEPTION); } finally { Thread.Sleep(1000); } } }
public void OnTimer() { int weekday = (int)(DateTime.Now.DayOfWeek) % 7 == 0 ? 7 : (int)(DateTime.Now.DayOfWeek); int now = int.Parse(DateTime.Now.ToString("HHmmss")) + weekday * 1000000; if (m_pState == EventState.IDLE && now >= _STARTUP_TIME && now < _END_TIME) { GenerateFlags(); foreach (var rank in m_pRanking.Values) { rank.Value1 = 0; rank.Value3 = 0; m_pRepo.SaveOrUpdate(rank); } foreach (var rank in m_pUserRank.Values) { rank.Value1 = 0; rank.Value3 = 0; m_pRepo.SaveOrUpdate(rank); } m_pState = EventState.RUNNING; } else if (m_pState == EventState.RUNNING) { if (m_tFlagGen.ToNextTime()) { GenerateFlags(); } if (m_tRankSend.ToNextTime()) { // todo send ctf rank List <string> pRank = new List <string>(9); pRank.Add("Capture The Flag"); int count = 0; foreach (var rnk in m_pRanking.Values.OrderByDescending(x => x.Value1)) { if (rnk.Value1 > 0) { if (count++ < 8) { pRank.Add(string.Format("Nº{0}. {1} - {2}", count, rnk.ObjectName.PadRight(16), rnk.Value1)); } else { break; } } } foreach (var player in m_pMap.Players.Values.ToList()) { player.Send(pRank[0], ChatTone.EVENT_RANKING); for (int i = 1; i < pRank.Count; i++) { player.Send(pRank[i], ChatTone.EVENT_RANKING_NEXT); } } } if (now < _STARTUP_TIME || now >= _END_TIME) { Finish(); DeliveRewards(); m_pState = EventState.IDLE; } } // if not, nothing will be done, event not loaded }
public bool NextAttack(int nFightPause) { return(m_tFight.ToNextTime(nFightPause)); }
public static void EventTasks() { m_pScorePK.Startup(1); m_pQuizShow.Startup(750); m_pPigeon.Startup(1); m_pMapEvent.Startup(10); m_pGuildWar.Startup(1); while (true) { try { if (m_pGuildWar.ToNextTime()) { foreach (var itr in ServerKernel.Maps.Values.Where(x => x.IsSynMap())) { foreach (var pNpc in itr.GameObjects.Values.OfType <DynamicNpc>()) { pNpc.CheckFightTime(); } } } if (m_pQuizShow.ToNextTime()) { ServerKernel.QuizShow.OnTimer(); } if (m_pPigeon.ToNextTime()) { ServerKernel.Broadcast.OnTimer(); } if (ServerKernel.ScorePkEvent.IsReady && m_pScorePK.ToNextTime()) { ServerKernel.ScorePkEvent.OnTimer(); } if (ServerKernel.CaptureTheFlag != null && ServerKernel.CaptureTheFlag.IsActive) { ServerKernel.CaptureTheFlag.OnTimer(); } if (ServerKernel.ArenaQualifier != null && ServerKernel.ArenaQualifier.Status == ArenaQualifierStatus.ENABLED) { ServerKernel.ArenaQualifier.OnTimer(); } if (ServerKernel.SyndicateScoreWar != null && ServerKernel.SyndicateScoreWar.IsAvaiable) { ServerKernel.SyndicateScoreWar.OnTimer(); } if (ServerKernel.LineSkillPk != null && ServerKernel.LineSkillPk.IsReady) { ServerKernel.LineSkillPk.OnTimer(); } if (m_pSynRecruit.ToNextTime()) { ServerKernel.SyndicateRecruitment.CheckSyndicates(); } DateTime now = DateTime.Now; if (now.Hour == 0 && now.Minute == 0 && now.Second == 0 && m_pUpdateLock.ToNextTime()) { foreach (var plr in ServerKernel.Players.Values.ToList()) { plr.Character.DailyReset(); } foreach (var arena in ServerKernel.ArenaRecord.Values) { DbUser dbUsr = Database.Characters.SearchByIdentity(arena.PlayerIdentity); if (dbUsr == null) { arena.Delete(); continue; } arena.LastRanking = arena.Ranking; arena.LastSeasonPoints = arena.Points; arena.LastSeasonWins = arena.TodayWins; arena.LastSeasonsLoses = arena.TodayLoses; arena.Lookface = dbUsr.Lookface; arena.Level = dbUsr.Level; arena.Profession = dbUsr.Profession; if (arena.Ranking > 0) { IHonorReward reward = ServerKernel.HonorRewards.Values.FirstOrDefault(x => x.Ranking == arena.Ranking); if (reward != null) { arena.HonorPoints += reward.DailyHonor; arena.TotalHonorPoints += reward.DailyHonor; } } arena.Level = dbUsr.Level; arena.Lookface = dbUsr.Lookface; arena.Profession = dbUsr.Profession; arena.PlayerName = dbUsr.Name; arena.Save(); } foreach (var arena in ServerKernel.ArenaRecord.Values) { arena.Points = ServerKernel.ArenaQualifier.GetStartupPoints(arena.Level); arena.TodayWins = 0; arena.TodayLoses = 0; arena.Save(); } } if (m_pMapEvent.ToNextTime()) { foreach ( var npc in ServerKernel.Maps.Values.Where(x => x.IsPkField() || x.IsPkGameMap() || x.IsSynMap()) .SelectMany(map => map.GameObjects.Values) .OfType <DynamicNpc>()) { if (npc.MapIdentity == 7600 || npc.MapIdentity == 2057) { continue; } npc.SendOwnerRanking(); } } } catch (Exception ex) { ServerKernel.Log.SaveLog(ex.ToString(), true, LogType.EXCEPTION); } finally { Thread.Sleep(750); } } #pragma warning disable CS0162 // Se detectó código inaccesible Console.WriteLine("Game Event Processing Thread exited"); #pragma warning restore CS0162 // Se detectó código inaccesible }