X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/16739dbe741b18f928453637e73507a16c7c2091..efe18ab74e250b0e0a65e8c5fc42220ba091be04:/lua/luacommands.c diff --git a/lua/luacommands.c b/lua/luacommands.c index 0ad3267c..2ed3b2b8 100644 --- a/lua/luacommands.c +++ b/lua/luacommands.c @@ -16,6 +16,11 @@ #include "../localuser/localuserchannel.h" #include "../lib/irc_string.h" #include "../lib/flags.h" +#include "../authext/authext.h" +#include "../glines/glines.h" +#include "../trusts/trusts.h" +#include "../bans/bans.h" +#include "../core/modules.h" #include "lua.h" #include "luabot.h" @@ -38,8 +43,8 @@ struct lua_pusher nickpusher[MAX_PUSHER]; struct lua_pusher chanpusher[MAX_PUSHER]; int nickpushercount, chanpushercount; -INLINE void lua_setuppusher(struct lua_pusher *pusherlist, lua_State *l, int index, struct lua_pusher **lp, int max, int pcount); -INLINE int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np); +void lua_setuppusher(struct lua_pusher *pusherlist, lua_State *l, int index, struct lua_pusher **lp, int max, int pcount); +int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np); void lua_initnickpusher(void); void lua_initchanpusher(void); @@ -209,17 +214,16 @@ 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); } static int lua_gline(lua_State *ps) { + glineinfo *info; const char *reason; nick *target; - char mask[512]; - int duration, usercount = 0; - host *hp; + int duration; if(!lua_isstring(ps, 1) || !lua_isint(ps, 2) || !lua_isstring(ps, 3)) LUA_RETURN(ps, LUA_FAIL); @@ -236,32 +240,11 @@ 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;jnext) - 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); - LUA_RETURN(ps, lua_cmsg(LUA_PUKECHAN, "lua-GLINE: %s (%d users, %d seconds -- %s)", mask, usercount, duration, reason)); + info = glinebynickex(target, duration, reason, 0, "lua"); + LUA_RETURN(ps, lua_cmsg(LUA_PUKECHAN, "lua-GLINE: %s (%d users, %d seconds -- %s)", info->mask, info->hits, duration, reason)); } static int lua_fastgetchaninfo(lua_State *ps) { @@ -364,30 +347,161 @@ static int lua_versioninfo(lua_State *ps) { return 5; } +static int lua_nickmatchban(lua_State *ps) { + const char *chanban_str; + long numeric; + chanban *cb; + nick *np; + + if(!lua_islong(ps, 1) || !lua_isstring(ps, 2)) + return 0; + + numeric = lua_tolong(ps, 1); + chanban_str = lua_tostring(ps, 2); + + np = getnickbynumeric(numeric); + if(!np) + return 0; + + cb = makeban(chanban_str); + if(!cb) + return 0; + + lua_pushboolean(ps, nickmatchban(np, cb, 1)); + + freechanban(cb); + + return 1; +} + +static int lua_nickbanned(lua_State *ps) { + const char *channel_str; + long numeric; + channel *cp; + nick *np; + + if(!lua_islong(ps, 1) || !lua_isstring(ps, 2)) + return 0; + + numeric = lua_tolong(ps, 1); + channel_str = lua_tostring(ps, 2); + + np = getnickbynumeric(numeric); + if(!np) + return 0; + + cp = findchannel((char *)channel_str); + if(!cp) + return 0; + + lua_pushboolean(ps, nickbanned(np, cp, 1)); + + return 1; +} + +static int lua_suggestbanmask(lua_State *ps) { + nick *np; + glinebuf gb; + gline *gl; + long numeric; + int i = 1; + + if (!lua_islong(ps, 1)) + return 0; + + numeric = lua_tolong(ps, 1); + + np = getnickbynumeric(numeric); + if (!np) + return 0; + + glinebufinit(&gb, 0); + glinebufaddbynick(&gb, np, 0, "Auto", "None", time(NULL), time(NULL), time(NULL)); + + lua_newtable(ps); + + for (gl = gb.glines; gl; gl = gl->next) { + if (gl->host && gl->host->content) { + char *mask = glinetostring(gl); + LUA_APUSHSTRING(ps, i, mask); + i++; + } + } + + glinebufabort(&gb); + + return 1; +} + +static int lua_nickistrusted(lua_State *ps) { + long numeric; + nick *np; + + if(!lua_islong(ps, 1)) + return 0; + + numeric = lua_tolong(ps, 1); + + np = getnickbynumeric(numeric); + if(!np) + return 0; + + lua_pushboolean(ps, istrusted(np)); + + return 1; +} + static int lua_basepath(lua_State *ps) { lua_pushfstring(ps, "%s/", cpath->content); return 1; } -/* O(n) */ +static int lua_botnick(lua_State *ps) { + lua_pushstring(ps, luabotnick->content); + + return 1; +} + +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_pushboolean(ps, match2strings(mask, string)); + return 1; +} + 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;inext) { - 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; @@ -846,6 +960,7 @@ void lua_registercommands(lua_State *l) { lua_register(l, "chanmsg", lua_chanmsg); lua_register(l, "versioninfo", lua_versioninfo); lua_register(l, "basepath", lua_basepath); + lua_register(l, "botnick", lua_botnick); lua_register(l, "irc_report", lua_chanmsg); lua_register(l, "irc_ctcp", lua_ctcp); @@ -893,6 +1008,14 @@ 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, "ircmatch", lua_match); + + lua_register(l, "irc_nickmatchban", lua_nickmatchban); + lua_register(l, "irc_nickistrusted", lua_nickistrusted); + lua_register(l, "irc_nickbanned", lua_nickbanned); + lua_register(l, "irc_suggestbanmask", lua_suggestbanmask); } /* --- */ @@ -943,6 +1066,10 @@ 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 +#define PUSHER_IS_SERVICE 18 void lua_initnickpusher(void) { int i = 0; @@ -961,12 +1088,16 @@ 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"); + PUSH_NICKPUSHER_CUSTOM(PUSHER_IS_SERVICE, "isservice"); nickpushercount = i; nickpusher[i].argtype = 0; } -INLINE void lua_setuppusher(struct lua_pusher *pusherlist, lua_State *l, int index, struct lua_pusher **lp, int max, int pcount) { +void lua_setuppusher(struct lua_pusher *pusherlist, lua_State *l, int index, struct lua_pusher **lp, int max, int pcount) { int current = 0; if(max > 0) @@ -995,7 +1126,7 @@ INLINE void lua_setuppusher(struct lua_pusher *pusherlist, lua_State *l, int ind lp[current] = NULL; } -INLINE int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np) { +int lua_usepusher(lua_State *l, struct lua_pusher **lp, void *np) { int i = 0; while(*lp) { @@ -1032,6 +1163,16 @@ INLINE 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); @@ -1069,6 +1210,15 @@ INLINE 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; + case PUSHER_IS_SERVICE: + lua_pushboolean(l, NickOnServiceServer((nick *)offset)); + break; } i++; @@ -1093,3 +1243,4 @@ void lua_initchanpusher(void) { chanpushercount = i; chanpusher[i].argtype = 0; } +