private static void RunFromEnv() { WindBotInfo Info = new WindBotInfo(); Info.Name = Environment.GetEnvironmentVariable("YGOPRO_NAME"); Info.Deck = Environment.GetEnvironmentVariable("YGOPRO_DECK"); Info.Host = Environment.GetEnvironmentVariable("YGOPRO_HOST"); Info.Port = Int32.Parse(Environment.GetEnvironmentVariable("YGOPRO_PORT")); string EnvDialog = Environment.GetEnvironmentVariable("YGOPRO_DIALOG"); if (EnvDialog != null) { Info.Dialog = EnvDialog; } string EnvVersion = Environment.GetEnvironmentVariable("YGOPRO_VERSION"); if (EnvVersion != null) { Info.Version = Int16.Parse(EnvVersion); } string EnvPassword = Environment.GetEnvironmentVariable("YGOPRO_PASSWORD"); if (EnvPassword != null) { Info.HostInfo = EnvPassword; } Run(Info); }
public static void RunAndroid(string arg) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); IList <string> args = ParseArgs(arg); WindBotInfo Info = new WindBotInfo(); foreach (string param in args) { string[] p = Regex.Split(param, "[=]"); p[1] = p[1].Replace("'", ""); if (p[0] == "Name") { Info.Name = p[1]; } if (p[0] == "Deck") { Info.Deck = p[1]; } if (p[0] == "Dialog") { Info.Dialog = p[1]; } if (p[0] == "Port") { Info.Port = int.Parse(p[1]); } if (p[0] == "Hand") { Info.Hand = int.Parse(p[1]); } if (p[0] == "Host") { Info.Host = p[1]; } if (p[0] == "HostInfo") { Info.HostInfo = p[1]; } if (p[0] == "Version") { Info.Version = int.Parse(p[1]); } if (p[0] == "Chat") { Info.Chat = int.Parse(p[1]) != 0; } if (p[0] == "Debug") { Info.Debug = int.Parse(p[1]) != 0; } } Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); }
private static void RunFromArgs(string[] args) { WindBotInfo Info = new WindBotInfo(); Info.Name = args[0]; Info.Deck = args[1]; Info.Host = args[2]; Info.Port = Int32.Parse(args[3]); Info.HostInfo = args[4]; Run(Info); }
public static void Test1(string test) { WindBotInfo Info = new WindBotInfo { Host = "118.178.111.167", Port = 9999, HostInfo = test }; Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); //Windbot.Run(Info); }
private static void Run(object o) { #if !DEBUG try { #endif WindBotInfo Info = (WindBotInfo)o; GameClient client = new GameClient(Info); client.Start(); Logger.DebugWriteLine(client.Username + " started."); while (client.Connection.IsConnected) { #if !DEBUG try { #endif client.Tick(); Thread.Sleep(30); #if !DEBUG } catch (Exception ex) { if (!DebugMode) { Logger.WriteErrorLine("Tick Error: " + ex); } else { throw ex; } } #endif } Logger.DebugWriteLine(client.Username + " end."); #if !DEBUG } catch (Exception ex) { if (!DebugMode) { Logger.WriteErrorLine("Run Error: " + ex); } else { throw ex; } } #endif }
private static void RunFromArgs() { WindBotInfo Info = new WindBotInfo(); Info.Name = Config.GetString("Name", Info.Name); Info.Deck = Config.GetString("Deck", Info.Deck); Info.Dialog = Config.GetString("Dialog", Info.Dialog); Info.Host = Config.GetString("Host", Info.Host); Info.Port = Config.GetInt("Port", Info.Port); Info.HostInfo = Config.GetString("HostInfo", Info.HostInfo); Info.Version = Config.GetInt("Version", Info.Version); Info.Hand = Config.GetInt("Hand", Info.Hand); Run(Info); }
private static void RunFromArgs() { WindBotInfo Info = new WindBotInfo(); Info.Name = Config.GetString("Name", Info.Name); Info.Deck = Config.GetString("Deck", Info.Deck); Info.DeckFile = Config.GetString("DeckFile", Info.DeckFile); Info.Dialog = Config.GetString("Dialog", Info.Dialog); ////////kdiy/////// Info.Deckfolder = Config.GetString("Deckfolder", Info.Deckfolder); Info.Deckpath = Config.GetString("Deckpath", Info.Deckpath); ////////kdiy/////// Info.Host = Config.GetString("Host", Info.Host); Info.Port = Config.GetInt("Port", Info.Port); Info.HostInfo = Config.GetString("HostInfo", Info.HostInfo); Info.Version = Config.GetInt("Version", Info.Version); Info.Hand = Config.GetInt("Hand", Info.Hand); Info.Debug = Config.GetBool("Debug", Info.Debug); Info.Chat = Config.GetBool("Chat", Info.Chat); ////////kdiy/////// Info.Seed = Config.GetInt("Seed", Info.Seed); ////////kdiy/////// Info.RoomId = Config.GetInt("RoomId", Info.RoomId); string b64CreateGame = Config.GetString("CreateGame"); if (b64CreateGame != null) { try { var ms = new MemoryStream(Convert.FromBase64String(b64CreateGame)); var ser = new DataContractJsonSerializer(typeof(CreateGameInfo)); Info.CreateGame = ser.ReadObject(ms) as CreateGameInfo; // "Best of 0" is not allowed by the server, use that to check for validity. if (Info.CreateGame.bestOf == 0) { Info.CreateGame = null; } } catch (Exception ex) { Info.CreateGame = null; Logger.DebugWriteLine("Error while parsing CreateGame json: " + ex); } } Run(Info); }
private static void Run(object o) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); #if !DEBUG try { //all errors will be catched instead of causing the program to crash. #endif WindBotInfo Info = (WindBotInfo)o; GameClient client = new GameClient(Info); client.Start(); Logger.DebugWriteLine(client.Username + " started."); while (client.Connection.IsConnected) { #if !DEBUG try { #endif client.Tick(); Thread.Sleep(30); #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Tick Error: " + ex); client.Chat("I crashed, check the crash.log file in the WindBot folder", true); using (StreamWriter sw = File.AppendText(Path.Combine(Program.AssetPath, "crash.log"))) { sw.WriteLine("[" + DateTime.Now.ToString("yy-MM-dd HH:mm:ss") + "] Tick Error: " + ex); } client.Connection.Close(); return; } #endif } Logger.DebugWriteLine(client.Username + " end."); #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Run Error: " + ex); } #endif }
private static void RunFromArgs() { WindBotInfo Info = new WindBotInfo(); Info.Name = Config.GetString("Name", Info.Name); Info.Deck = Config.GetString("Deck", Info.Deck); Info.Dialog = Config.GetString("Dialog", Info.Dialog); Info.Host = Config.GetString("Host", Info.Host); Info.Port = Config.GetInt("Port", Info.Port); Info.HostInfo = Config.GetString("HostInfo", Info.HostInfo); Info.Version = Config.GetInt("Version", Info.Version); Info.Hand = Config.GetInt("Hand", Info.Hand); Info.Debug = Config.GetBool("Debug", Info.Debug); Info.Chat = Config.GetBool("Chat", Info.Chat); Logger.Path = Info.Name + ".txt"; Logger.Name = Info.Name; Logger.DeleteFile(); Run(Info); }
private static void Run(object o) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); #if !DEBUG try { //all errors will be catched instead of causing the program to crash. #endif WindBotInfo Info = (WindBotInfo)o; GameClient client = new GameClient(Info); client.Start(); Logger.DebugWriteLine(client.Username + " started."); while (client.Connection.IsConnected) { #if !DEBUG try { #endif client.Tick(); Thread.Sleep(30); #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Tick Error: " + ex); } #endif } Logger.DebugWriteLine(client.Username + " end."); #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Run Error: " + ex); } #endif }
internal static void Main(string[] args) { InitDatas("cards.cdb"); int argc = args.Length; // If the first commandline parameter is DebugMode if (argc > 0 && args[0] == "DebugMode") { DebugMode = true; // Shift the args array to skip the first parameter argc--; Array.Copy(args, 1, args, 0, argc); } // Only one parameter will make Windbot run as a server, use the parameter as port // provide a http interface to create bot. // eg. http://127.0.0.1:2399/?name=%E2%91%A8&deck=Blue-Eyes&host=127.0.0.1&port=7911&dialog=cirno.zh-CN&version=4922 if (argc == 1) { RunAsServer(Int32.Parse(args[0])); } // Use all five parameters to run Windbot // The parameters should be name, deck, server ip, server port, password // eg. WindBot.exe "My Bot" "Zexal Weapons" 127.0.0.1 7911 "" else if (argc == 5) { RunFromArgs(args); } // Use environment variables to run Windbot // List of variables required: // YGOPRO_HOST // YGOPRO_PORT // YGOPRO_NAME // // List of variables optional: // YGOPRO_DECK // YGOPRO_VERSION // YGOPRO_DIALOG // YGOPRO_PASSWORD // // eg. (cmd) // set YGOPRO_VERSION=4922 // set YGOPRO_HOST=127.0.0.1 // set YGOPRO_PORT=7911 // set YGOPRO_NAME=Meow // set YGOPRO_DECK=Blue-Eyes // set YGOPRO_DIALOG=zh-CN // WindBot.exe else if (Environment.GetEnvironmentVariable("YGOPRO_NAME") != null) { RunFromEnv(); } // Else, run from the default settings else { WindBotInfo Info = new WindBotInfo(); Run(Info); } }
private static void RunAsServer(int ServerPort) { using (HttpListener MainServer = new HttpListener()) { MainServer.AuthenticationSchemes = AuthenticationSchemes.Anonymous; MainServer.Prefixes.Add("http://127.0.0.1:" + ServerPort + "/"); MainServer.Start(); Logger.WriteLine("Windbot Server Start Successed."); Logger.WriteLine("HTTP GET http://127.0.0.1:" + ServerPort + "/?name=Windbot&host=127.0.0.1&port=7911 to call the bot."); while (true) { try { HttpListenerContext ctx = MainServer.GetContext(); WindBotInfo Info = new WindBotInfo(); string RawUrl = Path.GetFileName(ctx.Request.RawUrl); Info.Name = HttpUtility.ParseQueryString(RawUrl).Get("name"); Info.Deck = HttpUtility.ParseQueryString(RawUrl).Get("deck"); Info.Host = HttpUtility.ParseQueryString(RawUrl).Get("host"); string port = HttpUtility.ParseQueryString(RawUrl).Get("port"); if (port != null) { Info.Port = Int32.Parse(port); } string dialog = HttpUtility.ParseQueryString(RawUrl).Get("dialog"); if (dialog != null) { Info.Dialog = dialog; } string version = HttpUtility.ParseQueryString(RawUrl).Get("version"); if (version != null) { Info.Version = Int16.Parse(version); } string password = HttpUtility.ParseQueryString(RawUrl).Get("password"); if (password != null) { Info.HostInfo = password; } if (Info.Name == null || Info.Host == null || port == null) { ctx.Response.StatusCode = 400; ctx.Response.Close(); } else { try { Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); } catch (Exception ex) { if (!DebugMode) { Logger.WriteErrorLine("Start Thread Error: " + ex); } else { throw ex; } } ctx.Response.StatusCode = 200; ctx.Response.Close(); } } catch (Exception ex) { if (!DebugMode) { Logger.WriteErrorLine("Parse Http Request Error: " + ex); } else { throw ex; } } } } }
private static void RunAsServer(int ServerPort) { using (HttpListener MainServer = new HttpListener()) { MainServer.AuthenticationSchemes = AuthenticationSchemes.Anonymous; MainServer.Prefixes.Add("http://+:" + ServerPort + "/"); MainServer.Start(); Logger.WriteLine("WindBot server start successed."); Logger.WriteLine("HTTP GET http://127.0.0.1:" + ServerPort + "/?name=WindBot&host=127.0.0.1&port=7911 to call the bot."); while (true) { #if !DEBUG try { #endif HttpListenerContext ctx = MainServer.GetContext(); WindBotInfo Info = new WindBotInfo(); string RawUrl = Path.GetFileName(ctx.Request.RawUrl); Info.Name = HttpUtility.ParseQueryString(RawUrl).Get("name"); Info.Deck = HttpUtility.ParseQueryString(RawUrl).Get("deck"); Info.Host = HttpUtility.ParseQueryString(RawUrl).Get("host"); string port = HttpUtility.ParseQueryString(RawUrl).Get("port"); if (port != null) { Info.Port = Int32.Parse(port); } string deckfile = HttpUtility.ParseQueryString(RawUrl).Get("deckfile"); if (deckfile != null) { Info.DeckFile = deckfile; } string dialog = HttpUtility.ParseQueryString(RawUrl).Get("dialog"); if (dialog != null) { Info.Dialog = dialog; } /////////kdiy////// string deckfolder = HttpUtility.ParseQueryString(RawUrl).Get("deckfolder"); if (deckfolder != null) { Info.Deckfolder = deckfolder; } string deckpath = HttpUtility.ParseQueryString(RawUrl).Get("deckpath"); if (deckpath != null) { Info.Deckpath = deckpath; } /////////kdiy////// string version = HttpUtility.ParseQueryString(RawUrl).Get("version"); if (version != null) { Info.Version = Int16.Parse(version); } string password = HttpUtility.ParseQueryString(RawUrl).Get("password"); if (password != null) { Info.HostInfo = password; } string hand = HttpUtility.ParseQueryString(RawUrl).Get("hand"); if (hand != null) { Info.Hand = Int32.Parse(hand); } string debug = HttpUtility.ParseQueryString(RawUrl).Get("debug"); if (debug != null) { Info.Debug = bool.Parse(debug); } string chat = HttpUtility.ParseQueryString(RawUrl).Get("chat"); if (chat != null) { Info.Chat = bool.Parse(chat); } //////kdiy//////// string seed = HttpUtility.ParseQueryString(RawUrl).Get("seed"); if (seed != null) { Info.Seed = Int32.Parse(seed); } //////kdiy//////// if (Info.Name == null || Info.Host == null || port == null) { ctx.Response.StatusCode = 400; ctx.Response.Close(); } else { #if !DEBUG try { #endif Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Start Thread Error: " + ex); } #endif ctx.Response.StatusCode = 200; ctx.Response.Close(); } #if !DEBUG } catch (Exception ex) { Logger.WriteErrorLine("Parse Http Request Error: " + ex); } #endif } } }
public static void RunAndroid(string arg) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); WindBotInfo Info = new WindBotInfo(); try { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(LaunchData)); MemoryStream json = new MemoryStream(Encoding.Unicode.GetBytes(arg)); LaunchData data = (LaunchData)serializer.ReadObject(json); if (data.Name != null) { Info.Name = data.Name; } if (data.Deck != null) { Info.Deck = data.Deck; } if (data.DeckFile != null) { Info.DeckFile = data.DeckFile; } if (data.Dialog != null) { Info.Dialog = data.Dialog; } /////////kdiy///////// if (data.Deckfolder != null) { Info.Deckfolder = data.Deckfolder; } if (data.Deckpath != null) { Info.Deckpath = data.Deckpath; } /////////kdiy///////// if (data.Port != null) { Info.Port = int.Parse(data.Port); } if (data.Hand != null) { Info.Hand = int.Parse(data.Hand); } if (data.Host != null) { Info.Host = data.Host; } if (data.HostInfo != null) { Info.HostInfo = data.HostInfo; } if (data.Version != null) { Info.Version = int.Parse(data.Version); } if (data.Chat != null) { Info.Chat = int.Parse(data.Chat) != 0; } /////////kdiy///////// if (data.Seed != null) { Info.Seed = int.Parse(data.Seed); } /////////kdiy///////// if (data.Debug != null) { Info.Debug = int.Parse(data.Debug) != 0; } } catch (Exception ex) { Logger.WriteErrorLine("Argument parsing error: " + ex); } Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); }
public static void RunAndroid(string arg) { IList <string> args = ParseArgs(arg); Match match = Regex.Match(arg, "Random=(\\w+)"); if (match.Success) { string randomFlag = match.Groups[1].Value; string command = GetRandomBot(randomFlag); if (command != "") { IList <string> randomArgs = ParseArgs(command); foreach (string param in randomArgs) { args.Add(param); } } } WindBotInfo Info = new WindBotInfo(); foreach (string param in args) { string[] p = param.Split('='); p[1] = p[1].Replace("'", ""); if (p[0] == "Name") { Info.Name = p[1]; } if (p[0] == "Deck") { Info.Deck = p[1]; } if (p[0] == "DeckFile") { Info.DeckFile = p[1]; } if (p[0] == "Dialog") { Info.Dialog = p[1]; } if (p[0] == "Port") { Info.Port = int.Parse(p[1]); } if (p[0] == "Hand") { Info.Hand = int.Parse(p[1]); } if (p[0] == "Host") { Info.Host = p[1]; } if (p[0] == "HostInfo") { Info.HostInfo = p[1]; } } Thread workThread = new Thread(new ParameterizedThreadStart(Run)); workThread.Start(Info); }