void lua_onjoin(int hooknum, void *arg);
void lua_onpart(int hooknum, void *arg);
+sstring *luabotnick;
+
void lua_registerevents(void) {
registerhook(HOOK_CHANNEL_MODECHANGE, &lua_onmode);
registerhook(HOOK_NICK_NEWNICK, &lua_onnewnick);
void lua_startbot(void *arg) {
channel *cp;
- sstring *n;
myureconnect = NULL;
- n = getcopyconfigitem("lua", "botnick", "U", NICKLEN);
- lua_nick = registerlocaluser(n->content, "lua", "quakenet.department.of.corrections", LUA_FULLVERSION, "U", UMODE_ACCOUNT | UMODE_DEAF | UMODE_OPER | UMODE_SERVICE, &lua_bothandler);
+ if(!luabotnick)
+ luabotnick = getcopyconfigitem("lua", "botnick", "U", NICKLEN);
+
+ lua_nick = registerlocaluser(luabotnick->content, "lua", "quakenet.department.of.corrections", LUA_FULLVERSION, "U", UMODE_ACCOUNT | UMODE_DEAF | UMODE_OPER | UMODE_SERVICE, &lua_bothandler);
if(!lua_nick) {
myureconnect = scheduleoneshot(time(NULL) + 1, &lua_startbot, NULL);
return;
if(lua_nick)
deregisterlocaluser(lua_nick, NULL);
+
+ if(luabotnick) {
+ freesstring(luabotnick);
+ luabotnick = NULL;
+ }
}
int _lua_vpcall(lua_State *l, void *function, int mode, const char *sig, ...) {
nres = strlen(sig);
if(lua_debugpcall(l, (mode==LUA_CHARMODE)?function:"some_handler", narg, nres, top + 1)) {
- Error("lua", ERR_ERROR, "Error pcalling %s: %s.", (mode==LUA_CHARMODE)?function:"some_handler", lua_tostring(l, -1));
+ Error("lua", ERR_ERROR, "Error pcalling %s: %s.", (mode==LUA_CHARMODE)?(char *)function:"some_handler", lua_tostring(l, -1));
} else {
nres = -nres;
while(*sig) {
p[le - 1] = '\000';
lua_avpcall("irc_onctcp", "ls", np->numeric, p + 1);
-
+ } else {
+ lua_avpcall("irc_onnotice", "ls", np->numeric, p);
}
break;
void **arglist = (void **)arg;
chanindex *ci = ((channel *)arglist[0])->index;
nick *np = arglist[1];
+ char *reason = arglist[2];
if(!ci || !np)
return;
- lua_avpcall("irc_onpart", "Sl", ci->name, np->numeric);
+ lua_avpcall("irc_onpart", "Sls", ci->name, np->numeric, reason);
}
void lua_onrename(int hooknum, void *arg) {
- nick *np = (void *)arg;
+ void **harg = (void **)arg;
+ nick *np = harg[0];
+ char *oldnick = harg[1];
if(!np)
return;
- lua_avpcall("irc_onrename", "l", np->numeric);
+ lua_avpcall("irc_onrename", "ls", np->numeric, oldnick);
}
void lua_onquit(int hooknum, void *arg) {
return buf;
}
+static char *printlimitedmodes(channel *cp, flag_t before) {
+ static char buf[1024];
+
+ snprintf(buf, sizeof(buf), "%s", printflags(cp->flags, cmodeflags));
+
+ return buf;
+}
+
void lua_onmode(int hooknum, void *arg) {
void **arglist = (void **)arg;
channel *cp = (channel *)arglist[0];
chanindex *ci = cp->index;
nick *np = arglist[1];
+ flag_t beforeflags = (flag_t)(long)arglist[3];
if(np) {
- lua_avpcall("irc_onmode", "Sls", ci->name, np->numeric, printallmodes(cp));
+ lua_avpcall("irc_onmode", "Slss", ci->name, np->numeric, printallmodes(cp), printlimitedmodes(cp, beforeflags));
} else {
- lua_avpcall("irc_onmode", "S0s", ci->name, printallmodes(cp));
+ lua_avpcall("irc_onmode", "S0ss", ci->name, printallmodes(cp), printlimitedmodes(cp, beforeflags));
}
}