File: WritingModules.html

package info (click to toggle)
znc 0.045-3%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,120 kB
  • ctags: 2,324
  • sloc: cpp: 17,406; sh: 2,380; perl: 448; makefile: 134
file content (75 lines) | stat: -rw-r--r-- 2,261 bytes parent folder | download | duplicates (2)
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 &lt;main.h&gt; and &lt;Modules.h&gt;
<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 &lt;main.h&gt;
 #include &lt;Modules.h&gt;
</pre>
<pre>
 class CExampleMod : public CModule {
 public:
     MODCONSTRUCTOR(CExampleMod) {}
     virtual ~CExampleMod() {}
</pre>
<pre>
     virtual void OnModCommand(const string&amp; 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>
 &lt;zncuser&gt; test
 &lt;*example&gt; Unknown command, try HELP
 &lt;zncuser&gt; help
 &lt;*example&gt; I'd like to help, but I am just an example
</pre>

</body>
</html>