Commit a7c41a11 authored by Dustin L. Howett's avatar Dustin L. Howett

Replace the event handler array with a std::map.

parent 90f30f31
......@@ -8,15 +8,13 @@
#include "event.h"
#include "commands.h"
#include <string>
#include <map>
std::map<std::string, event_handler_func> event_handlers;
void dispatch_event(struct server *server, char *name, struct sender *sender, char *msgbuf) {
event_handler_func handler = NULL;
eventhandler *c;
for(c = &event_handlers[0]; c->name; ++c) {
if(strcmp(c->name, name) == 0) {
handler = c->handler;
break;
}
}
event_handler_func handler = event_handlers[name];
if(handler) {
handler(server, sender, msgbuf);
......@@ -79,9 +77,8 @@ _EVENT(privmsg) {
free(argv);
}
eventhandler event_handlers[] = {
{ "001", &evt_001, },
{ "PING", &evt_ping, },
{ "PRIVMSG", &evt_privmsg, },
{ NULL, NULL, },
};
static __attribute__((constructor)) void _events_init() {
event_handlers["PRIVMSG"] = &evt_privmsg;
event_handlers["PING"] = &evt_ping;
event_handlers["001"] = &evt_001;
}
......@@ -3,13 +3,6 @@
typedef void (*event_handler_func)(struct server *server, struct sender *sender, char *msgbuf);
typedef struct {
const char *name;
event_handler_func handler;
} eventhandler;
extern eventhandler event_handlers[];
void dispatch_event(struct server *server, char *name, struct sender *sender, char *msgbuf);
#endif /* end of include guard: EVENT_H */
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