// MQ2Remote.cpp
// This was developed from the MQ2MasterMind to work with IRC instead of /tells. All credit goes to the great people that
// have worked on MQ2MasterMind.
#include "../MQ2Plugin.h"
char MyRemoteMaster[MAX_STRING] = "None Set";
char MyRemoteMaster2[MAX_STRING] = "None Set";
char MCleared[MAX_STRING] = "None Set";
char szMasterRemoteTrigger[MAX_STRING];
char szMasterRemoteTrigger2[MAX_STRING];
char szMasterRemoteKey[MAX_STRING] = "Remote1";
char szMasterRemoteKey2[MAX_STRING] = "Remote2";
char szMasterRemoteKeyDefault[MAX_STRING] = "Remote1";
char szMasterRemoteKeyDefault2[MAX_STRING] = "Remote2";
bool bGotMaster=false;
bool bGotMaster2=false;
bool Initialized = false;
void ClearRemoteMaster(PSPAWNINFO pChar, PCHAR szLine);
void ClearRemoteMaster2(PSPAWNINFO pChar, PCHAR szLine);
void SetMasterRemoteKey(PSPAWNINFO pChar, PCHAR szLine);
void SetMasterRemoteKey2(PSPAWNINFO pChar, PCHAR szLine);
void ClearAll(PSPAWNINFO pChar, PCHAR szLine);
void SpewAll(PSPAWNINFO pChar, PCHAR szLine);
void SpewHelp(PSPAWNINFO pChar, PCHAR szLine);
void LoadINI();
PreSetup("MQ2Remote");
VOID ClearRemoteMaster(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote Master Cleared");
bGotMaster=false;
strcpy(MyRemoteMaster, MCleared);
WriteChatColor("Master has been Reset", USERCOLOR_SYSTEM);
}
VOID ClearRemoteMaster2(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote Master2 Cleared");
bGotMaster2=false;
strcpy(MyRemoteMaster2, MCleared);
WriteChatColor("Master2 has been Reset", USERCOLOR_SYSTEM);
}
VOID ClearAll(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote All Masters Cleared");
bGotMaster=false;
bGotMaster2=false;
strcpy(MyRemoteMaster, MCleared);
strcpy(MyRemoteMaster2, MCleared);
WriteChatColor("All Masters have been Reset", USERCOLOR_SYSTEM);
}
VOID SpewAll(PSPAWNINFO pChar, PCHAR szLine) {
char szTemp[MAX_STRING];
DebugSpewAlways("MQ2Remote echoing Masters");
sprintf(szTemp, "Master is '%s'", MyRemoteMaster);
WriteChatColor(szTemp, USERCOLOR_SYSTEM);
sprintf(szTemp, "Master2 is '%s'", MyRemoteMaster2);
WriteChatColor(szTemp, USERCOLOR_SYSTEM);
}
VOID SetMasterRemoteKey(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote setting MasterRemoteKey",szLine);
strcpy(szMasterRemoteKey, szLine);
WritePrivateProfileString("MQ2Remote", "MasterRemoteKey", szMasterRemoteKey, INIFileName);
bGotMaster=false;
WriteChatColor("Master has been Reset and Redefined", USERCOLOR_SYSTEM);
}
VOID SetMasterRemoteKey2(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote setting MasterRemoteKey2",szLine);
strcpy(szMasterRemoteKey2, szLine);
WritePrivateProfileString("MQ2Remote", "MasterRemoteKey2", szMasterRemoteKey2, INIFileName);
bGotMaster2=false;
WriteChatColor("Master2 has been Reset and Redefined", USERCOLOR_SYSTEM);
}
VOID SpewHelp(PSPAWNINFO pChar, PCHAR szLine) {
DebugSpewAlways("MQ2Remote displaying plugin commands");
WriteChatColor("MQ2Remote Commands:", USERCOLOR_SYSTEM);
WriteChatColor("/smkey, /smkey2 to set passwords for Masters 1 & 2", USERCOLOR_SYSTEM);
WriteChatColor("/rstm, /rstm2, and /rstall to reset the controling Masters 1 & 2", USERCOLOR_SYSTEM);
WriteChatColor("/masters to view all current Masters", USERCOLOR_SYSTEM);
}
VOID LoadINI() {
// This load the master keys from the INI file
DebugSpewAlways("MQ2Remote loading INI MasterRemoteKey");
GetPrivateProfileString("MQ2Remote", "MasterRemoteKey", szMasterRemoteKeyDefault, szMasterRemoteKey, MAX_STRING, INIFileName);
GetPrivateProfileString("MQ2Remote", "MasterRemoteKey2", szMasterRemoteKeyDefault2, szMasterRemoteKey2, MAX_STRING, INIFileName);
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing MQ2Remote");
AddCommand("/rstm", ClearRemoteMaster, 0, 0, 1);
AddCommand("/rstm2", ClearRemoteMaster2, 0, 0, 1);
AddCommand("/rstall", ClearAll, 0, 0, 1);
AddCommand("/smkey", SetMasterRemoteKey, 0, 0, 1);
AddCommand("/smkey2", SetMasterRemoteKey2, 0, 0, 1);
AddCommand("/masters", SpewAll, 0, 0, 1);
AddCommand("/bhelp", SpewHelp, 0, 0, 1);
if (gGameState==GAMESTATE_INGAME) {
LoadINI();
WriteChatColor("MQ2Remote Commands: (/bhelp to show help)", USERCOLOR_SYSTEM);
WriteChatColor("/smkey, /smkey2 to set passwords for Masters 1 & 2", USERCOLOR_SYSTEM);
WriteChatColor("/rstm, /rstm2 and /rstall to reset the controling Masters 1 & 2", USERCOLOR_SYSTEM);
WriteChatColor("/masters to view all current Masters", USERCOLOR_SYSTEM);
}
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down MQ2Remote");
RemoveCommand("/rstm");
RemoveCommand("/rstm2");
RemoveCommand("/rstall");
RemoveCommand("/smkey");
RemoveCommand("/smkey2");
RemoveCommand("/masters");
RemoveCommand("/bhelp");
WritePrivateProfileString("MQ2Remote", "MasterRemoteKey", szMasterRemoteKey, INIFileName);
WritePrivateProfileString("MQ2Remote", "MasterRemoteKey2", szMasterRemoteKey2, INIFileName);
}
//IRC support
PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter)
{
DebugSpewAlways("OnWriteChatColor(%s)",Line);
if (!bGotMaster && strstr(Line, szMasterRemoteKey) && (strstr(Line,GetCharInfo()->Name) == 0))
{
char* Father;
Father=strtok(Line," ");
strcpy(MyRemoteMaster, Father);
char szTemp[MAX_STRING];
sprintf(szTemp, "Master set to: '%s'", MyRemoteMaster);
WriteChatColor(szTemp, USERCOLOR_SYSTEM);
sprintf(szMasterRemoteTrigger,"%s", MyRemoteMaster);
bGotMaster=true;
return 0;
}
else if (!bGotMaster2 && strstr(Line, szMasterRemoteKey2) && (strstr(Line,GetCharInfo()->Name) == 0))
{
char* Father;
Father=strtok(Line," ");
strcpy(MyRemoteMaster2, Father);
char szTemp[MAX_STRING];
sprintf(szTemp, "Master2 set to: '%s'", MyRemoteMaster2);
WriteChatColor(szTemp, USERCOLOR_SYSTEM);
sprintf(szMasterRemoteTrigger2,"%s", MyRemoteMaster2);
bGotMaster2=true;
return 0;
}
if (bGotMaster && strstr(Line,szMasterRemoteTrigger) && (strstr(szMasterRemoteTrigger,GetCharInfo()->Name) == 0))
{
PSTR Text;
Text=Line+strlen(szMasterRemoteTrigger)+1;
{
DoCommand((PSPAWNINFO)pCharSpawn,Text);
WriteChatColor("Executing from Master", USERCOLOR_SYSTEM);
}
return 0;
}
else if (bGotMaster2 && strstr(Line,szMasterRemoteTrigger2) && (strstr(szMasterRemoteTrigger2,GetCharInfo()->Name) == 0))
{
PSTR Text;
Text=Line+strlen(szMasterRemoteTrigger2)+1;
if (Text[0] == '/') {
DoCommand((PSPAWNINFO)pCharSpawn,Text);
WriteChatColor("Executing from Master2", USERCOLOR_SYSTEM);
}
return 0;
}
return 0;
}
PLUGIN_API VOID SetGameState(DWORD GameState)
{
if (GameState==GAMESTATE_INGAME) {
if(!Initialized) {
Initialized = true;
LoadINI();
}
}
else
Initialized = false;
}