]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lua/lualocal.c
Remove trusts2 from paulbranch.
[irc/quakenet/newserv.git] / lua / lualocal.c
index 505b8fbc0d1d725a385d9ba4339f4eab2da68cff..237b6f021614798ec8ff7e813a4ecab2ddbbf687 100644 (file)
 void lua_localnickhandler(nick *target, int type, void **args);
 void lua_reconnectlocal(void *arg);
 
-static int lua_registerlocaluser(lua_State *ps) {
+static int lua_registerlocaluserid(lua_State *ps) {
   lua_list *l;
   lua_localnick *ln;
   char *nickname, *ident, *hostname, *realname, *account;
   flag_t modes = 0;
+  long userid;
   
-  if(!lua_isstring(ps, 1) || !lua_isstring(ps, 2) || !lua_isstring(ps, 3) || !lua_isstring(ps, 4) || !lua_isstring(ps, 5) || !lua_isstring(ps, 6) || !lua_isfunction(ps, 7))
+  if(!lua_isstring(ps, 1) || !lua_isstring(ps, 2) || !lua_isstring(ps, 3) || !lua_isstring(ps, 4) || !lua_isstring(ps, 5) || !lua_isstring(ps, 7) || !lua_isfunction(ps, 8))
     return 0;
 
   nickname = (char *)lua_tostring(ps, 1);
@@ -27,8 +28,13 @@ static int lua_registerlocaluser(lua_State *ps) {
   hostname = (char *)lua_tostring(ps, 3);
   realname = (char *)lua_tostring(ps, 4);
   account = (char *)lua_tostring(ps, 5);
+  if(lua_islong(ps, 6)) {
+    userid = lua_tolong(ps, 6);
+  } else {
+    userid = 0;
+  }
 
-  setflags(&modes, UMODE_ALL, (char *)lua_tostring(ps, 6), umodeflags, REJECT_NONE);
+  setflags(&modes, UMODE_ALL, (char *)lua_tostring(ps, 7), umodeflags, REJECT_NONE);
 
   if(!lua_lineok(nickname) || !lua_lineok(ident) || !lua_lineok(hostname) || !lua_lineok(realname) || !lua_lineok(account))
     return 0;
@@ -37,15 +43,15 @@ 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;
 
   ln->reconnect = NULL;
 
-  ln->nick = registerlocaluser(nickname, ident, hostname, realname, account, modes, &lua_localnickhandler);
+  ln->nick = registerlocaluserflags(nickname, ident, hostname, realname, account, userid, 0, modes, &lua_localnickhandler);
   if(!ln->nick) {
-    free(ln);
+    luafree(ln);
     return 0;
   }
 
@@ -67,7 +73,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) {
@@ -101,7 +107,7 @@ static int lua_deregisterlocaluser(lua_State *ps) {
   l = lua_listfromstate(ps);
 
   for(l2=l->nicks;l2;lp=l2,l2=l2->next) {
-    if(l2->nick->numeric == numeric) {
+    if(l2->nick && l2->nick->numeric == numeric) {
       if(lp) {
         lp->next = l2->next;
       } else {
@@ -119,7 +125,9 @@ static int lua_deregisterlocaluser(lua_State *ps) {
 void lua_deregisternicks(lua_list *l) {
   struct lua_localnick *ln, *pn;
 
-  for(ln=l->nicks;ln;ln=pn) {
+  ln = l->nicks;
+  l->nicks = NULL;
+  for(;ln;ln=pn) {
     pn = ln->next;
 
     lua_freelocalnick(l->l, ln, "Script unloaded.");
@@ -239,7 +247,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);
@@ -252,10 +260,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);
   }
@@ -344,7 +360,7 @@ static int lua_localprivmsg(lua_State *ps) {
 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))
@@ -520,8 +536,26 @@ static int lua_localkick(lua_State *ps) {
   LUA_RETURN(ps, LUA_OK);
 }
 
+static int lua_localrename(lua_State *ps) {
+  nick *np;
+  char *changeto;
+
+  if(!lua_islong(ps, 1) || !lua_isstring(ps, 2) )
+    LUA_RETURN(ps, LUA_FAIL);
+
+  np = getnickbynumeric(lua_tolong(ps, 1));
+  changeto = (char *)lua_tostring(ps, 2);
+
+  if(!lua_lineok(changeto))
+    LUA_RETURN(ps, LUA_FAIL);
+
+  renamelocaluser(np, changeto);
+
+  LUA_RETURN(ps, LUA_OK);
+}
+
 void lua_registerlocalcommands(lua_State *l) {
-  lua_register(l, "irc_localregisteruser", lua_registerlocaluser);
+  lua_register(l, "irc_localregisteruserid", lua_registerlocaluserid);
   lua_register(l, "irc_localderegisteruser", lua_deregisterlocaluser);
   lua_register(l, "irc_localjoin", lua_localjoin);
   lua_register(l, "irc_localpart", lua_localpart);
@@ -535,5 +569,7 @@ void lua_registerlocalcommands(lua_State *l) {
   lua_register(l, "irc_localban", lua_localban);
   lua_register(l, "irc_localkick", lua_localkick);
   lua_register(l, "irc_localumodes", lua_localumodes);
+
+  lua_register(l, "irc_localrename", lua_localrename);
 }