1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="index,follow" />
<meta name="language" content="en" />
<title>ZNC - Writing Modules</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" alink="#993333" link="#333399" vlink="#666666">
[<a href="index.php">Home</a>]
-
[<a href="http://sourceforge.net/projects/znc">Project Page</a>]
<hr noshade>
<p />
<h2>
Overview
</h2>
<ul>
<li> Create your own module.cpp file
<li> #include <main.h> and <Modules.h>
<li> Create a new class derived from CModule overriding any <a href="ModuleHooks.html">ModuleHooks</a> that you need
<li> Be sure to add the macro call <em>MODULEDEFS(CYourClass)</em> at the END of the file
<li> Compile your module into a shared object (.so file)
<ul>
<li> The easy way to compile is to use the znc-buildmod script as long as your module is a single .cpp file
<ul>
<li> <em>znc-buildmod example.cpp</em>
</ul>
<li> alternative is to manually compile using znc-config to ensure that you are using the same flags and libs that the znc engine was compiled with
<ul>
<li> <em>g++ `znc-config --cflags` `znc-config --include` `znc-config --libs` -shared -o example.so example.cpp</em>
</ul>
</ul>
<li> Place the .so file into your ~/.znc/modules directory !!!WARNING!!! if you overwrite a .so file while znc has it loaded it can and probably will crash znc, <em>/msg *status unloadmod foo</em> first!
</ul>
<h2>
Code
</h2>
<pre>
#include <main.h>
#include <Modules.h>
</pre>
<pre>
class CExampleMod : public CModule {
public:
MODCONSTRUCTOR(CExampleMod) {}
virtual ~CExampleMod() {}
</pre>
<pre>
virtual void OnModCommand(const string& sCommand) {
if (strcasecmp(sCommand.c_str(), "HELP") == 0) {
PutModule("I'd like to help, but I am just an example");
} else {
PutModule("Unknown command, try HELP");
}
}
};
</pre>
<pre>
MODULEDEFS(CExampleMod)
</pre>
<h2>
Output
</h2>
<pre>
<zncuser> test
<*example> Unknown command, try HELP
<zncuser> help
<*example> I'd like to help, but I am just an example
</pre>
</body>
</html>
|