public void OnCommand(GameClient client, string[] args) { int i = 0; Hashtable ip = new Hashtable(); string accip; foreach (GameClient cl in WorldMgr.GetAllClients()) { accip = ((IPEndPoint)cl.Socket.RemoteEndPoint).Address.ToString(); if (!ip.Contains(accip)) { ip.Add(accip, cl); } else { GameClient cls = (GameClient)ip[accip]; string name1 = cl.Player != null ? cl.Player.Name : "Entering game..."; string ip1 = ((IPEndPoint)cl.Socket.RemoteEndPoint).Address.ToString(); string name2 = cls.Player != null ? cls.Player.Name : "Entering game..."; string ip2 = ((IPEndPoint)cls.Socket.RemoteEndPoint).Address.ToString(); DisplayMessage(client, "IP: {0} AccountName: {1} (Player: {2}) ", ip1, cl.Account.Name, name1); DisplayMessage(client, "IP: {0} AccountName: {1} (Player: {2}) ", ip2, cls.Account.Name, name2); i++; } } //DisplayMessage.Out.SendMessage(client, "{0} double IP found.", i, eChatType.CT_Say, eChatLoc.CL_PopupWindow); DisplayMessage(client, "{0} double IP found.", i); }
public static void CreateNews(string message, eRealm realm, eNewsType type, bool sendMessage) { if (sendMessage) { foreach (GameClient client in WorldMgr.GetAllClients()) { if (client.Player == null) { continue; } if ((client.Account.PrivLevel != 1 || realm == eRealm.None) || client.Player.Realm == realm) { client.Out.SendMessage(message, eChatType.CT_System, eChatLoc.CL_SystemWindow); } } } if (ServerProperties.Properties.RECORD_NEWS) { DBNews news = new DBNews(); news.Type = (byte)type; news.Realm = (byte)realm; news.Text = message; GameServer.Database.AddObject(news); GameEventMgr.Notify(DatabaseEvent.NewsCreated, new NewsEventArgs(news)); } }
public void OnCommand(GameClient client, string[] args) { if (client.Player.IsMuted) { client.Player.Out.SendMessage("You have been muted and are not allowed to speak in this channel.", eChatType.CT_Staff, eChatLoc.CL_SystemWindow); return; } if (IsSpammingCommand(client.Player, "advice")) { return; } string msg = string.Empty; if (args.Length >= 2) { for (int i = 1; i < args.Length; ++i) { msg += args[i] + " "; } } else { int total = 0; foreach (GameClient playerClient in WorldMgr.GetAllClients()) { if (playerClient.Player == null) { continue; } if (playerClient.Player.Advisor && ((playerClient.Player.Realm == client.Player.Realm && playerClient.Player.IsAnonymous == false) || client.Account.PrivLevel > 1)) { total++; client.Out.SendMessage(total + ")" + playerClient.Player.Name + (playerClient.Player.IsAnonymous ? " [ANON]" : string.Empty), eChatType.CT_System, eChatLoc.CL_SystemWindow); } } client.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Advice.AdvicersOn", total), eChatType.CT_System, eChatLoc.CL_PopupWindow); return; } foreach (GameClient playerClient in WorldMgr.GetAllClients()) { if (playerClient.Player == null) { continue; } if ((playerClient.Player.Advisor && playerClient.Player.Realm == client.Player.Realm) || playerClient.Account.PrivLevel > 1) { playerClient.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "Scripts.Players.Advice.Advice", getRealmString(client.Player.Realm), client.Player.Name, msg), eChatType.CT_Staff, eChatLoc.CL_ChatWindow); } } }
/// <summary> /// Method to broadcast messages, if eRealm.None all can see, /// else only the right realm can see /// </summary> /// <param name="message">The message</param> /// <param name="realm">The realm</param> public static void BroadcastMessage(string message, eRealm realm) { foreach (GameClient client in WorldMgr.GetAllClients()) { if (client.Player == null) { continue; } if ((client.Account.PrivLevel != 1 || realm == eRealm.None) || client.Player.Realm == realm) { client.Out.SendMessage(message, eChatType.CT_Important, eChatLoc.CL_SystemWindow); } } }
public List <string> GetOnlineInfo(bool bGM) { List <string> output = new List <string>(); ArrayList clients = WorldMgr.GetAllClients(); int gms = 0, connecting = 0, charscreen = 0, enterworld = 0, playing = 0, linkdeath = 0, disconnecting = 0; int midTanks = 0, hibTanks = 0, albTanks = 0, midCasters = 0, hibCasters = 0, albCasters = 0, midSupport = 0, hibSupport = 0, albSupport = 0, hibStealthers = 0, midStealthers = 0, albStealthers = 0; #region filling classcount list classcount.Clear(); classcount.Add(new ClassToCount("Armsman", 0)); // 0 classcount.Add(new ClassToCount("Mercenary", 0)); //1 classcount.Add(new ClassToCount("Paladin", 0)); //2 classcount.Add(new ClassToCount("Reaver", 0)); //3 classcount.Add(new ClassToCount("Heretic", 0)); //4 classcount.Add(new ClassToCount("Albion Mauler", 0)); //5 classcount.Add(new ClassToCount("Cabalist", 0)); //6 classcount.Add(new ClassToCount("Sorcerer", 0)); //7 classcount.Add(new ClassToCount("Theurgist", 0)); //8 classcount.Add(new ClassToCount("Wizard", 0)); //9 classcount.Add(new ClassToCount("Necromancer", 0)); //10 classcount.Add(new ClassToCount("Cleric", 0)); //11 classcount.Add(new ClassToCount("Friar", 0)); //12 classcount.Add(new ClassToCount("Minstrel", 0)); //13 classcount.Add(new ClassToCount("Infiltrator", 0)); //14 classcount.Add(new ClassToCount("Scout", 0)); //15 classcount.Add(new ClassToCount("Berserker", 0)); //16 classcount.Add(new ClassToCount("Savage", 0)); //17 classcount.Add(new ClassToCount("Skald", 0)); //18 classcount.Add(new ClassToCount("Thane", 0)); //19 classcount.Add(new ClassToCount("Warrior", 0)); //20 classcount.Add(new ClassToCount("Valkyrie", 0)); //21 classcount.Add(new ClassToCount("Midgard Mauler", 0)); //22 classcount.Add(new ClassToCount("Bonedancer", 0)); //23 classcount.Add(new ClassToCount("Runemaster", 0)); //24 classcount.Add(new ClassToCount("Spiritmaster", 0)); //25 classcount.Add(new ClassToCount("Warlock", 0)); //26 classcount.Add(new ClassToCount("Healer", 0)); //27 classcount.Add(new ClassToCount("Shaman", 0)); //28 classcount.Add(new ClassToCount("Hunter", 0)); //29 classcount.Add(new ClassToCount("Shadowblade", 0)); //30 classcount.Add(new ClassToCount("Blademaster", 0)); //31 classcount.Add(new ClassToCount("Champion", 0)); //32 classcount.Add(new ClassToCount("Hero", 0)); //33 classcount.Add(new ClassToCount("Valewalker", 0)); //34 classcount.Add(new ClassToCount("Hibernia Mauler", 0)); //35 classcount.Add(new ClassToCount("Vampiir", 0)); //36 classcount.Add(new ClassToCount("Eldritch", 0)); //37 classcount.Add(new ClassToCount("Enchanter", 0)); //38 classcount.Add(new ClassToCount("Mentalist", 0)); //39 classcount.Add(new ClassToCount("Animist", 0)); //40 classcount.Add(new ClassToCount("Bainshee", 0)); //41 classcount.Add(new ClassToCount("Bard", 0)); //42 classcount.Add(new ClassToCount("Druid", 0)); //43 classcount.Add(new ClassToCount("Warden", 0)); //44 classcount.Add(new ClassToCount("Nightshade", 0)); //45 classcount.Add(new ClassToCount("Ranger", 0)); //46 #endregion // Number of Alb, Mid and Hib tanks: foreach (GameClient c in clients) { if (c == null) { continue; } #region count GMs, and different client states if (c.ClientState == GameClient.eClientState.Connecting) { ++connecting; } else if (c.ClientState == GameClient.eClientState.Disconnected) { ++disconnecting; } else if (c.ClientState == GameClient.eClientState.CharScreen) { ++charscreen; } else if (c.ClientState == GameClient.eClientState.Linkdead) { ++linkdeath; } else if (c.ClientState == GameClient.eClientState.WorldEnter) { ++enterworld; } else if (c.ClientState == GameClient.eClientState.Playing) { ++playing; } else { continue; } // if a legal playing client, count some special things if (!c.IsPlaying || c.Account == null || c.Player == null || c.Player.ObjectState != GameObject.eObjectState.Active) { continue; } if (c.Account.PrivLevel >= (uint)ePrivLevel.GM) { ++gms; continue; } #endregion #region class specific counting switch (c.Player.CharacterClass.ID) { // Alb tanks: case (int)eCharacterClass.Armsman: { ++albTanks; classcount[0].count++; } break; case (int)eCharacterClass.Mercenary: { ++albTanks; classcount[1].count++; } break; case (int)eCharacterClass.Paladin: { ++albTanks; classcount[2].count++; } break; case (int)eCharacterClass.Reaver: { ++albTanks; classcount[3].count++; } break; case (int)eCharacterClass.Heretic: { ++albTanks; classcount[4].count++; } break; case (int)eCharacterClass.Mauler_Alb: { ++albTanks; classcount[5].count++; } break; // Alb casters: case (int)eCharacterClass.Cabalist: { ++albCasters; classcount[6].count++; } break; case (int)eCharacterClass.Sorcerer: { ++albCasters; classcount[7].count++; } break; case (int)eCharacterClass.Theurgist: { ++albCasters; classcount[8].count++; } break; case (int)eCharacterClass.Wizard: { ++albCasters; classcount[9].count++; } break; case (int)eCharacterClass.Necromancer: { ++albCasters; classcount[10].count++; } break; // Alb support: case (int)eCharacterClass.Cleric: { ++albSupport; classcount[11].count++; } break; case (int)eCharacterClass.Friar: { ++albSupport; classcount[12].count++; } break; case (int)eCharacterClass.Minstrel: { ++albSupport; classcount[13].count++; } break; // Alb stealthers: case (int)eCharacterClass.Infiltrator: { ++albStealthers; classcount[14].count++; } break; case (int)eCharacterClass.Scout: { ++albStealthers; classcount[15].count++; } break; // Mid tanks: case (int)eCharacterClass.Berserker: { ++midTanks; classcount[16].count++; } break; case (int)eCharacterClass.Savage: { ++midTanks; classcount[17].count++; } break; case (int)eCharacterClass.Skald: { ++midTanks; classcount[18].count++; } break; case (int)eCharacterClass.Thane: { ++midTanks; classcount[19].count++; } break; case (int)eCharacterClass.Warrior: { ++midTanks; classcount[20].count++; } break; case (int)eCharacterClass.Valkyrie: { ++midTanks; classcount[21].count++; } break; case (int)eCharacterClass.Mauler_Mid: { ++midTanks; classcount[22].count++; } break; // Mid casters: case (int)eCharacterClass.Bonedancer: { ++midCasters; classcount[23].count++; } break; case (int)eCharacterClass.Runemaster: { ++midCasters; classcount[24].count++; } break; case (int)eCharacterClass.Spiritmaster: { ++midCasters; classcount[25].count++; } break; case (int)eCharacterClass.Warlock: { ++midCasters; classcount[26].count++; } break; // Mid support: case (int)eCharacterClass.Healer: { ++midSupport; classcount[27].count++; } break; case (int)eCharacterClass.Shaman: { ++midSupport; classcount[28].count++; } break; // Mid stealthers: case (int)eCharacterClass.Hunter: { ++midStealthers; classcount[29].count++; } break; case (int)eCharacterClass.Shadowblade: { ++midStealthers; classcount[30].count++; } break; // Hib tanks: case (int)eCharacterClass.Blademaster: { ++hibTanks; classcount[31].count++; } break; case (int)eCharacterClass.Champion: { ++hibTanks; classcount[32].count++; } break; case (int)eCharacterClass.Hero: { ++hibTanks; classcount[33].count++; } break; case (int)eCharacterClass.Valewalker: { ++hibTanks; classcount[34].count++; } break; case (int)eCharacterClass.Mauler_Hib: { ++hibTanks; classcount[35].count++; } break; case (int)eCharacterClass.Vampiir: { ++hibTanks; classcount[36].count++; } break; // Hib casters: case (int)eCharacterClass.Eldritch: { ++hibCasters; classcount[37].count++; } break; case (int)eCharacterClass.Enchanter: { ++hibCasters; classcount[38].count++; } break; case (int)eCharacterClass.Mentalist: { ++hibCasters; classcount[39].count++; } break; case (int)eCharacterClass.Animist: { ++hibCasters; classcount[40].count++; } break; case (int)eCharacterClass.Bainshee: { ++hibCasters; classcount[41].count++; } break; // Hib support: case (int)eCharacterClass.Bard: { ++hibSupport; classcount[42].count++; } break; case (int)eCharacterClass.Druid: { ++hibSupport; classcount[43].count++; } break; case (int)eCharacterClass.Warden: { ++hibSupport; classcount[44].count++; } break; // Hib stealthers: case (int)eCharacterClass.Nightshade: { ++hibStealthers; classcount[45].count++; } break; case (int)eCharacterClass.Ranger: { ++hibStealthers; classcount[46].count++; } break; } #endregion } #region overview and class-specific int entering = connecting + enterworld + charscreen; int leaving = disconnecting + linkdeath; int albTotal = albTanks + albCasters + albSupport + albStealthers; int midTotal = midTanks + midCasters + midSupport + midStealthers; int hibTotal = hibTanks + hibCasters + hibSupport + hibStealthers; int total = entering + playing + leaving; output.Add(string.Format("Currently online: {0}\n Playing: {1} | Entering: {2} | Leaving: {3}", total, playing, entering, leaving)); if (showAddOnlineInfo == true) { output.Add(string.Format("\n (Connecting: {0} | CharScreen: {1} | EnterWorld: {2} \nPlaying: {3} | LinkDeath: {4} | Disconnected: {5} \nGMs: {6})", connecting, enterworld, charscreen, playing, linkdeath, disconnecting, gms)); } if (showRealms == true) { output.Add(string.Format("\nAlbion: {4} ( {5}% )\n Tanks: {0} | Casters: {1} \n Supporters: {2} | Stealthers: {3}", albTanks, albCasters, albSupport, albStealthers, albTotal, (int)(albTotal * 100 / total))); output.Add(string.Format("\nMidgard: {4} ( {5}% )\n Tanks: {0} | Casters: {1} \n Supporters: {2} | Stealthers: {3}", midTanks, midCasters, midSupport, midStealthers, midTotal, (int)(midTotal * 100 / total))); output.Add(string.Format("\nHibernia: {4} ( {5}% )\n Tanks: {0} | Casters: {1} \n Supporters: {2} | Stealthers: {3}", hibTanks, hibCasters, hibSupport, hibStealthers, hibTotal, (int)(hibTotal * 100 / total))); } Zone zone = null; ArrayList cls = new ArrayList(); int albsinregion = 0; int midsinregion = 0; int hibsinregion = 0; int totalinregion = 0; if (zoneIDs.Length > 0 && showByZone == true) { for (int r = 0; r < zoneIDs.Length; r++) { albsinregion = 0; midsinregion = 0; hibsinregion = 0; totalinregion = 0; zone = WorldMgr.GetZone(zoneIDs[r]); cls = WorldMgr.GetClientsOfRegion(zone.ZoneRegion.ID); foreach (GameClient cir in cls) { if (!cir.IsPlaying || cir.Account == null || cir.Player == null || cir.Player.ObjectState != GameObject.eObjectState.Active) { continue; } if (cir.Account.PrivLevel >= (uint)ePrivLevel.GM) { continue; } if (cir.Player.CurrentZone.Description != zone.Description) { continue; } if (cir.Player.Realm == eRealm.Albion) { albsinregion++; } else if (cir.Player.Realm == eRealm.Midgard) { midsinregion++; } else if (cir.Player.Realm == eRealm.Hibernia) { hibsinregion++; } totalinregion++; } output.Add(string.Format("\nPlayers in {0}: {1} \n Albs: {2} | Mids: {3} | Hibs: {4}", zone.Description, totalinregion, albsinregion, midsinregion, hibsinregion)); } } if (showDetailedClass == true) { output.Add(string.Format("\n")); lock (classcount) { classcount.Sort(delegate(ClassToCount ctc1, ClassToCount ctc2) { return(ctc1.count.CompareTo(ctc2.count)); }); classcount.Reverse(); for (int c = 0; c < classcount.Count; c++) { if (classcount[c].count > 0) { output.Add(string.Format("{0}: {1} ({2}%)", classcount[c].name, classcount[c].count.ToString(), (int)(classcount[c].count * 100 / total))); } } } } #endregion return(output); }
/// <summary> /// This thread updates the NPCs and objects around the player at very short /// intervalls! But since the update is very quick the thread will /// sleep most of the time! /// </summary> public static void WorldUpdateThreadStart() { /// Tasks Collection of running Player updates, with starting time. Dictionary <GameClient, Tuple <long, Task, Region> > clientsUpdateTasks = new Dictionary <GameClient, Tuple <long, Task, Region> >(); bool running = true; if (log.IsInfoEnabled) { log.InfoFormat("World Update Thread Starting - ThreadId = {0}", Thread.CurrentThread.ManagedThreadId); } while (running) { try { // Start Time of the loop long begin = GameTimer.GetTickCount(); // Get All Clients IList <GameClient> clients = WorldMgr.GetAllClients(); // Clean Tasks Dict on Client Exiting. foreach (GameClient cli in new List <GameClient>(clientsUpdateTasks.Keys)) { if (cli == null) { continue; } if (!clients.Contains(cli)) { clientsUpdateTasks.Remove(cli); cli.GameObjectUpdateArray.Clear(); cli.HouseUpdateArray.Clear(); } } // Browse all clients to check if they can be updated. for (int cl = 0; cl < clients.Count; cl++) { GameClient client = clients[cl]; // Check that client is healthy if (client == null) { continue; } GamePlayer player = client.Player; if (client.ClientState == GameClient.eClientState.Playing && player == null) { if (log.IsErrorEnabled) { log.Error("account has no active player but is playing, disconnecting! => " + client.Account.Name); } // Disconnect buggy Client GameServer.Instance.Disconnect(client); continue; } // Check that player is active. if (client.ClientState != GameClient.eClientState.Playing || player == null || player.ObjectState != GameObject.eObjectState.Active) { continue; } // Check for existing Task Tuple <long, Task, Region> clientEntry; if (!clientsUpdateTasks.TryGetValue(client, out clientEntry)) { // Client not in tasks, create it and run it ! clientEntry = new Tuple <long, Task, Region>(begin, Task.Factory.StartNew(() => UpdatePlayerWorld(player)), player.CurrentRegion); // Register. clientsUpdateTasks.Add(client, clientEntry); } else { // Get client entry data. long lastUpdate = clientEntry.Item1; Task taskEntry = clientEntry.Item2; Region lastRegion = clientEntry.Item3; //Check if task finished if (!taskEntry.IsCompleted) { // Check for how long if ((begin - lastUpdate) > GetPlayerWorldUpdateInterval()) { if (log.IsWarnEnabled && (GameTimer.GetTickCount() - player.TempProperties.getProperty <long>("LAST_WORLD_UPDATE_THREAD_WARNING", 0) >= 1000)) { log.WarnFormat("Player Update Task ({0}) Taking more than world update refresh rate : {1} ms (real {2} ms) - Task Status : {3}!", player.Name, GetPlayerWorldUpdateInterval(), begin - lastUpdate, taskEntry.Status); player.TempProperties.setProperty("LAST_WORLD_UPDATE_THREAD_WARNING", GameTimer.GetTickCount()); } } // Continue loop continue; } // Display Exception if (taskEntry.IsFaulted) { if (log.IsErrorEnabled) { log.ErrorFormat("Error in World Update Thread, Player Task ({0})! Exception : {1}", player.Name, taskEntry.Exception); } } // Region Refresh if (player.CurrentRegion != lastRegion) { if (client.GameObjectUpdateArray != null) { client.GameObjectUpdateArray.Clear(); } if (client.HouseUpdateArray != null) { client.HouseUpdateArray.Clear(); } lastUpdate = 0; lastRegion = player.CurrentRegion; } // If this player need update. if (PlayerNeedUpdate(lastUpdate)) { // Update Time, Region and Create Task Tuple <long, Task, Region> newClientEntry = new Tuple <long, Task, Region>(begin, Task.Factory.StartNew(() => UpdatePlayerWorld(player)), lastRegion); // Register Tuple clientsUpdateTasks[client] = newClientEntry; } } } long took = GameTimer.GetTickCount() - begin; if (took >= 500) { if (log.IsWarnEnabled) { log.WarnFormat("World Update Thread (NPC/Object update) took {0} ms", took); } } // relaunch update thread every 100 ms to check if any player need updates. Thread.Sleep((int)Math.Max(1, 100 - took)); } catch (ThreadAbortException) { if (log.IsInfoEnabled) { log.Info("World Update Thread stopping..."); } running = false; break; } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Error in World Update (NPC/Object Update) Thread!", e); } } } }
private static void Resynch(object nullValue) { long syncTime = watch.ElapsedMilliseconds; //Check alive foreach (GameTimer.TimeManager mgr in WorldMgr.GetRegionTimeManagers()) { if (old_time.ContainsKey(mgr) && old_time[mgr] > 0 && old_time[mgr] == mgr.CurrentTime) { if (log.IsErrorEnabled) { // Tolakram: Can't do StackTrace call here. If thread is stopping will result in UAE app stop log.ErrorFormat("----- Found Frozen Region Timer -----\nName: {0} - Current Time: {1}", mgr.Name, mgr.CurrentTime); } //if(mgr.Running) try { if (!mgr.Stop()) { log.ErrorFormat("----- Failed to Stop the TimeManager: {0}", mgr.Name); } } catch (Exception mex) { log.ErrorFormat("----- Errors while trying to stop the TimeManager: {0}\n{1}", mgr.Name, mex); } foreach (GameClient clients in WorldMgr.GetAllClients()) { if (clients.Player == null || clients.ClientState == GameClient.eClientState.Linkdead) { if (log.IsErrorEnabled) { log.ErrorFormat("----- Disconnected Client: {0}", clients.Account.Name); } if (clients.Player != null) { clients.Player.SaveIntoDatabase(); clients.Player.Quit(true); } clients.Out.SendPlayerQuit(true); clients.Disconnect(); GameServer.Instance.Disconnect(clients); WorldMgr.RemoveClient(clients); } } if (!mgr.Start()) { log.ErrorFormat("----- Failed to (re)Start the TimeManager: {0}", mgr.Name); } foreach (Region reg in WorldMgr.GetAllRegions()) { if (reg.TimeManager == mgr) { foreach (GameObject obj in reg.Objects) { //Restart Player regen & remove PvP immunity if (obj is GamePlayer) { GamePlayer plr = obj as GamePlayer; if (plr.IsAlive) { plr.StopHealthRegeneration(); plr.StopPowerRegeneration(); plr.StopEnduranceRegeneration(); plr.StopCurrentSpellcast(); plr.StartHealthRegeneration(); plr.StartPowerRegeneration(); plr.StartEnduranceRegeneration(); plr.StartInvulnerabilityTimer(1000, null); try { foreach (IGameEffect effect in plr.EffectList) { var gsp = effect as GameSpellEffect; if (gsp != null) { gsp.RestartTimers(); } } } catch (Exception e) { log.Error("Can't cancel immunty effect : " + e); } } // Warn Player plr.Client.Out.SendMessage("[" + reg.Description + "] detected as frozen, restarting the zone.", eChatType.CT_Broadcast, eChatLoc.CL_ChatWindow); } //Restart Brains & Paths if (obj is GameNPC && (obj as GameNPC).Brain != null) { GameNPC npc = obj as GameNPC; if (npc.Brain is IControlledBrain) { npc.Die(null); } else if (!(npc.Brain is BlankBrain)) { npc.Brain.Stop(); DOL.AI.ABrain brain = npc.Brain; npc.RemoveBrain(npc.Brain); //npc.Brain.Stop(); if (npc.MaxSpeedBase > 0 && npc.PathID != null && npc.PathID != "" && npc.PathID != "NULL") { npc.StopMovingOnPath(); PathPoint path = MovementMgr.LoadPath(npc.PathID); if (path != null) { var p = path.GetNearestNextPoint(npc.Position); npc.CurrentWayPoint = p; npc.MoveOnPath((short)p.MaxSpeed); } } try { npc.SetOwnBrain(brain); npc.Brain.Start(); } catch (Exception e) { log.Error("Can't restart Brain in RegionTimerResynch, NPC Name = " + npc.Name + " Position=" + npc.Position.ToString("F0") + "/R=" + npc.CurrentRegion.ID + " " + e); try { npc.Die(null); } catch (Exception ee) { log.Error("Can't restart Brain and Kill NPC in RegionTimerResynch, NPC Name = " + npc.Name + " Position=" + npc.Position.ToString("F0") + "/R=" + npc.CurrentRegion.ID + " " + ee); } } } } } //Restart Respawn Timers List <GameNPC> respawnings = new List <GameNPC>(reg.MobsRespawning.Keys); foreach (GameNPC deadMob in respawnings) { GameNPC mob = deadMob; if (mob != null) { mob.StartRespawn(); } } } } //RegionTimerUnfrozen(mgr, syncTime); } if (old_time.ContainsKey(mgr)) { old_time[mgr] = mgr.CurrentTime; } else { old_time.Add(mgr, mgr.CurrentTime); } } }
/// <summary> /// This thread updates the NPCs and objects around the player at very short /// intervalls! But since the update is very quick the thread will /// sleep most of the time! /// </summary> public static void WorldUpdateThreadStart() { // Tasks Collection of running Player updates, with starting time. var clientsUpdateTasks = new Dictionary <GameClient, Tuple <long, Task, Region> >(); bool running = true; if (log.IsInfoEnabled) { log.InfoFormat("World Update Thread Starting - ThreadId = {0}", Thread.CurrentThread.ManagedThreadId); } while (running) { try { // Start Time of the loop long begin = GameTimer.GetTickCount(); // Get All Clients var clients = WorldMgr.GetAllClients(); // Clean Tasks Dict on Client Exiting. foreach (GameClient cli in clientsUpdateTasks.Keys.ToArray()) { if (cli == null) { continue; } GamePlayer player = cli.Player; bool notActive = cli.ClientState != GameClient.eClientState.Playing || player == null || player.ObjectState != GameObject.eObjectState.Active; bool notConnected = !clients.Contains(cli); if (notConnected || (notActive && IsTaskCompleted(cli, clientsUpdateTasks))) { clientsUpdateTasks.Remove(cli); cli.GameObjectUpdateArray.Clear(); cli.HouseUpdateArray.Clear(); } } // Browse all clients to check if they can be updated. for (int cl = 0; cl < clients.Count; cl++) { GameClient client = clients[cl]; // Check that client is healthy if (client == null) { continue; } GamePlayer player = client.Player; if (client.ClientState == GameClient.eClientState.Playing && player == null) { if (log.IsErrorEnabled) { log.Error("account has no active player but is playing, disconnecting! => " + client.Account.Name); } // Disconnect buggy Client GameServer.Instance.Disconnect(client); continue; } // Check that player is active. if (client.ClientState != GameClient.eClientState.Playing || player == null || player.ObjectState != GameObject.eObjectState.Active) { continue; } // Start Update Task StartPlayerUpdateTask(client, clientsUpdateTasks, begin); } long took = GameTimer.GetTickCount() - begin; if (took >= 500) { if (log.IsWarnEnabled) { log.WarnFormat("World Update Thread (NPC/Object update) took {0} ms", took); } } // relaunch update thread every 100 ms to check if any player need updates. Thread.Sleep((int)Math.Max(1, 100 - took)); } catch (ThreadInterruptedException) { if (log.IsInfoEnabled) { log.Info("World Update Thread stopping..."); } running = false; break; } catch (Exception e) { if (log.IsErrorEnabled) { log.Error("Error in World Update (NPC/Object Update) Thread!", e); } } } }
/// <summary> /// Builds the javascript block /// </summary> private static void InitJS() { m_js = new System.Text.StringBuilder(); StreamWriter nl = new StreamWriter(new MemoryStream()); m_js.Append(nl.NewLine); m_js.Append("<script type=\"text/javascript\">"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); m_js.AppendFormat("var dateTime = \"{0}\"", DateTime.Now.ToString()); m_js.Append(nl.NewLine); m_js.AppendFormat("var srvrName = \"{0}\"", GameServer.Instance.Configuration.ServerName); m_js.Append(nl.NewLine); int gm = 0; int admin = 0; foreach (GameClient client in WorldMgr.GetAllClients()) { if (client.Account.PrivLevel == (int)ePrivLevel.GM) { gm++; } if (client.Account.PrivLevel == (int)ePrivLevel.Admin) { admin++; } } m_js.AppendFormat("var numClientsConnected = {0}", GameServer.Instance.ClientCount); m_js.Append(nl.NewLine); m_js.AppendFormat("var numGMsConnected = {0}", gm); m_js.Append(nl.NewLine); m_js.AppendFormat("var numAdminsConnected = {0}", admin); m_js.Append(nl.NewLine); m_js.AppendFormat("var numAccts = {0}", GameServer.Database.GetObjectCount <Account>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numMobs = {0}", GameServer.Database.GetObjectCount <Mob>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numInvItems = {0}", GameServer.Database.GetObjectCount <InventoryItem>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numPlrChars = {0}", GameServer.Database.GetObjectCount <DOLCharacters>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numMerchantItems = {0}", GameServer.Database.GetObjectCount <MerchantItem>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numItemTemplates = {0}", GameServer.Database.GetObjectCount <ItemTemplate>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var numWorldObjects = {0}", GameServer.Database.GetObjectCount <WorldObject>()); m_js.Append(nl.NewLine); m_js.AppendFormat("var srvrType = \"{0}\"", GameServer.Instance.Configuration.ServerType.ToString()); m_js.Append(nl.NewLine); m_js.AppendFormat("var aac = \"{0}\"", GameServer.Instance.Configuration.AutoAccountCreation ? "enabled" : "disabled"); m_js.Append(nl.NewLine); m_js.AppendFormat("var srvrStatus = \"{0}\"", GameServer.Instance.ServerStatus.ToString()); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // begin function m_js.Append("function WritePlrTable()"); m_js.Append(nl.NewLine); m_js.Append("{"); m_js.Append(nl.NewLine); // begin table m_js.Append("document.write(\"<table width=\\\"100%\\\" border=\\\"0\\\" cellpadding=\\\"4\\\">\")"); m_js.Append(nl.NewLine); // first row m_js.Append("document.write(\"<tr>\")"); m_js.Append(nl.NewLine); // name column m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Name\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // last name column m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Last Name\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Class m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Class\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Race m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Race\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Guild m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Guild\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Level m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Level\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Alive m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Alive\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Realm m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Realm\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Current Region m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Current Region\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // X m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"X\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Y m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"Y\")"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // end row m_js.Append("document.write(\"</tr>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); foreach (GameClient client in WorldMgr.GetAllPlayingClients()) { GamePlayer plr = client.Player; m_js.Append("document.write(\"<tr>\")"); m_js.Append(nl.NewLine); // name column m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.Name); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // last name column m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.LastName); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Class m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.CharacterClass.Name); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Race m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.RaceName); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Guild m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.GuildName); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Level m_js.Append("document.write(\"<td align=\\\"center\\\" bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.Level); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Alive m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.IsAlive ? "yes" : "no"); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Realm m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", ((eRealm)plr.Realm).ToString()); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Current Region m_js.Append("document.write(\"<td bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.CurrentRegion.Description); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // X m_js.Append("document.write(\"<td align=\\\"center\\\" bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.X); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); // Y m_js.Append("document.write(\"<td align=\\\"center\\\" bgcolor=\\\"#333333\\\">\")"); m_js.Append(nl.NewLine); m_js.AppendFormat("document.write(\"{0}\")", plr.Y); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</td>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); m_js.Append("document.write(\"</tr>\")"); m_js.Append(nl.NewLine); m_js.Append(nl.NewLine); } m_js.Append("document.write(\"</table>\")"); m_js.Append(nl.NewLine); m_js.Append("}"); m_js.Append(nl.NewLine); m_js.Append("</script>"); m_js.Append(nl.NewLine); }