Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (62 loc) · 2.15 KB
/
Copy pathProgram.cs
File metadata and controls
69 lines (62 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.IO;
using Newtonsoft.Json;
using PKHeX.Core;
using SysBot.Base;
namespace SysBot.Pokemon.ConsoleApp
{
public static class Program
{
private const string ConfigPath = "config.json";
private static void Main(string[] args)
{
Console.WriteLine("Starting up...");
PokeTradeBot.SeedChecker = new Z3SeedSearchHandler<PK8>();
if (args.Length > 1)
Console.WriteLine("This program does not support command line arguments.");
if (File.Exists(ConfigPath))
{
var lines = File.ReadAllText(ConfigPath);
var prog = JsonConvert.DeserializeObject<ProgramConfig>(lines);
var env = new PokeBotRunnerImpl(prog.Hub);
foreach (var bot in prog.Bots)
{
bot.Initialize();
AddBot(env, bot);
}
LogUtil.Forwarders.Add((msg, ident) => Console.WriteLine($"{ident}: {msg}"));
env.StartAll();
Console.WriteLine("Started all bots.");
Console.WriteLine("Press any key to stop execution and quit.");
Console.ReadKey();
env.StopAll();
}
else
{
Console.WriteLine("Unable to parse config file. Please copy your config from the WinForms project.");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
private static bool AddBot(PokeBotRunner env, PokeBotConfig cfg)
{
if (!cfg.IsValidIP())
{
Console.WriteLine($"{cfg.IP}'s config is not valid.");
return false;
}
var newbot = env.CreateBotFromConfig(cfg);
try
{
env.Add(newbot);
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
return false;
}
Console.WriteLine($"Added: {cfg.IP}: {cfg.InitialRoutine}");
return true;
}
}
}