public static void Main(string[] args) { if (!File.Exists("config.json")) { Console.WriteLine("Please copy config.template.json to config.json and fill it out"); return; } Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json")); Logger.Instance.Log(LogLevel.Info, $"Loaded settings, user: {config.Username}, server: {config.Server}"); // Setup OGameStringProvider stringProvider = OGameStringProvider.Load(@"Resources\strings-en.json"); CultureInfo clientServerCulture = CultureInfo.GetCultureInfo("da-DK"); // Processing OGameClient client = new OGameClient(config.Server, stringProvider, config.Username, config.Password); client.Settings.ServerUtcOffset = TimeSpan.FromHours(1); client.Settings.Galaxies = 8; client.Settings.Systems = 499; client.ServerCulture = clientServerCulture; Logger.Instance.Log(LogLevel.Debug, "Prepared OGameClient"); // Savers client.RegisterSaver(new GalaxyPageSaver()); client.RegisterSaver(new EspionageReportSaver()); client.RegisterSaver(new GalaxyPageDebrisSaver()); client.RegisterSaver(new MessageSaver()); // UA stuff client.RegisterDefaultHeader("Accept-Language", "en-GB,en;q=0.8,da;q=0.6"); client.RegisterDefaultHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.RegisterDefaultHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"); Logger.Instance.Log(LogLevel.Debug, "Prepared user agent"); // Show details foreach (IInterventionHandler item in client.GetIntervention()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Intervention Handler: {item.GetType().FullName}"); } foreach (BaseParser item in client.GetParsers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Parser: {item.GetType().FullName}"); } foreach (SaverBase item in client.GetSavers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Saver: {item.GetType().FullName}"); } // Start proxy OgameClientProxy proxy = new OgameClientProxy("127.0.0.1", 9400, client); proxy.SubstituteRoot = new Uri($"https://{config.Server}"); proxy.Start(); Logger.Instance.Log(LogLevel.Warning, $"Prepared reverse proxy, visit: {proxy.ListenPrefix}"); // Kick-off client.PerformLogin(); // Example job ApiImporterJob job1 = new ApiImporterJob(client, new DirectoryInfo("temp")); job1.Start(); MessageReaderJob job2 = new MessageReaderJob(client); job2.Start(); SessionKeepAliveJob job3 = new SessionKeepAliveJob(client); job3.Start(); // Farming bot FarmingBot bot = new FarmingBot(client, SystemCoordinate.Create(6, 60), SystemCoordinate.Create(6, 100)); bot.Start(); // Work Console.ReadLine(); }
public static void Main(string[] args) { // F**k that, it's impossible to make Mono accept certificates from OGame, at least I'm too stupid to do it apparently. if (IsRunningOnMono()) { System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; } if (!File.Exists("config.json")) { Console.WriteLine("Please copy config.template.json to config.json and fill it out"); return; } IExitSignal onExitSignal = null; if (IsRunningOnMono()) { onExitSignal = new UnixExitSignal(); } else { onExitSignal = new WindowsExitSignal(); } Config config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json")); Logger.Instance.MinimumLogLevel = config.LogLevel; Logger.Instance.IncludeTimestamp = config.LogIncludeTimestamp; Logger.Instance.Log(LogLevel.Info, $"Loaded settings, user: {config.Username}, server: {config.Server}"); // Setup OGameStringProvider stringProvider = OGameStringProvider.Load(@"Resources/strings-en.json"); CultureInfo clientServerCulture = CultureInfo.GetCultureInfo("da-DK"); var commander = new CommandBase.Commander(); // Processing OGameClient client = new OGameClient(config.Server, stringProvider, config.Username, config.Password, commander); client.Settings.ServerUtcOffset = TimeSpan.FromHours(1); client.Settings.Galaxies = 8; client.Settings.Systems = 499; client.ServerCulture = clientServerCulture; Logger.Instance.Log(LogLevel.Debug, "Prepared OGameClient"); // Savers client.RegisterSaver(new GalaxyPageSaver()); client.RegisterSaver(new EspionageReportSaver()); client.RegisterSaver(new GalaxyPageDebrisSaver()); client.RegisterSaver(new MessageSaver()); client.RegisterSaver(new PlayerPlanetSaver()); client.RegisterSaver(new GalaxyActivitySaver()); client.RegisterSaver(new HostileAttackEmailSender(config.HostileWarning.From, config.HostileWarning.To, config.HostileWarning.Server, config.HostileWarning.Login, config.HostileWarning.Password)); // Injects client.RegisterInject(new CommandsInject()); client.RegisterInject(new CargosForTransportInject()); client.RegisterInject(new PlanetExclusiveInject(client)); client.RegisterInject(new CommonInject()); client.RegisterInject(new BuildQueueInject()); client.RegisterInject(new CustomPlanetOrderInject(config.CustomOrder)); client.RegisterInject(new EventListTotalsInject()); // UA stuff client.RegisterDefaultHeader("Accept-Language", "en-GB,en;q=0.8,da;q=0.6"); client.RegisterDefaultHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.RegisterDefaultHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"); Logger.Instance.Log(LogLevel.Debug, "Prepared user agent"); // Show details foreach (IInterventionHandler item in client.GetIntervention()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Intervention Handler: {item.GetType().FullName}"); } foreach (BaseParser item in client.GetParsers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Parser: {item.GetType().FullName}"); } foreach (SaverBase item in client.GetSavers()) { Logger.Instance.Log(LogLevel.Info, $"Loaded Saver: {item.GetType().FullName}"); } // Start proxy OgameClientProxy proxy = new OgameClientProxy(config.ListenAddress, config.ListenPort, client); proxy.SubstituteRoot = new Uri($"https://{config.Server}"); proxy.Start(); Logger.Instance.Log(LogLevel.Success, $"Prepared reverse proxy, visit: {proxy.ListenPrefix}"); // Kick-off client.IssueRequest(client.RequestBuilder.GetPage(Objects.Types.PageType.Overview)); // Example job ApiImporterJob job1 = new ApiImporterJob(client, new DirectoryInfo("temp")); job1.Start(); AuctionMonitor monitor = new AuctionMonitor(client); client.RegisterInject(new AuctionStatusInject(monitor)); monitor.Start(); SessionKeepAliveJob job3 = new SessionKeepAliveJob(client, config.SessionKeepaliveMode); if (config.SessionKeepaliveMode == SessionKeepAliveMode.Single) { job3.PlanetId = config.SessionKeepalivePlanet; } job3.Start(); commander.Start(); Action <int> recallAction = (fleet) => { RecallFleetCommand recall = new RecallFleetCommand() { FleetId = fleet }; recall.Run(); }; if (config.FleetToRecall > 0) { recallAction(config.FleetToRecall); Thread.Sleep(5000); return; } if (config.SystemsToScan?.Count > 0) { SystemScanner sysScanner = new SystemScanner(config.SystemsToScan.Select(z => SystemCoordinate.Parse(z))); sysScanner.Start(); } SetupProxyCommands(client, config, proxy); onExitSignal.Exit += (sender, eventArgs) => { client.SaveCookies(); }; Console.TreatControlCAsInput = true; Console.ReadKey(true); client.SaveCookies(); }