public override void Execute(Level level) { if (level.Avatar.AccountPrivileges >= GetRequiredAccountPrivileges()) { if (m_vArgs.Length >= 1) { ClientAvatar avatar = level.Avatar; var mail = new AllianceMailStreamEntry(); mail.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; mail.SetSender(avatar); mail.IsNew = 2; mail.AllianceId = 0; mail.AllianceBadgeData = 1526735450; mail.AllianceName = "UCS Server Information"; mail.Message = @"Online Players: " + ResourcesManager.m_vOnlinePlayers.Count + "\nIn Memory Players: " + ResourcesManager.m_vInMemoryLevels.Count + "\nConnected Players: " + ResourcesManager.GetConnectedClients().Count + "\nServer Ram: " + Performances.GetUsedMemory() + "% / " + Performances.GetTotalMemory() + "MB"; var p = new AvatarStreamEntryMessage(level.Client); p.SetAvatarStreamEntry(mail); Processor.Send(p); } } else { SendCommandFailedMessage(level.Client); } }
public override void Execute(Level level) { if (level.GetAccountPrivileges() >= GetRequiredAccountPrivileges()) { if (m_vArgs.Length >= 1) { var avatar = level.GetPlayerAvatar(); var mail = new AllianceMailStreamEntry(); mail.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds); mail.SetSenderId(avatar.GetId()); mail.SetSenderAvatarId(avatar.GetId()); mail.SetSenderName(avatar.GetAvatarName()); mail.SetIsNew(2); mail.SetAllianceId(0); mail.SetAllianceBadgeData(1526735450); mail.SetAllianceName("UCS Server Information"); mail.SetMessage(@"Online Players: " + ResourcesManager.GetOnlinePlayers().Count + "\nIn Memory Players: " + ResourcesManager.GetInMemoryLevels().Count + "\nConnected Players: " + ResourcesManager.GetConnectedClients().Count + "\nServer Ram: " + Performances.GetUsedMemory() + "% / " + Performances.GetTotalMemory() + "MB" ); mail.SetSenderLevel(avatar.GetAvatarLevel()); mail.SetSenderLeagueId(avatar.GetLeagueId()); var p = new AvatarStreamEntryMessage(level.GetClient()); p.SetAvatarStreamEntry(mail); PacketProcessor.Send(p); } } else { SendCommandFailedMessage(level.GetClient()); } }
private void Handler(string type) { try { if (type == "inmemclans") { jsonapp = Convert.ToString(ObjectManager.GetInMemoryAlliances().Count); } else if (type == "inmemplayers") { jsonapp = Convert.ToString(ResourcesManager.GetInMemoryLevels().Count); } else if (type == "onlineplayers") { jsonapp = Convert.ToString(ResourcesManager.GetOnlinePlayers().Count); } else if (type == "totalclients") { jsonapp = Convert.ToString(ResourcesManager.GetConnectedClients().Count); } else if (type == "all") { var json = new JsonApi { UCS = new Dictionary <string, string> { { "PatchingServer", ConfigurationManager.AppSettings["patchingServer"] }, { "Maintenance", ConfigurationManager.AppSettings["maintenanceMode"] }, { "MaintenanceTimeLeft", ConfigurationManager.AppSettings["maintenanceTimeLeft"] }, { "ClientVersion", ConfigurationManager.AppSettings["clientVersion"] }, { "ServerVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString() }, { "OnlinePlayers", Convert.ToString(ResourcesManager.GetOnlinePlayers().Count) }, { "InMemoryPlayers", Convert.ToString(ResourcesManager.GetInMemoryLevels().Count) }, { "InMemoryClans", Convert.ToString(ObjectManager.GetInMemoryAlliances().Count) }, { "TotalConnectedClients", Convert.ToString(ResourcesManager.GetConnectedClients().Count) } } }; jsonapp = JsonConvert.SerializeObject(json); mime = "application/json"; } else if (type == "ram") { jsonapp = Performances.GetUsedMemory(); } else { jsonapp = "OK"; } } catch (Exception ex) { jsonapp = "An exception occured in UCS : \n" + ex; } }
public override void Execute(Level level) { if (level.Avatar.AccountPrivileges >= GetRequiredAccountPrivileges()) { if (m_vArgs.Length >= 1) { ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_PerfFormattedData_PerfOS_Processor"); var cpuTimes = searcher.Get() .Cast <ManagementObject>() .Select(mo => new { Name = mo["Name"], Usage = mo["PercentProcessorTime"] } ) .ToList(); var query = cpuTimes.Where(x => x.Name.ToString() == "_Total").Select(x => x.Usage); var CPUParcentage = query.SingleOrDefault(); RAMUsage = PerformanceInfo.GetTotalMemoryInMiB() - PerformanceInfo.GetPhysicalAvailableMemoryInMiB(); DriveLetter = Path.GetPathRoot(Directory.GetCurrentDirectory()); DiskSpace = new DriveInfo(DriveLetter.Substring(0, DriveLetter.Length - 2)); TotalFreeSpace = DiskSpace.TotalFreeSpace / 1073741824; TotalDiskSize = DiskSpace.TotalSize / 1073741824; DiskspaceUsed = TotalDiskSize - TotalFreeSpace; ClientAvatar avatar = level.Avatar; var mail = new AllianceMailStreamEntry(); mail.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; mail.SetSender(avatar); mail.IsNew = 2; mail.AllianceId = 0; mail.AllianceBadgeData = 1526735450; mail.AllianceName = "UCS Server Information"; mail.Message = @"Online Players: " + ResourcesManager.m_vOnlinePlayers.Count + "\nIn Memory Players: " + ResourcesManager.m_vInMemoryLevels.Count + "\nConnected Players: " + ResourcesManager.GetConnectedClients().Count + "\nTotal System CPU Usage: " + CPUParcentage + "%" + "\nServer RAM: " + Performances.GetUsedMemory() + "% / " + Performances.GetTotalMemory() + "MB" + "\nTotal Server Ram Usage: " + RAMUsage + "MB / " + Performances.GetTotalMemory() + "MB" + "\nServer Disk Space Used: " + Math.Round(DiskspaceUsed, 2) + "GB / " + Math.Round(TotalDiskSize, 2) + "GB"; var p = new AvatarStreamEntryMessage(level.Client); p.SetAvatarStreamEntry(mail); Processor.Send(p); } } else { SendCommandFailedMessage(level.Client); } }
static ParserThread() { T = new Thread((ThreadStart)(() => { while (true) { string entry = Console.ReadLine().ToLower(); switch (entry) { case "/help": Print("------------------------------------------------------------------------------>"); Say("/status - Shows the actual UCS status."); Say("/clear - Clears the console screen."); Say("/gui - Shows the UCS Graphical User Interface."); Say("/restart - Restarts UCS instantly."); Say("/shutdown - Shuts UCS down instantly."); Say("/banned - Writes all Banned IP's into the Console."); Say("/addip - Add an IP to the Blacklist"); Say("/maintenance - Begin Server Maintenance."); Say("/saveall - Saves everything in memory to the Database"); Say("/dl csv - Downloads latest CSV Files (if Fingerprint is up to Date)."); Say("/info - Shows the UCS Informations."); Say("/info 'command' - More Info On a Command. Ex: /info gui"); Print("------------------------------------------------------------------------------>"); break; case "/info": Console.WriteLine("------------------------------------->"); Say($"UCS Version: {Constants.Version}"); Say($"Build: {Constants.Build}"); Say($"LicenseID: {Constants.LicensePlanID}"); Say($"CoC Version from SC: {VersionChecker.LatestCoCVersion()}"); Say($"Ultrapower - {DateTime.Now.Year}"); Console.WriteLine("------------------------------------->"); break; case "/dl csv": CSVManager.DownloadLatestCSVFiles(); break; case "/info dl csv": Print("------------------------------------------------------------------------------>"); Say(@"/dl csv > Downloads COC Assets such as CSVs and if enabled:"); Say(@" - Logic,"); Say(@" - Sound Files "); Say(@" - SCs"); Print("------------------------------------------------------------------------------>"); break; case "/banned": Console.WriteLine("------------------------------------->"); Say("Banned IP Addresses:"); ConnectionBlocker.GetBannedIPs(); Console.WriteLine("------------------------------------->"); break; case "/addip": Console.WriteLine("------------------------------------->"); Console.Write("IP: "); string s = Console.ReadLine(); ConnectionBlocker.AddNewIpToBlackList(s); Console.WriteLine("------------------------------------->"); break; case "/saveall": Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("----------------------------------------------------->"); Say($"Starting saving of all Players... ({ResourcesManager.m_vInMemoryLevels.Count})"); Resources.DatabaseManager.Save(ResourcesManager.m_vInMemoryLevels.Values.ToList()).Wait(); Say("Finished saving of all Players!"); Say($"Starting saving of all Alliances... ({ResourcesManager.GetInMemoryAlliances().Count})"); Resources.DatabaseManager.Save(ResourcesManager.GetInMemoryAlliances()).Wait(); Say("Finished saving of all Alliances!"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("----------------------------------------------------->"); Console.ResetColor(); break; case "/maintenance": StartMaintenance(); break; case "/info maintenance": Print("------------------------------------------------------------------------------>"); Say(@"/maintenance > Enables Maintenance which will do the following:"); Say(@" - All Online Users will be notified (Attacks will be disabled),"); Say(@" - All new connections get a Maintenace Message at the Login. "); Say(@" - After 5min all Players will be kicked."); Say(@" - After the Maintenance Players will be able to connect again."); Print("------------------------------------------------------------------------------>"); break; case "/status": Say($"Please wait retrieving Ultrapower Server status"); ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_PerfFormattedData_PerfOS_Processor"); var cpuTimes = searcher.Get() .Cast <ManagementObject>() .Select(mo => new { Name = mo["Name"], Usage = mo["PercentProcessorTime"] } ) .ToList(); var query = cpuTimes.Where(x => x.Name.ToString() == "_Total").Select(x => x.Usage); var CPUParcentage = query.SingleOrDefault(); Print("------------------------------------------------------->"); Say($"CPU Usage: {CPUParcentage}%"); Say($"RAM Usage: {Performances.GetUsedMemory()}%"); Say($"Time: {DateTime.Now}"); Say($"IP Address: {Dns.GetHostByName(Dns.GetHostName()).AddressList[0]}"); Say($"Online Players: {ResourcesManager.m_vOnlinePlayers.Count}"); Say($"Connected Players: {ResourcesManager.GetConnectedClients().Count}"); Say($"In Memory Players: {ResourcesManager.m_vInMemoryLevels.Values.ToList().Count}"); Say($"In Memory Alliances: {ResourcesManager.GetInMemoryAlliances().Count}"); Say($"Client Version: {ConfigurationManager.AppSettings["ClientVersion"]}"); Print("------------------------------------------------------->"); break; case "/info status": Print("----------------------------------------------------------------->"); Say(@"/status > Shows current state of server including:"); Say(@" - Online Status"); Say(@" - Server IP Address"); Say(@" - Amount of Online Players"); Say(@" - Amount of Connected Players"); Say(@" - Amount of Players in Memory"); Say(@" - Amount of Alliances in Memory"); Say(@" - Clash of Clans Version."); Print("----------------------------------------------------------------->"); break; case "/clear": Clear(); break; case "/info shutdown": Print("---------------------------------------------------------------------------->"); Say(@"/shutdown > Shuts Down UCS instantly after doing the following:"); Say(@" - Throws all Players an 'Client Out of Sync Message'"); Say(@" - Disconnects All Players From the Server"); Say(@" - Saves all Players in Database"); Say(@" - Shutsdown UCS."); Print("---------------------------------------------------------------------------->"); break; case "/gui": Application.Run(new UCSUI()); break; case "/info gui": Print("------------------------------------------------------------------------------->"); Say(@"/gui > Starts the UCS Gui which includes many features listed here:"); Say(@" - Status Controler/Manager"); Say(@" - Player Editor"); Say(@" - Config.UCS editor."); Print("------------------------------------------------------------------------------->"); break; case "/restart": UCSControl.UCSRestart(); break; case "/shutdown": UCSControl.UCSClose(); break; case "/info restart": Print("---------------------------------------------------------------------------->"); Say(@"/restart > Restarts UCS instantly after doing the following:"); Say(@" - Throws all Players an 'Client Out of Sync Message'"); Say(@" - Disconnects All Players From the Server"); Say(@" - Saves all Players in Database"); Say(@" - Restarts UCS."); Print("---------------------------------------------------------------------------->"); break; default: Say("Unknown command, type \"/help\" for a list containing all available commands."); break; } } })); T.Start(); }