ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ctcp-common.C
Revision: 1.2
Committed: Sat Jul 21 01:29:10 2007 UTC (16 years, 10 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
3     * Copyright © 2005-2006 Atheme Development Group
4 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
5 pippijn 1.1 *
6     * CTCP command handling.
7     */
8    
9     static char const rcsid[] = "$Id";
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    
28     s = strtok (args, "\001");
29     if (s != NULL)
30     strip (s);
31     else
32     s = "pong!";
33    
34     notice (svsnick, origin, "\001PING %.100s\001", s);
35     }
36    
37     static void
38     ctcp_version_handler (char *cmd, char *args, char *origin, char *svsnick)
39     {
40     notice (svsnick, origin, "\001VERSION " PACKAGE_NAME "-%s. %s %s%s%s%s%s%s%s%s%s%s [%s]\001",
41     version,
42     me.name,
43     match_mapping ? "A" : "",
44     log_debug_enabled () ? "d" : "",
45     me.auth ? "e" : "",
46     config_options.flood_msgs ? "F" : "",
47     config_options.leave_chans ? "l" : "",
48     config_options.join_chans ? "j" : "",
49     chansvs.changets ? "t" : "",
50     !match_mapping ? "R" : "",
51     config_options.raw ? "r" : "",
52     runflags & RF_LIVE ? "n" : "",
53     ircd->ircdname);
54     }
55    
56     static void
57     ctcp_clientinfo_handler (char *cmd, char *args, char *origin, char *svsnick)
58     {
59     /* easter egg :X */
60     notice (svsnick, origin, "\001CLIENTINFO 114 97 107 97 117 114\001");
61     }
62    
63     void
64     common_ctcp_init (void)
65     {
66     handlers["\001PING"] = ctcp_ping_handler;
67     handlers["\001VERSION\001"] = ctcp_version_handler;
68     handlers["\001CLIENTINFO\001"] = ctcp_clientinfo_handler;
69     }
70    
71     unsigned int
72     handle_ctcp_common (sourceinfo_t *si, char *cmd, char *args)
73     {
74     ctcp_map::iterator handler = handlers.find (cmd);
75    
76     if (handler != handlers.end ())
77     {
78     handler->second (cmd, args, si->su->nick, si->service->name);
79     return 1;
80     }
81    
82     return 0;
83     }