Permalink
Browse files

Tidied up plugin scripting callbacks

  • Loading branch information...
1 parent 8363e59 commit 54797dc5f747869caa5d867b7de73302fecb6722 @nickgammon committed Sep 17, 2010
Showing with 474 additions and 2,234 deletions.
  1. +13 −13 MUSHclient.dsp
  2. +5 −57 OtherTypes.h
  3. +2 −13 ProcessPreviousLine.cpp
  4. +33 −114 chatsock.cpp
  5. +183 −187 doc.cpp
  6. +31 −0 doc.h
  7. +36 −1,266 mushclient.clw
  8. +9 −70 mushview.cpp
  9. +8 −44 mxp/mxpClose.cpp
  10. +5 −15 mxp/mxpDefs.cpp
  11. +7 −18 mxp/mxpError.cpp
  12. +2 −21 mxp/mxpOnOff.cpp
  13. +6 −20 mxp/mxpStart.cpp
  14. +16 −58 plugins.cpp
  15. +3 −3 scripting/lua_utils.cpp
  16. +17 −65 scripting/methods.cpp
  17. +13 −94 sendvw.cpp
  18. +13 −92 telnet_phases.cpp
  19. +1 −11 worldsock.cpp
  20. +71 −73 xml/xml_load_world.cpp
View
@@ -1423,6 +1423,19 @@ SOURCE=.\install\readme.txt
# Section MUSHclient : {00000000-0001-0000-0000-000000000000}
# 1:23:CG_IDR_POPUP_MAIN_FRAME:126
# End Section
+# Section MUSHclient : {F3B1306C-16CC-11D0-B7D0-00A0247B3BFD}
+# 0:8:Splash.h:D:\SOURCE\MUSHclient\Splash.h
+# 0:10:Splash.cpp:D:\SOURCE\MUSHclient\Splash.cpp
+# 1:10:IDB_SPLASH:102
+# 2:10:ResHdrName:resource.h
+# 2:11:ProjHdrName:stdafx.h
+# 2:10:WrapperDef:_SPLASH_SCRN_
+# 2:12:SplClassName:CSplashWnd
+# 2:21:SplashScreenInsertKey:4.0
+# 2:10:HeaderName:Splash.h
+# 2:10:ImplemName:Splash.cpp
+# 2:7:BmpID16:IDB_SPLASH
+# End Section
# Section MUSHclient : {F3B13065-16CC-11D0-B7D0-00A0247B3BFD}
# 0:8:TipDlg.h:D:\SOURCE\MUSHclient\TipDlg.h
# 0:10:TipDlg.cpp:D:\SOURCE\MUSHclient\TipDlg.cpp
@@ -1448,19 +1461,6 @@ SOURCE=.\install\readme.txt
# 2:18:CG_IDS_FILE_ABSENT:CG_IDS_FILE_ABSENT
# 2:10:TipDlg.cpp:TipDlg.cpp
# End Section
-# Section MUSHclient : {F3B1306C-16CC-11D0-B7D0-00A0247B3BFD}
-# 0:8:Splash.h:D:\SOURCE\MUSHclient\Splash.h
-# 0:10:Splash.cpp:D:\SOURCE\MUSHclient\Splash.cpp
-# 1:10:IDB_SPLASH:102
-# 2:10:ResHdrName:resource.h
-# 2:11:ProjHdrName:stdafx.h
-# 2:10:WrapperDef:_SPLASH_SCRN_
-# 2:12:SplClassName:CSplashWnd
-# 2:21:SplashScreenInsertKey:4.0
-# 2:10:HeaderName:Splash.h
-# 2:10:ImplemName:Splash.cpp
-# 2:7:BmpID16:IDB_SPLASH
-# End Section
# Section MUSHclient : {00000000-0000-0000-0000-000000000000}
# 1:22:CG_IDR_POPUP_SEND_VIEW:124
# End Section
View
@@ -954,83 +954,31 @@ class CPlugin :public CObject
// WARNING! PHP currently uses a DISPID of zero, so that can't be used as a "not found" flag.
- DISPID m_dispid_plugin_install ; // "OnPluginInstall"
- DISPID m_dispid_plugin_connect ; // "OnPluginConnect"
- DISPID m_dispid_plugin_disconnect ; // "OnPluginDisconnect"
- DISPID m_dispid_plugin_close ; // "OnPluginClose"
- DISPID m_dispid_plugin_save_state ; // "OnPluginSaveState"
- DISPID m_dispid_plugin_world_save ; // "OnPluginWorldSave"
- DISPID m_dispid_plugin_enable ; // "OnPluginEnable"
- DISPID m_dispid_plugin_disable ; // "OnPluginDisable"
- DISPID m_dispid_plugin_command ; // "OnPluginCommand"
- DISPID m_dispid_plugin_command_entered; // "OnPluginCommandEntered"
- DISPID m_dispid_plugin_get_focus ; // "OnPluginGetFocus"
- DISPID m_dispid_plugin_lose_focus ; // "OnPluginLoseFocus"
- DISPID m_dispid_plugin_trace ; // "OnPluginTrace"
- DISPID m_dispid_plugin_broadcast ; // "OnPluginBroadcast"
- DISPID m_dispid_plugin_screendraw ; // "OnPluginScreendraw"
- DISPID m_dispid_plugin_playsound ; // "OnPluginPlaySound"
- DISPID m_dispid_plugin_tabcomplete ; // "OnPluginTabComplete"
- // DISPID m_dispid_plugin_tooltip ; // "OnPluginToolTip"
- DISPID m_dispid_plugin_list_changed ; // "OnPluginListChanged"
- DISPID m_dispid_plugin_tick ; // "OnPluginTick"
- DISPID m_dispid_plugin_mouse_moved ; // "OnPluginMouseMoved"
-
- DISPID m_dispid_plugin_send ; // "OnPluginSend"
- DISPID m_dispid_plugin_sent ; // "OnPluginSent"
- DISPID m_dispid_plugin_line_received; // "OnPluginLineReceived"
- DISPID m_dispid_plugin_packet_received; // "OnPluginPacketReceived"
- DISPID m_dispid_plugin_partial_line; // "OnPluginPartialLine"
- DISPID m_dispid_plugin_telnet_option; // "OnPluginTelnetOption"
- DISPID m_dispid_plugin_telnet_request; // "OnPluginTelnetRequest"
- DISPID m_dispid_plugin_telnet_subnegotiation; // "OnPluginTelnetSubnegotiation"
- DISPID m_dispid_plugin_IAC_GA; // "OnPlugin_IAC_GA"
- DISPID m_dispid_plugin_on_world_output_resized; // "OnPluginWorldOutputResized"
- DISPID m_dispid_plugin_on_command_changed; // "OnPluginCommandChanged"
-
- DISPID m_dispid_plugin_OnMXP_Start; // "OnPluginMXPstart"
- DISPID m_dispid_plugin_OnMXP_Stop; // "OnPluginMXPstop"
- DISPID m_dispid_plugin_OnMXP_OpenTag; // "OnPluginMXPopenTag"
- DISPID m_dispid_plugin_OnMXP_CloseTag; // "OnPluginMXPcloseTag"
- DISPID m_dispid_plugin_OnMXP_SetVariable; // "OnPluginMXPsetVariable"
- DISPID m_dispid_plugin_OnMXP_SetEntity; // "OnPluginMXPsetEntity"
- DISPID m_dispid_plugin_OnMXP_Error; // "OnPluginMXPerror"
-
- DISPID m_dispid_plugin_On_Chat_Accept; // "OnPluginChatAccept"
- DISPID m_dispid_plugin_On_Chat_Message; // "OnPluginChatMessage"
- DISPID m_dispid_plugin_On_Chat_MessageOut;// "OnPluginChatMessageOut"
- DISPID m_dispid_plugin_On_Chat_Display; // "OnPluginChatDisplay"
- DISPID m_dispid_plugin_On_Chat_NewUser; // "OnPluginChatNewUser"
- DISPID m_dispid_plugin_On_Chat_UserDisconnect; // "OnPluginChatUserDisconnect"
+ map<const char *, DISPID> m_PluginCallbacks; // maps plugin callback names to their DISPIDs
+
// methods
CPlugin (CMUSHclientDoc * pDoc); // constructor
~CPlugin (); // destructor
bool SaveState (const bool bScripted = false);
DISPID GetPluginDispid (const char * sName);
- void ExecutePluginScript (const char * sName,
- DISPID & iRoutine); // no arguments
+ void ExecutePluginScript (const char * sName); // no arguments
bool ExecutePluginScript (const char * sName,
- DISPID & iRoutine,
const char * sText); // 1 argument
bool ExecutePluginScript (const char * sName,
- DISPID & iRoutine,
const long arg1, // 2 arguments
const string sText);
bool ExecutePluginScript (const char * sName,
- DISPID & iRoutine,
const long arg1, // 3 arguments
const long arg2,
const string sText);
bool ExecutePluginScript (const char * sName,
- DISPID & iRoutine,
const long arg1, // 1 number, 3 strings
const char * arg2,
const char * arg3,
const char * arg4);
- void ExecutePluginScript (const char * sName,
- CString & strResult, // taking and returning a string
- DISPID & iRoutine);
+ void ExecutePluginScriptRtn (const char * sName,
+ CString & strResult); // taking and returning a string
};
@@ -455,19 +455,8 @@ assemble the full text of the original line.
m_iCurrentActionSource = eInputFromServer;
- // tell each plugin what we have received
- for (POSITION pluginpos = m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- if (!pPlugin->ExecutePluginScript (ON_PLUGIN_LINE_RECEIVED, pPlugin->m_dispid_plugin_line_received, strCurrentLine))
- bNoOutput = true;
- } // end of doing each plugin
- m_CurrentPlugin = NULL;
+ if (!SendToAllPluginCallbacks (ON_PLUGIN_LINE_RECEIVED, strCurrentLine))
+ bNoOutput = true;
m_iCurrentActionSource = eUnknownActionSource;
View
@@ -118,24 +118,12 @@ CChatSocket::~CChatSocket()
if (m_bWasConnected)
{
- CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
// tell each plugin about the departing user
- for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_USERDISCONNECT,
- pPlugin->m_dispid_plugin_On_Chat_UserDisconnect,
- m_iChatID, // user ID
- string (m_strRemoteUserName) // user name
- );
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
+ m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_USERDISCONNECT,
+ m_iChatID, // user ID
+ string (m_strRemoteUserName),
+ false, false);
} // end of needing to notify about him
}
@@ -185,7 +173,6 @@ void CChatSocket::OnReceive(int nErrorCode)
char buff [1000];
int count = Receive (buff, sizeof (buff) - 1);
-POSITION pluginpos;
if (count == SOCKET_ERROR)
{
@@ -258,24 +245,12 @@ POSITION pluginpos;
SendChatMessage (CHAT_STAMP, MakeStamp (m_zChatStamp)); // send it
}
- CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
-
// tell each plugin about the new user
- for (pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_NEWUSER,
- pPlugin->m_dispid_plugin_On_Chat_NewUser,
- m_iChatID, // user ID
- string (m_strRemoteUserName) // user name
- );
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
+ m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_NEWUSER,
+ m_iChatID, // user ID
+ string (m_strRemoteUserName),
+ false,
+ false);
if (count <= 0)
return; // only the negotiation text here
@@ -354,32 +329,18 @@ POSITION pluginpos;
count = 0; // can't see how this packet can be reasonably terminated
- CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
-
- // tell each plugin what we are about to display
- for (pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_ACCEPT,
- pPlugin->m_dispid_plugin_On_Chat_Accept,
- CFormat ("%s,%s",
- (LPCTSTR) inet_ntoa (m_ServerAddr.sin_addr),
- (LPCTSTR) m_strRemoteUserName
- )))
+ if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_ACCEPT,
+ CFormat ("%s,%s",
+ (LPCTSTR) inet_ntoa (m_ServerAddr.sin_addr),
+ (LPCTSTR) m_strRemoteUserName
+ ),
+ true)) // stop on false response
{
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
// tell them our rejection
SendData ("NO");
OnClose (0);
return; // false means plugin rejects him
}
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
if (m_pDoc->m_bValidateIncomingCalls)
{
@@ -421,24 +382,12 @@ POSITION pluginpos;
SendChatMessage (CHAT_STAMP, MakeStamp (m_zChatStamp)); // send it
}
- pSavedPlugin = m_pDoc->m_CurrentPlugin;
-
// tell each plugin about the new user
- for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_NEWUSER,
- pPlugin->m_dispid_plugin_On_Chat_NewUser,
- m_iChatID, // user ID
- string (m_strRemoteUserName) // user name
- );
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
+ m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_NEWUSER,
+ m_iChatID, // user ID
+ string (m_strRemoteUserName),
+ false,
+ false);
if (count <= 0)
return; // only the negotiation text here
@@ -733,29 +682,14 @@ void CChatSocket::ProcessChatMessage (const int iMessage, const CString strMessa
#endif
- CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
+ if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_MESSAGE,
+ m_iChatID, // who we are
+ iMessage, // message number
+ string (strMessage), // message text
+ false,
+ true)) // stop on false response
+ return; // false means plugin handled it
- // tell each plugin what we are about to display
- for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_MESSAGE,
- pPlugin->m_dispid_plugin_On_Chat_Message,
- m_iChatID, // who we are
- iMessage, // message number
- string (strMessage) // message text
- ))
- {
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
- return; // false means plugin handled it
- }
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
switch (iMessage)
{
@@ -821,28 +755,13 @@ void CChatSocket::SendChatMessage (const int iMessage,
#endif
- CPlugin * pSavedPlugin = m_pDoc->m_CurrentPlugin;
- // tell each plugin what we are about to display
- for (POSITION pluginpos = m_pDoc->m_PluginList.GetHeadPosition(); pluginpos; )
- {
- CPlugin * pPlugin = m_pDoc->m_PluginList.GetNext (pluginpos);
-
- if (!(pPlugin->m_bEnabled)) // ignore disabled plugins
- continue;
-
- // see what the plugin makes of this,
- if (!pPlugin->ExecutePluginScript (ON_PLUGIN_CHAT_MESSAGE_OUT,
- pPlugin->m_dispid_plugin_On_Chat_MessageOut,
- m_iChatID, // which chat ID
- iMessage, // message number
- string (strMessage) // message text
- ))
- {
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
+ if (!m_pDoc->SendToAllPluginCallbacks (ON_PLUGIN_CHAT_MESSAGE_OUT,
+ m_iChatID, // which chat ID
+ iMessage, // message number
+ string (strMessage), // message text
+ false,
+ true)) // stop on false response
return; // false means plugin discarded it
- }
- } // end of doing each plugin
- m_pDoc->m_CurrentPlugin = pSavedPlugin;
if (iMessage == CHAT_SNOOP && m_bYouAreSnooping)
m_bYouAreSnooping = false;
Oops, something went wrong.

0 comments on commit 54797dc

Please sign in to comment.