]> jfr.im git - irc/quakenet/newserv.git/blobdiff - lua/luacommands.c
Export the mask matching function to lua (to match bans, ignores, etc.).
[irc/quakenet/newserv.git] / lua / luacommands.c
index ce00d522a4bae26d9f94bdb51700e96f96f08368..222396ad14be7025acf26e12b11d3a177c373028 100644 (file)
@@ -16,6 +16,8 @@
 #include "../localuser/localuserchannel.h"
 #include "../lib/irc_string.h"
 #include "../lib/flags.h"
+#include "../authext/authext.h"
+#include "../glines/glines.h"
 
 #include "lua.h"
 #include "luabot.h"
@@ -209,7 +211,7 @@ static int lua_invite(lua_State *ps) {
   if(!cp)
     LUA_RETURN(ps, LUA_FAIL);
 
-  localinvite(lua_nick, cp, np);
+  localinvite(lua_nick, cp->index, np);
 
   LUA_RETURN(ps, LUA_OK);
 }
@@ -219,7 +221,6 @@ static int lua_gline(lua_State *ps) {
   nick *target;
   char mask[512];
   int duration, usercount = 0;
-  host *hp;
   
   if(!lua_isstring(ps, 1) || !lua_isint(ps, 2) || !lua_isstring(ps, 3))
     LUA_RETURN(ps, LUA_FAIL);
@@ -236,31 +237,10 @@ static int lua_gline(lua_State *ps) {
   if(!target || (IsOper(target) || IsXOper(target) || IsService(target)))
     LUA_RETURN(ps, LUA_FAIL);
 
-  hp = target->host;
-  if(!hp)
+  if(glinebynick(target, duration, reason, GLINE_SIMULATE, "lua") > 50)
     LUA_RETURN(ps, LUA_FAIL);
 
-  usercount = hp->clonecount;
-  if(usercount > 10) { /* (decent) trusted host */
-    int j;
-    nick *np;
-
-    usercount = 0;
-
-    for (j=0;j<NICKHASHSIZE;j++)
-      for (np=nicktable[j];np;np=np->next)
-        if (np && (np->host == hp) && (!ircd_strcmp(np->ident, target->ident)))
-          usercount++;
-
-    if(usercount > 50)
-      LUA_RETURN(ps, LUA_FAIL);
-
-    snprintf(mask, sizeof(mask), "*%s@%s", target->ident, IPtostr(target->p_ipaddr));
-  } else {
-    snprintf(mask, sizeof(mask), "*@%s", IPtostr(target->p_ipaddr));
-  }
-
-  irc_send("%s GL * +%s %d :%s", mynumeric->content, mask, duration, reason);
+  usercount = glinebynick(target, duration, reason, 0, "lua");
   LUA_RETURN(ps, lua_cmsg(LUA_PUKECHAN, "lua-GLINE: %s (%d users, %d seconds -- %s)", mask, usercount, duration, reason));
 }
 
@@ -376,24 +356,44 @@ static int lua_botnick(lua_State *ps) {
   return 1;
 }
 
-/* O(n) */
+static int lua_numerictobase64(lua_State *ps) {
+  if(!lua_islong(ps, 1))
+    return 0;
+
+  lua_pushstring(ps, longtonumeric(lua_tolong(ps, 1), 5));
+  return 1;
+}
+
+static int lua_match(lua_State *ps) {
+  const char *mask, *string;
+
+  if(!lua_isstring(ps, 1) || !lua_isstring(ps, 2))
+    return 0;
+
+  mask = lua_tostring(ps, 1);
+  string = lua_tostring(ps, 2);
+
+  if (!mask || !mask[0] || !string || !string[0])
+    return 0;
+
+  LUA_RETURN(ps, match2strings(mask, string));
+}
+
 static int lua_getuserbyauth(lua_State *l) {
-  const char *acc;
   nick *np;
-  int i, found = 0;
+  int found = 0;
+  authname *au;
 
   if(!lua_isstring(l, 1))
     return 0;
 
-  acc = lua_tostring(l, 1);
+  au = getauthbyname(lua_tostring(l, 1));
+  if(!au)
+    return 0;
 
-  for(i=0;i<NICKHASHSIZE;i++) {
-    for(np=nicktable[i];np;np=np->next) {
-      if(np && np->authname[0] && !ircd_strcmp(np->authname, acc)) {  
-        lua_pushnumeric(l, np->numeric);
-        found++;
-      }
-    }
+  for(np=au->nicks;np;np=np->nextbyauthname) {
+    lua_pushnumeric(l, np->numeric);
+    found++;
   }
 
   return found;
@@ -900,6 +900,9 @@ void lua_registercommands(lua_State *l) {
 
   lua_register(l, "irc_simplechanmode", lua_simplechanmode);
   lua_register(l, "irc_sethost", lua_sethost);
+
+  lua_register(l, "irc_numerictobase64", lua_numerictobase64);
+  lua_register(l, "irc_match", lua_match);
 }
 
 /* --- */
@@ -950,6 +953,9 @@ static int lua_skill(lua_State *ps) {
 #define PUSHER_CHANMODES 12
 #define PUSHER_TIMESTAMP 13
 #define PUSHER_STRING_INDIRECT 14
+#define PUSHER_ACC_ID 15
+#define PUSHER_SERVER_NAME 16
+#define PUSHER_SERVER_NUMERIC 17
 
 void lua_initnickpusher(void) {
   int i = 0;
@@ -968,6 +974,9 @@ void lua_initnickpusher(void) {
   PUSH_NICKPUSHER(PUSHER_LONG, accountts);
   PUSH_NICKPUSHER(PUSHER_UMODES, umodes);
   PUSH_NICKPUSHER_CUSTOM(PUSHER_COUNTRY, "country");
+  PUSH_NICKPUSHER_CUSTOM(PUSHER_ACC_ID, "accountid");
+  PUSH_NICKPUSHER_CUSTOM(PUSHER_SERVER_NAME, "servername");
+  PUSH_NICKPUSHER_CUSTOM(PUSHER_SERVER_NUMERIC, "servernumeric");
 
   nickpushercount = i;
   nickpusher[i].argtype = 0;
@@ -1039,6 +1048,16 @@ int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np) {
       case PUSHER_CHANMODES:
         lua_pushstring(l, printallmodes(*((channel **)offset)));
         break;
+      case PUSHER_ACC_ID:
+        {
+          nick *tnp = (nick *)np;
+          if(IsAccount(tnp) && tnp->auth) {
+            lua_pushlong(l, tnp->auth->userid);
+          } else {
+            lua_pushnil(l);
+          }
+          break;
+        }
       case PUSHER_REALUSERS:
         {
           channel *cp = *((channel **)offset);
@@ -1076,6 +1095,12 @@ int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np) {
           lua_pushint(l, (long)((nick *)offset)->exts[geoipext]);
         }
         break;
+      case PUSHER_SERVER_NAME:
+        lua_pushstring(l, serverlist[homeserver(((nick *)offset)->numeric)].name->content);
+        break;
+      case PUSHER_SERVER_NUMERIC:
+        lua_pushint(l, homeserver(((nick *)offset)->numeric));
+        break;
     }
 
     i++;
@@ -1100,3 +1125,4 @@ void lua_initchanpusher(void) {
   chanpushercount = i;
   chanpusher[i].argtype = 0;
 }
+