ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/ctcp-common.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +4 -3 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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 pippijn 1.4 static char const rcsid[] = "$Id: ctcp-common.C,v 1.3 2007-07-21 13:23:21 pippijn Exp $";
10 pippijn 1.1
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 pippijn 1.4 char const *m = 0;
28 pippijn 1.1
29     s = strtok (args, "\001");
30     if (s != NULL)
31     strip (s);
32     else
33 pippijn 1.4 m = "pong!";
34 pippijn 1.1
35 pippijn 1.4 notice (svsnick, origin, "\001PING %.100s\001", s ? s : m);
36 pippijn 1.1 }
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     }