]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules.cpp
Initial revision
[user/henk/code/inspircd.git] / src / modules.cpp
1 /*
2
3 $Log$
4 Revision 1.1  2003/01/23 19:45:58  brain
5 Initial revision
6
7 Revision 1.7  2003/01/22 20:49:16  brain
8 Added FileReader file-caching class
9 Changed m_randquote to use FileReader class
10
11 Revision 1.6  2003/01/21 20:31:24  brain
12 Modified to add documentation
13 Added ConfigReader class for modules
14
15 Revision 1.5  2003/01/13 22:30:50  brain
16 Added Admin class (holds /admin info for modules)
17 Added methods to Server class
18
19
20 */
21
22
23
24 #include <typeinfo>
25 #include <iostream.h>
26 #include "globals.h"
27 #include "modules.h"
28 #include "inspircd_io.h"
29
30 // version is a simple class for holding a modules version number
31
32 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
33
34 // admin is a simple class for holding a server's administrative info
35
36 Admin::Admin(string name, string email, string nick) : Name(name), Email(email), Nick(nick) { };
37
38 //
39 // Announce to the world that the Module base
40 // class has been created or destroyed
41 //
42
43 Module::Module() { }
44 Module::~Module() { }
45 void Module::OnUserConnect(userrec* user) { }
46 void Module::OnUserQuit(userrec* user) { }
47 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
48 void Module::OnUserPart(userrec* user, chanrec* channel) { }
49 Version Module::GetVersion() { return Version(1,0,0,0); }
50
51 // server is a wrapper class that provides methods to all of the C-style
52 // exports in the core
53 //
54
55 Server::Server()
56 {
57 }
58
59 Server::~Server()
60 {
61 }
62
63 void Server::SendOpers(string s)
64 {
65         WriteOpers("%s",s.c_str());
66 }
67
68 void Server::Debug(string s)
69 {
70         debug("%s",s.c_str());
71 }
72
73 void Server::Send(int Socket, string s)
74 {
75         Write(Socket,"%s",s.c_str());
76 }
77
78 void Server::SendServ(int Socket, string s)
79 {
80         WriteServ(Socket,"%s",s.c_str());
81 }
82
83 void Server::SendFrom(int Socket, userrec* User, string s)
84 {
85         WriteFrom(Socket,User,"%s",s.c_str());
86 }
87
88 void Server::SendTo(userrec* Source, userrec* Dest, string s)
89 {
90         WriteTo(Source,Dest,"%s",s.c_str());
91 }
92
93 void Server::SendChannel(userrec* User, chanrec* Channel, string s,bool IncludeSender)
94 {
95         if (IncludeSender)
96         {
97                 WriteChannel(Channel,User,"%s",s.c_str());
98         }
99         else
100         {
101                 ChanExceptSender(Channel,User,"%s",s.c_str());
102         }
103 }
104
105 bool Server::CommonChannels(userrec* u1, userrec* u2)
106 {
107         return (common_channels(u1,u2) != 0);
108 }
109
110 void Server::SendCommon(userrec* User, string text,bool IncludeSender)
111 {
112         if (IncludeSender)
113         {
114                 WriteCommon(User,"%s",text.c_str());
115         }
116         else
117         {
118                 WriteCommonExcept(User,"%s",text.c_str());
119         }
120 }
121
122 void Server::SendWallops(userrec* User, string text)
123 {
124         WriteWallOps(User,"%s",text.c_str());
125 }
126
127 bool Server::IsNick(string nick)
128 {
129         return (isnick(nick.c_str()) != 0);
130 }
131
132 userrec* Server::FindNick(string nick)
133 {
134         return Find(nick);
135 }
136
137 chanrec* Server::FindChannel(string channel)
138 {
139         return FindChan(channel.c_str());
140 }
141
142 string Server::ChanMode(userrec* User, chanrec* Chan)
143 {
144         string mode = cmode(User,Chan);
145         return mode;
146 }
147
148 string Server::GetServerName()
149 {
150         return getservername();
151 }
152
153 string Server::GetNetworkName()
154 {
155         return getnetworkname();
156 }
157
158 Admin Server::GetAdmin()
159 {
160         return Admin(getadminname(),getadminemail(),getadminnick());
161 }
162
163
164 ConfigReader::ConfigReader()
165 {
166         fname = CONFIG_FILE;
167 }
168
169
170 ConfigReader::~ConfigReader()
171 {
172 }
173
174
175 ConfigReader::ConfigReader(string filename) : fname(filename) { };
176
177 string ConfigReader::ReadValue(string tag, string name, int index)
178 {
179         char val[MAXBUF];
180         ReadConf(fname.c_str(),tag.c_str(),name.c_str(),index,val);
181         string s = val;
182         return s;
183 }
184
185
186 int ConfigReader::Enumerate(string tag)
187 {
188         return EnumConf(fname.c_str(),tag.c_str());
189 }
190
191
192 bool ConfigReader::Verify()
193 {
194         return true;
195 }
196
197
198 FileReader::FileReader(string filename)
199 {
200         file_cache c;
201         readfile(c,filename.c_str());
202         this->fc = c;
203 }
204
205 FileReader::FileReader()
206 {
207 }
208
209 void FileReader::LoadFile(string filename)
210 {
211         file_cache c;
212         readfile(c,filename.c_str());
213         this->fc = c;
214 }
215
216 FileReader::~FileReader()
217 {
218 }
219
220 string FileReader::GetLine(int x)
221 {
222         if ((x<0) || (x>fc.size()))
223                 return "";
224         return fc[x];
225 }
226
227 int FileReader::FileSize()
228 {
229         return fc.size();
230 }
231
232