/// <summary>
        /// Handles BotGetInfoEvent - used to send back bot info to modules
        /// </summary>
        /// <param name="chatEvent"></param>

        /*private void HandleBotInfoCommand(ChatEvent chatEvent)
         * {
         *  BotGetInfoEvent infoEvent = new BotGetInfoEvent ();
         *  try
         *  {
         *      infoEvent.PlayerId = chatEvent.PlayerId;
         *      infoEvent.ModLevel = chatEvent.ModLevel;
         *      // Send the botinfo event to the core handler
         *      m_core.OnCoreEvent(this, infoEvent);
         *  }
         *  catch (Exception e)
         *  {
         *      // Create the chat response message
         *      ChatPacket response = new ChatPacket();
         *
         *      // Set the response message information
         *      response.Event.PlayerId = chatEvent.PlayerId;
         *      response.Event.ChatType = ChatTypes.Private;
         *
         *      // Set the response message
         *      response.Event.Message = e.Message;
         *
         *      // Send the exception message to the player
         *      m_session.TransmitPacket(response);
         *  }
         * }*/

        /// <summary>
        /// Handle the list information command.  This command lists
        /// information about the core and all loaded behaviors.
        /// </summary>
        /// <param name="chatEvent"></param>
        private void HandleSpawnCommand(ChatEvent chatEvent)
        {
            // Create the bot spawn event
            BotSpawnEvent spawnEvent = new BotSpawnEvent();

            try
            {
                // parse the spawn parameters from the message
                spawnEvent.Parameters = chatEvent.Message.Remove(0, 7);
                spawnEvent.PlayerId   = chatEvent.PlayerId;
                spawnEvent.ModLevel   = chatEvent.ModLevel;

                // Send the spawn event to the core handler
                m_core.OnCoreEvent(this, spawnEvent);
            }
            catch (Exception e)
            {
                // Create the chat response message
                ChatPacket response = new ChatPacket();

                // Set the response message information
                response.Event.PlayerId = chatEvent.PlayerId;
                response.Event.ChatType = ChatTypes.Private;

                // Set the response message
                response.Event.Message = e.Message;

                // Send the exception message to the player
                m_session.TransmitPacket(response);
            }
        }
Example #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);
        }