static ParserThread()
        {
            T = new Thread(() =>
            {
                while (true)
                {
                    var entry = 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("/addpremium        - Add a Premium Player.");
                        Say("/maintenance       - Begin Server Maintenance.");
                        Say("/saveall           - Saves everything 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":
                        WriteLine("------------------------------------->");
                        Say($"UCS Version:         {Constants.Version}");
                        Say($"Build:               {Constants.Build}");
                        Say($"CoC Version from SC: {VersionChecker.LatestBBVersion()}");
                        Say("");
                        Say($"©Ultrapowa 2014 - {DateTime.Now.Year}");
                        WriteLine("------------------------------------->");
                        break;

                    case "/dl csv":
                        CSVManager.DownloadLatestCSVFiles();
                        break;

                    case "/saveall":
                        ForegroundColor = ConsoleColor.Yellow;
                        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.m_vInMemoryAlliances.Values.Count})");
                        //Resources.DatabaseManager.Save(ResourcesManager.m_vInMemoryAlliances.Values.ToList()).Wait();
                        //Say("Finished saving of all Alliances!");
                        ForegroundColor = ConsoleColor.Yellow;
                        WriteLine("----------------------------------------------------->");
                        ResetColor();
                        break;

                    /*case "/addpremium":
                     *  Print("------------------------------------->");
                     *  Say("Type in now the Player ID: ");
                     *  var id = ReadLine();
                     *  Print("------------------------------------->");
                     *  try
                     *  {
                     *      var l = await ResourcesManager.GetPlayer(long.Parse(id));
                     *      var avatar = l.Avatar;
                     *      var playerID = avatar.GetId();
                     *      var p = avatar.GetPremium();
                     *      Say("Set the Privileges for Player: '" + avatar.AvatarName + "' ID: '" + avatar.GetId() + "' to Premium?");
                     *      Say("Type in 'y':Yes or 'n': Cancel");
                     *      loop:
                     *      var a = ReadLine();
                     *      if (a == "y")
                     *      {
                     *          if (p == true)
                     *          {
                     *              Say("Privileges already set to 'Premium'");
                     *          }
                     *          else if (p == false)
                     *          {
                     *              ResourcesManager.GetPlayer(playerID).Avatar.SetPremium(true);
                     *              Say("Privileges set succesfully for: '" + avatar.AvatarName + "' ID: '" + avatar.GetId() + "'");
                     *              DatabaseManager.Single().Save(ResourcesManager.GetInMemoryLevels());
                     *          }
                     *      }
                     *      else if (a == "n")
                     *      {
                     *          Say("Canceled.");
                     *      }
                     *      else
                     *      {
                     *          Error("Type in 'y':Yes or 'n': Cancel");
                     *          goto loop;
                     *      }
                     *  }
                     *  catch (NullReferenceException)
                     *  {
                     *      Say("Player doesn't exists!");
                     *  }
                     *  break;*/

                    case "/info addpremium":
                        Print("------------------------------------------------------------------------------->");
                        Say("/addpremium > Adds a Premium Player, which will get more Privileges.");
                        Print("------------------------------------------------------------------------------->");
                        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":
                        Print("------------------------------------------------------->");
                        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.m_vInMemoryAlliances.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 "/exit":
                        UCSControl.UCSClose();
                        break;

                    case "/info exit":
                        Print("---------------------------------------------------------------------------->");
                        Say(@"/exit > 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 "/info restart":
                        Print("---------------------------------------------------------------------------->");
                        Say(@"/shutdown > 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();
        }
示例#2
0
        public static void Start()
        {
            T = new Thread(() =>
            {
                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("/addpremium        - Add a Premium Player.");
                        Say("/maintenance       - Begin Server Maintenance.");
                        Say("/info 'command'    - More Info On a Command. Ex: /info gui");
                        Print("------------------------------------------------------------------------------>");
                        break;

                    case "/loadalliance":
                        Print("------------------------------------->");
                        Say("Type in now the Alliance ID: ");
                        var allianceid = ReadLine();
                        Print("------------------------------------->");
                        try
                        {
                            ObjectManager.GetAlliance(long.Parse(allianceid));
                        }
                        catch (NullReferenceException)
                        {
                            Say("Alliance doesn't exists!");
                        }
                        break;

                    case "/addpremium":
                        Print("------------------------------------->");
                        Say("Type in now the Player ID: ");
                        var id = ReadLine();
                        Print("------------------------------------->");
                        try
                        {
                            var avatar   = ResourcesManager.GetPlayer(long.Parse(id)).GetPlayerAvatar();
                            var playerID = avatar.GetId();
                            var p        = avatar.GetPremium();
                            Say("Set the Privileges for Player: '" + avatar.GetAvatarName() + "' ID: '" + avatar.GetId() + "' to Premium?");
                            Say("Type in 'y':Yes or 'n': Cancel");
                            loop:
                            var a = ReadLine();
                            if (a == "y")
                            {
                                if (p == true)
                                {
                                    Say("Privileges already set to 'Premium'");
                                }
                                else if (p == false)
                                {
                                    ResourcesManager.GetPlayer(playerID).GetPlayerAvatar().SetPremium(true);
                                    Say("Privileges set succesfully for: '" + avatar.GetAvatarName() + "' ID: '" + avatar.GetId() + "'");
                                    var levels = DatabaseManager.Single().Save(ResourcesManager.GetInMemoryLevels());
                                    levels.Wait();
                                }
                            }
                            else if (a == "n")
                            {
                                Say("Canceled.");
                            }
                            else
                            {
                                Error("Type in 'y':Yes or 'n': Cancel");
                                goto loop;
                            }
                        }
                        catch (NullReferenceException)
                        {
                            Say("Player doesn't exists!");
                        }
                        break;

                    case "/info addpremium":
                        Print("------------------------------------------------------------------------------->");
                        Say("/addpremium > Adds a Premium Player, which will get more Privileges.");
                        Print("------------------------------------------------------------------------------->");
                        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":
                        Print("------------------------------------------------------->");
                        Say("Status:                 " + "Online");
                        Say("IP Address:             " +
                            Dns.GetHostByName(Dns.GetHostName()).AddressList[0]);
                        Say("Online players:         " +
                            ResourcesManager.GetOnlinePlayers().Count);
                        Say("Connected players:      " +
                            ResourcesManager.GetConnectedClients().Count);
                        Say("In Memory Players:      " +
                            ResourcesManager.GetInMemoryLevels().Count);
                        Say("Clash 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(@"     - Clash of Clans Version.");
                        Print("----------------------------------------------------------------->");
                        break;

                    case "/clear":
                        Clear();
                        break;

                    case "/shutdown":
                        UCSControl.UCSClose();
                        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 "/info restart":
                        Print("---------------------------------------------------------------------------->");
                        Say(@"/shutdown > 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();
            T.Priority = ThreadPriority.Normal;
        }
示例#3
0
 //Shutdown UCS Button
 private void materialRaisedButton12_Click(Object sender, EventArgs e)
 {
     Close();
     UCSControl.UCSClose();
 }
示例#4
0
        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();
        }