Пример #1
0
        /// <summary>
        /// OnStart: Put startup code here
        ///  - Start threads, get inital data, etc.
        /// </summary>
        /// <param name="args"></param>
        public void OnStart(string[] args)
        {
            string assemblyLoc      = Assembly.GetExecutingAssembly().Location;
            string currentDirectory = assemblyLoc.Substring(0, assemblyLoc.LastIndexOf(Path.DirectorySeparatorChar) + 1);
            string securityFile     = Path.Combine(currentDirectory, "security.dat");

            // Check if the security file exists
            if (File.Exists(securityFile))
            {
                try
                {
                    // Open the configuration file
                    FileStream securityStream = new FileStream(securityFile, FileMode.Open);

                    // Create the service provider
                    DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();

                    // Create the encryption keys
                    cryptic.Key = ASCIIEncoding.ASCII.GetBytes("ALTT1029");
                    cryptic.IV  = ASCIIEncoding.ASCII.GetBytes("ALTT1029");

                    // Create the Decryption stream provider
                    CryptoStream crStream = new CryptoStream(securityStream,
                                                             cryptic.CreateDecryptor(),
                                                             CryptoStreamMode.Read);

                    // Create the binary formatter for the settings
                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize the decrypted stream into the core settings
                    String strPassword = (String)formatter.Deserialize(crStream);

                    // Close the file stream
                    crStream.Close();

                    // Create the core settings object
                    CoreSettings coreSettings = new CoreSettings(strPassword);

                    // Get a List of each bot configuration
                    foreach (BotSettings botSettings in coreSettings.ConfiguredBots)
                    {
                        // Create the new bot instance
                        BotInstance bot = new BotInstance(botSettings);

                        // Add the core event manager
                        bot.CoreEventManager += (new BotEvent(HandleCoreEvents));

                        // if the bot is to be loaded automatically
                        if (botSettings.AutoLoad)
                        {
                            // Add a bot to the bot list
                            m_activeBots.Add(bot.Settings.SessionSettings.UserName.ToUpper(), bot);

                            // Start the bot
                            bot.Start();
                        }
                        else
                        {
                            // Add a bot to the bot list
                            m_availableBots.Add(bot.Settings.SessionSettings.UserName.ToUpper(), bot);
                        }
                    }

                    // Show the tray icon
                    m_trayIcon.Visible = true;
                }
                catch (Exception)
                {
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handle a bot spawn command to create a new bot instance
        /// </summary>
        /// <param name="sender">Sending object</param>
        /// <param name="spawnEvent"></param>
        internal void HandleBotSpawnEvent(object sender, BotSpawnEvent spawnEvent)
        {
            // Send the response message to the bot
            BotInstance sourceBot = (sender as BotInstance);

            // Create the chat response packet
            ChatEvent response = new ChatEvent();

            // Set the player Identifier to reply to
            response.PlayerId = spawnEvent.PlayerId;
            response.ChatType = ChatTypes.Private;

            // Check if the spawn bot name is valid
            if (spawnEvent.BotName.Length > 0)
            {
                // Find the bot in the available bot list
                int nIndex = m_availableBots.IndexOfKey(spawnEvent.BotName.ToUpper());

                if (nIndex >= 0)
                {
                    // Get the bot instance from the available bots
                    BotInstance bot = m_availableBots[spawnEvent.BotName.ToUpper()];

                    if (spawnEvent.Arena.Length > 0)
                    {
                        // Set the new arena to enter
                        bot.Settings.SessionSettings.InitialArena = spawnEvent.Arena;
                    }

                    // Remove the bot from the available list
                    m_availableBots.Remove(spawnEvent.BotName.ToUpper());

                    // Add the bot to the active bot list
                    m_activeBots.Add(spawnEvent.BotName.ToUpper(), bot);

                    // Create the response message
                    response.Message = "Spawning bot: " + spawnEvent.BotName;

                    // Start the bot
                    bot.Start();
                }
                else if (m_activeBots.IndexOfKey(spawnEvent.BotName.ToUpper()) != -1)
                {
                    response.Message = "Error: " + spawnEvent.BotName + "is already active!";
                }
                else
                {
                    response.Message = "Error: " + spawnEvent.BotName + "is not a valid bot name!";
                }

                /*
                 * else if (spawnEvent.ModLevel == ModLevels.Sysop)
                 * {
                 *
                 * // Create the core settings object
                 * CoreSettings coreSettings = new CoreSettings ();
                 *
                 * // Create the bot settings object
                 * BotSettings spawnSettings = new BotSettings ();
                 *
                 * // Get the settings for the source bot
                 * BotSettings sourceSettings = sourceBot.Settings;
                 *
                 * // Set the bot settings
                 * spawnSettings.BotDirectory = spawnEvent.BotName;
                 * spawnSettings.AutoLoad = false;
                 *
                 * // Set the session connection settings
                 * spawnSettings.SessionSettings.UserName = spawnEvent.BotName;
                 * spawnSettings.SessionSettings.Password = sourceSettings.SessionSettings.Password;
                 * spawnSettings.SessionSettings.StaffPassword = sourceSettings.SessionSettings.StaffPassword;
                 * spawnSettings.SessionSettings.InitialArena = spawnEvent.Arena;
                 *
                 * // Set the server address and port of the sending bot
                 * spawnSettings.SessionSettings.ServerAddress = sourceSettings.SessionSettings.ServerAddress;
                 * spawnSettings.SessionSettings.ServerPort = sourceSettings.SessionSettings.ServerPort;
                 *
                 * // Add the new bot to the core settings
                 * coreSettings.ConfiguredBots.Add (spawnSettings);
                 * coreSettings.WriteSettings ();
                 *
                 * // Create the new bot instance
                 * BotInstance bot = new BotInstance (spawnSettings);
                 *
                 * // Add the core event manager
                 * bot.CoreEventManager += (new BotEvent (HandleCoreEvents));
                 *
                 * // Start the bot
                 * bot.Start ();
                 *
                 * // Add a bot to the bot list
                 * m_activeBots.Add (spawnEvent.BotName.ToUpper(), bot);
                 *
                 * // Create the response message
                 * response.Message = "Bot does not exist. Creating a new bot: " + spawnEvent.BotName;
                 * }
                 */
            }
            else
            {
                response.Message = "!spawn usage:  !spawn bot   !spawn bot:arena";
            }

            // Send the response message to the bot
            sourceBot.SendGameEvent(response);
        }