]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lua/lualocal.c
gline playground
[irc/quakenet/newserv.git] / lua / lualocal.c
index e2150339654337ddaec88ec287d9b414ec71d5e6..983103896f3c3fdab0834083c34044c2b87b928d 100644 (file)
@@ -37,7 +37,7 @@ static int lua_registerlocaluser(lua_State *ps) {
   if(!l)
     return 0;
 
-  ln = (lua_localnick *)malloc(sizeof(lua_localnick));
+  ln = (lua_localnick *)luamalloc(sizeof(lua_localnick));
   if(!ln)
     return 0;
 
@@ -45,7 +45,7 @@ static int lua_registerlocaluser(lua_State *ps) {
 
   ln->nick = registerlocaluser(nickname, ident, hostname, realname, account, modes, &lua_localnickhandler);
   if(!ln->nick) {
-    free(ln);
+    luafree(ln);
     return 0;
   }
 
@@ -67,7 +67,7 @@ void lua_freelocalnick(lua_State *ps, lua_localnick *l, char *quitm) {
 
   luaL_unref(ps, LUA_REGISTRYINDEX, l->handler);
 
-  free(l);
+  luafree(l);
 }
 
 int lua_getlocalnickbynick(nick *np, lua_list **rl, lua_localnick **rln) {
@@ -94,13 +94,20 @@ static int lua_deregisterlocaluser(lua_State *ps) {
   if(!lua_islong(ps, 1))
     LUA_RETURN(ps, LUA_FAIL);
 
+  numeric = lua_tolong(ps, 1);
+
   quitm = lua_isstring(ps, 2)?(char *)lua_tostring(ps, 2):"localuser unregistered.";
 
   l = lua_listfromstate(ps);
 
   for(l2=l->nicks;l2;lp=l2,l2=l2->next) {
     if(l2->nick->numeric == numeric) {
-      lp->next = l2->next;
+      if(lp) {
+        lp->next = l2->next;
+      } else {
+        l->nicks = l2->next;
+      }
+
       lua_freelocalnick(ps, l2, quitm);
       LUA_RETURN(ps, LUA_OK);
     }
@@ -156,7 +163,8 @@ void lua_localnickhandler(nick *target, int type, void **args) {
       break;
 
     case LU_KILLED:
-      lua_vlpcall(l, ln, "irc_onkilled", "");
+      p = (char *)args[2];
+      lua_vlpcall(l, ln, "irc_onkilled", "s", p);
 
       strlcpy(ln->nickname, target->nick, sizeof(ln->nickname));
       strlcpy(ln->ident, target->ident, sizeof(ln->ident));
@@ -169,6 +177,16 @@ void lua_localnickhandler(nick *target, int type, void **args) {
 
       ln->reconnect = scheduleoneshot(time(NULL) + 1, &lua_reconnectlocal, ln);
 
+      break;
+    case LU_INVITE:
+    /* we were invited, check if someone invited us to PUBLICCHAN */
+      np = (nick *)args[0];
+      c = (channel *)args[1];
+
+      if(!c || !np || !c->index || !c->index->name || !c->index->name->content)
+        return;
+
+      lua_vlpcall(l, ln, "irc_oninvite", "Ns", np, c->index->name->content);
       break;
   }
 }
@@ -202,6 +220,8 @@ static int lua_localjoin(lua_State *ps) {
     LUA_RETURN(ps, LUA_FAIL);
 
   chan = (char *)lua_tostring(ps, 2);
+  if(chan[0] != '#')
+    LUA_RETURN(ps, LUA_FAIL);
 
   if(!lua_lineok(chan)) 
     LUA_RETURN(ps, LUA_FAIL);
@@ -219,7 +239,7 @@ static int lua_localjoin(lua_State *ps) {
 static int lua_localpart(lua_State *ps) {
   nick *source;
   channel *target;
-  char *chan;
+  char *chan, *reason;
 
   if(!lua_islong(ps, 1) || !lua_isstring(ps, 2))
     LUA_RETURN(ps, LUA_FAIL);
@@ -232,10 +252,18 @@ static int lua_localpart(lua_State *ps) {
 
   if(!lua_lineok(chan)) 
     LUA_RETURN(ps, LUA_FAIL);
-    
+  
+  if(lua_isstring(ps, 3)) {
+    reason = (char *)lua_tostring(ps, 3);
+    if(!lua_lineok(reason))
+      LUA_RETURN(ps, LUA_FAIL);
+  } else {
+    reason = NULL;
+  }
+
   target = findchannel(chan);
   if(target) {
-    localpartchannel(source, target);
+    localpartchannel(source, target, reason);
   } else {
     LUA_RETURN(ps, LUA_FAIL);
   }
@@ -295,10 +323,36 @@ static int lua_localnotice(lua_State *ps) {
   LUA_RETURN(ps, LUA_OK);
 }
 
+static int lua_localprivmsg(lua_State *ps) {
+  char *msg;
+  nick *source;
+  nick *target;
+
+  if(!lua_islong(ps, 1) || !lua_islong(ps, 2) || !lua_isstring(ps, 3))
+    LUA_RETURN(ps, LUA_FAIL);
+
+  source = getnickbynumeric(lua_tolong(ps, 1));
+  if(!source)
+    LUA_RETURN(ps, LUA_FAIL);
+
+  target = getnickbynumeric(lua_tolong(ps, 2));
+  if(!target)
+    LUA_RETURN(ps, LUA_FAIL);
+
+  msg = (char *)lua_tostring(ps, 3);
+
+  if(!lua_lineok(msg))
+    LUA_RETURN(ps, LUA_FAIL);
+
+  sendmessagetouser(source, target, "%s", msg);
+
+  LUA_RETURN(ps, LUA_OK);
+}
+
 static int lua_localovmode(lua_State *l) {
   nick *source;
   channel *chan;
-  int state = 0, add, realmode, ignoring = 0;
+  int state = 0, add = 0, realmode = 0, ignoring = 0;
   modechanges changes;
 
   if(!lua_islong(l, 1) || !lua_isstring(l, 2) || !lua_istable(l, 3))
@@ -360,6 +414,26 @@ static int lua_localovmode(lua_State *l) {
   LUA_RETURN(l, LUA_OK);
 }
 
+static int lua_localumodes(lua_State *ps) {
+  nick *np;
+  char *modes;
+  flag_t newmodes = 0;
+
+  if(!lua_islong(ps, 1) || !lua_isstring(ps, 2))
+    LUA_RETURN(ps, LUA_FAIL);
+
+  np = getnickbynumeric(lua_tolong(ps, 1));
+  if(!np)
+    LUA_RETURN(ps, LUA_FAIL);
+
+  modes = (char *)lua_tostring(ps, 2);
+
+  setflags(&newmodes, UMODE_ALL, modes, umodeflags, REJECT_NONE);
+
+  localusersetumodes(np, newmodes);
+  LUA_RETURN(ps, LUA_OK);
+}
+
 static int lua_localtopic(lua_State *ps) {
   nick *np;
   channel *cp;
@@ -461,11 +535,13 @@ void lua_registerlocalcommands(lua_State *l) {
   lua_register(l, "irc_localpart", lua_localpart);
   lua_register(l, "irc_localchanmsg", lua_localchanmsg);
   lua_register(l, "irc_localnotice", lua_localnotice);
+  lua_register(l, "irc_localprivmsg", lua_localprivmsg);
 
   lua_register(l, "irc_localovmode", lua_localovmode);
   lua_register(l, "irc_localtopic", lua_localtopic);
 
   lua_register(l, "irc_localban", lua_localban);
   lua_register(l, "irc_localkick", lua_localkick);
+  lua_register(l, "irc_localumodes", lua_localumodes);
 }