Skip to content

Commit

Permalink
More code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Sep 18, 2010
1 parent e38cf98 commit b1b2ab6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 205 deletions.
128 changes: 0 additions & 128 deletions OtherTypes.h
Expand Up @@ -901,134 +901,6 @@ class CActiveTag :public CObject

typedef CTypedPtrList <CPtrList, CActiveTag*> CActiveTagList;


/////////////////////////////////////////////////////////////////////////////
// CPlugin - these are world plugins

// for storing dispatch IDs, and how many times each one is called
class CScriptDispatchID
{
public:
// default constructor
CScriptDispatchID () :
_dispid (DISPID_UNKNOWN),
_count (0) {};

// copy constructor
CScriptDispatchID (const CScriptDispatchID & d)
: _dispid (d._dispid),
_count (d._count)
{};

// operator =
const CScriptDispatchID & operator= (const CScriptDispatchID & rhs)
{
_dispid = rhs._dispid;
_count = rhs._count;
return *this;
};

// returns true if DISPID is valid
inline bool isvalid () const { return _dispid != DISPID_UNKNOWN; };

DISPID _dispid; // the dispatch ID from the COM engine, or DISPID_UNKNOWN
__int64 _count; // count of attempts to call it (if not DISPID_UNKNOWN)
}; // end of class CScriptDispatchID

typedef map<const string, CScriptDispatchID> CScriptDispatchIDsMap;
typedef map<const string, CScriptDispatchID>::const_iterator CScriptDispatchIDIterator;

class CScriptCallInfo
{
public:

CScriptCallInfo (const string name, CScriptDispatchID & dispid_info)
: _dispid_info (dispid_info), _name (name) {};

CScriptDispatchID & _dispid_info;
const string _name;

}; // end of class CScriptCallInfo

class CScriptEngine;

class CPlugin :public CObject
{

public:

CString m_strName; // name of plugin
CString m_strAuthor; // who wrote it
CString m_strPurpose; // what it does (short description)
CString m_strDescription; // what it does (long description)
CString m_strScript; // script source (ie. from <script> tags)
CString m_strLanguage; // script language (eg. vbscript)
CString m_strSource; // include file that contains this plugin
CString m_strDirectory; // directory source is in (m_strSource minus the actual filename)
CString m_strID; // unique ID
CTime m_tDateWritten; // date written
CTime m_tDateModified; // date last modified
double m_dVersion; // plugin version
double m_dRequiredVersion; // minimum MUSHclient version required
CTime m_tDateInstalled; // date installed
CString m_strCallingPluginID; // during a CallPlugin - the ID of the calling plugin

CScriptEngine * m_ScriptEngine; // script engine for script, if any

CAliasMap m_AliasMap; // aliases
CAliasArray m_AliasArray; // array of aliases for sequencing
CAliasRevMap m_AliasRevMap; // for getting name back from pointer
CTriggerMap m_TriggerMap; // triggers
CTriggerArray m_TriggerArray; // array of triggers for sequencing
CTriggerRevMap m_TriggerRevMap; // for getting name back from pointer
CTimerMap m_TimerMap; // timers
CTimerRevMap m_TimerRevMap; // for getting name back from pointer
CVariableMap m_VariableMap; // variables
tStringMapOfMaps m_Arrays; // map of arrays (for scripting)

bool m_bEnabled; // true if active (enabled)
CMUSHclientDoc * m_pDoc; // related MUSHclient document
bool m_bSaveState; // true to save plugin state
bool m_bSendToScriptUsed; // plugin sends to script
bool m_bGlobal; // true if plugin was loaded from global prefs
long m_iLoadOrder; // sequence in which plugins are processed

// Lua note - for Lua the DISPID is a flag indicating whether or not
// the routine exists. It is set to DISPID_UNKNOWN if the last call caused an error
// It will be 1 if the routine exists, and DISPID_UNKNOWN if it doesn't.

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

CScriptDispatchIDsMap 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 (CScriptCallInfo & callinfo); // no arguments
bool ExecutePluginScript (CScriptCallInfo & callinfo,
const char * sText); // 1 argument
bool ExecutePluginScript (CScriptCallInfo & callinfo,
const long arg1, // 2 arguments
const string sText);
bool ExecutePluginScript (CScriptCallInfo & callinfo,
const long arg1, // 3 arguments
const long arg2,
const string sText);
bool ExecutePluginScript (CScriptCallInfo & callinfo,
const long arg1, // 1 number, 3 strings
const char * arg2,
const char * arg3,
const char * arg4);
void ExecutePluginScriptRtn (CScriptCallInfo & callinfo,
CString & strResult); // taking and returning a string

};

typedef CTypedPtrList <CPtrList, CPlugin*> CPluginList;

// for storing map directions, and inverses of them
class CMapDirection
{
Expand Down
12 changes: 6 additions & 6 deletions doc.cpp
Expand Up @@ -8050,7 +8050,7 @@ static bool bInPluginListChanged = false;
} // end CMUSHclientDoc::PluginListChanged


void CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName) // no arguments
void CMUSHclientDoc::SendToAllPluginCallbacks (const string & sName) // no arguments
{
CPlugin * pSavedPlugin = m_CurrentPlugin;

Expand All @@ -8073,7 +8073,7 @@ void CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName) // no argum
} // end of CMUSHclientDoc::SendToAllPluginCallbacks

// this is for when we want the first available plugin to handle something (eg. Trace, Sound)
bool CMUSHclientDoc::SendToFirstPluginCallbacks (const char * sName, const char * sText) // one argument
bool CMUSHclientDoc::SendToFirstPluginCallbacks (const string & sName, const char * sText) // one argument
{
CPlugin * pSavedPlugin = m_CurrentPlugin;

Expand Down Expand Up @@ -8105,7 +8105,7 @@ bool CMUSHclientDoc::SendToFirstPluginCallbacks (const char * sName, const char

// this is for when each plugin gets a chance to "black ball" an action (like sending a line)
// we only return true if each plugin returned true
bool CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName,
bool CMUSHclientDoc::SendToAllPluginCallbacks (const string & sName,
const char * sText, // one argument
const bool bStopOnFalse)
{
Expand Down Expand Up @@ -8137,7 +8137,7 @@ bool CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName,


// this sends a string to all plugins and allows them to modify it
void CMUSHclientDoc::SendToAllPluginCallbacksRtn (const char * sName, CString & strResult) // taking and returning a string
void CMUSHclientDoc::SendToAllPluginCallbacksRtn (const string & sName, CString & strResult) // taking and returning a string
{
CPlugin * pSavedPlugin = m_CurrentPlugin;

Expand All @@ -8161,7 +8161,7 @@ void CMUSHclientDoc::SendToAllPluginCallbacksRtn (const char * sName, CString &


// this sends a number and a string to all plugins, and optionally stops on a true or false response
bool CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName,
bool CMUSHclientDoc::SendToAllPluginCallbacks (const string & sName,
const long arg1, // 2 arguments
const string sText,
const bool bStopOnTrue,
Expand Down Expand Up @@ -8200,7 +8200,7 @@ bool CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName,
} // end of CMUSHclientDoc::SendToAllPluginCallbacks

// this sends two numbers and a string to all plugins, and optionally stops on a true or false response
bool CMUSHclientDoc::SendToAllPluginCallbacks (const char * sName,
bool CMUSHclientDoc::SendToAllPluginCallbacks (const string & sName,
const long arg1, // 3 arguments
const long arg2,
const string sText,
Expand Down
13 changes: 7 additions & 6 deletions doc.h
Expand Up @@ -13,6 +13,7 @@
#include "xml\xmlparse.h"
#include "paneline.h"
#include "miniwindow.h"
#include "plugins.h"

#define COMPRESS_BUFFER_LENGTH 1024 // size of decompression buffer

Expand Down Expand Up @@ -1865,30 +1866,30 @@ class CMUSHclientDoc : public CDocument
CMUSHView * GetFirstOutputWindow ();

// calls sName in all plugins
void SendToAllPluginCallbacks (const char * sName); // no arguments
void SendToAllPluginCallbacks (const string & sName); // no arguments

// sends sText to all plugins, stops when one handles it, returns true if handled
bool SendToFirstPluginCallbacks (const char * sName,
bool SendToFirstPluginCallbacks (const string & sName,
const char * sText); // one argument

// sends sText to all plugins, returns false if one returned false
bool SendToAllPluginCallbacks (const char * sName,
bool SendToAllPluginCallbacks (const string & sName,
const char * sText, // one argument
const bool bStopOnFalse = false);

// send strResult to all plugins, allow them to modify it
void SendToAllPluginCallbacksRtn (const char * sName,
void SendToAllPluginCallbacksRtn (const string & sName,
CString & strResult); // taking and returning a string

// send a number and a string to all plugins, optionally stopping when one returns true or false
bool SendToAllPluginCallbacks (const char * sName,
bool SendToAllPluginCallbacks (const string & sName,
const long arg1, // 2 arguments
const string sText,
const bool bStopOnTrue,
const bool bStopOnFalse);

// send two numbers and a string to all plugins, optionally stopping when one returns true or false
bool SendToAllPluginCallbacks (const char * sName,
bool SendToAllPluginCallbacks (const string & sName,
const long arg1, // 3 arguments
const long arg2,
const string sText,
Expand Down
4 changes: 2 additions & 2 deletions plugins.cpp
Expand Up @@ -11,7 +11,7 @@ static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

// possible plugin callbacks
const char * PluginCallbacksNames [] = {
string PluginCallbacksNames [] = {

ON_PLUGIN_BROADCAST,

Expand Down Expand Up @@ -64,7 +64,7 @@ const char * PluginCallbacksNames [] = {
ON_PLUGIN_WORLD_OUTPUT_RESIZED,
ON_PLUGIN_WORLD_SAVE,

NULL // end of table marker
"" // end of table marker

}; // end of PluginCallbacksNames

Expand Down
6 changes: 2 additions & 4 deletions scripting/lua_utils.cpp
Expand Up @@ -540,16 +540,14 @@ static int functionargs (lua_State *L)
return 1; // 1 table
} // end of functionargs

extern const char * PluginCallbacksNames [1];

// returns table of internal functions
static int callbackslist (lua_State *L)
{
lua_newtable(L); // table of function names

for (int i = 0; PluginCallbacksNames [i]; i++)
for (int i = 0; PluginCallbacksNames [i] != ""; i++)
{
lua_pushstring (L, PluginCallbacksNames [i]);
lua_pushstring (L, PluginCallbacksNames [i].c_str ());
lua_rawseti(L, -2, i + 1); // make 1-relative
}

Expand Down
56 changes: 0 additions & 56 deletions stdafx.h
Expand Up @@ -499,62 +499,6 @@ class CStyle;
CStyle * GetNewStyle (const char * filename, const long linenumber);
void DeleteStyle (CStyle * pStyle, const char * filename, const long linenumber);

// plugin callback routines - start with OnPlugin so that we can advise
// users not to use that string for their own routines

#define ON_PLUGIN_INSTALL "OnPluginInstall"
#define ON_PLUGIN_CONNECT "OnPluginConnect"
#define ON_PLUGIN_DISCONNECT "OnPluginDisconnect"
#define ON_PLUGIN_CLOSE "OnPluginClose"
#define ON_PLUGIN_SAVE_STATE "OnPluginSaveState"
#define ON_PLUGIN_WORLD_SAVE "OnPluginWorldSave"
#define ON_PLUGIN_ENABLE "OnPluginEnable"
#define ON_PLUGIN_DISABLE "OnPluginDisable"
#define ON_PLUGIN_COMMAND "OnPluginCommand"
#define ON_PLUGIN_COMMAND_ENTERED "OnPluginCommandEntered"
#define ON_PLUGIN_GETFOCUS "OnPluginGetFocus"
#define ON_PLUGIN_LOSEFOCUS "OnPluginLoseFocus"
#define ON_PLUGIN_TRACE "OnPluginTrace"
#define ON_PLUGIN_BROADCAST "OnPluginBroadcast"
#define ON_PLUGIN_SCREENDRAW "OnPluginScreendraw"
#define ON_PLUGIN_PLAYSOUND "OnPluginPlaySound"
#define ON_PLUGIN_TABCOMPLETE "OnPluginTabComplete"
#define ON_PLUGIN_LIST_CHANGED "OnPluginListChanged"

//#define ON_PLUGIN_TOOLTIP "OnPluginToolTip"

// stuff received/send
#define ON_PLUGIN_SEND "OnPluginSend"
#define ON_PLUGIN_SENT "OnPluginSent"
#define ON_PLUGIN_LINE_RECEIVED "OnPluginLineReceived"
#define ON_PLUGIN_PACKET_RECEIVED "OnPluginPacketReceived"
#define ON_PLUGIN_PARTIAL_LINE "OnPluginPartialLine"
#define ON_PLUGIN_TELNET_OPTION "OnPluginTelnetOption"
#define ON_PLUGIN_TELNET_REQUEST "OnPluginTelnetRequest"
#define ON_PLUGIN_TELNET_SUBNEGOTIATION "OnPluginTelnetSubnegotiation"
#define ON_PLUGIN_IAC_GA "OnPlugin_IAC_GA"
#define ON_PLUGIN_WORLD_OUTPUT_RESIZED "OnPluginWorldOutputResized"
#define ON_PLUGIN_TICK "OnPluginTick"
#define ON_PLUGIN_MOUSE_MOVED "OnPluginMouseMoved"
#define ON_PLUGIN_COMMAND_CHANGED "OnPluginCommandChanged"

// MXP stuff
#define ON_PLUGIN_MXP_START "OnPluginMXPstart"
#define ON_PLUGIN_MXP_STOP "OnPluginMXPstop"
#define ON_PLUGIN_MXP_OPENTAG "OnPluginMXPopenTag"
#define ON_PLUGIN_MXP_CLOSETAG "OnPluginMXPcloseTag"
#define ON_PLUGIN_MXP_SETVARIABLE "OnPluginMXPsetVariable"
#define ON_PLUGIN_MXP_SETENTITY "OnPluginMXPsetEntity"
#define ON_PLUGIN_MXP_ERROR "OnPluginMXPerror"

// chat stuff
#define ON_PLUGIN_CHAT_ACCEPT "OnPluginChatAccept"
#define ON_PLUGIN_CHAT_MESSAGE "OnPluginChatMessage"
#define ON_PLUGIN_CHAT_MESSAGE_OUT "OnPluginChatMessageOut"
#define ON_PLUGIN_CHAT_DISPLAY "OnPluginChatDisplay"
#define ON_PLUGIN_CHAT_NEWUSER "OnPluginChatNewUser"
#define ON_PLUGIN_CHAT_USERDISCONNECT "OnPluginChatUserDisconnect"

// ANSI Colour Codes

#define ANSI_RESET 0
Expand Down
6 changes: 3 additions & 3 deletions xml/xml_load_world.cpp
Expand Up @@ -96,7 +96,7 @@ the root level. ie.
*/

extern const char * PluginCallbacksNames [1];
extern string PluginCallbacksNames [1];
extern tConfigurationNumericOption OptionsTable [];
extern tConfigurationAlphaOption AlphaOptionsTable [];
extern UINT iLineLastItemFound;
Expand Down Expand Up @@ -421,9 +421,9 @@ LONGLONG iCounterFrequency = large_int_frequency.QuadPart;

// find all plugin callbacks by looping through table - add to map

for (int i = 0; PluginCallbacksNames [i]; i++)
for (int i = 0; PluginCallbacksNames [i] != ""; i++)
m_CurrentPlugin->m_PluginCallbacks [PluginCallbacksNames [i]]._dispid =
m_CurrentPlugin->GetPluginDispid (PluginCallbacksNames [i]);
m_CurrentPlugin->GetPluginDispid (PluginCallbacksNames [i].c_str ());

// note if we need to call these routines (that is, if *any* plugin supports them)

Expand Down

0 comments on commit b1b2ab6

Please sign in to comment.