Example #1
0
void ShowPopup(HWND hwnd, HWND target_hwnd)
{
    // リソースからメニューを取得
    const auto hMenu    = ::LoadMenu(g_hInst, MAKEINTRESOURCE(100));
    const auto hSubMenu = ::GetSubMenu(hMenu, 0);

    // チェックマークを付ける
    CheckTopMost (target_hwnd, hSubMenu);
    CheckOpaque  (target_hwnd, ::GetSubMenu(hSubMenu, 2));
    CheckPriority(target_hwnd, ::GetSubMenu(hSubMenu, 3));

    // Article ID: Q135788
    // ポップアップメニューから処理を戻すために必要
    ::SetForegroundWindow(hwnd);

    // ポップアップメニューを表示
    POINT pt;
    ::GetCursorPos(&pt);

    const auto CmdID = ::TrackPopupMenu
    (
        hSubMenu, TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RETURNCMD,
        pt.x, pt.y, 0, hwnd, nullptr
    );
    //WriteLog(elDebug, TEXT("%s: CmdId = %d"), PLUGIN_NAME, CmdID);

    // 表示したメニューを破棄
    ::DestroyMenu(hMenu);

    // Article ID: Q135788
    // ポップアップメニューから処理を戻すために必要
    ::PostMessage(hwnd, WM_NULL, 0, 0);

    // コマンドを実行
    if ( CmdID == 40000 )
    {
        ToggleTopMost(target_hwnd);
    }
    else if ( CmdID == 40001 )
    {
        OpenAppFolder(target_hwnd);
    }
    else if ( 40002 <= CmdID && CmdID <= 40005 )
    {
        ExecutePluginCommand(TEXT(":system"), CmdID - 40002);
    }
    else if ( CmdID == 40006 )
    {
        settings->load();
    }
    else if ( 41000 < CmdID && CmdID < 42000 )
    {
        SetOpaque(target_hwnd, BYTE(255 * (CmdID - 41000) / 100));
    }
    else if ( 42000 < CmdID && CmdID < 43000 )
    {
        SetPriority(target_hwnd, priority_sheet[CmdID - 42001]);
    }
}
Example #2
0
void ParseCommand(char* cmd, char* arg)
{
	// Acquire the mutex
	if(WaitForSingleObject(hMutex, PLUGIN_THREAD_TIMEOUT) != WAIT_OBJECT_0)
	{
		ts3Functions.logMessage("Timeout while waiting for mutex", LogLevel_WARNING, "NiftyKb Plugin", 0);
		return;
	}

	// Get the active server
	uint64 scHandlerID = niftykbFunctions.GetActiveServerConnectionHandlerID();
	if(scHandlerID == NULL)
	{
		ts3Functions.logMessage("Failed to get an active server, falling back to current server", LogLevel_DEBUG, "NiftyKb Plugin", 0);
		scHandlerID = ts3Functions.getCurrentServerConnectionHandlerID();
	}

	/***** Communication *****/
	if(!strcmp(cmd, "TS3_PTT_ACTIVATE"))
	{
		if(IsConnected(scHandlerID))
		{
			CancelWaitableTimer(hPttDelayTimer);
			niftykbFunctions.SetPushToTalk(scHandlerID, true);
		}
	}
	else if(!strcmp(cmd, "TS3_PTT_DEACTIVATE"))
	{
		if(IsConnected(scHandlerID))
		{
			if(!PTTDelay()) // If query failed
				niftykbFunctions.SetPushToTalk(scHandlerID, false);
		}
	}
	else if(!strcmp(cmd, "TS3_PTT_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
		{
			if(niftykbFunctions.pttActive) CancelWaitableTimer(hPttDelayTimer);
			niftykbFunctions.SetPushToTalk(scHandlerID, !niftykbFunctions.pttActive);
		}
	}
	else if(!strcmp(cmd, "TS3_VAD_ACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetVoiceActivation(scHandlerID, true);
	}
	else if(!strcmp(cmd, "TS3_VAD_DEACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetVoiceActivation(scHandlerID, false);
	}
	else if(!strcmp(cmd, "TS3_VAD_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetVoiceActivation(scHandlerID, !niftykbFunctions.vadActive);
	}
	else if(!strcmp(cmd, "TS3_CT_ACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetContinuousTransmission(scHandlerID, true);
	}
	else if(!strcmp(cmd, "TS3_CT_DEACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetContinuousTransmission(scHandlerID, false);
	}
	else if(!strcmp(cmd, "TS3_CT_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetContinuousTransmission(scHandlerID, !niftykbFunctions.inputActive);
	}
	else if(!strcmp(cmd, "TS3_INPUT_MUTE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetInputMute(scHandlerID, true);
	}
	else if(!strcmp(cmd, "TS3_INPUT_UNMUTE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetInputMute(scHandlerID, false);
	}
	else if(!strcmp(cmd, "TS3_INPUT_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
		{
			int muted;
			ts3Functions.getClientSelfVariableAsInt(scHandlerID, CLIENT_INPUT_MUTED, &muted);
			niftykbFunctions.SetInputMute(scHandlerID, !muted);
		}
	}
	else if(!strcmp(cmd, "TS3_OUTPUT_MUTE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetOutputMute(scHandlerID, true);
	}
	else if(!strcmp(cmd, "TS3_OUTPUT_UNMUTE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetOutputMute(scHandlerID, false);
	}
	else if(!strcmp(cmd, "TS3_OUTPUT_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
		{
			int muted;
			ts3Functions.getClientSelfVariableAsInt(scHandlerID, CLIENT_OUTPUT_MUTED, &muted);
			niftykbFunctions.SetOutputMute(scHandlerID, !muted);
		}
	}
	/***** Server interaction *****/
	else if(!strcmp(cmd, "TS3_AWAY_ZZZ"))
	{
		niftykbFunctions.SetAway(scHandlerID, true, arg);
	}
	else if(!strcmp(cmd, "TS3_AWAY_NONE"))
	{
		niftykbFunctions.SetAway(scHandlerID, false);
	}
	else if(!strcmp(cmd, "TS3_AWAY_TOGGLE"))
	{
		int away;
		ts3Functions.getClientSelfVariableAsInt(scHandlerID, CLIENT_AWAY, &away);
		niftykbFunctions.SetAway(scHandlerID, !away, arg);
	}
	else if(!strcmp(cmd, "TS3_GLOBALAWAY_ZZZ"))
	{
		niftykbFunctions.SetGlobalAway(true, arg);
	}
	else if(!strcmp(cmd, "TS3_GLOBALAWAY_NONE"))
	{
		niftykbFunctions.SetGlobalAway(false);
	}
	else if(!strcmp(cmd, "TS3_GLOBALAWAY_TOGGLE"))
	{
		int away;
		ts3Functions.getClientSelfVariableAsInt(scHandlerID, CLIENT_AWAY, &away);
		niftykbFunctions.SetGlobalAway(!away, arg);
	}
	else if(!strcmp(cmd, "TS3_ACTIVATE_SERVER"))
	{
		if(!IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 handle = niftykbFunctions.GetServerHandleByVariable(arg, VIRTUALSERVER_NAME);
			if(handle != (uint64)NULL && handle != scHandlerID)
			{
				CancelWaitableTimer(hPttDelayTimer);
				niftykbFunctions.SetActiveServer(handle);
			}
			else niftykbFunctions.ErrorMessage(scHandlerID, "Server not found");
		}
	}
	else if(!strcmp(cmd, "TS3_ACTIVATE_SERVERID"))
	{
		if(!IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 handle = niftykbFunctions.GetServerHandleByVariable(arg, VIRTUALSERVER_UNIQUE_IDENTIFIER);
			if(handle != (uint64)NULL)
			{
				CancelWaitableTimer(hPttDelayTimer);
				niftykbFunctions.SetActiveServer(handle);
			}
			else niftykbFunctions.ErrorMessage(scHandlerID, "Server not found");
		}
	}
	else if(!strcmp(cmd, "TS3_ACTIVATE_SERVERIP"))
	{
		if(!IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 handle = niftykbFunctions.GetServerHandleByVariable(arg, VIRTUALSERVER_IP);
			if(handle != (uint64)NULL)
			{
				CancelWaitableTimer(hPttDelayTimer);
				niftykbFunctions.SetActiveServer(handle);
			}
			else niftykbFunctions.ErrorMessage(scHandlerID, "Server not found");
		}
	}
	else if(!strcmp(cmd, "TS3_ACTIVATE_CURRENT"))
	{
		uint64 handle = ts3Functions.getCurrentServerConnectionHandlerID();
		if(handle != (uint64)NULL)
		{
			CancelWaitableTimer(hPttDelayTimer);
			niftykbFunctions.SetActiveServer(handle);
		}
		else niftykbFunctions.ErrorMessage(scHandlerID, "Server not found");
	}
	else if(!strcmp(cmd, "TS3_SERVER_NEXT"))
	{
		CancelWaitableTimer(hPttDelayTimer);
		niftykbFunctions.SetNextActiveServer(scHandlerID);
	}
	else if(!strcmp(cmd, "TS3_SERVER_PREV"))
	{
		CancelWaitableTimer(hPttDelayTimer);
		niftykbFunctions.SetPrevActiveServer(scHandlerID);
	}
	else if(!strcmp(cmd, "TS3_JOIN_CHANNEL"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 id = niftykbFunctions.GetChannelIDFromPath(scHandlerID, arg);
			if(id == (uint64)NULL) id = niftykbFunctions.GetChannelIDByVariable(scHandlerID, arg, CHANNEL_NAME);
			if(id != (uint64)NULL) niftykbFunctions.JoinChannel(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Channel not found");
		}
	}
	else if(!strcmp(cmd, "TS3_JOIN_CHANNELID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 id = atoi(arg);
			if(id != (uint64)NULL) niftykbFunctions.JoinChannel(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Channel not found");
		}
	}
	else if(!strcmp(cmd, "TS3_CHANNEL_NEXT"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.JoinNextChannel(scHandlerID);
	}
	else if(!strcmp(cmd, "TS3_CHANNEL_PREV"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.JoinPrevChannel(scHandlerID);
	}
	else if(!strcmp(cmd, "TS3_KICK_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL) niftykbFunctions.ServerKickClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_KICK_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL) niftykbFunctions.ServerKickClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_CHANKICK_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL) niftykbFunctions.ChannelKickClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_CHANKICK_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL) niftykbFunctions.ChannelKickClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_BOOKMARK_CONNECT"))
	{
		if(!IsArgumentEmpty(scHandlerID, arg))
			niftykbFunctions.ConnectToBookmark(arg, PLUGIN_CONNECT_TAB_NEW_IF_CURRENT_CONNECTED, &scHandlerID);
	}
	/***** Whispering *****/
	else if(!strcmp(cmd, "TS3_WHISPER_ACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetWhisperList(scHandlerID, TRUE);
	}
	else if(!strcmp(cmd, "TS3_WHISPER_DEACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetWhisperList(scHandlerID, FALSE);
	}
	else if(!strcmp(cmd, "TS3_WHISPER_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetWhisperList(scHandlerID, !niftykbFunctions.whisperActive);
	}
	else if(!strcmp(cmd, "TS3_WHISPER_CLEAR"))
	{
		niftykbFunctions.WhisperListClear(scHandlerID);
	}
	else if(!strcmp(cmd, "TS3_WHISPER_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL) niftykbFunctions.WhisperAddClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_WHISPER_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL) niftykbFunctions.WhisperAddClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_WHISPER_CHANNEL"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 id = niftykbFunctions.GetChannelIDFromPath(scHandlerID, arg);
			if(id == (uint64)NULL) id = niftykbFunctions.GetChannelIDByVariable(scHandlerID, arg, CHANNEL_NAME);
			if(id != (uint64)NULL) niftykbFunctions.WhisperAddChannel(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Channel not found");
		}
	}
	else if(!strcmp(cmd, "TS3_WHISPER_CHANNELID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			uint64 id = atoi(arg);
			if(id != (uint64)NULL) niftykbFunctions.WhisperAddChannel(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Channel not found");
		}
	}
	else if(!strcmp(cmd, "TS3_REPLY_ACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetReplyList(scHandlerID, TRUE);
	}
	else if(!strcmp(cmd, "TS3_REPLY_DEACTIVATE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetReplyList(scHandlerID, FALSE);
	}
	else if(!strcmp(cmd, "TS3_REPLY_TOGGLE"))
	{
		if(IsConnected(scHandlerID))
			niftykbFunctions.SetReplyList(scHandlerID, !niftykbFunctions.replyActive);
	}
	else if(!strcmp(cmd, "TS3_REPLY_CLEAR"))
	{
		niftykbFunctions.ReplyListClear(scHandlerID);
	}
	/***** Miscellaneous *****/
	else if(!strcmp(cmd, "TS3_MUTE_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL) niftykbFunctions.MuteClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_MUTE_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL) niftykbFunctions.MuteClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_UNMUTE_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL) niftykbFunctions.UnmuteClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_UNMUTE_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL) niftykbFunctions.UnmuteClient(scHandlerID, id);
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_MUTE_TOGGLE_CLIENT"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_NICKNAME);
			if(id != (anyID)NULL)
			{
				int muted;
				ts3Functions.getClientVariableAsInt(scHandlerID, id, CLIENT_IS_MUTED, &muted);
				if(!muted) niftykbFunctions.MuteClient(scHandlerID, id);
				else niftykbFunctions.UnmuteClient(scHandlerID, id);
			}
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_MUTE_TOGGLE_CLIENTID"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			anyID id = niftykbFunctions.GetClientIDByVariable(scHandlerID, arg, CLIENT_UNIQUE_IDENTIFIER);
			if(id != (anyID)NULL)
			{
				int muted;
				ts3Functions.getClientVariableAsInt(scHandlerID, id, CLIENT_IS_MUTED, &muted);
				if(!muted) niftykbFunctions.MuteClient(scHandlerID, id);
				else niftykbFunctions.UnmuteClient(scHandlerID, id);
			}
			else niftykbFunctions.ErrorMessage(scHandlerID, "Client not found");
		}
	}
	else if(!strcmp(cmd, "TS3_VOLUME_UP"))
	{
		if(IsConnected(scHandlerID))
		{
			float diff = (arg!=NULL && *arg != (char)NULL)?(float)atof(arg):1.0f;
			float value;
			ts3Functions.getPlaybackConfigValueAsFloat(scHandlerID, "volume_modifier", &value);
			niftykbFunctions.SetMasterVolume(scHandlerID, value+diff);
		}
	}
	else if(!strcmp(cmd, "TS3_VOLUME_DOWN"))
	{
		if(IsConnected(scHandlerID))
		{
			float diff = (arg!=NULL && *arg != (char)NULL)?(float)atof(arg):1.0f;
			float value;
			ts3Functions.getPlaybackConfigValueAsFloat(scHandlerID, "volume_modifier", &value);
			niftykbFunctions.SetMasterVolume(scHandlerID, value-diff);
		}
	}
	else if(!strcmp(cmd, "TS3_VOLUME_SET"))
	{
		if(IsConnected(scHandlerID) && !IsArgumentEmpty(scHandlerID, arg))
		{
			float value = (float)atof(arg);
			niftykbFunctions.SetMasterVolume(scHandlerID, value);
		}
	}
	else if(!strcmp(cmd, "TS3_PLUGIN_COMMAND"))
	{
		if(!IsArgumentEmpty(scHandlerID, arg))
		{
			char* keyword = arg;
			char* command = strchr(arg, ' ');
			if(*keyword == '/') keyword++; // Skip the slash
			if(command != NULL)
			{
				// Split the string by inserting a NULL-terminator
				*command = (char)NULL;
				command++;

				// Execute the command
				if(!IsArgumentEmpty(scHandlerID, command))
					ExecutePluginCommand(scHandlerID, keyword, command);
			}
		}
	}
	/***** Error handler *****/
	else
	{
		ts3Functions.logMessage("Command not recognized:", LogLevel_WARNING, "NiftyKb Plugin", 0);
		ts3Functions.logMessage(cmd, LogLevel_WARNING, "NiftyKb Plugin", 0);
		niftykbFunctions.ErrorMessage(scHandlerID, "Command not recognized");
	}

	// Release the mutex
	ReleaseMutex(hMutex);
}