private void DisplayHelp() { ServerConsole.WriteLine("-=- Server Command Help -=-"); ServerConsole.WriteLine("Available Commands:"); ServerConsole.WriteLine("/help - Shows help"); ServerConsole.WriteLine("/clear - Clears the command prompt"); ServerConsole.WriteLine("/global [string]msg - Sends a global message"); ServerConsole.WriteLine("/masskick - Kicks all players, excluding staff"); ServerConsole.WriteLine("/masswarp [int]map [int]x [int]y - Warps all players to the specified location"); ServerConsole.WriteLine("/kick [string]playername - Kicks the player specified"); ServerConsole.WriteLine("/warp [string]playername [int]map [int]x [int]y - Warps the player to the specified location"); ServerConsole.WriteLine("/mapmsg [int]mapnum [string]msg - Sends a message to the map"); ServerConsole.WriteLine("/reloadscripts - Reloads the scripts"); ServerConsole.WriteLine("/togglescripts [bool]value - Turns the scripts on/off based on the value"); ServerConsole.WriteLine("/players - Gets a list of all online players"); Scripting.ScriptManager.InvokeSub("DisplayServerCommandHelp"); }
private static void LoadServerBackground(Object param) { Migrations.MigrationRunner.MigrateDatabase(); System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(LoadDatasBackground)); t.Name = "Data Load Thread"; t.Start(); resetEvent.WaitOne(); ServerConsole.WriteLine("Initializing TCP..."); NetworkManager.Initialize(); NetworkManager.TcpListener.Listen(System.Net.IPAddress.Any, Settings.GamePort); ServerConsole.WriteLine("Server loaded!"); if (LoadComplete != null) { LoadComplete(null, EventArgs.Empty); } }
static void Main() { try { AppDomain.CurrentDomain.FirstChanceException += new EventHandler <System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs>(CurrentDomain_FirstChanceException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.WriteLine("Pulling scripts..."); Scripting.ScriptRepoHelper.PullChanges(); ServerLoader.LoadServer(); while (true) { Console.ReadLine(); } } catch (Exception ex) { ServerConsole.WriteLine(ex.ToString()); } }
public void ProcessCommandCallback(object obj) { int activeLine = (int)((ParamObject)obj).Param[0]; string command = (string)((ParamObject)obj).Param[1]; Command fullCommand = Server.CommandProcessor.ParseCommand(command); string fullArgs = CommandProcessor.JoinArgs(fullCommand.CommandArgs.ToArray()); switch (fullCommand.CommandArgs[0].ToLower()) { case "/help": { DisplayHelp(); } break; case "/clear": { } break; case "/global": { Messenger.GlobalMsg(fullArgs, Text.White); ServerConsole.WriteLine("Global: " + fullArgs); } break; case "/masskick": { foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor)) { Messenger.GlobalMsg(i.Player.Name + " has been kicked by the server!", Text.White); Messenger.AlertMsg(i, "You have been kicked by the server!"); } } ServerConsole.WriteLine("Everyone has been kicked."); } break; case "/dumpstats": { Statistics.PacketStatistics.DumpStatistics(); ServerConsole.WriteLine("Packet statistics dumped to database."); } break; case "/clearstats": { Statistics.PacketStatistics.ClearStatistics(); ServerConsole.WriteLine("Packet statistics cleared."); } break; case "/masswarp": { if (fullCommand.CommandArgs.Count == 4) { int map = fullCommand.CommandArgs[1].ToInt(-1); int x = fullCommand.CommandArgs[2].ToInt(-1); int y = fullCommand.CommandArgs[3].ToInt(-1); if (map <= 0) { ServerConsole.WriteLine("Invalid Map."); break; } else if (x == -1) { ServerConsole.WriteLine("Invalid X coordinate."); break; } else if (y == -1) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } // TODO: Mass Warp //if (x > MapManager.Maps[map].MaxX) { // ServerConsole.WriteLine("Invalid X coordinate."); // break; //} //if (y > MapManager.Maps[map].MaxY) { // ServerConsole.WriteLine("Invalid Y coordinate."); // break; //} foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor)) { Messenger.GlobalMsg("The server has warped everyone!", Text.White); Messenger.PlayerWarp(i, map, x, y); } } ServerConsole.WriteLine("Everyone has been warped."); } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/kick": { if (fullCommand.CommandArgs.Count == 2) { Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]); if (client == null) { ServerConsole.WriteLine("Player is offline."); } else { Messenger.GlobalMsg(client.Player.Name + " has been kicked by the server!", Text.White); Messenger.AlertMsg(client, "You have been kicked by the server!"); ServerConsole.WriteLine(client.Player.Name + " has been kicked!"); } } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/warp": { if (fullCommand.CommandArgs.Count == 5) { Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]); if (client == null) { ServerConsole.WriteLine("Player is offline."); } else { int mapNum = fullCommand.CommandArgs[2].ToInt(-1); int x = fullCommand.CommandArgs[3].ToInt(-1); int y = fullCommand.CommandArgs[4].ToInt(-1); if (mapNum <= 0) { ServerConsole.WriteLine("Invalid Map."); break; } else if (x == -1) { ServerConsole.WriteLine("Invalid X coordinate."); break; } else if (y == -1) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } IMap map; if (MapManager.IsMapActive(MapManager.GenerateMapID(mapNum))) { map = MapManager.RetrieveActiveMap(MapManager.GenerateMapID(mapNum)); } else { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { map = MapManager.LoadStandardMap(dbConnection, MapManager.GenerateMapID(mapNum)); } } if (x > map.MaxX) { ServerConsole.WriteLine("Invalid X coordinate."); break; } if (y > map.MaxY) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } Messenger.PlayerMsg(client, "You have been warped by the server!", Text.White); Messenger.PlayerWarp(client, mapNum, x, y); ServerConsole.WriteLine(client.Player.Name + " has been warped."); } } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/mapmsg": { if (fullCommand.CommandArgs.Count == 3) { string map = fullCommand.CommandArgs[1]; // Check if the map is active if (!MapManager.IsMapActive(map)) { ServerConsole.WriteLine("Invalid Map."); break; } Messenger.MapMsg(map, fullCommand.CommandArgs[2], Text.DarkGrey); ServerConsole.WriteLine("Map Msg (Map " + map.ToString() + "): " + fullCommand.CommandArgs[2]); } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/reloadscripts": { Scripting.ScriptManager.Reload(); ServerConsole.WriteLine("Scripts reloaded."); } break; case "/players": { string players = ""; int count = 0; foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying()) { count++; players += i.Player.Name + "\r\n"; } } ServerConsole.WriteLine("Players online: \r\n" + players); ServerConsole.WriteLine("There are " + count.ToString() + " players online"); } break; case "/test": { //Email.Email.SendEmail("test"); //ServerConsole.WriteLine("Mail sent!"); //ServerConsole.WriteLine("There are currently no benchmarking tests"); //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); //watch.Start(); //MapGeneralInfo genInfo = MapManager.RetrieveMapGeneralInfo(10); //watch.Stop(); //ServerConsole.WriteLine("Elapsed, New: " + watch.Elapsed.ToString()); //watch.Reset(); //watch.Start(); //Map map = MapManager.LoadMap(10); //watch.Stop(); //ServerConsole.WriteLine("Elapsed, Old: " + watch.Elapsed.ToString()); //ServerConsole.WriteLine("Name: " + genInfo.Name); } break; case "/finditem": { int itemsFound = 0; for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++) { if (ItemManager.Items[i].Name.ToLower().StartsWith(fullCommand.CommandArgs[1].ToLower())) { ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString()); itemsFound++; //return; } } if (itemsFound == 0) { ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'"); } } break; case "/finditemc": { int itemsFound = 0; for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++) { if (ItemManager.Items[i].Name.ToLower().Contains(fullCommand.CommandArgs[1].ToLower())) { ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString()); itemsFound++; //return; } } if (itemsFound == 0) { ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'"); } } break; case "/calcwm": { ServerConsole.WriteLine("Factorial: " + Server.Math.CalculateFactorial(fullCommand.CommandArgs[1].ToInt()).ToString("R")); } break; case "/gmmode": { Globals.GMOnly = !Globals.GMOnly; ServerConsole.WriteLine("GM Only Mode Active: " + Globals.GMOnly); } break; default: { Scripting.ScriptManager.InvokeSub("ProcessServerCommand", fullCommand, fullArgs); } break; } }
private static void LoadDatasBackground(object data) { //ThreadManager.SetMaxThreads(Settings.MaxWorkerThreads, Settings.MaxCompletionThreads); // Load pokedex //Pokedex.Pokedex.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Pokedex... " + e.Percent.ToString() + "%"); }; Pokedex.Pokedex.Initialize(); Pokedex.Pokedex.LoadAllPokemon(); // Load emoticons //Emoticons.EmoticonManagerBase.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { loading.UpdateStatus("Loading Emoticons... " + e.Percent.ToString() + "%"); }; //Emoticons.EmoticonManagerBase.Initialize(Settings.MaxEmoticons); //Emoticons.EmoticonManagerBase.LoadEmotions(null); // Load zones ServerConsole.WriteLine("Loading Zones..."); Zones.ZoneManager.Initialize(); Zones.ZoneManager.LoadZones(null); // Load exp ServerConsole.WriteLine("Loading Exp..."); //Exp.ExpManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Experience values... " + e.Percent.ToString() + "%"); }; Exp.ExpManager.Initialize(); Exp.ExpManager.LoadExps(null); // Load maps ServerConsole.WriteLine("Loading Maps..."); //Maps.MapManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Maps... " + e.Percent.ToString() + "%"); }; Maps.MapManager.Initialize(); //Maps.MapManager.LoadMaps(null); // Load items ServerConsole.WriteLine("Loading Items..."); //Items.ItemManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Items... " + e.Percent.ToString() + "%"); }; Items.ItemManager.Initialize(); Items.ItemManager.LoadItems(null); // Load npcs ServerConsole.WriteLine("Loading Npcs..."); //Npcs.NpcManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Npcs... " + e.Percent.ToString() + "%"); }; Npcs.NpcManager.Initialize(); Npcs.NpcManager.LoadNpcs(null); // Load shops ServerConsole.WriteLine("Loading Shops..."); //Shops.ShopManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Shops... " + e.Percent.ToString() + "%"); }; Shops.ShopManager.Initialize(); Shops.ShopManager.LoadShops(null); // Load moves ServerConsole.WriteLine("Loading Moves..."); //Moves.MoveManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Moves... " + e.Percent.ToString() + "%"); }; Moves.MoveManager.Initialize(); Moves.MoveManager.LoadMoves(null); // Load evos ServerConsole.WriteLine("Loading Evolutions..."); //Evolutions.EvolutionManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Evolutions... " + e.Percent.ToString() + "%"); }; Evolutions.EvolutionManager.Initialize(); Evolutions.EvolutionManager.LoadEvos(null); // Load stories ServerConsole.WriteLine("Loading Stories..."); //Stories.StoryManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Stories... " + e.Percent.ToString() + "%"); }; Stories.StoryManager.Initialize(); Stories.StoryManager.LoadStories(null); // Load rdungeons ServerConsole.WriteLine("Loading RDungeons..."); //RDungeons.RDungeonManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading RDungeons... " + e.Percent.ToString() + "%"); }; RDungeons.RDungeonManager.Initialize(); RDungeons.RDungeonManager.LoadRDungeons(null); // Load dungeons ServerConsole.WriteLine("Loading Dungeons..."); //Dungeons.DungeonManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading Dungeons... " + e.Percent.ToString() + "%"); }; Dungeons.DungeonManager.Initialize(); Dungeons.DungeonManager.LoadDungeons(null); //Load wonder mail ServerConsole.WriteLine("Loading WonderMail..."); //WonderMails.WonderMailManager.LoadUpdate += delegate(System.Object o, Server.LoadingUpdateEventArgs e) { ServerConsole.WriteLine("Loading WonderMail... " + e.Percent.ToString() + "%"); }; WonderMails.WonderMailManager.Initialize(); WonderMails.WonderMailManager.LoadMissionPools(null); //WonderMails.WonderMailSystem.Initialize(); // Initialize the tournament subsystem Tournaments.TournamentManager.Initialize(); // Initialize the party subsystem Players.Parties.PartyManager.Initialize(); // Initialize statistics Statistics.PacketStatistics.Initialize(); // Initialize logs Logging.Logger.Initialize(); //var pokedexSync = new Pokedex.PokedexSync(); //pokedexSync.SyncPokedex(Constants.TOTAL_POKEMON_GEN6 + 1, Constants.TOTAL_POKEMON).GetAwaiter().GetResult(); // Load scripts ServerConsole.WriteLine("Loading scripts... "); Scripting.ScriptManager.Initialize(); Scripting.ScriptManager.CompileScript(IO.Paths.ScriptsFolder, true); ServerConsole.WriteLine("Loading script editor data..."); Scripting.Editor.EditorHelper.Initialize(); Scripting.ScriptManager.InvokeSub("ServerInit"); // Finalizing load ServerConsole.WriteLine("Starting game loop..."); AI.AIProcessor.InitGameLoop(); resetEvent.Set(); loadingComplete = true; }
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { ServerConsole.WriteLine("First Chance Exception: " + ((Exception)e.ExceptionObject).ToString()); }