]>
jfr.im git - irc/quakenet/newserv.git/blob - lua/luacommands.c
1 /* Copyright (C) Chris Porter 2005-2007 */
2 /* ALL RIGHTS RESERVED. */
3 /* Don't put this into the SVN repo. */
7 - Write a nick printf type thing for pcalled functions.
8 - Make commands register as apposed to blinding calling.
9 - Use numerics instead of huge structures, and add lookup functions.
12 #include "../channel/channel.h"
13 #include "../control/control.h"
14 #include "../nick/nick.h"
15 #include "../localuser/localuser.h"
16 #include "../localuser/localuserchannel.h"
17 #include "../lib/irc_string.h"
18 #include "../lib/flags.h"
19 #include "../authext/authext.h"
29 static int lua_smsg(lua_State
*ps
);
30 static int lua_skill(lua_State
*ps
);
32 typedef struct lua_pusher
{
35 const char *structname
;
38 struct lua_pusher nickpusher
[MAX_PUSHER
];
39 struct lua_pusher chanpusher
[MAX_PUSHER
];
40 int nickpushercount
, chanpushercount
;
42 void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
);
43 int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
);
45 void lua_initnickpusher(void);
46 void lua_initchanpusher(void);
48 #define lua_setupnickpusher(L2, I2, P2, M2) lua_setuppusher(&nickpusher[0], L2, I2, P2, M2, nickpushercount)
49 #define lua_setupchanpusher(L2, I2, P2, M2) lua_setuppusher(&chanpusher[0], L2, I2, P2, M2, chanpushercount)
51 int lua_cmsg(char *channell
, char *message
, ...) __attribute__ ((format (printf
, 2, 3)));
53 int lua_cmsg(char *channell
, char *message
, ...) {
58 va_start(va
, message
);
59 vsnprintf(buf
, sizeof(buf
), message
, va
);
62 cp
= findchannel(channell
);
69 lua_channelmessage(cp
, "%s", buf
);
74 static int lua_chanmsg(lua_State
*ps
) {
75 if(!lua_isstring(ps
, 1))
76 LUA_RETURN(ps
, LUA_FAIL
);
78 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua: %s", lua_tostring(ps
, 1)));
81 static int lua_ctcp(lua_State
*ps
) {
85 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
86 LUA_RETURN(ps
, LUA_FAIL
);
88 n
= lua_tostring(ps
, 1);
89 msg
= lua_tostring(ps
, 2);
91 np
= getnickbynick(n
);
92 if(!np
|| !lua_lineok(msg
))
93 LUA_RETURN(ps
, LUA_FAIL
);
95 lua_message(np
, "\001%s\001", msg
);
97 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-ctcp: %s (%s)", np
->nick
, msg
));
100 static int lua_noticecmd(lua_State
*ps
) {
104 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
105 LUA_RETURN(ps
, LUA_FAIL
);
107 n
= lua_tostring(ps
, 1);
108 msg
= lua_tostring(ps
, 2);
110 np
= getnickbynick(n
);
111 if(!np
|| !lua_lineok(msg
))
112 LUA_RETURN(ps
, LUA_FAIL
);
114 lua_notice(np
, "%s", msg
);
116 LUA_RETURN(ps
, LUA_OK
);
119 static int lua_privmsgcmd(lua_State
*ps
) {
123 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
124 LUA_RETURN(ps
, LUA_FAIL
);
126 n
= lua_tostring(ps
, 1);
127 msg
= lua_tostring(ps
, 2);
129 np
= getnickbynick(n
);
130 if(!np
|| !lua_lineok(msg
))
131 LUA_RETURN(ps
, LUA_FAIL
);
133 lua_message(np
, "%s", msg
);
135 LUA_RETURN(ps
, LUA_OK
);
138 static int lua_kill(lua_State
*ps
) {
142 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
143 LUA_RETURN(ps
, LUA_FAIL
);
145 n
= lua_tostring(ps
, 1);
146 msg
= lua_tostring(ps
, 2);
148 np
= getnickbynick(n
);
150 LUA_RETURN(ps
, LUA_FAIL
);
152 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
153 LUA_RETURN(ps
, LUA_FAIL
);
156 LUA_RETURN(ps
, LUA_FAIL
);
158 killuser(lua_nick
, np
, "%s", msg
);
160 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-KILL: %s (%s)", np
->nick
, msg
));
163 static int lua_kick(lua_State
*ps
) {
164 const char *n
, *msg
, *chan
;
169 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
170 LUA_RETURN(ps
, LUA_FAIL
);
172 chan
= lua_tostring(ps
, 1);
173 n
= lua_tostring(ps
, 2);
174 msg
= lua_tostring(ps
, 3);
176 if(lua_isboolean(ps
, 4) && !lua_toboolean(ps
, 4))
179 np
= getnickbynick(n
);
181 LUA_RETURN(ps
, LUA_FAIL
);
183 if(dochecks
&& (IsOper(np
) || IsXOper(np
) || IsService(np
)))
184 LUA_RETURN(ps
, LUA_FAIL
);
186 cp
= findchannel((char *)chan
);
188 LUA_RETURN(ps
, LUA_FAIL
);
191 LUA_RETURN(ps
, LUA_FAIL
);
193 localkickuser(lua_nick
, cp
, np
, msg
);
195 LUA_RETURN(ps
, LUA_OK
);
198 static int lua_invite(lua_State
*ps
) {
202 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
203 LUA_RETURN(ps
, LUA_FAIL
);
205 np
= getnickbynick((char *)lua_tostring(ps
, 1));
207 LUA_RETURN(ps
, LUA_FAIL
);
209 cp
= findchannel((char *)lua_tostring(ps
, 2));
211 LUA_RETURN(ps
, LUA_FAIL
);
213 localinvite(lua_nick
, cp
, np
);
215 LUA_RETURN(ps
, LUA_OK
);
218 static int lua_gline(lua_State
*ps
) {
222 int duration
, usercount
= 0;
225 if(!lua_isstring(ps
, 1) || !lua_isint(ps
, 2) || !lua_isstring(ps
, 3))
226 LUA_RETURN(ps
, LUA_FAIL
);
228 duration
= lua_toint(ps
, 2);
229 if((duration
< 1) || (duration
> 31 * 86400))
230 LUA_RETURN(ps
, LUA_FAIL
);
232 reason
= lua_tostring(ps
, 3);
233 if(!lua_lineok(reason
) || !reason
)
234 LUA_RETURN(ps
, LUA_FAIL
);
236 target
= getnickbynick(lua_tostring(ps
, 1));
237 if(!target
|| (IsOper(target
) || IsXOper(target
) || IsService(target
)))
238 LUA_RETURN(ps
, LUA_FAIL
);
242 LUA_RETURN(ps
, LUA_FAIL
);
244 usercount
= hp
->clonecount
;
245 if(usercount
> 10) { /* (decent) trusted host */
251 for (j
=0;j
<NICKHASHSIZE
;j
++)
252 for (np
=nicktable
[j
];np
;np
=np
->next
)
253 if (np
&& (np
->host
== hp
) && (!ircd_strcmp(np
->ident
, target
->ident
)))
257 LUA_RETURN(ps
, LUA_FAIL
);
259 snprintf(mask
, sizeof(mask
), "*%s@%s", target
->ident
, IPtostr(target
->p_ipaddr
));
261 snprintf(mask
, sizeof(mask
), "*@%s", IPtostr(target
->p_ipaddr
));
264 irc_send("%s GL * +%s %d :%s", mynumeric
->content
, mask
, duration
, reason
);
265 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-GLINE: %s (%d users, %d seconds -- %s)", mask
, usercount
, duration
, reason
));
268 static int lua_fastgetchaninfo(lua_State
*ps
) {
269 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
272 if(!lua_isstring(ps
, 1))
275 cp
= findchannel((char *)lua_tostring(ps
, 1));
276 if(!cp
|| cp
->index
->channel
!= cp
)
279 lua_setupchanpusher(ps
, 2, ourpusher
, MAX_PUSHER
);
280 return lua_usepusher(ps
, ourpusher
, cp
->index
);
283 static int lua_opchan(lua_State
*ps
) {
287 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
288 LUA_RETURN(ps
, LUA_FAIL
);
290 cp
= findchannel((char *)lua_tostring(ps
, 1));
292 LUA_RETURN(ps
, LUA_FAIL
);
294 np
= getnickbynick((char *)lua_tostring(ps
, 2));
296 LUA_RETURN(ps
, LUA_FAIL
);
298 localsetmodes(lua_nick
, cp
, np
, MC_OP
);
299 LUA_RETURN(ps
, LUA_OK
);
302 static int lua_deopchan(lua_State
*ps
) {
306 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
307 LUA_RETURN(ps
, LUA_FAIL
);
309 cp
= findchannel((char *)lua_tostring(ps
, 1));
311 LUA_RETURN(ps
, LUA_FAIL
);
313 np
= getnickbynick((char *)lua_tostring(ps
, 2));
315 LUA_RETURN(ps
, LUA_FAIL
);
317 localsetmodes(lua_nick
, cp
, np
, MC_DEOP
);
318 LUA_RETURN(ps
, LUA_OK
);
321 static int lua_voicechan(lua_State
*ps
) {
325 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
326 LUA_RETURN(ps
, LUA_FAIL
);
328 cp
= findchannel((char *)lua_tostring(ps
, 1));
330 LUA_RETURN(ps
, LUA_FAIL
);
332 np
= getnickbynick((char *)lua_tostring(ps
, 2));
334 LUA_RETURN(ps
, LUA_FAIL
);
336 localsetmodes(lua_nick
, cp
, np
, MC_VOICE
);
337 LUA_RETURN(ps
, LUA_OK
);
340 static int lua_counthost(lua_State
*ps
) {
344 if(!lua_islong(ps
, 1))
347 numeric
= lua_tolong(ps
, 1);
349 np
= getnickbynumeric(numeric
);
353 lua_pushint(ps
, np
->host
->clonecount
);
357 static int lua_versioninfo(lua_State
*ps
) {
358 lua_pushstring(ps
, LUA_VERSION
);
359 lua_pushstring(ps
, LUA_BOTVERSION
);
360 lua_pushstring(ps
, __DATE__
);
361 lua_pushstring(ps
, __TIME__
);
363 lua_pushstring(ps
, LUA_AUXVERSION
);
368 static int lua_basepath(lua_State
*ps
) {
369 lua_pushfstring(ps
, "%s/", cpath
->content
);
374 static int lua_botnick(lua_State
*ps
) {
375 lua_pushstring(ps
, luabotnick
->content
);
380 static int lua_getuserbyauth(lua_State
*l
) {
385 if(!lua_isstring(l
, 1))
388 au
= getauthbyname(lua_tostring(l
, 1));
392 for(np
=au
->nicks
;np
;np
=np
->nextbyauthname
) {
393 lua_pushnumeric(l
, np
->numeric
);
400 static int lua_getnickchans(lua_State
*l
) {
405 if(!lua_islong(l
, 1))
408 np
= getnickbynumeric(lua_tolong(l
, 1));
412 channels
= (channel
**)np
->channels
->content
;
413 for(i
=0;i
<np
->channels
->cursi
;i
++)
414 lua_pushstring(l
, channels
[i
]->index
->name
->content
);
416 return np
->channels
->cursi
;
419 static int lua_getnickchanindex(lua_State
*l
) {
423 if(!lua_islong(l
, 1) || !lua_isint(l
, 2))
426 np
= getnickbynumeric(lua_tolong(l
, 1));
430 offset
= lua_toint(l
, 2);
431 if((offset
< 0) || (offset
>= np
->channels
->cursi
))
434 lua_pushstring(l
, ((channel
**)np
->channels
->content
)[offset
]->index
->name
->content
);
443 struct lua_pusher
*nickhashpusher
[MAX_PUSHER
];
445 static int lua_getnextnick(lua_State
*l
) {
446 if(!lasthashnick
&& (hashindex
!= -1))
452 if(hashindex
>= NICKHASHSIZE
)
454 lasthashnick
= nicktable
[hashindex
];
456 lasthashnick
= lasthashnick
->next
;
458 } while(!lasthashnick
);
460 return lua_usepusher(l
, nickhashpusher
, lasthashnick
);
463 static int lua_getfirstnick(lua_State
*l
) {
467 lua_setupnickpusher(l
, 1, nickhashpusher
, MAX_PUSHER
);
468 geoipext
= findnickext("geoip");
470 return lua_getnextnick(l
);
474 chanindex
*lasthashchan
;
476 struct lua_pusher
*chanhashpusher
[MAX_PUSHER
];
478 static int lua_getnextchan(lua_State
*l
) {
479 if(!lasthashchan
&& (chanhashindex
!= -1))
485 if(chanhashindex
>= CHANNELHASHSIZE
)
487 lasthashchan
= chantable
[chanhashindex
];
489 lasthashchan
= lasthashchan
->next
;
491 } while(!lasthashchan
|| !lasthashchan
->channel
);
493 return lua_usepusher(l
, chanhashpusher
, lasthashchan
);
496 static int lua_getfirstchan(lua_State
*l
) {
500 lua_setupchanpusher(l
, 1, chanhashpusher
, MAX_PUSHER
);
502 return lua_getnextchan(l
);
505 static int lua_getnickchancount(lua_State
*l
) {
508 if(!lua_islong(l
, 1))
511 np
= getnickbynumeric(lua_tolong(l
, 1));
515 lua_pushint(l
, np
->channels
->cursi
);
520 static int lua_gethostusers(lua_State
*l
) {
524 if(!lua_islong(l
, 1))
527 np
= getnickbynumeric(lua_tolong(l
, 1));
528 if(!np
|| !np
->host
|| !np
->host
->nicks
)
531 np
= np
->host
->nicks
;
532 count
= np
->host
->clonecount
;
535 lua_pushnumeric(l
, np
->numeric
);
542 static int lua_getnickcountry(lua_State
*l
) {
546 ext
= findnickext("geoip");
550 if(!lua_islong(l
, 1))
553 np
= getnickbynumeric(lua_tolong(l
, 1));
557 lua_pushint(l
, (long)np
->exts
[ext
]);
561 static int lua_chanfix(lua_State
*ps
) {
565 if(!lua_isstring(ps
, 1))
566 LUA_RETURN(ps
, LUA_FAIL
);
568 cp
= findchannel((char *)lua_tostring(ps
, 1));
569 if(!cp
|| !cp
->index
)
570 LUA_RETURN(ps
, LUA_FAIL
);
572 np
= getnickbynick(LUA_CHANFIXBOT
);
574 LUA_RETURN(ps
, LUA_FAIL
);
576 lua_message(np
, "chanfix %s", cp
->index
->name
->content
);
578 LUA_RETURN(ps
, LUA_OK
);
581 static int lua_clearmode(lua_State
*ps
) {
588 if(!lua_isstring(ps
, 1))
589 LUA_RETURN(ps
, LUA_FAIL
);
591 cp
= findchannel((char *)lua_tostring(ps
, 1));
592 if(!cp
|| !cp
->users
)
593 LUA_RETURN(ps
, LUA_FAIL
);
595 localsetmodeinit(&changes
, cp
, lua_nick
);
597 localdosetmode_key(&changes
, NULL
, MCB_DEL
);
598 localdosetmode_simple(&changes
, 0, CHANMODE_INVITEONLY
| CHANMODE_LIMIT
);
601 localdosetmode_ban(&changes
, bantostring(cp
->bans
), MCB_DEL
);
603 for(i
=0,lp
=cp
->users
->content
;i
<cp
->users
->hashsize
;i
++,lp
++)
604 if((*lp
!= nouser
) && (*lp
& CUMODE_OP
)) {
605 np
= getnickbynumeric(*lp
);
606 if(np
&& !IsService(np
))
607 localdosetmode_nick(&changes
, np
, MC_DEOP
);
610 localsetmodeflush(&changes
, 1);
612 LUA_RETURN(ps
, LUA_OK
);
615 static int lua_ban(lua_State
*ps
) {
621 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
622 LUA_RETURN(ps
, LUA_FAIL
);
624 if(lua_isboolean(ps
, 3) && lua_toboolean(ps
, 3))
627 cp
= findchannel((char *)lua_tostring(ps
, 1));
629 LUA_RETURN(ps
, LUA_FAIL
);
631 mask
= lua_tostring(ps
, 2);
632 if(!mask
|| !mask
[0] || !lua_lineok(mask
))
633 LUA_RETURN(ps
, LUA_FAIL
);
635 localsetmodeinit(&changes
, cp
, lua_nick
);
636 localdosetmode_ban(&changes
, mask
, dir
);
637 localsetmodeflush(&changes
, 1);
639 LUA_RETURN(ps
, LUA_OK
);
642 static int lua_topic(lua_State
*ps
) {
646 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
647 LUA_RETURN(ps
, LUA_FAIL
);
649 cp
= findchannel((char *)lua_tostring(ps
, 1));
651 LUA_RETURN(ps
, LUA_FAIL
);
653 topic
= (char *)lua_tostring(ps
, 2);
654 if(!topic
|| !lua_lineok(topic
))
655 LUA_RETURN(ps
, LUA_FAIL
);
657 localsettopic(lua_nick
, cp
, topic
);
659 LUA_RETURN(ps
, LUA_OK
);
662 static int lua_getuserchanmodes(lua_State
*l
) {
667 if(!lua_islong(l
, 1) || !lua_isstring(l
, 2))
670 np
= getnickbynumeric(lua_tolong(l
, 1));
674 cp
= findchannel((char *)lua_tostring(l
, 2));
675 if(!cp
|| !cp
->users
)
678 lp
= getnumerichandlefromchanhash(cp
->users
, np
->numeric
);
682 LUA_PUSHNICKCHANMODES(l
, lp
);
686 static int lua_getusermodes(lua_State
*l
) {
689 if(!lua_islong(l
, 1))
692 np
= getnickbynumeric(lua_tolong(l
, 1));
696 lua_pushstring(l
, printflags(np
->umodes
, umodeflags
));
700 static int lua_fastgetnickbynumeric(lua_State
*l
) {
701 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
704 if(!lua_islong(l
, 1))
707 np
= getnickbynumeric(lua_tolong(l
, 1));
711 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
712 return lua_usepusher(l
, ourpusher
, np
);
715 static int lua_fastgetnickbynick(lua_State
*l
) {
716 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
719 if(!lua_isstring(l
, 1))
722 np
= getnickbynick((char *)lua_tostring(l
, 1));
726 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
727 return lua_usepusher(l
, ourpusher
, np
);
730 int channelnicklistindex
, channelnicklistcount
= -1;
731 channel
*channelnicklist
;
733 struct lua_pusher
*channelnickpusher
[MAX_PUSHER
];
735 static int lua_getnextchannick(lua_State
*l
) {
739 channelnicklistindex
++;
741 if(channelnicklistindex
>= channelnicklistcount
)
743 } while((channelnicklist
->users
->content
[channelnicklistindex
] == nouser
) || !(np
= getnickbynumeric(channelnicklist
->users
->content
[channelnicklistindex
])));
745 return lua_usepusher(l
, channelnickpusher
, np
);
748 static int lua_getfirstchannick(lua_State
*l
) {
749 if(!lua_isstring(l
, 1))
752 channelnicklist
= findchannel((char *)lua_tostring(l
, 1));
753 if(!channelnicklist
|| !channelnicklist
->users
)
756 channelnicklistindex
= -1;
757 channelnicklistcount
= channelnicklist
->users
->hashsize
;
759 lua_setupnickpusher(l
, 2, channelnickpusher
, MAX_PUSHER
);
761 return lua_getnextchannick(l
);
764 static int lua_nickonchan(lua_State
*l
) {
766 if(lua_islong(l
, 1) && lua_isstring(l
, 2)) {
767 channel
*cp
= findchannel((char *)lua_tostring(l
, 2));
768 if(cp
&& cp
->users
) {
769 unsigned long *lp
= getnumerichandlefromchanhash(cp
->users
, lua_tolong(l
, 1));
775 lua_pushboolean(l
, success
);
779 static int lua_simplechanmode(lua_State
*ps
) {
782 flag_t add
= 0, del
= ~add
;
783 flag_t permitted
= CHANMODE_NOEXTMSG
| CHANMODE_TOPICLIMIT
| CHANMODE_SECRET
| CHANMODE_PRIVATE
| CHANMODE_INVITEONLY
| CHANMODE_MODERATE
| CHANMODE_NOCOLOUR
| CHANMODE_NOCTCP
| CHANMODE_REGONLY
| CHANMODE_DELJOINS
| CHANMODE_NOQUITMSG
| CHANMODE_NONOTICE
| CHANMODE_MODNOAUTH
| CHANMODE_SINGLETARG
;
786 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
787 LUA_RETURN(ps
, LUA_FAIL
);
789 cp
= findchannel((char *)lua_tostring(ps
, 1));
791 LUA_RETURN(ps
, LUA_FAIL
);
793 modes
= (char *)lua_tostring(ps
, 2);
795 LUA_RETURN(ps
, LUA_FAIL
);
797 if(setflags(&add
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
798 LUA_RETURN(ps
, LUA_FAIL
);
800 if(setflags(&del
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
801 LUA_RETURN(ps
, LUA_FAIL
);
803 localsetmodeinit(&changes
, cp
, lua_nick
);
804 localdosetmode_simple(&changes
, add
, ~del
);
805 localsetmodeflush(&changes
, 1);
807 LUA_RETURN(ps
, LUA_OK
);
810 static int lua_sethost(lua_State
*ps
) {
814 if(!lua_islong(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
815 LUA_RETURN(ps
, LUA_FAIL
);
817 np
= getnickbynumeric(lua_tolong(ps
, 1));
819 LUA_RETURN(ps
, LUA_FAIL
);
821 ident
= (char *)lua_tostring(ps
, 2);
822 host
= (char *)lua_tostring(ps
, 3);
823 if(!lua_lineok(ident
) || !lua_lineok(host
))
824 LUA_RETURN(ps
, LUA_FAIL
);
826 sethostuser(np
, ident
, host
);
828 LUA_RETURN(ps
, LUA_OK
);
831 static int lua_getvisiblehostmask(lua_State
*l
) {
833 char buf
[HOSTLEN
+USERLEN
+NICKLEN
+REALLEN
+10];
835 if(!lua_islong(l
, 1))
838 np
= getnickbynumeric(lua_tolong(l
, 1));
842 lua_pushstring(l
, visiblehostmask(np
, buf
));
846 void lua_registercommands(lua_State
*l
) {
847 lua_register(l
, "irc_smsg", lua_smsg
);
848 lua_register(l
, "irc_skill", lua_skill
);
850 lua_register(l
, "chanmsg", lua_chanmsg
);
851 lua_register(l
, "versioninfo", lua_versioninfo
);
852 lua_register(l
, "basepath", lua_basepath
);
853 lua_register(l
, "botnick", lua_botnick
);
855 lua_register(l
, "irc_report", lua_chanmsg
);
856 lua_register(l
, "irc_ctcp", lua_ctcp
);
857 lua_register(l
, "irc_kill", lua_kill
);
858 lua_register(l
, "irc_kick", lua_kick
);
859 lua_register(l
, "irc_invite", lua_invite
);
860 lua_register(l
, "irc_gline", lua_gline
);
861 lua_register(l
, "irc_counthost", lua_counthost
);
862 lua_register(l
, "irc_getuserbyauth", lua_getuserbyauth
);
863 lua_register(l
, "irc_notice", lua_noticecmd
);
864 lua_register(l
, "irc_privmsg", lua_privmsgcmd
);
865 lua_register(l
, "irc_opchan", lua_opchan
);
866 lua_register(l
, "irc_voicechan", lua_voicechan
);
867 lua_register(l
, "irc_chanfix", lua_chanfix
);
868 lua_register(l
, "irc_clearmode", lua_clearmode
);
869 lua_register(l
, "irc_ban", lua_ban
);
870 lua_register(l
, "irc_deopchan", lua_deopchan
);
871 lua_register(l
, "irc_topic", lua_topic
);
873 lua_register(l
, "irc_getfirstnick", lua_getfirstnick
);
874 lua_register(l
, "irc_getnextnick", lua_getnextnick
);
876 lua_register(l
, "irc_getnickchans", lua_getnickchans
);
877 lua_register(l
, "irc_getnickchanindex", lua_getnickchanindex
);
878 lua_register(l
, "irc_getnickchancount", lua_getnickchancount
);
880 lua_register(l
, "irc_getuserchanmodes", lua_getuserchanmodes
);
882 lua_register(l
, "irc_getfirstchannick", lua_getfirstchannick
);
883 lua_register(l
, "irc_getnextchannick", lua_getnextchannick
);
885 lua_register(l
, "irc_gethostusers", lua_gethostusers
);
886 lua_register(l
, "irc_getnickcountry", lua_getnickcountry
);
888 lua_register(l
, "irc_getfirstchan", lua_getfirstchan
);
889 lua_register(l
, "irc_getnextchan", lua_getnextchan
);
890 lua_register(l
, "irc_getusermodes", lua_getusermodes
);
891 lua_register(l
, "irc_nickonchan", lua_nickonchan
);
893 lua_register(l
, "irc_fastgetnickbynumeric", lua_fastgetnickbynumeric
);
894 lua_register(l
, "irc_fastgetnickbynick", lua_fastgetnickbynick
);
895 lua_register(l
, "irc_fastgetchaninfo", lua_fastgetchaninfo
);
897 lua_register(l
, "irc_getvisiblehostmask", lua_getvisiblehostmask
);
899 lua_register(l
, "irc_simplechanmode", lua_simplechanmode
);
900 lua_register(l
, "irc_sethost", lua_sethost
);
905 static int lua_smsg(lua_State
*ps
) {
906 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
907 LUA_RETURN(ps
, LUA_FAIL
);
909 LUA_RETURN(ps
, lua_cmsg((char *)lua_tostring(ps
, 2), "%s", lua_tostring(ps
, 1)));
912 static int lua_skill(lua_State
*ps
) {
916 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
917 LUA_RETURN(ps
, LUA_FAIL
);
919 n
= lua_tostring(ps
, 1);
920 msg
= lua_tostring(ps
, 2);
922 np
= getnickbynick(n
);
924 LUA_RETURN(ps
, LUA_FAIL
);
926 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
927 LUA_RETURN(ps
, LUA_FAIL
);
930 LUA_RETURN(ps
, LUA_FAIL
);
932 killuser(lua_nick
, np
, "%s", msg
);
934 LUA_RETURN(ps
, LUA_OK
);
937 #define PUSHER_STRING 1
938 #define PUSHER_REALNAME 2
940 #define PUSHER_LONG 4
941 #define PUSHER_HOSTNAME 5
942 #define PUSHER_SSTRING 6
943 #define PUSHER_TOTALUSERS 7
944 #define PUSHER_TOPIC 8
945 #define PUSHER_UMODES 9
946 #define PUSHER_COUNTRY 10
947 #define PUSHER_REALUSERS 11
948 #define PUSHER_CHANMODES 12
949 #define PUSHER_TIMESTAMP 13
950 #define PUSHER_STRING_INDIRECT 14
952 void lua_initnickpusher(void) {
955 #define PUSH_NICKPUSHER(F2, O2) nickpusher[i].argtype = F2; nickpusher[i].structname = #O2; nickpusher[i].offset = offsetof(nick, O2); i++;
956 #define PUSH_NICKPUSHER_CUSTOM(F2, custom) nickpusher[i].argtype = F2; nickpusher[i].structname = custom; nickpusher[i].offset = 0; i++;
958 PUSH_NICKPUSHER(PUSHER_STRING
, nick
);
959 PUSH_NICKPUSHER(PUSHER_STRING
, ident
);
960 PUSH_NICKPUSHER(PUSHER_HOSTNAME
, host
);
961 PUSH_NICKPUSHER(PUSHER_REALNAME
, realname
);
962 PUSH_NICKPUSHER(PUSHER_STRING_INDIRECT
, authname
);
963 PUSH_NICKPUSHER(PUSHER_IP
, ipnode
);
964 PUSH_NICKPUSHER(PUSHER_LONG
, numeric
);
965 PUSH_NICKPUSHER(PUSHER_LONG
, timestamp
);
966 PUSH_NICKPUSHER(PUSHER_LONG
, accountts
);
967 PUSH_NICKPUSHER(PUSHER_UMODES
, umodes
);
968 PUSH_NICKPUSHER_CUSTOM(PUSHER_COUNTRY
, "country");
971 nickpusher
[i
].argtype
= 0;
974 void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
) {
980 if(!lua_istable(l
, index
) || (max
< 2))
987 while(lua_next(l
, index
)) {
988 if(lua_isint(l
, -1)) {
989 int index
= lua_toint(l
, -1);
990 if((index
>= 0) && (index
< pcount
))
991 lp
[current
++] = &pusherlist
[index
];
1003 int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
) {
1007 void *offset
= (void *)np
+ (*lp
)->offset
;
1009 switch((*lp
)->argtype
) {
1011 lua_pushstring(l
, (char *)offset
);
1013 case PUSHER_STRING_INDIRECT
:
1014 lua_pushstring(l
, *(char **)offset
);
1016 case PUSHER_HOSTNAME
:
1017 lua_pushstring(l
, (*(host
**)offset
)->name
->content
);
1019 case PUSHER_REALNAME
:
1020 lua_pushstring(l
, (*(realname
**)offset
)->name
->content
);
1022 case PUSHER_SSTRING
:
1023 lua_pushstring(l
, (*((sstring
**)offset
))->content
);
1026 lua_pushlong(l
, *((long *)offset
));
1028 case PUSHER_TIMESTAMP
:
1029 lua_pushlong(l
, (*((channel
**)offset
))->timestamp
);
1032 lua_pushstring(l
, IPtostr((*((patricia_node_t
**)offset
))->prefix
->sin
));
1034 case PUSHER_TOTALUSERS
:
1035 lua_pushint(l
, (*((channel
**)offset
))->users
->totalusers
);
1037 case PUSHER_CHANMODES
:
1038 lua_pushstring(l
, printallmodes(*((channel
**)offset
)));
1040 case PUSHER_REALUSERS
:
1042 channel
*cp
= *((channel
**)offset
);
1044 int i
, currentusers
= countuniquehosts(cp
);
1045 for(i
=0;i
<cp
->users
->hashsize
;i
++) {
1046 if(cp
->users
->content
[i
]==nouser
)
1049 if((np2
=getnickbynumeric(cp
->users
->content
[i
]))==NULL
) {
1050 Error("lua", ERR_ERROR
, "Found unknown numeric %lu on channel %s", cp
->users
->content
[i
], cp
->index
->name
->content
);
1054 if (IsXOper(np2
) || IsService(np2
))
1057 lua_pushint(l
, currentusers
);
1061 lua_pushstring(l
, printflags(*((flag_t
*)offset
), umodeflags
));
1064 if((*((channel
**)offset
))->topic
) {
1065 lua_pushstring(l
, (*((channel
**)offset
))->topic
->content
);
1070 case PUSHER_COUNTRY
:
1074 lua_pushint(l
, (long)((nick
*)offset
)->exts
[geoipext
]);
1086 void lua_initchanpusher(void) {
1089 #define PUSH_CHANPUSHER(F2, O2, N2) chanpusher[i].argtype = F2; chanpusher[i].structname = N2; chanpusher[i].offset = offsetof(chanindex, O2); i++;
1091 PUSH_CHANPUSHER(PUSHER_SSTRING
, name
, "name");
1092 PUSH_CHANPUSHER(PUSHER_TOTALUSERS
, channel
, "totalusers");
1093 PUSH_CHANPUSHER(PUSHER_TOPIC
, channel
, "topic");
1094 PUSH_CHANPUSHER(PUSHER_REALUSERS
, channel
, "realusers");
1095 PUSH_CHANPUSHER(PUSHER_TIMESTAMP
, channel
, "timestamp");
1096 PUSH_CHANPUSHER(PUSHER_CHANMODES
, channel
, "modes");
1098 chanpushercount
= i
;
1099 chanpusher
[i
].argtype
= 0;