public bool ChangeData(int nPower, int nSecs, int nTimes = 0, uint wCaster = 0) { try { m_nData = nPower; m_tKeep.SetInterval(nSecs * 1000); m_tKeep.Update(); m_dwCaster = wCaster; if (m_pOwner is Character) { Character pUser = m_pOwner as Character; if (Identity == FlagInt.AZURE_SHIELD) { pUser.UpdateAzureShield(nSecs, nPower, Level); } pUser.RecalculateAttributes(); } return(true); } catch { return(false); } }
public void SetDelay() { if (m_dbMagictype == null) { return; } if (m_tDelay == null) { m_tDelay = new TimeOutMS((int)Timeout); } m_tDelay.Startup((int)Timeout); m_tDelay.SetInterval((int)Timeout); m_tDelay.Update(); }
public bool Create(IRole pRole, int nStatus, int nPower, int nSecs, int nTimes, uint caster = 0, byte level = 0) { m_pOwner = pRole; m_dwCaster = caster; m_nStatus = nStatus; m_nData = nPower; m_tKeep = new TimeOutMS(nSecs * 1000); m_tKeep.Startup((int)Math.Min(((long)nSecs * 1000), int.MaxValue)); m_tKeep.Update(); m_tInterval = new TimeOutMS(1000); m_tInterval.Update(); m_pLevel = level; return(true); }
public bool DelNpc() { SetAttribute(ClientUpdateType.HITPOINTS, 0, true); m_tDeathTime.Update(); if (IsSynFlag()) { Map.SetStatus(1, false); //Map.SetSynId(0, true); // todo } else { Database.DynamicNpcRepository.Delete(m_dbNpc); } RemoveFromMap(); return(true); }
/// <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); } } }