//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_mixer_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_mixer_create_xp (agent * a, char * parameterstring)
{
	bool errorflag = false; //If there's an error

	//Check for error conditions
	if (strlen(parameterstring) >= 30) return false;
	//Break up the parts
	int tokensfound = BBTokenize(parameterstring, mixer_tokenptrs, 4, NULL);
	//Three tokens exactly required
	if (tokensfound != 3) return 1;

	long values[3];
	//Make sure they are all valid integers
	for (int i = 0; i < 3; i++)
		if (!config_set_long(mixer_tokenptrs[i], &values[i]))
			return 1;

	AgentType_Mixer_XP * details = new AgentType_Mixer_XP(values);
	if (details->Init())
	{
		//Set the window property
		SetProp(details->m_hwnd_reciever, "mixagtptr", a);
		a->agentdetails = static_cast<void *>(details);
	}
	else
	{
		details->Destroy();
		delete details;
		a->agentdetails = NULL;

		agent_destroy(&a);
		return 1;   
	}
	return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//message_interpret
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void message_interpret(const char *message, bool from_core, module* caller)
{
    if (!message || !(*message)) return; //If the message is invalid, or empty, don't bother
    if (caller == NULL) caller = currentmodule;

    char buffer[BBI_MAX_LINE_LENGTH];

    // Check, if the message is for us...
    if (memcmp(message, szBBroam, szBBroamLength))
    {
        //The standard BlackBox Messages
        if (!stricmp(message, "@BBShowPlugins"))
        {
            control_pluginsvisible(true);
            return;
        }
        if (!stricmp(message, "@BBHidePlugins"))
        {
            control_pluginsvisible(false);
            return;
        }
        if (!memicmp(message, "@Script",7))
        {
            char* buf = new char[strlen(message)+1]; // local buffer.
            strcpy(buf,message); //NOTE: possible alternate method would be copying out the messages one by one.
            char *start = strchr(buf,'[');
            char *end = strrchr(buf,']');
            if (start && end)
            {
                ++start;
                *end = 0; //terminate string here.
                while (end = strchr(start,'|'))
                {
                    *end = 0;
                    while (*start == ' ') ++start; // skip whitespace
                    message_interpret(start, from_core, caller);
                    start = end+1;
                }
                while (*start == ' ') ++start; // skip whitespace
                message_interpret(start, from_core, caller); // interpret message after last separator character
            }
            else if (!plugin_suppresserrors)
            {
                sprintf(buffer,"Invalid @Script syntax in line:\n\n%s",buf);
                MessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
            }
            delete[] buf;
            return;
        }

        if (from_core) return;
        message = message_preprocess(strcpy(buffer, message)); //NOTE: FIX, possibly should this use the caller argument as well?
        if ('@' == message[0])
        {
            SendMessage(plugin_hwnd_blackbox, BB_BROADCAST, 0, (LPARAM)buffer);
        }
        else
        {
            // bblean only: SendMessage(plugin_hwnd_blackbox, BB_EXECUTE, 0, (LPARAM)string);
            char command[MAX_PATH], arguments[MAX_PATH], *token = command;
            BBTokenize(message, &token, 1, arguments);
            shell_exec(command, arguments);
        }
        return;
    }
    //Tokenize the string
    char *message_tokenptrs[32];
    int tokensfound = tokenize_message(message, 32, message_tokenptrs, buffer, caller);

    //Token Check - we always need at least two tokens for all purposes
    if (tokensfound < 2) return;

    //Find someone to send the message to
    int result = 1;

    for (int i = 0; i < MESSAGE_ENTITY_COUNT; i++)
    {
        if (!strcmp(message_tokenptrs[1], message_entitynames[i]))
        {
            result = (message_functions[i])(tokensfound, message_tokenptrs, from_core, caller);
            break;
        }
    }

    if (1 == result) // 0=ok, 1=error, 2=error&dontcare
    {
        //On an error
        if (!plugin_suppresserrors)
        {
            sprintf(buffer,
                    "There was an error executing your Bro@m command:"
                    "\n"
                    "\n%s"
                    "\n"
                    "\nPossible reasons:"
                    "\n - An control or agent referenced may not exist"
                    "\n - The command may be malformed"
                    "\n - An error occurred while performing the requested action"
                    , message
                   );
            MessageBox(NULL, buffer, szAppName, MB_OK|MB_SYSTEMMODAL);
        }
    }
}
示例#3
0
//====================
void CommandItem::Invoke(int button)
{
    LPCITEMIDLIST pidl = GetPidl();
    if (INVOKE_PROP & button)
    {
        show_props(pidl);
        return;
    }
		/*BlackboxZero 1.7.2012 */
        char szPath[MAX_PATH];
		szPath[0] = '\0';

    if (INVOKE_LEFT & button)
    {

        m_pMenu->hide_on_click();
        if (m_pszCommand) {
			/*BlackboxZero 1.7.2012 */
			//if (const char *p = strstr(m_pszCommand, "%b")) {
            //    post_command_fmt(m_pszCommand, false == m_bChecked);
			if (const char *p = stristr(m_pszCommand, "@BBCore.exec ")) {
                _strcpy(szPath, p+13);
				post_command(m_pszCommand);
			} else
                post_command(m_pszCommand);
		} else if (pidl) {
			char buf[MAX_PATH];
		/*BlackboxZero 1.7.2012 */
			char szMenuPath[MAX_PATH];
			szMenuPath[0] = '\0';
			if (SHGetPathFromIDList(pidl, buf))
				sprintf(szPath, "\"%s\"", buf);
			/*BlackboxZero 1.7.2012 */

            BBExecute_pidl(NULL, pidl);

			/*BlackboxZero 1.7.2012 */
			strcpy(szMenuPath, unquote(Settings_recentMenu));
			int nKeep = Settings_recentItemKeepSize;
			int nSort = Settings_recentItemSortSize;
			bool bBeginEnd = Settings_recentBeginEnd;

			if (szPath[0] && szMenuPath[0] && (nKeep || nSort))
				CreateRecentItemMenu(szMenuPath, szPath, m_pszTitle, m_pszIcon, nKeep, nSort, bBeginEnd);
			/*BlackboxZero 1.7.2012 */
		}
        return;
    }

    if (INVOKE_RIGHT & button)
    {
        if (m_pszRightCommand)
            post_command(m_pszRightCommand);
        else
        if (m_pRightmenu)
            m_pRightmenu->incref(), ShowRightMenu(m_pRightmenu);
        else
		if ((GetAsyncKeyState (VK_SHIFT) & 0x8000))
		{
			char buffer[MAX_PATH], param[MAX_PATH];
			char *tokens[1];
			tokens[0] = param;
			BBTokenize((const char*)m_pszCommand, tokens, 1, param);
			if (0 == _memicmp(m_pszCommand, "@BBCfg.plugin", 12)) 
			{
				if ((GetAsyncKeyState (VK_CONTROL) & 0x8000))
					sprintf(buffer, "@BBCfg.plugin.remove %s", param);
				else
					sprintf(buffer, "@BBCfg.plugin.edit %s", param);
				post_command(buffer);
			}
			else
				if (0 == _memicmp(m_pszCommand, "@BBCore.style", 12)) 
				{
					sprintf(buffer, "@BBCore.edit %s", param);
					post_command(buffer);
				}
		}
		else
            ShowContextMenu(m_pszCommand, pidl);
        return;
    }

    if (INVOKE_MID & button)
    {
		if (0 == _memicmp(m_pszCommand, "@BBCfg.plugin", 12)) 
		{
			char buffer[MAX_PATH], param[MAX_PATH];
			char *tokens[1];
			tokens[0] = param;
			BBTokenize((const char*)m_pszCommand, tokens, 1, param);
			sprintf(buffer, "@BBCfg.plugin.docs %s", param);
			post_command(buffer);
		}
		return;
	}

    if (INVOKE_DRAG & button)
    {
        m_pMenu->start_drag(m_pszCommand, pidl);
        return;
    }
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_mixer_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_mixer_create(agent *a, char *parameterstring)
{
	//If there's an error
	bool errorflag = false;;

	//Check for error conditions
	if (strlen(parameterstring) >= 30) return false;

	//Break up the parts
	int tokensfound = BBTokenize(parameterstring, mixer_tokenptrs, 4, NULL);

	//Three tokens exactly required
	if (tokensfound != 3) return 1;

	long values[3];
	//Make sure they are all valid integers
	for (int i = 0; i < 3; i++)
	{
		if (!config_set_long(mixer_tokenptrs[i], &values[i])) return 1;
	}

	//Create the details
	agenttype_mixer_details *details = new agenttype_mixer_details;
	a->agentdetails = (void *) details;

	//Copy the values
	details->device = values[0];
	details->line = values[1];
	details->control = values[2];

	//Create the reciever window class if neccessary
	//No errors
	mixer_controlcount++;
	if (mixer_controlcount > 0 && !mixer_recieverregistered)
	{
		if (!window_helper_register(mixer_recieverclass, &agenttype_mixer_recieverevent)) mixer_recieverregistered = true;
		else errorflag = true;
	}

	//Create the reciever window
	details->hwnd_reciever = NULL;
	if (!errorflag)
	{
		details->hwnd_reciever = window_helper_create(mixer_recieverclass);
		if (!details->hwnd_reciever) errorflag = true;
	}

	if (!errorflag)
	{
		//Initialize the mixer values
		if (MMSYSERR_NOERROR != mixerOpen(&details->mixer_handle, details->device, (DWORD_PTR) details->hwnd_reciever, 0, CALLBACK_WINDOW)) errorflag = true;
	}

	if (!errorflag)
	{
		//Set the control properties
		details->mixer_controldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
		details->mixer_controldetails.dwControlID = details->control;
		details->mixer_controldetails.cChannels = 1;
		details->mixer_controldetails.cMultipleItems = 0;
		details->mixer_controldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);

		//Set the window property
		SetProp(details->hwnd_reciever, "mixagtptr", a);
	}

	if (errorflag)
	{
		if (details->hwnd_reciever)
			window_helper_destroy(details->hwnd_reciever);

		delete details;
		a->agentdetails = NULL;

		agent_destroy(&a);
		return 1;
	}

	return 0;
}