]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lua/luabot.c
CHANSERV: temporarily disable qusers
[irc/quakenet/newserv.git] / lua / luabot.c
index 97b2413ed3c4ef9f6dd77389969e1a9a95c2acde..9e7ae143748a1e9fc79b987c13ff1b56c354f123 100644 (file)
@@ -33,6 +33,8 @@ void lua_onconnect(int hooknum, void *arg);
 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);
@@ -73,12 +75,13 @@ void lua_deregisterevents(void) {
 
 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;
@@ -118,6 +121,11 @@ void lua_destroybot(void) {
 
   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, ...) {
@@ -152,7 +160,7 @@ int _lua_vpcall(lua_State *l, void *function, int mode, const char *sig, ...) {
       case 'S':
         lua_pushstring(l, ((sstring *)(va_arg(va, sstring *)))->content);
         break;
-      case 'L':
+      case 'L': /* BE VERY CAREFUL USING THIS, MAKE SURE YOU CAST THE VALUE TO LONG */
         {
           char *p = va_arg(va, char *);
           long len = va_arg(va, long);
@@ -162,7 +170,7 @@ int _lua_vpcall(lua_State *l, void *function, int mode, const char *sig, ...) {
       case 'N':
         {
           nick *np = va_arg(va, nick *);
-          LUA_PUSHNICK(l, np);
+          lua_pushnumeric(l, np->numeric);
           break;
         }
       case 'C':
@@ -194,7 +202,7 @@ endwhile:
   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) {
@@ -352,12 +360,14 @@ void lua_onpart(int hooknum, void *arg) {
 }
 
 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) {