Skip to content

Commit 54797dc

Browse files
committed
Tidied up plugin scripting callbacks
1 parent 8363e59 commit 54797dc

20 files changed

+474
-2234
lines changed

MUSHclient.dsp

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OtherTypes.h

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -954,83 +954,31 @@ class CPlugin :public CObject
954954

955955
// WARNING! PHP currently uses a DISPID of zero, so that can't be used as a "not found" flag.
956956

957-
DISPID m_dispid_plugin_install ; // "OnPluginInstall"
958-
DISPID m_dispid_plugin_connect ; // "OnPluginConnect"
959-
DISPID m_dispid_plugin_disconnect ; // "OnPluginDisconnect"
960-
DISPID m_dispid_plugin_close ; // "OnPluginClose"
961-
DISPID m_dispid_plugin_save_state ; // "OnPluginSaveState"
962-
DISPID m_dispid_plugin_world_save ; // "OnPluginWorldSave"
963-
DISPID m_dispid_plugin_enable ; // "OnPluginEnable"
964-
DISPID m_dispid_plugin_disable ; // "OnPluginDisable"
965-
DISPID m_dispid_plugin_command ; // "OnPluginCommand"
966-
DISPID m_dispid_plugin_command_entered; // "OnPluginCommandEntered"
967-
DISPID m_dispid_plugin_get_focus ; // "OnPluginGetFocus"
968-
DISPID m_dispid_plugin_lose_focus ; // "OnPluginLoseFocus"
969-
DISPID m_dispid_plugin_trace ; // "OnPluginTrace"
970-
DISPID m_dispid_plugin_broadcast ; // "OnPluginBroadcast"
971-
DISPID m_dispid_plugin_screendraw ; // "OnPluginScreendraw"
972-
DISPID m_dispid_plugin_playsound ; // "OnPluginPlaySound"
973-
DISPID m_dispid_plugin_tabcomplete ; // "OnPluginTabComplete"
974-
// DISPID m_dispid_plugin_tooltip ; // "OnPluginToolTip"
975-
DISPID m_dispid_plugin_list_changed ; // "OnPluginListChanged"
976-
DISPID m_dispid_plugin_tick ; // "OnPluginTick"
977-
DISPID m_dispid_plugin_mouse_moved ; // "OnPluginMouseMoved"
978-
979-
DISPID m_dispid_plugin_send ; // "OnPluginSend"
980-
DISPID m_dispid_plugin_sent ; // "OnPluginSent"
981-
DISPID m_dispid_plugin_line_received; // "OnPluginLineReceived"
982-
DISPID m_dispid_plugin_packet_received; // "OnPluginPacketReceived"
983-
DISPID m_dispid_plugin_partial_line; // "OnPluginPartialLine"
984-
DISPID m_dispid_plugin_telnet_option; // "OnPluginTelnetOption"
985-
DISPID m_dispid_plugin_telnet_request; // "OnPluginTelnetRequest"
986-
DISPID m_dispid_plugin_telnet_subnegotiation; // "OnPluginTelnetSubnegotiation"
987-
DISPID m_dispid_plugin_IAC_GA; // "OnPlugin_IAC_GA"
988-
DISPID m_dispid_plugin_on_world_output_resized; // "OnPluginWorldOutputResized"
989-
DISPID m_dispid_plugin_on_command_changed; // "OnPluginCommandChanged"
990-
991-
DISPID m_dispid_plugin_OnMXP_Start; // "OnPluginMXPstart"
992-
DISPID m_dispid_plugin_OnMXP_Stop; // "OnPluginMXPstop"
993-
DISPID m_dispid_plugin_OnMXP_OpenTag; // "OnPluginMXPopenTag"
994-
DISPID m_dispid_plugin_OnMXP_CloseTag; // "OnPluginMXPcloseTag"
995-
DISPID m_dispid_plugin_OnMXP_SetVariable; // "OnPluginMXPsetVariable"
996-
DISPID m_dispid_plugin_OnMXP_SetEntity; // "OnPluginMXPsetEntity"
997-
DISPID m_dispid_plugin_OnMXP_Error; // "OnPluginMXPerror"
998-
999-
DISPID m_dispid_plugin_On_Chat_Accept; // "OnPluginChatAccept"
1000-
DISPID m_dispid_plugin_On_Chat_Message; // "OnPluginChatMessage"
1001-
DISPID m_dispid_plugin_On_Chat_MessageOut;// "OnPluginChatMessageOut"
1002-
DISPID m_dispid_plugin_On_Chat_Display; // "OnPluginChatDisplay"
1003-
DISPID m_dispid_plugin_On_Chat_NewUser; // "OnPluginChatNewUser"
1004-
DISPID m_dispid_plugin_On_Chat_UserDisconnect; // "OnPluginChatUserDisconnect"
957+
map<const char *, DISPID> m_PluginCallbacks; // maps plugin callback names to their DISPIDs
958+
1005959
// methods
1006960

1007961
CPlugin (CMUSHclientDoc * pDoc); // constructor
1008962
~CPlugin (); // destructor
1009963
bool SaveState (const bool bScripted = false);
1010964
DISPID GetPluginDispid (const char * sName);
1011-
void ExecutePluginScript (const char * sName,
1012-
DISPID & iRoutine); // no arguments
965+
void ExecutePluginScript (const char * sName); // no arguments
1013966
bool ExecutePluginScript (const char * sName,
1014-
DISPID & iRoutine,
1015967
const char * sText); // 1 argument
1016968
bool ExecutePluginScript (const char * sName,
1017-
DISPID & iRoutine,
1018969
const long arg1, // 2 arguments
1019970
const string sText);
1020971
bool ExecutePluginScript (const char * sName,
1021-
DISPID & iRoutine,
1022972
const long arg1, // 3 arguments
1023973
const long arg2,
1024974
const string sText);
1025975
bool ExecutePluginScript (const char * sName,
1026-
DISPID & iRoutine,
1027976
const long arg1, // 1 number, 3 strings
1028977
const char * arg2,
1029978
const char * arg3,
1030979
const char * arg4);
1031-
void ExecutePluginScript (const char * sName,
1032-
CString & strResult, // taking and returning a string
1033-
DISPID & iRoutine);
980+
void ExecutePluginScriptRtn (const char * sName,
981+
CString & strResult); // taking and returning a string
1034982

1035983
};
1036984

ProcessPreviousLine.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,8 @@ assemble the full text of the original line.
455455

456456
m_iCurrentActionSource = eInputFromServer;
457457

458-
// tell each plugin what we have received
459-
for (POSITION pluginpos = m_PluginList.GetHeadPosition(); pluginpos; )
460-
{
461-
CPlugin * pPlugin = m_PluginList.GetNext (pluginpos);
462-
463-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
464-
continue;
465-
466-
// see what the plugin makes of this,
467-
if (!pPlugin->ExecutePluginScript (ON_PLUGIN_LINE_RECEIVED, pPlugin->m_dispid_plugin_line_received, strCurrentLine))
468-
bNoOutput = true;
469-
} // end of doing each plugin
470-
m_CurrentPlugin = NULL;
458+
if (!SendToAllPluginCallbacks (ON_PLUGIN_LINE_RECEIVED, strCurrentLine))
459+
bNoOutput = true;
471460

472461
m_iCurrentActionSource = eUnknownActionSource;
473462

chatsock.cpp

Lines changed: 33 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,12 @@ CChatSocket::~CChatSocket()
118118

119119
if (m_bWasConnected)
120120
{
121-
CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
122121

123122
// tell each plugin about the departing user
124-
for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
125-
{
126-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
127-
128-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
129-
continue;
130-
131-
// see what the plugin makes of this,
132-
pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_USERDISCONNECT,
133-
pPlugin->m_dispid_plugin_On_Chat_UserDisconnect,
134-
m_iChatID, // user ID
135-
string (m_strRemoteUserName) // user name
136-
);
137-
} // end of doing each plugin
138-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
123+
m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_USERDISCONNECT,
124+
m_iChatID, // user ID
125+
string (m_strRemoteUserName),
126+
false, false);
139127
} // end of needing to notify about him
140128
}
141129

@@ -185,7 +173,6 @@ void CChatSocket::OnReceive(int nErrorCode)
185173

186174
char buff [1000];
187175
int count = Receive (buff, sizeof (buff) - 1);
188-
POSITION pluginpos;
189176

190177
if (count == SOCKET_ERROR)
191178
{
@@ -258,24 +245,12 @@ POSITION pluginpos;
258245
SendChatMessage (CHAT_STAMP, MakeStamp (m_zChatStamp)); // send it
259246
}
260247

261-
CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
262-
263248
// tell each plugin about the new user
264-
for (pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
265-
{
266-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
267-
268-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
269-
continue;
270-
271-
// see what the plugin makes of this,
272-
pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_NEWUSER,
273-
pPlugin->m_dispid_plugin_On_Chat_NewUser,
274-
m_iChatID, // user ID
275-
string (m_strRemoteUserName) // user name
276-
);
277-
} // end of doing each plugin
278-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
249+
m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_NEWUSER,
250+
m_iChatID, // user ID
251+
string (m_strRemoteUserName),
252+
false,
253+
false);
279254

280255
if (count <= 0)
281256
return; // only the negotiation text here
@@ -354,32 +329,18 @@ POSITION pluginpos;
354329

355330
count = 0; // can't see how this packet can be reasonably terminated
356331

357-
CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
358-
359-
// tell each plugin what we are about to display
360-
for (pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
361-
{
362-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
363-
364-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
365-
continue;
366-
367-
// see what the plugin makes of this,
368-
if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_ACCEPT,
369-
pPlugin->m_dispid_plugin_On_Chat_Accept,
370-
CFormat ("%s,%s",
371-
(LPCTSTR) inet_ntoa (m_ServerAddr.sin_addr),
372-
(LPCTSTR) m_strRemoteUserName
373-
)))
332+
if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_ACCEPT,
333+
CFormat ("%s,%s",
334+
(LPCTSTR) inet_ntoa (m_ServerAddr.sin_addr),
335+
(LPCTSTR) m_strRemoteUserName
336+
),
337+
true)) // stop on false response
374338
{
375-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
376339
// tell them our rejection
377340
SendData ("NO");
378341
OnClose (0);
379342
return; // false means plugin rejects him
380343
}
381-
} // end of doing each plugin
382-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
383344

384345
if (m_pDoc->m_bValidateIncomingCalls)
385346
{
@@ -421,24 +382,12 @@ POSITION pluginpos;
421382
SendChatMessage (CHAT_STAMP, MakeStamp (m_zChatStamp)); // send it
422383
}
423384

424-
pSavedPlugin = m_pDoc->m_CurrentPlugin;
425-
426385
// tell each plugin about the new user
427-
for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
428-
{
429-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
430-
431-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
432-
continue;
433-
434-
// see what the plugin makes of this,
435-
pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_NEWUSER,
436-
pPlugin->m_dispid_plugin_On_Chat_NewUser,
437-
m_iChatID, // user ID
438-
string (m_strRemoteUserName) // user name
439-
);
440-
} // end of doing each plugin
441-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
386+
m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_NEWUSER,
387+
m_iChatID, // user ID
388+
string (m_strRemoteUserName),
389+
false,
390+
false);
442391

443392
if (count <= 0)
444393
return; // only the negotiation text here
@@ -733,29 +682,14 @@ void CChatSocket::ProcessChatMessage (const int iMessage, const CString strMessa
733682

734683
#endif
735684

736-
CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
685+
if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_MESSAGE,
686+
m_iChatID, // who we are
687+
iMessage, // message number
688+
string (strMessage), // message text
689+
false,
690+
true)) // stop on false response
691+
return; // false means plugin handled it
737692

738-
// tell each plugin what we are about to display
739-
for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
740-
{
741-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
742-
743-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
744-
continue;
745-
746-
// see what the plugin makes of this,
747-
if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_MESSAGE,
748-
pPlugin->m_dispid_plugin_On_Chat_Message,
749-
m_iChatID, // who we are
750-
iMessage, // message number
751-
string (strMessage) // message text
752-
))
753-
{
754-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
755-
return; // false means plugin handled it
756-
}
757-
} // end of doing each plugin
758-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
759693

760694
switch (iMessage)
761695
{
@@ -821,28 +755,13 @@ void CChatSocket::SendChatMessage (const int iMessage,
821755

822756
#endif
823757

824-
CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
825-
// tell each plugin what we are about to display
826-
for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
827-
{
828-
CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
829-
830-
if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
831-
continue;
832-
833-
// see what the plugin makes of this,
834-
if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_MESSAGE_OUT,
835-
pPlugin->m_dispid_plugin_On_Chat_MessageOut,
836-
m_iChatID, // which chat ID
837-
iMessage, // message number
838-
string (strMessage) // message text
839-
))
840-
{
841-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
758+
if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_MESSAGE_OUT,
759+
m_iChatID, // which chat ID
760+
iMessage, // message number
761+
string (strMessage), // message text
762+
false,
763+
true)) // stop on false response
842764
return; // false means plugin discarded it
843-
}
844-
} // end of doing each plugin
845-
m_pDoc->m_CurrentPlugin = pSavedPlugin;
846765

847766
if (iMessage == CHAT_SNOOP && m_bYouAreSnooping)
848767
m_bYouAreSnooping = false;

0 commit comments

Comments
 (0)