public void OnTimer(Character pOwner) { if (m_pExpire.IsActive() && m_pExpire.IsTimeOut(60)) { pOwner.Disconnect("PROBABLY AN AUTOCLICKER"); } }
public bool Accept(Character pSender) { if (pSender == m_pPlayer1) { m_bP1Accept = true; } else if (pSender == m_pPlayer2) { m_bP2Accept = true; } else { return(false); } return(m_tStartup.IsActive() && m_tStartup.IsTimeOut()); }
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() { if (m_pState == SyndicateWarState.NOT_BUILT) { return; } int now = int.Parse(DateTime.Now.ToString("HHmmss")); if (m_pState == SyndicateWarState.NOT_RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // start foreach (var syn in m_pSynPoints.Values) { syn.Value1 = 0; m_pRepo.SaveOrUpdate(syn); } foreach (var user in m_pUserPoints.Values) { user.Value1 = 0; m_pRepo.SaveOrUpdate(user); } IScreenObject pScrObj; if (m_pMainMap.GameObjects.TryGetValue(920, out pScrObj) && pScrObj is DynamicNpc) { DynamicNpc pNpc = pScrObj as DynamicNpc; pNpc.Life = pNpc.MaxLife; pNpc.SendToRange(); } m_tRank.Startup(10); m_pState = SyndicateWarState.RUNNING; } else if (m_pState == SyndicateWarState.RUNNING && (now >= _STARTUP_TIME && now < _END_TIME)) { // running if (m_tRank.IsActive() && m_tRank.ToNextTime()) { List <string> pRank = new List <string>(9); pRank.Add("Syndicate Score War"); int count = 0; foreach (var rnk in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rnk.Value1 > 0) { if (count++ < 8) { pRank.Add(string.Format("Nº{0}. {1,16} - {2}", count, rnk.ObjectName.PadRight(16), rnk.Value1)); } else { break; } } } foreach (var player in m_pMainMap.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); } } } } else if (m_pState == SyndicateWarState.RUNNING && (now < _STARTUP_TIME || now > _END_TIME)) { // prepare to finish ServerKernel.SendMessageToAll(string.Format("The time is up! The Guild Score War is over."), ChatTone.TOP_LEFT); m_pState = SyndicateWarState.ENDING; } else if (m_pState == SyndicateWarState.ENDING) { // end time int rank = 0; foreach (var syn in m_pSynPoints.Values.OrderByDescending(x => x.Value1)) { if (rank++ >= 4) { break; } uint synId = syn.ObjectIdentity; int deliverMoney = 0; int deliverEmoney = 0; uint totalMoney = ServerKernel.SYN_SCORE_MONEY_REWARD[rank - 1]; uint totalEmoney = ServerKernel.SYN_SCORE_EMONEY_REWARD[rank - 1]; foreach (var user in m_pUserPoints.Values.Where(x => x.ObjectIdentity == synId && x.PlayerIdentity > 0) .OrderByDescending(x => x.Value1)) { float nPercent = (user.Value1 / (float)syn.Value1); int money = (int)(totalMoney * nPercent); int emoney = (int)(totalEmoney * nPercent); deliverMoney += money; deliverEmoney += emoney; if (money <= 0 && emoney <= 0) { continue; } Client pClient; if (ServerKernel.Players.TryGetValue(user.PlayerIdentity, out pClient)) { pClient.Character.AwardMoney(money); pClient.Character.AwardEmoney(emoney); pClient.SendMessage(string.Format(ServerString.STR_SSPK_AWARDED_PRIZE, user.Value1, money, emoney), ChatTone.GUILD); } else { DbUser pUser = Database.Characters.SearchByIdentity(user.PlayerIdentity); if (pUser != null) { pUser.Money = (uint)Math.Min(int.MaxValue, pUser.Money + money); pUser.Emoney = (uint)Math.Min(int.MaxValue, pUser.Emoney + emoney); Database.Characters.SaveOrUpdate(pUser); } } } } ServerKernel.SendMessageToAll(string.Format("The Guild Score War is over."), ChatTone.TALK); m_pState = SyndicateWarState.NOT_RUNNING; } }