File indexing completed on 2025-01-12 06:47:29
0001 // 0002 // C++ Interface: cplugin 0003 // 0004 // Description: see below 0005 // 0006 /* 0007 Copyright 2006-2011 Tomas Mecir <kmuddy@kmuddy.com> 0008 0009 This program is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU General Public License as 0011 published by the Free Software Foundation; either version 2 of 0012 the License, or (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef CPLUGIN_H 0024 #define CPLUGIN_H 0025 0026 #include <ctextchunk.h> 0027 #include <kmuddy_export.h> 0028 0029 /** 0030 This class represents one plug-in for KMuddy. It is created by a plug-in factory. 0031 0032 The cSession pointer is passed in all routines, so that you can distinguish between events in 0033 different connections. 0034 0035 Note that plug-ins link to libkmuddy, allowing you to use cActionManager, cMacroManager and other useful classes, if the provided 0036 interface is not sufficient, or if you want to define your own macros or 0037 functions in the plug-in. 0038 0039 @author Tomas Mecir 0040 */ 0041 0042 class KMUDDY_EXPORT cPlugin : public QObject 0043 { 0044 Q_OBJECT 0045 public: 0046 cPlugin (); 0047 ~cPlugin () override; 0048 0049 /** priority in which this plug-in receives texts/events. Lower number means higher priority. */ 0050 int priority () { return _priority; }; 0051 0052 /** Called when a session has been added. If the session has existed before, fresh is set 0053 to false. This can happen if the plug-in is loaded manually. */ 0054 virtual void sessionAdd (int /*sess*/, bool /*fresh*/ = true) {}; 0055 /** Called when a session should be removed. Closed is false, if the session isn't being 0056 closed. This hapens when the plug-in is being unloaded manually. */ 0057 virtual void sessionRemove (int /*sess*/, bool /*closed*/ = true) {}; 0058 /** called when the user switches to another session. Sess is the number of the new session. */ 0059 virtual void sessionSwitch (int /*sess*/) {}; 0060 /** The session has just been connected. Not called when manually loading the plug-in. */ 0061 virtual void connected (int /*sess*/) {}; 0062 /** The session has just been disconnected. Not called when manually unloading the plug-in. */ 0063 virtual void disconnected (int /*sess*/) {}; 0064 /** Request to save data. */ 0065 virtual void save (int /*sess*/) {}; 0066 0067 /** raw data from the socket, before any processing; data can be modified by the plug-in 0068 if desired */ 0069 virtual void rawData (int /*sess*/, char * /*data*/) {}; 0070 /** raw data, after MCCP decompression, data is equivalent to rawData if MCCP is not used; 0071 data can be modified by plug-in if desired */ 0072 virtual void decompressedData (int /*sess*/, char * /*data*/) {}; 0073 /** process one line of input from the MUD; called after telnet/ANSI processing; 0074 this function is called TWICE for each line, first time before triggers get the line, second 0075 time right before displaying the line (or discarding if gagged). 0076 Data can be modified if desired. 0077 @param sess session pointer 0078 @param phase which phase are we in? 1 means before triggers, 2 means after triggers 0079 @param chunk the line 0080 @param gagged only valid if phase is 2, it says whether this line is to be gagged */ 0081 virtual void processInput (int /*sess*/, int /*phase*/, cTextChunk * /*chunk*/, 0082 bool /*gagged*/) {}; 0083 /** prompt that will be displayed; you can modify it is desired */ 0084 virtual void processPrompt (int /*sess*/, cTextChunk * /*chunk*/) {}; 0085 /** Command that is to be sent to the MUD. Aliases have already been expanded. 0086 Command can be modified if desired. If you set dontSend to true, the command won't be 0087 sent and plug-ins with lower priority won't receive this command either. */ 0088 virtual void processCommand (int /*sess*/, QString & /*command*/, bool & /*dontSend*/) {}; 0089 0090 // *** some functions, provided for convenience *** 0091 0092 /** set active session - should only be used by cPluginManager */ 0093 void setActiveSession (int sess) { activesess = sess; }; 0094 /** Returns the active session. Provided for convenience. */ 0095 int activeSession () { return activesess; }; 0096 /** Displays a system message. Provided for convenience. */ 0097 void systemMessage (int sess, const QString &message); 0098 /** Sends a command. Provided for convenience. */ 0099 void sendCommand (int sess, const QString &command); 0100 0101 protected: 0102 int activesess; 0103 int _priority; 0104 }; 0105 0106 #endif