ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ctcp-common.C
Revision: 1.7
Committed: Sat Sep 22 14:27:30 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -2 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

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