static void Main(string[] args) { Console.Title = "TS3GameBot by MrDj and Exp111"; Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; #region CredCheck if (!CredManager.CredCheck(CredPathJson)) { MyCreds = CredManager.CreateCreds(); JsonSerialization.WriteToJsonFile <Creds>(CredPathJson, MyCreds); } else { MyCreds = JsonSerialization.ReadFromJsonFile <Creds>(CredPathJson); if (MyCreds == null) { throw new Exception("shit"); } } #endregion Console.Clear(); #region DBConnection Console.WriteLine("Connecting to Database..."); ConnectionResult CResult = DbInterface.CheckConnection(); switch (CResult) { case ConnectionResult.OK: Console.WriteLine("Connected!"); break; case ConnectionResult.SQLERROR: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nCould not connect to Database! Error: " + CResult + " Check your Settings! (" + CredPathJson + ")\n\nPress Enter to exit"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; return; // break; case ConnectionResult.UNKNOWN: default: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nCould not connect to Database! Error: " + CResult + "\n\nPress Enter to exit"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; return; // break; } Console.WriteLine(DbInterface.GetPlayerCount() + " Players found!"); // Making an Initial DB call, to get rid of the Delay on the first Commnand #endregion #region TS3Connection Console.WriteLine("Connecting to TeamSpeak Server..."); TS3QueryInfo ts3ServerInfo; if (MyCreds.TS3InfoList.Count > 1) { Console.WriteLine("You have more than 1 TS3 Server configured!\nPlease choose 1 of the following:\n"); foreach (var item in MyCreds.TS3InfoList) { Console.WriteLine("[" + item.Key + "] on " + item.Value.ServerAddress); } Console.Write("> "); String input = Console.ReadLine(); ts3ServerInfo = MyCreds.TS3InfoList.Where(e => e.Key.ToLower().Equals(input.ToLower())).FirstOrDefault().Value; while (ts3ServerInfo == null) { Console.WriteLine("Not found. Try Again!"); Console.Write("> "); ts3ServerInfo = MyCreds.TS3InfoList.Where(e => e.Key.ToLower().Equals(Console.ReadLine().ToLower())).First().Value; } } else { ts3ServerInfo = MyCreds.TS3InfoList.First().Value; } switch (GameBot.Instance.Login(ts3ServerInfo).GetAwaiter().GetResult()) { case ConnectionResult.OK: Console.WriteLine("Connected!"); break; case ConnectionResult.SOCKET: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nCould not connect to TeamSpeak Server! Is the Server offline?\n\nPress Enter to exit"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } return; // break; case ConnectionResult.QUERY: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nPlease Enter the correct Login Credentials! (" + CredPathJson + ")\n\nPress Enter to exit"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } return; // break; case ConnectionResult.UNKNOWN: default: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nCould not connect to TeamSpeak Server!\n\nPress Enter to exit"); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } return; // break; } #endregion #region ThreadStuff Thread botThread = new Thread(RunBot); botThread.Start(); #endregion ConsoleCommandManager.RegisterCommands(); // Registering all Console Commands List <String> commandArgs = new List <string>(); Console.WriteLine("Welcome to Dj's GameBot!\nUse 'help' for a list of commands.\nUse 'help <command>' for Usage of given Command."); while (Running) { Console.Write("> "); commandArgs.Clear(); String shit = Console.ReadLine().Trim(); ConsoleCommandBase cmd; String[] parts = shit.Split(" "); for (int i = 1; i < parts.Length; i++) { commandArgs.Add(parts[i]); // Putin all the args in a List } try { cmd = ConsoleCommandManager.Commands[parts[0].ToLower()]; // Getting the Command Assosciated to the give Command CCR result = ConsoleCommandManager.ExecuteCommand(cmd, commandArgs); // Tempsaving the Result #region ErrorHandling for Console Commands switch (result) { case CCR.OK: break; case CCR.WRONGPARAM: Console.WriteLine(cmd.GetUsage()); break; case CCR.INVALIDPARAM: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid Parameter! "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(cmd.GetUsage()); break; case CCR.PLAYERNOTFOUND: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Player not Found!"); Console.ForegroundColor = ConsoleColor.Green; break; case CCR.BELOWZERO: case CCR.NOTENOUGHPOINTS: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Points can't go below 0!"); Console.ForegroundColor = ConsoleColor.Green; break; case CCR.UNKNOWN: default: Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nUnknown Error appeared! Code: " + result + "\n"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; break; } #endregion } catch (KeyNotFoundException) // If the given command is not found withing the Commands Dictionary { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unknown Command '" + shit.Split(" ")[0] + "'!"); Console.ForegroundColor = ConsoleColor.Green; Console.Beep(); } } // Changing the Color back to normal Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.Clear(); // Clearing the Console // Waiting for the Bot Thread to finish while (!botThread.IsAlive) { Console.WriteLine("Waiting for Bot Thread to finish!"); } }