예제 #1
0
 /// <summary>
 /// Called when a server was successfully joined
 /// </summary>
 public void OnGameJoined()
 {
     if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
     {
         handler.SendBrandInfo(Settings.BrandInfo.Trim());
     }
     if (Settings.MCSettings_Enabled)
     {
         handler.SendClientSettings(
             Settings.MCSettings_Locale,
             Settings.MCSettings_RenderDistance,
             Settings.MCSettings_Difficulty,
             Settings.MCSettings_ChatMode,
             Settings.MCSettings_ChatColors,
             Settings.MCSettings_Skin_All,
             Settings.MCSettings_MainHand);
     }
     foreach (ChatBot bot in bots)
     {
         bot.AfterGameJoined();
     }
     if (inventoryHandlingRequested)
     {
         inventoryHandlingRequested = false;
         inventoryHandlingEnabled   = true;
         ConsoleIO.WriteLogLine("Inventory handling is now enabled.");
     }
 }
 public void Info(string msg, params object[] args)
 {
     if (infoEnabled)
     {
         ConsoleIO.WriteLogLine(string.Format(msg, args));
     }
 }
 public void Info(string msg)
 {
     if (infoEnabled)
     {
         ConsoleIO.WriteLogLine(msg);
     }
 }
 public void Info(object msg)
 {
     if (infoEnabled)
     {
         ConsoleIO.WriteLogLine(msg.ToString());
     }
 }
예제 #5
0
 /// <summary>
 /// Disconnect from the server and restart the program
 /// It will unload and reload all the bots and then reconnect to the server
 /// </summary>
 /// <param name="ExtraAttempts">In case of failure, maximum extra attempts before aborting</param>
 /// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
 protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0)
 {
     if (Settings.DebugMessages)
     {
         ConsoleIO.WriteLogLine(String.Format("[{0}] Disconnecting and Reconnecting to the Server", this.GetType().Name));
     }
     McTcpClient.ReconnectionAttemptsLeft = ExtraAttempts;
     Program.Restart(delaySeconds);
 }
예제 #6
0
        /// <summary>
        /// Load translation file depends on system language or by giving a file path. Default to English if translation file does not exist
        /// </summary>
        public static void LoadExternalTranslationFile(string language)
        {
            /*
             * External translation files
             * These files are loaded from the installation directory as:
             * Lang/abc.ini, e.g. Lang/eng.ini which is the default language file
             * Useful for adding new translations of fixing typos without recompiling
             */

            // Try to convert Minecraft language file name to two letters language name
            if (language == "zh_cn")
            {
                language = "zh-CHS";
            }
            else if (language == "zh_tw")
            {
                language = "zh-CHT";
            }
            else
            {
                language = language.Split('_')[0];
            }

            string systemLanguage = string.IsNullOrEmpty(CultureInfo.CurrentCulture.Parent.Name) // Parent.Name might be empty
                    ? CultureInfo.CurrentCulture.Name
                    : CultureInfo.CurrentCulture.Parent.Name;
            string langDir = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + translationFilePath + Path.DirectorySeparatorChar;
            string langFileSystemLanguage = langDir + systemLanguage + ".ini";
            string langFileConfigLanguage = langDir + language + ".ini";

            if (File.Exists(langFileConfigLanguage))
            {// Language set in ini config
                ParseTranslationContent(File.ReadAllLines(langFileConfigLanguage));
                return;
            }
            else
            {
                if (Settings.DebugMessages)
                {
                    ConsoleIO.WriteLogLine("[Translations] No translation file found for " + language + ". (Looked '" + langFileConfigLanguage + "'");
                }
            }

            if (File.Exists(langFileSystemLanguage))
            {// Fallback to system language
                ParseTranslationContent(File.ReadAllLines(langFileSystemLanguage));
                return;
            }
            else
            {
                if (Settings.DebugMessages)
                {
                    ConsoleIO.WriteLogLine("[Translations] No translation file found for system language (" + systemLanguage + "). (Looked '" + langFileSystemLanguage + "'");
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Convert the specified string to an integer, defaulting to zero if invalid argument
 /// </summary>
 /// <param name="str">String to parse as an integer</param>
 /// <returns>Integer value</returns>
 public static int str2int(string str)
 {
     try
     {
         return(Convert.ToInt32(str.Trim()));
     }
     catch {
         ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2int", str));
         return(0);
     }
 }
예제 #8
0
        /// <summary>
        /// Called when the player respawns, which happens on login, respawn and world change.
        /// </summary>
        public void OnRespawn()
        {
            if (terrainAndMovementsRequested)
            {
                terrainAndMovementsEnabled   = true;
                terrainAndMovementsRequested = false;
                ConsoleIO.WriteLogLine("Terrain and Movements is now enabled.");
            }

            if (terrainAndMovementsEnabled)
            {
                world.Clear();
            }
        }
예제 #9
0
        /// <summary>
        /// Convert the specified string to a float number, defaulting to zero if invalid argument
        /// </summary>
        /// <param name="str">String to parse as a float number</param>
        /// <returns>Float number</returns>
        public static float str2float(string str)
        {
            float f;

            if (float.TryParse(str.Trim(), out f))
            {
                return(f);
            }
            else
            {
                ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2int", str));
                return(0);
            }
        }
예제 #10
0
        /// <summary>
        /// Write some text in the console. Nothing will be sent to the server.
        /// </summary>
        /// <param name="text">Log text to write</param>

        protected void LogToConsole(object text)
        {
            ConsoleIO.WriteLogLine(String.Format("[{0}] {1}", this.GetType().Name, text));
            string logfile = Settings.ExpandVars(Settings.chatbotLogFile);

            if (!String.IsNullOrEmpty(logfile))
            {
                if (!File.Exists(logfile))
                {
                    try { Directory.CreateDirectory(Path.GetDirectoryName(logfile)); }
                    catch { return; /* Invalid path or access denied */ }
                    try { File.WriteAllText(logfile, ""); }
                    catch { return; /* Invalid file name or access denied */ }
                }

                File.AppendAllLines(logfile, new string[] { GetTimestamp() + ' ' + text });
            }
        }
예제 #11
0
        /// <summary>
        /// Load settings from the given INI file
        /// </summary>
        /// <param name="file">File to load</param>
        public static void LoadFile(string file)
        {
            ConsoleIO.WriteLogLine("[Settings] Loading Settings from " + Path.GetFullPath(file));
            if (File.Exists(file))
            {
                try
                {
                    string[] Lines   = File.ReadAllLines(file);
                    Section  section = Section.Default;
                    foreach (string lineRAW in Lines)
                    {
                        string line = section == Section.Main && lineRAW.ToLower().Trim().StartsWith("password")
                            ? lineRAW.Trim() //Do not strip # in passwords
                            : lineRAW.Split('#')[0].Trim();

                        if (line.Length > 0)
                        {
                            if (line[0] == '[' && line[line.Length - 1] == ']')
                            {
                                section = GetSection(line.Substring(1, line.Length - 2).ToLower());
                            }
                            else
                            {
                                string argName = line.Split('=')[0];
                                if (line.Length > (argName.Length + 1))
                                {
                                    string argValue = line.Substring(argName.Length + 1);
                                    LoadSingleSetting(section, argName, argValue);
                                }
                            }
                        }
                    }
                }
                catch (IOException) { }
            }
        }
예제 #12
0
        /// <summary>
        /// Load settings from the give INI file
        /// </summary>
        /// <param name="settingsfile">File to load</param>
        public static void LoadSettings(string settingsfile)
        {
            ConsoleIO.WriteLogLine("[Settings] Loading Settings from " + Path.GetFullPath(settingsfile));
            if (File.Exists(settingsfile))
            {
                try
                {
                    string    serverAlias = "";
                    string[]  Lines       = File.ReadAllLines(settingsfile);
                    ParseMode pMode       = ParseMode.Default;
                    foreach (string lineRAW in Lines)
                    {
                        string line = pMode == ParseMode.Main && lineRAW.ToLower().Trim().StartsWith("password")
                            ? lineRAW.Trim() //Do not strip # in passwords
                            : lineRAW.Split('#')[0].Trim();

                        if (line.Length > 0)
                        {
                            if (line[0] == '[' && line[line.Length - 1] == ']')
                            {
                                switch (line.Substring(1, line.Length - 2).ToLower())
                                {
                                case "alerts": pMode = ParseMode.Alerts; break;

                                case "antiafk": pMode = ParseMode.AntiAFK; break;

                                case "autorelog": pMode = ParseMode.AutoRelog; break;

                                case "chatlog": pMode = ParseMode.ChatLog; break;

                                case "hangman": pMode = ParseMode.Hangman; break;

                                case "main": pMode = ParseMode.Main; break;

                                case "mcsettings": pMode = ParseMode.MCSettings; break;

                                case "scriptscheduler": pMode = ParseMode.ScriptScheduler; break;

                                case "remotecontrol": pMode = ParseMode.RemoteControl; break;

                                case "proxy": pMode = ParseMode.Proxy; break;

                                case "appvars": pMode = ParseMode.AppVars; break;

                                case "autorespond": pMode = ParseMode.AutoRespond; break;

                                case "chatformat": pMode = ParseMode.ChatFormat; break;

                                case "autoattack": pMode = ParseMode.AutoAttack; break;

                                case "autofishing": pMode = ParseMode.AutoFishing; break;

                                case "autoeat": pMode = ParseMode.AutoEat; break;

                                case "autocraft": pMode = ParseMode.AutoCraft; break;

                                case "mailer": pMode = ParseMode.Mailer; break;

                                case "autodrop": pMode = ParseMode.AutoDrop; break;

                                case "replaymod": pMode = ParseMode.ReplayMod; break;

                                default: pMode = ParseMode.Default; break;
                                }
                            }
                            else
                            {
                                string argName = line.Split('=')[0];
                                if (line.Length > (argName.Length + 1))
                                {
                                    string argValue = line.Substring(argName.Length + 1);
                                    switch (pMode)
                                    {
                                    case ParseMode.Main:
                                        switch (argName.ToLower())
                                        {
                                        case "login": Login = argValue; break;

                                        case "password": Password = argValue; break;

                                        case "serverip": if (!SetServerIP(argValue))
                                            {
                                                serverAlias = argValue;
                                            }
                                            ; break;

                                        case "singlecommand": SingleCommand = argValue; break;

                                        case "language": Language = argValue; break;

                                        case "consoletitle": ConsoleTitle = argValue; break;

                                        case "timestamps": ConsoleIO.EnableTimestamps = str2bool(argValue); break;

                                        case "exitonfailure": interactiveMode = !str2bool(argValue); break;

                                        case "playerheadicon": playerHeadAsIcon = str2bool(argValue); break;

                                        case "chatbotlogfile": chatbotLogFile = argValue; break;

                                        case "mcversion": ServerVersion = argValue; break;

                                        case "messagecooldown": messageCooldown = TimeSpan.FromSeconds(str2int(argValue)); break;

                                        case "scriptcache": CacheScripts = str2bool(argValue); break;

                                        case "showsystemmessages": DisplaySystemMessages = str2bool(argValue); break;

                                        case "showxpbarmessages": DisplayXPBarMessages = str2bool(argValue); break;

                                        case "showchatlinks": DisplayChatLinks = str2bool(argValue); break;

                                        case "terrainandmovements": TerrainAndMovements = str2bool(argValue); break;

                                        case "entityhandling": EntityHandling = str2bool(argValue); break;

                                        case "enableentityhandling": EntityHandling = str2bool(argValue); break;

                                        case "inventoryhandling": InventoryHandling = str2bool(argValue); break;

                                        case "privatemsgscmdname": PrivateMsgsCmdName = argValue.ToLower().Trim(); break;

                                        case "debugmessages": DebugMessages = str2bool(argValue); break;

                                        case "autorespawn": AutoRespawn = str2bool(argValue); break;

                                        case "botowners":
                                            Bots_Owners.Clear();
                                            string[] names = argValue.ToLower().Split(',');
                                            if (!argValue.Contains(",") && argValue.ToLower().EndsWith(".txt") && File.Exists(argValue))
                                            {
                                                names = File.ReadAllLines(argValue);
                                            }
                                            foreach (string name in names)
                                            {
                                                if (!String.IsNullOrWhiteSpace(name))
                                                {
                                                    Bots_Owners.Add(name.Trim());
                                                }
                                            }
                                            break;

                                        case "internalcmdchar":
                                            switch (argValue.ToLower())
                                            {
                                            case "none": internalCmdChar = ' '; break;

                                            case "slash": internalCmdChar = '/'; break;

                                            case "backslash": internalCmdChar = '\\'; break;
                                            }
                                            break;

                                        case "sessioncache":
                                            if (argValue == "none")
                                            {
                                                SessionCaching = CacheType.None;
                                            }
                                            else if (argValue == "memory")
                                            {
                                                SessionCaching = CacheType.Memory;
                                            }
                                            else if (argValue == "disk")
                                            {
                                                SessionCaching = CacheType.Disk;
                                            }
                                            break;

                                        case "accountlist":
                                            if (File.Exists(argValue))
                                            {
                                                foreach (string account_line in File.ReadAllLines(argValue))
                                                {
                                                    //Each line contains account data: 'Alias,Login,Password'
                                                    string[] account_data = account_line.Split('#')[0].Trim().Split(',');
                                                    if (account_data.Length == 3)
                                                    {
                                                        Accounts[account_data[0].ToLower()]
                                                            = new KeyValuePair <string, string>(account_data[1], account_data[2]);
                                                    }
                                                }

                                                //Try user value against aliases after load
                                                Settings.SetAccount(Login);
                                            }
                                            break;

                                        case "serverlist":
                                            if (File.Exists(argValue))
                                            {
                                                //Backup current server info
                                                string server_host_temp = ServerIP;
                                                ushort server_port_temp = ServerPort;

                                                foreach (string server_line in File.ReadAllLines(argValue))
                                                {
                                                    //Each line contains server data: 'Alias,Host:Port'
                                                    string[] server_data = server_line.Split('#')[0].Trim().Split(',');
                                                    server_data[0] = server_data[0].ToLower();
                                                    if (server_data.Length == 2 &&
                                                        server_data[0] != "localhost" &&
                                                        !server_data[0].Contains('.') &&
                                                        SetServerIP(server_data[1]))
                                                    {
                                                        Servers[server_data[0]]
                                                            = new KeyValuePair <string, ushort>(ServerIP, ServerPort);
                                                    }
                                                }

                                                //Restore current server info
                                                ServerIP   = server_host_temp;
                                                ServerPort = server_port_temp;

                                                //Try server value against aliases after load
                                                SetServerIP(serverAlias);
                                            }
                                            break;

                                        case "brandinfo":
                                            switch (argValue.Trim().ToLower())
                                            {
                                            case "mcc": BrandInfo = MCCBrandInfo; break;

                                            case "vanilla": BrandInfo = "vanilla"; break;

                                            default: BrandInfo = null; break;
                                            }
                                            break;

                                        case "resolvesrvrecords":
                                            if (argValue.Trim().ToLower() == "fast")
                                            {
                                                ResolveSrvRecords             = true;
                                                ResolveSrvRecordsShortTimeout = true;
                                            }
                                            else
                                            {
                                                ResolveSrvRecords             = str2bool(argValue);
                                                ResolveSrvRecordsShortTimeout = false;
                                            }
                                            break;

                                        case "mcforge":
                                            if (argValue.ToLower() == "auto")
                                            {
                                                ServerAutodetectForge = true;
                                                ServerForceForge      = false;
                                            }
                                            else
                                            {
                                                ServerAutodetectForge = false;
                                                ServerForceForge      = str2bool(argValue);
                                            }
                                            break;
                                        }
                                        break;

                                    case ParseMode.Alerts:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": Alerts_Enabled = str2bool(argValue); break;

                                        case "alertsfile": Alerts_MatchesFile = argValue; break;

                                        case "excludesfile": Alerts_ExcludesFile = argValue; break;

                                        case "beeponalert": Alerts_Beep_Enabled = str2bool(argValue); break;
                                        }
                                        break;

                                    case ParseMode.AntiAFK:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AntiAFK_Enabled = str2bool(argValue); break;

                                        case "delay": AntiAFK_Delay = str2int(argValue); break;

                                        case "command": AntiAFK_Command = argValue == "" ? "/ping" : argValue; break;
                                        }
                                        break;

                                    case ParseMode.AutoRelog:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoRelog_Enabled = str2bool(argValue); break;

                                        case "retries": AutoRelog_Retries = str2int(argValue); break;

                                        case "ignorekickmessage": AutoRelog_IgnoreKickMessage = str2bool(argValue); break;

                                        case "kickmessagesfile": AutoRelog_KickMessagesFile = argValue; break;

                                        case "delay":
                                            string[] delayParts = argValue.Split('-');
                                            if (delayParts.Length == 1)
                                            {
                                                AutoRelog_Delay_Min = str2int(delayParts[0]);
                                                AutoRelog_Delay_Max = AutoRelog_Delay_Min;
                                            }
                                            else
                                            {
                                                AutoRelog_Delay_Min = str2int(delayParts[0]);
                                                AutoRelog_Delay_Max = str2int(delayParts[1]);
                                            }
                                            break;
                                        }
                                        break;

                                    case ParseMode.ChatLog:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": ChatLog_Enabled = str2bool(argValue); break;

                                        case "timestamps": ChatLog_DateTime = str2bool(argValue); break;

                                        case "filter": ChatLog_Filter = ChatBots.ChatLog.str2filter(argValue); break;

                                        case "logfile": ChatLog_File = argValue; break;
                                        }
                                        break;

                                    case ParseMode.Hangman:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": Hangman_Enabled = str2bool(argValue); break;

                                        case "english": Hangman_English = str2bool(argValue); break;

                                        case "wordsfile": Hangman_FileWords_EN = argValue; break;

                                        case "fichiermots": Hangman_FileWords_FR = argValue; break;
                                        }
                                        break;

                                    case ParseMode.ScriptScheduler:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": ScriptScheduler_Enabled = str2bool(argValue); break;

                                        case "tasksfile": ScriptScheduler_TasksFile = argValue; break;
                                        }
                                        break;

                                    case ParseMode.RemoteControl:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": RemoteCtrl_Enabled = str2bool(argValue); break;

                                        case "autotpaccept": RemoteCtrl_AutoTpaccept = str2bool(argValue); break;

                                        case "tpaccepteveryone": RemoteCtrl_AutoTpaccept_Everyone = str2bool(argValue); break;
                                        }
                                        break;

                                    case ParseMode.ChatFormat:
                                        switch (argName.ToLower())
                                        {
                                        case "builtins": ChatFormat_Builtins = str2bool(argValue); break;

                                        case "public": ChatFormat_Public = new Regex(argValue); break;

                                        case "private": ChatFormat_Private = new Regex(argValue); break;

                                        case "tprequest": ChatFormat_TeleportRequest = new Regex(argValue); break;
                                        }
                                        break;

                                    case ParseMode.Proxy:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled":
                                            ProxyEnabledLogin = ProxyEnabledIngame = str2bool(argValue);
                                            if (argValue.Trim().ToLower() == "login")
                                            {
                                                ProxyEnabledLogin = true;
                                            }
                                            break;

                                        case "type":
                                            argValue = argValue.ToLower();
                                            if (argValue == "http")
                                            {
                                                proxyType = Proxy.ProxyHandler.Type.HTTP;
                                            }
                                            else if (argValue == "socks4")
                                            {
                                                proxyType = Proxy.ProxyHandler.Type.SOCKS4;
                                            }
                                            else if (argValue == "socks4a")
                                            {
                                                proxyType = Proxy.ProxyHandler.Type.SOCKS4a;
                                            }
                                            else if (argValue == "socks5")
                                            {
                                                proxyType = Proxy.ProxyHandler.Type.SOCKS5;
                                            }
                                            break;

                                        case "server":
                                            string[] host_splitted = argValue.Split(':');
                                            if (host_splitted.Length == 1)
                                            {
                                                ProxyHost = host_splitted[0];
                                                ProxyPort = 80;
                                            }
                                            else if (host_splitted.Length == 2)
                                            {
                                                ProxyHost = host_splitted[0];
                                                ProxyPort = str2int(host_splitted[1]);
                                            }
                                            break;

                                        case "username": ProxyUsername = argValue; break;

                                        case "password": ProxyPassword = argValue; break;
                                        }
                                        break;

                                    case ParseMode.AppVars:
                                        SetVar(argName, argValue);
                                        break;

                                    case ParseMode.AutoRespond:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoRespond_Enabled = str2bool(argValue); break;

                                        case "matchesfile": AutoRespond_Matches = argValue; break;
                                        }
                                        break;

                                    case ParseMode.AutoAttack:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoAttack_Enabled = str2bool(argValue); break;

                                        case "mode": AutoAttack_Mode = argValue.ToLower(); break;

                                        case "priority": AutoAttack_Priority = argValue.ToLower(); break;
                                        }
                                        break;

                                    case ParseMode.AutoFishing:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoFishing_Enabled = str2bool(argValue); break;

                                        case "antidespawn": AutoFishing_Antidespawn = str2bool(argValue); break;
                                        }
                                        break;

                                    case ParseMode.AutoEat:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoEat_Enabled = str2bool(argValue); break;

                                        case "threshold": AutoEat_hungerThreshold = str2int(argValue); break;
                                        }
                                        break;

                                    case ParseMode.AutoCraft:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoCraft_Enabled = str2bool(argValue); break;

                                        case "configfile": AutoCraft_configFile = argValue; break;
                                        }
                                        break;

                                    case ParseMode.AutoDrop:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": AutoDrop_Enabled = str2bool(argValue); break;

                                        case "mode": AutoDrop_Mode = argValue; break;

                                        case "items": AutoDrop_items = argValue; break;
                                        }
                                        break;

                                    case ParseMode.MCSettings:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": MCSettings_Enabled = str2bool(argValue); break;

                                        case "locale": MCSettings_Locale = argValue; break;

                                        case "difficulty":
                                            switch (argValue.ToLower())
                                            {
                                            case "peaceful": MCSettings_Difficulty = 0; break;

                                            case "easy": MCSettings_Difficulty = 1; break;

                                            case "normal": MCSettings_Difficulty = 2; break;

                                            case "difficult": MCSettings_Difficulty = 3; break;
                                            }
                                            break;

                                        case "renderdistance":
                                            MCSettings_RenderDistance = 2;
                                            if (argValue.All(Char.IsDigit))
                                            {
                                                MCSettings_RenderDistance = (byte)str2int(argValue);
                                            }
                                            else
                                            {
                                                switch (argValue.ToLower())
                                                {
                                                case "tiny": MCSettings_RenderDistance = 2; break;

                                                case "short": MCSettings_RenderDistance = 4; break;

                                                case "medium": MCSettings_RenderDistance = 8; break;

                                                case "far": MCSettings_RenderDistance = 16; break;
                                                }
                                            }
                                            break;

                                        case "chatmode":
                                            switch (argValue.ToLower())
                                            {
                                            case "enabled": MCSettings_ChatMode = 0; break;

                                            case "commands": MCSettings_ChatMode = 1; break;

                                            case "disabled": MCSettings_ChatMode = 2; break;
                                            }
                                            break;

                                        case "chatcolors": MCSettings_ChatColors = str2bool(argValue); break;

                                        case "skin_cape": MCSettings_Skin_Cape = str2bool(argValue); break;

                                        case "skin_jacket": MCSettings_Skin_Jacket = str2bool(argValue); break;

                                        case "skin_sleeve_left": MCSettings_Skin_Sleeve_Left = str2bool(argValue); break;

                                        case "skin_sleeve_right": MCSettings_Skin_Sleeve_Right = str2bool(argValue); break;

                                        case "skin_pants_left": MCSettings_Skin_Pants_Left = str2bool(argValue); break;

                                        case "skin_pants_right": MCSettings_Skin_Pants_Right = str2bool(argValue); break;

                                        case "skin_hat": MCSettings_Skin_Hat = str2bool(argValue); break;

                                        case "main_hand":
                                            switch (argValue.ToLower())
                                            {
                                            case "left": MCSettings_MainHand = 0; break;

                                            case "right": MCSettings_MainHand = 1; break;
                                            }
                                            break;
                                        }
                                        break;

                                    case ParseMode.Mailer:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": Mailer_Enabled = str2bool(argValue); break;

                                        case "database": Mailer_DatabaseFile = argValue; break;

                                        case "ignorelist": Mailer_IgnoreListFile = argValue; break;

                                        case "publicinteractions": Mailer_PublicInteractions = str2bool(argValue); break;

                                        case "maxmailsperplayer": Mailer_MaxMailsPerPlayer = str2int(argValue); break;

                                        case "maxdatabasesize": Mailer_MaxDatabaseSize = str2int(argValue); break;

                                        case "retentiondays": Mailer_MailRetentionDays = str2int(argValue); break;
                                        }
                                        break;

                                    case ParseMode.ReplayMod:
                                        switch (argName.ToLower())
                                        {
                                        case "enabled": ReplayMod_Enabled = str2bool(argValue); break;

                                        case "backupinterval": ReplayMod_BackupInterval = str2int(argValue); break;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (IOException) { }
            }
        }
예제 #13
0
        /// <summary>
        /// Starts the main chat client, wich will login to the server using the MinecraftCom class.
        /// </summary>
        /// <param name="user">The chosen username of a premium Minecraft Account</param>
        /// <param name="sessionID">A valid sessionID obtained with MinecraftCom.GetLogin()</param>
        /// <param name="server_ip">The server IP</param>
        /// <param name="port">The server port to use</param>
        /// <param name="protocolversion">Minecraft protocol version to use</param>
        /// <param name="uuid">The player's UUID for online-mode authentication</param>
        /// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param>
        /// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param>
        private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
        {
            terrainAndMovementsEnabled = Settings.TerrainAndMovements;

            bool retry = false;

            this.sessionid = sessionID;
            this.uuid      = uuid;
            this.username  = user;
            this.host      = server_ip;
            this.port      = port;

            if (!singlecommand)
            {
                if (botsOnHold.Count == 0)
                {
                    if (Settings.AntiAFK_Enabled)
                    {
                        BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay));
                    }
                    if (Settings.Hangman_Enabled)
                    {
                        BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English));
                    }
                    if (Settings.Alerts_Enabled)
                    {
                        BotLoad(new ChatBots.Alerts());
                    }
                    if (Settings.ChatLog_Enabled)
                    {
                        BotLoad(new ChatBots.ChatLog(Settings.ExpandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime));
                    }
                    if (Settings.PlayerLog_Enabled)
                    {
                        BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.ExpandVars(Settings.PlayerLog_File)));
                    }
                    if (Settings.AutoRelog_Enabled)
                    {
                        BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries));
                    }
                    if (Settings.ScriptScheduler_Enabled)
                    {
                        BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile)));
                    }
                    if (Settings.RemoteCtrl_Enabled)
                    {
                        BotLoad(new ChatBots.RemoteControl());
                    }
                    if (Settings.AutoRespond_Enabled)
                    {
                        BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches));
                    }
                    //Add your ChatBot here by uncommenting and adapting
                    //BotLoad(new ChatBots.YourBot());
                }
            }

            try
            {
                client = ProxyHandler.newTcpClient(host, port);
                client.ReceiveBufferSize = 1024 * 1024;
                handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this);
                Console.WriteLine("Version is supported.\nLogging in...");

                try
                {
                    if (handler.Login())
                    {
                        if (singlecommand)
                        {
                            handler.SendChatMessage(command);
                            ConsoleIO.WriteLineFormatted("§7Command §8" + command + "§7 sent.");
                            Thread.Sleep(5000);
                            handler.Disconnect();
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            foreach (ChatBot bot in botsOnHold)
                            {
                                BotLoad(bot, false);
                            }
                            botsOnHold.Clear();

                            Console.WriteLine("Server was successfully joined.\nType '"
                                              + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar)
                                              + "quit' to leave the server.");

                            cmdprompt      = new Thread(new ThreadStart(CommandPrompt));
                            cmdprompt.Name = "MCC Command prompt";
                            cmdprompt.Start();
                        }
                    }
                }
                catch (Exception e)
                {
                    ConsoleIO.WriteLineFormatted("§8" + e.Message);
                    Console.WriteLine("Failed to join this server.");
                    retry = true;
                }
            }
            catch (SocketException e)
            {
                ConsoleIO.WriteLineFormatted("§8" + e.Message);
                Console.WriteLine("Failed to connect to this IP.");
                retry = true;
            }

            if (retry)
            {
                if (ReconnectionAttemptsLeft > 0)
                {
                    ConsoleIO.WriteLogLine("Waiting 5 seconds (" + ReconnectionAttemptsLeft + " attempts left)...");
                    Thread.Sleep(5000); ReconnectionAttemptsLeft--; Program.Restart();
                }
                else if (!singlecommand && Settings.interactiveMode)
                {
                    Program.HandleFailure();
                }
            }
        }
예제 #14
0
 /// <summary>
 /// Translate the key and write the result with a prefixed log line. Prefix is set in LogPrefix.
 /// </summary>
 /// <param name="key">Translation key</param>
 /// <param name="acceptnewlines">Allow line breaks</param>
 public static void WriteLogLine(string key, bool acceptnewlines = true)
 {
     ConsoleIO.WriteLogLine(Get(key), acceptnewlines);
 }