ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ctcp-common.C
Revision: 1.5
Committed: Sun Sep 9 20:05:52 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +5 -5 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

# Content
1 /**
2 * ctcp-common.C: CTCP command handling.
3 * Rights to this code are documented in doc/pod/license.pod.
4 *
5 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team (http://ermyth.schmorp.de)
6 * Copyright © 2005-2006 Atheme Development Group
7 */
8
9 static char const rcsid[] = "$Id: ctcp-common.C,v 1.4 2007-08-28 17:08:12 pippijn Exp $";
10
11 #include <map>
12
13 #include "atheme.h"
14 #include "users.h"
15 #include "datastream.h"
16 #include "privs.h"
17
18 #include <common/util.h>
19
20 typedef std::map<char const *, void (*) (char *, char *, char *, char *), str_lt> ctcp_map;
21 ctcp_map handlers;
22
23 static void
24 ctcp_ping_handler (char *cmd, char *args, char *origin, char *svsnick)
25 {
26 char *s;
27 char const *m = 0;
28
29 s = strtok (args, "\001");
30 if (s != NULL)
31 strip (s);
32 else
33 m = "pong!";
34
35 notice (svsnick, origin, "\001PING %.100s\001", s ? s : m);
36 }
37
38 static void
39 ctcp_version_handler (char *cmd, char *args, char *origin, char *svsnick)
40 {
41 notice (svsnick, origin, "\001VERSION " PACKAGE_NAME "-%s. %s %s%s%s%s%s%s%s%s%s%s [%s]\001",
42 version,
43 me.name,
44 match_mapping ? "A" : "",
45 log_debug_enabled () ? "d" : "",
46 me.auth ? "e" : "",
47 config_options.flood_msgs ? "F" : "",
48 config_options.leave_chans ? "l" : "",
49 config_options.join_chans ? "j" : "",
50 chansvs.changets ? "t" : "",
51 !match_mapping ? "R" : "",
52 config_options.raw ? "r" : "",
53 runflags & RF_LIVE ? "n" : "",
54 ircd->ircdname);
55 }
56
57 static void
58 ctcp_clientinfo_handler (char *cmd, char *args, char *origin, char *svsnick)
59 {
60 /* easter egg :X */
61 notice (svsnick, origin, "\001CLIENTINFO 114 97 107 97 117 114\001");
62 }
63
64 void
65 common_ctcp_init (void)
66 {
67 handlers["\001PING"] = ctcp_ping_handler;
68 handlers["\001VERSION\001"] = ctcp_version_handler;
69 handlers["\001CLIENTINFO\001"] = ctcp_clientinfo_handler;
70 }
71
72 unsigned int
73 handle_ctcp_common (sourceinfo_t *si, char *cmd, char *args)
74 {
75 ctcp_map::iterator handler = handlers.find (cmd);
76
77 if (handler != handlers.end ())
78 {
79 handler->second (cmd, args, si->su->nick, si->service->name);
80 return 1;
81 }
82
83 return 0;
84 }