Commit 574e1f4f authored by Dustin L. Howett's avatar Dustin L. Howett

Replace the single event constructor with a bunch of tiny constructors that...

Replace the single event constructor with a bunch of tiny constructors that are created by the _EVENT macro.
parent caaf4fcd
......@@ -11,6 +11,10 @@
#include <string>
#include <map>
#define _EVENT(name) void evt_ ## name (struct server *, struct sender *, char *); \
static __attribute__((constructor)) void _evt_ ## name ## _init() { event_handlers[#name] = &evt_ ## name; } \
void evt_ ## name (struct server *server, struct sender *sender, char *msgbuf)
std::map<std::string, event_handler_func> event_handlers;
void dispatch_event(struct server *server, char *name, struct sender *sender, char *msgbuf) {
......@@ -21,7 +25,6 @@ void dispatch_event(struct server *server, char *name, struct sender *sender, ch
}
}
#define _EVENT(name) void evt_ ## name (struct server *server, struct sender *sender, char *msgbuf)
_EVENT(001) {
char *nick = strsep(&msgbuf, " ");
server->nick = strdup(nick);
......@@ -35,11 +38,11 @@ _EVENT(433) {
ircprintf(server, "NICK %s_", nick);
}
_EVENT(ping) {
_EVENT(PING) {
ircprintf(server, "PONG %s", msgbuf);
}
_EVENT(privmsg) {
_EVENT(PRIVMSG) {
char *recipient = strsep(&msgbuf, " ");
bool priv = false;
if(server->nick && strcmp(recipient, server->nick) == 0) {
......@@ -83,10 +86,3 @@ _EVENT(privmsg) {
free(argv);
}
static __attribute__((constructor)) void _events_init() {
event_handlers["PRIVMSG"] = &evt_privmsg;
event_handlers["PING"] = &evt_ping;
event_handlers["001"] = &evt_001;
event_handlers["433"] = &evt_433;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment