]>
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"
28 static int lua_smsg(lua_State
*ps
);
29 static int lua_skill(lua_State
*ps
);
31 typedef struct lua_pusher
{
34 const char *structname
;
37 struct lua_pusher nickpusher
[MAX_PUSHER
];
38 struct lua_pusher chanpusher
[MAX_PUSHER
];
39 int nickpushercount
, chanpushercount
;
41 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
);
42 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
);
44 void lua_initnickpusher(void);
45 void lua_initchanpusher(void);
47 #define lua_setupnickpusher(L2, I2, P2, M2) lua_setuppusher(&nickpusher[0], L2, I2, P2, M2, nickpushercount)
48 #define lua_setupchanpusher(L2, I2, P2, M2) lua_setuppusher(&chanpusher[0], L2, I2, P2, M2, chanpushercount)
50 int lua_cmsg(char *channell
, char *message
, ...) {
55 va_start(va
, message
);
56 vsnprintf(buf
, sizeof(buf
), message
, va
);
59 cp
= findchannel(channell
);
66 lua_channelmessage(cp
, "%s", buf
);
71 static int lua_chanmsg(lua_State
*ps
) {
72 if(!lua_isstring(ps
, 1))
73 LUA_RETURN(ps
, LUA_FAIL
);
75 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua: %s", lua_tostring(ps
, 1)));
78 static int lua_ctcp(lua_State
*ps
) {
82 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
83 LUA_RETURN(ps
, LUA_FAIL
);
85 n
= lua_tostring(ps
, 1);
86 msg
= lua_tostring(ps
, 2);
88 np
= getnickbynick(n
);
89 if(!np
|| !lua_lineok(msg
))
90 LUA_RETURN(ps
, LUA_FAIL
);
92 lua_message(np
, "\001%s\001", msg
);
94 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-ctcp: %s (%s)", np
->nick
, msg
));
97 static int lua_noticecmd(lua_State
*ps
) {
101 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
102 LUA_RETURN(ps
, LUA_FAIL
);
104 n
= lua_tostring(ps
, 1);
105 msg
= lua_tostring(ps
, 2);
107 np
= getnickbynick(n
);
108 if(!np
|| !lua_lineok(msg
))
109 LUA_RETURN(ps
, LUA_FAIL
);
111 lua_notice(np
, "%s", msg
);
113 LUA_RETURN(ps
, LUA_OK
);
116 static int lua_privmsgcmd(lua_State
*ps
) {
120 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
121 LUA_RETURN(ps
, LUA_FAIL
);
123 n
= lua_tostring(ps
, 1);
124 msg
= lua_tostring(ps
, 2);
126 np
= getnickbynick(n
);
127 if(!np
|| !lua_lineok(msg
))
128 LUA_RETURN(ps
, LUA_FAIL
);
130 lua_message(np
, "%s", msg
);
132 LUA_RETURN(ps
, LUA_OK
);
135 static int lua_kill(lua_State
*ps
) {
139 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
140 LUA_RETURN(ps
, LUA_FAIL
);
142 n
= lua_tostring(ps
, 1);
143 msg
= lua_tostring(ps
, 2);
145 np
= getnickbynick(n
);
147 LUA_RETURN(ps
, LUA_FAIL
);
149 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
150 LUA_RETURN(ps
, LUA_FAIL
);
153 LUA_RETURN(ps
, LUA_FAIL
);
155 killuser(lua_nick
, np
, "%s", msg
);
157 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-KILL: %s (%s)", np
->nick
, msg
));
160 static int lua_kick(lua_State
*ps
) {
161 const char *n
, *msg
, *chan
;
166 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
167 LUA_RETURN(ps
, LUA_FAIL
);
169 chan
= lua_tostring(ps
, 1);
170 n
= lua_tostring(ps
, 2);
171 msg
= lua_tostring(ps
, 3);
173 if(lua_isboolean(ps
, 4) && !lua_toboolean(ps
, 4))
176 np
= getnickbynick(n
);
178 LUA_RETURN(ps
, LUA_FAIL
);
180 if(dochecks
&& (IsOper(np
) || IsXOper(np
) || IsService(np
)))
181 LUA_RETURN(ps
, LUA_FAIL
);
183 cp
= findchannel((char *)chan
);
185 LUA_RETURN(ps
, LUA_FAIL
);
188 LUA_RETURN(ps
, LUA_FAIL
);
190 localkickuser(lua_nick
, cp
, np
, msg
);
192 LUA_RETURN(ps
, LUA_OK
);
195 static int lua_invite(lua_State
*ps
) {
199 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
200 LUA_RETURN(ps
, LUA_FAIL
);
202 np
= getnickbynick((char *)lua_tostring(ps
, 1));
204 LUA_RETURN(ps
, LUA_FAIL
);
206 cp
= findchannel((char *)lua_tostring(ps
, 2));
208 LUA_RETURN(ps
, LUA_FAIL
);
210 localinvite(lua_nick
, cp
, np
);
212 LUA_RETURN(ps
, LUA_OK
);
215 static int lua_gline(lua_State
*ps
) {
219 int duration
, usercount
= 0;
222 if(!lua_isstring(ps
, 1) || !lua_isint(ps
, 2) || !lua_isstring(ps
, 3))
223 LUA_RETURN(ps
, LUA_FAIL
);
225 duration
= lua_toint(ps
, 2);
226 if((duration
< 1) || (duration
> 31 * 86400))
227 LUA_RETURN(ps
, LUA_FAIL
);
229 reason
= lua_tostring(ps
, 3);
230 if(!lua_lineok(reason
) || !reason
)
231 LUA_RETURN(ps
, LUA_FAIL
);
233 target
= getnickbynick(lua_tostring(ps
, 1));
234 if(!target
|| (IsOper(target
) || IsXOper(target
) || IsService(target
)))
235 LUA_RETURN(ps
, LUA_FAIL
);
239 LUA_RETURN(ps
, LUA_FAIL
);
241 usercount
= hp
->clonecount
;
242 if(usercount
> 10) { /* (decent) trusted host */
248 for (j
=0;j
<NICKHASHSIZE
;j
++)
249 for (np
=nicktable
[j
];np
;np
=np
->next
)
250 if (np
&& (np
->host
== hp
) && (!ircd_strcmp(np
->ident
, target
->ident
)))
254 LUA_RETURN(ps
, LUA_FAIL
);
256 snprintf(mask
, sizeof(mask
), "*%s@%s", target
->ident
, IPtostr(target
->p_ipaddr
));
258 snprintf(mask
, sizeof(mask
), "*@%s", IPtostr(target
->p_ipaddr
));
261 irc_send("%s GL * +%s %d :%s", mynumeric
->content
, mask
, duration
, reason
);
262 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-GLINE: %s (%d users, %d seconds -- %s)", mask
, usercount
, duration
, reason
));
265 static int lua_getchaninfo(lua_State
*ps
) {
268 if(!lua_isstring(ps
, 1))
271 cp
= findchannel((char *)lua_tostring(ps
, 1));
275 LUA_PUSHCHAN(ps
, cp
);
280 static int lua_opchan(lua_State
*ps
) {
284 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
285 LUA_RETURN(ps
, LUA_FAIL
);
287 cp
= findchannel((char *)lua_tostring(ps
, 1));
289 LUA_RETURN(ps
, LUA_FAIL
);
291 np
= getnickbynick((char *)lua_tostring(ps
, 2));
293 LUA_RETURN(ps
, LUA_FAIL
);
295 localsetmodes(lua_nick
, cp
, np
, MC_OP
);
296 LUA_RETURN(ps
, LUA_OK
);
299 static int lua_deopchan(lua_State
*ps
) {
303 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
304 LUA_RETURN(ps
, LUA_FAIL
);
306 cp
= findchannel((char *)lua_tostring(ps
, 1));
308 LUA_RETURN(ps
, LUA_FAIL
);
310 np
= getnickbynick((char *)lua_tostring(ps
, 2));
312 LUA_RETURN(ps
, LUA_FAIL
);
314 localsetmodes(lua_nick
, cp
, np
, MC_DEOP
);
315 LUA_RETURN(ps
, LUA_OK
);
318 static int lua_voicechan(lua_State
*ps
) {
322 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
323 LUA_RETURN(ps
, LUA_FAIL
);
325 cp
= findchannel((char *)lua_tostring(ps
, 1));
327 LUA_RETURN(ps
, LUA_FAIL
);
329 np
= getnickbynick((char *)lua_tostring(ps
, 2));
331 LUA_RETURN(ps
, LUA_FAIL
);
333 localsetmodes(lua_nick
, cp
, np
, MC_VOICE
);
334 LUA_RETURN(ps
, LUA_OK
);
337 static int lua_counthost(lua_State
*ps
) {
341 if(!lua_islong(ps
, 1))
344 numeric
= lua_tolong(ps
, 1);
346 np
= getnickbynumeric(numeric
);
350 lua_pushint(ps
, np
->host
->clonecount
);
354 static int lua_versioninfo(lua_State
*ps
) {
355 lua_pushstring(ps
, LUA_VERSION
);
356 lua_pushstring(ps
, LUA_BOTVERSION
);
357 lua_pushstring(ps
, __DATE__
);
358 lua_pushstring(ps
, __TIME__
);
360 lua_pushstring(ps
, LUA_AUXVERSION
);
365 static int lua_basepath(lua_State
*ps
) {
366 lua_pushfstring(ps
, "%s/", cpath
->content
);
372 static int lua_getuserbyauth(lua_State
*l
) {
377 if(!lua_isstring(l
, 1))
380 acc
= lua_tostring(l
, 1);
382 for(i
=0;i
<NICKHASHSIZE
;i
++) {
383 for(np
=nicktable
[i
];np
;np
=np
->next
) {
384 if(np
&& np
->authname
&& !ircd_strcmp(np
->authname
, acc
)) {
394 static int lua_getnickchans(lua_State
*l
) {
399 if(!lua_islong(l
, 1))
402 np
= getnickbynumeric(lua_tolong(l
, 1));
406 channels
= (channel
**)np
->channels
->content
;
407 for(i
=0;i
<np
->channels
->cursi
;i
++)
408 lua_pushstring(l
, channels
[i
]->index
->name
->content
);
410 return np
->channels
->cursi
;
413 static int lua_getnickchanindex(lua_State
*l
) {
417 if(!lua_islong(l
, 1) || !lua_isint(l
, 2))
420 np
= getnickbynumeric(lua_tolong(l
, 1));
424 offset
= lua_toint(l
, 2);
425 if((offset
< 0) || (offset
>= np
->channels
->cursi
))
428 lua_pushstring(l
, ((channel
**)np
->channels
->content
)[offset
]->index
->name
->content
);
437 struct lua_pusher
*nickhashpusher
[MAX_PUSHER
];
439 static int lua_getnextnick(lua_State
*l
) {
440 if(!lasthashnick
&& (hashindex
!= -1))
446 if(hashindex
>= NICKHASHSIZE
)
448 lasthashnick
= nicktable
[hashindex
];
450 lasthashnick
= lasthashnick
->next
;
452 } while(!lasthashnick
);
454 return lua_usepusher(l
, nickhashpusher
, lasthashnick
);
457 static int lua_getfirstnick(lua_State
*l
) {
461 lua_setupnickpusher(l
, 1, nickhashpusher
, MAX_PUSHER
);
462 geoipext
= findnickext("geoip");
464 return lua_getnextnick(l
);
468 chanindex
*lasthashchan
;
470 struct lua_pusher
*chanhashpusher
[MAX_PUSHER
];
472 static int lua_getnextchan(lua_State
*l
) {
473 if(!lasthashchan
&& (chanhashindex
!= -1))
479 if(chanhashindex
>= CHANNELHASHSIZE
)
481 lasthashchan
= chantable
[chanhashindex
];
483 lasthashchan
= lasthashchan
->next
;
485 } while(!lasthashchan
|| !lasthashchan
->channel
);
487 return lua_usepusher(l
, chanhashpusher
, lasthashchan
);
490 static int lua_getfirstchan(lua_State
*l
) {
494 lua_setupchanpusher(l
, 1, chanhashpusher
, MAX_PUSHER
);
496 return lua_getnextchan(l
);
499 static int lua_getnickchancount(lua_State
*l
) {
502 if(!lua_islong(l
, 1))
505 np
= getnickbynumeric(lua_tolong(l
, 1));
509 lua_pushint(l
, np
->channels
->cursi
);
514 static int lua_gethostusers(lua_State
*l
) {
518 if(!lua_islong(l
, 1))
521 np
= getnickbynumeric(lua_tolong(l
, 1));
522 if(!np
|| !np
->host
|| !np
->host
->nicks
)
525 np
= np
->host
->nicks
;
526 count
= np
->host
->clonecount
;
536 static int lua_getnickcountry(lua_State
*l
) {
540 ext
= findnickext("geoip");
544 if(!lua_islong(l
, 1))
547 np
= getnickbynumeric(lua_tolong(l
, 1));
551 lua_pushint(l
, (long)np
->exts
[ext
]);
555 static int lua_chanfix(lua_State
*ps
) {
559 if(!lua_isstring(ps
, 1))
560 LUA_RETURN(ps
, LUA_FAIL
);
562 cp
= findchannel((char *)lua_tostring(ps
, 1));
563 if(!cp
|| !cp
->index
)
564 LUA_RETURN(ps
, LUA_FAIL
);
566 np
= getnickbynick(LUA_CHANFIXBOT
);
568 LUA_RETURN(ps
, LUA_FAIL
);
570 lua_message(np
, "chanfix %s", cp
->index
->name
->content
);
572 LUA_RETURN(ps
, LUA_OK
);
575 static int lua_clearmode(lua_State
*ps
) {
582 if(!lua_isstring(ps
, 1))
583 LUA_RETURN(ps
, LUA_FAIL
);
585 cp
= findchannel((char *)lua_tostring(ps
, 1));
586 if(!cp
|| !cp
->users
)
587 LUA_RETURN(ps
, LUA_FAIL
);
589 localsetmodeinit(&changes
, cp
, lua_nick
);
591 localdosetmode_key(&changes
, NULL
, MCB_DEL
);
592 localdosetmode_simple(&changes
, 0, CHANMODE_INVITEONLY
| CHANMODE_LIMIT
);
595 localdosetmode_ban(&changes
, bantostring(cp
->bans
), MCB_DEL
);
597 for(i
=0,lp
=cp
->users
->content
;i
<cp
->users
->hashsize
;i
++,lp
++)
598 if((*lp
!= nouser
) && (*lp
& CUMODE_OP
)) {
599 np
= getnickbynumeric(*lp
);
600 if(np
&& !IsService(np
))
601 localdosetmode_nick(&changes
, np
, MC_DEOP
);
604 localsetmodeflush(&changes
, 1);
606 LUA_RETURN(ps
, LUA_OK
);
609 static int lua_ban(lua_State
*ps
) {
615 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
616 LUA_RETURN(ps
, LUA_FAIL
);
618 if(lua_isboolean(ps
, 3) && lua_toboolean(ps
, 3))
621 cp
= findchannel((char *)lua_tostring(ps
, 1));
623 LUA_RETURN(ps
, LUA_FAIL
);
625 mask
= lua_tostring(ps
, 2);
626 if(!mask
|| !mask
[0] || !lua_lineok(mask
))
627 LUA_RETURN(ps
, LUA_FAIL
);
629 localsetmodeinit(&changes
, cp
, lua_nick
);
630 localdosetmode_ban(&changes
, mask
, dir
);
631 localsetmodeflush(&changes
, 1);
633 LUA_RETURN(ps
, LUA_OK
);
636 static int lua_topic(lua_State
*ps
) {
640 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
641 LUA_RETURN(ps
, LUA_FAIL
);
643 cp
= findchannel((char *)lua_tostring(ps
, 1));
645 LUA_RETURN(ps
, LUA_FAIL
);
647 topic
= (char *)lua_tostring(ps
, 2);
648 if(!topic
|| !lua_lineok(topic
))
649 LUA_RETURN(ps
, LUA_FAIL
);
651 localsettopic(lua_nick
, cp
, topic
);
653 LUA_RETURN(ps
, LUA_OK
);
656 static int lua_getuserchanmodes(lua_State
*l
) {
661 if(!lua_islong(l
, 1) || !lua_isstring(l
, 2))
664 np
= getnickbynumeric(lua_tolong(l
, 1));
668 cp
= findchannel((char *)lua_tostring(l
, 2));
669 if(!cp
|| !cp
->users
)
672 lp
= getnumerichandlefromchanhash(cp
->users
, np
->numeric
);
676 LUA_PUSHNICKCHANMODES(l
, lp
);
680 static int lua_getusermodes(lua_State
*l
) {
683 if(!lua_islong(l
, 1))
686 np
= getnickbynumeric(lua_tolong(l
, 1));
690 lua_pushstring(l
, printflags(np
->umodes
, umodeflags
));
694 static int lua_getnickbynick(lua_State
*l
) {
697 if(!lua_isstring(l
, 1))
700 np
= getnickbynick(lua_tostring(l
, 1));
708 static int lua_getnickbynumeric(lua_State
*l
) {
711 if(!lua_islong(l
, 1))
714 np
= getnickbynumeric(lua_tolong(l
, 1));
722 static int lua_fastgetnickbynumeric(lua_State
*l
) {
723 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
726 if(!lua_islong(l
, 1))
729 np
= getnickbynumeric(lua_tolong(l
, 1));
733 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
734 return lua_usepusher(l
, ourpusher
, np
);
737 int channelnicklistindex
, channelnicklistcount
= -1;
738 channel
*channelnicklist
;
740 struct lua_pusher
*channelnickpusher
[MAX_PUSHER
];
742 static int lua_getnextchannick(lua_State
*l
) {
746 channelnicklistindex
++;
748 if(channelnicklistindex
>= channelnicklistcount
)
750 } while((channelnicklist
->users
->content
[channelnicklistindex
] == nouser
) || !(np
= getnickbynumeric(channelnicklist
->users
->content
[channelnicklistindex
])));
752 return lua_usepusher(l
, channelnickpusher
, np
);
755 static int lua_getfirstchannick(lua_State
*l
) {
756 if(!lua_isstring(l
, 1))
759 channelnicklist
= findchannel((char *)lua_tostring(l
, 1));
760 if(!channelnicklist
|| !channelnicklist
->users
)
763 channelnicklistindex
= -1;
764 channelnicklistcount
= channelnicklist
->users
->hashsize
;
766 lua_setupnickpusher(l
, 2, channelnickpusher
, MAX_PUSHER
);
768 return lua_getnextchannick(l
);
771 static int lua_nickonchan(lua_State
*l
) {
773 if(lua_islong(l
, 1) && lua_isstring(l
, 2)) {
774 channel
*cp
= findchannel((char *)lua_tostring(l
, 2));
775 if(cp
&& cp
->users
) {
776 unsigned long *lp
= getnumerichandlefromchanhash(cp
->users
, lua_tolong(l
, 1));
782 lua_pushboolean(l
, success
);
786 static int lua_simplechanmode(lua_State
*ps
) {
789 flag_t add
= 0, del
= ~add
;
790 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
;
793 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
794 LUA_RETURN(ps
, LUA_FAIL
);
796 cp
= findchannel((char *)lua_tostring(ps
, 1));
798 LUA_RETURN(ps
, LUA_FAIL
);
800 modes
= (char *)lua_tostring(ps
, 2);
802 LUA_RETURN(ps
, LUA_FAIL
);
804 if(setflags(&add
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
805 LUA_RETURN(ps
, LUA_FAIL
);
807 if(setflags(&del
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
808 LUA_RETURN(ps
, LUA_FAIL
);
810 localsetmodeinit(&changes
, cp
, lua_nick
);
811 localdosetmode_simple(&changes
, add
, ~del
);
812 localsetmodeflush(&changes
, 1);
814 LUA_RETURN(ps
, LUA_OK
);
817 static int lua_sethost(lua_State
*ps
) {
821 if(!lua_islong(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
822 LUA_RETURN(ps
, LUA_FAIL
);
824 np
= getnickbynumeric(lua_tolong(ps
, 1));
826 LUA_RETURN(ps
, LUA_FAIL
);
828 ident
= (char *)lua_tostring(ps
, 2);
829 host
= (char *)lua_tostring(ps
, 3);
830 if(!lua_lineok(ident
) || !lua_lineok(host
))
831 LUA_RETURN(ps
, LUA_FAIL
);
833 sethostuser(np
, ident
, host
);
835 LUA_RETURN(ps
, LUA_OK
);
838 void lua_registercommands(lua_State
*l
) {
839 lua_register(l
, "irc_smsg", lua_smsg
);
840 lua_register(l
, "irc_skill", lua_skill
);
842 lua_register(l
, "chanmsg", lua_chanmsg
);
843 lua_register(l
, "versioninfo", lua_versioninfo
);
844 lua_register(l
, "basepath", lua_basepath
);
846 lua_register(l
, "irc_report", lua_chanmsg
);
847 lua_register(l
, "irc_ctcp", lua_ctcp
);
848 lua_register(l
, "irc_kill", lua_kill
);
849 lua_register(l
, "irc_kick", lua_kick
);
850 lua_register(l
, "irc_invite", lua_invite
);
851 lua_register(l
, "irc_gline", lua_gline
);
852 lua_register(l
, "irc_getchaninfo", lua_getchaninfo
);
853 lua_register(l
, "irc_counthost", lua_counthost
);
854 lua_register(l
, "irc_getuserbyauth", lua_getuserbyauth
);
855 lua_register(l
, "irc_notice", lua_noticecmd
);
856 lua_register(l
, "irc_privmsg", lua_privmsgcmd
);
857 lua_register(l
, "irc_opchan", lua_opchan
);
858 lua_register(l
, "irc_voicechan", lua_voicechan
);
859 lua_register(l
, "irc_chanfix", lua_chanfix
);
860 lua_register(l
, "irc_clearmode", lua_clearmode
);
861 lua_register(l
, "irc_ban", lua_ban
);
862 lua_register(l
, "irc_deopchan", lua_deopchan
);
863 lua_register(l
, "irc_topic", lua_topic
);
865 lua_register(l
, "irc_getnickbynick", lua_getnickbynick
);
866 lua_register(l
, "irc_getnickbynumeric", lua_getnickbynumeric
);
867 lua_register(l
, "irc_getfirstnick", lua_getfirstnick
);
868 lua_register(l
, "irc_getnextnick", lua_getnextnick
);
870 lua_register(l
, "irc_getnickchans", lua_getnickchans
);
871 lua_register(l
, "irc_getnickchanindex", lua_getnickchanindex
);
872 lua_register(l
, "irc_getnickchancount", lua_getnickchancount
);
874 lua_register(l
, "irc_getuserchanmodes", lua_getuserchanmodes
);
876 lua_register(l
, "irc_getfirstchannick", lua_getfirstchannick
);
877 lua_register(l
, "irc_getnextchannick", lua_getnextchannick
);
879 lua_register(l
, "irc_gethostusers", lua_gethostusers
);
880 lua_register(l
, "irc_getnickcountry", lua_getnickcountry
);
882 lua_register(l
, "irc_getfirstchan", lua_getfirstchan
);
883 lua_register(l
, "irc_getnextchan", lua_getnextchan
);
884 lua_register(l
, "irc_getusermodes", lua_getusermodes
);
885 lua_register(l
, "irc_nickonchan", lua_nickonchan
);
887 lua_register(l
, "irc_fastgetnickbynumeric", lua_fastgetnickbynumeric
);
889 lua_register(l
, "irc_simplechanmode", lua_simplechanmode
);
890 lua_register(l
, "irc_sethost", lua_sethost
);
895 static int lua_smsg(lua_State
*ps
) {
896 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
897 LUA_RETURN(ps
, LUA_FAIL
);
899 LUA_RETURN(ps
, lua_cmsg((char *)lua_tostring(ps
, 2), "%s", lua_tostring(ps
, 1)));
902 static int lua_skill(lua_State
*ps
) {
906 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
907 LUA_RETURN(ps
, LUA_FAIL
);
909 n
= lua_tostring(ps
, 1);
910 msg
= lua_tostring(ps
, 2);
912 np
= getnickbynick(n
);
914 LUA_RETURN(ps
, LUA_FAIL
);
916 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
917 LUA_RETURN(ps
, LUA_FAIL
);
920 LUA_RETURN(ps
, LUA_FAIL
);
922 killuser(lua_nick
, np
, "%s", msg
);
924 LUA_RETURN(ps
, LUA_OK
);
927 #define PUSHER_STRING 1
928 #define PUSHER_REALNAME 2
930 #define PUSHER_LONG 4
931 #define PUSHER_HOSTNAME 5
932 #define PUSHER_SSTRING 6
933 #define PUSHER_TOTALUSERS 7
934 #define PUSHER_TOPIC 8
935 #define PUSHER_UMODES 9
936 #define PUSHER_COUNTRY 10
938 void lua_initnickpusher(void) {
941 #define PUSH_NICKPUSHER(F2, O2) nickpusher[i].argtype = F2; nickpusher[i].structname = #O2; nickpusher[i].offset = offsetof(nick, O2); i++;
942 #define PUSH_NICKPUSHER_CUSTOM(F2, custom) nickpusher[i].argtype = F2; nickpusher[i].structname = custom; nickpusher[i].offset = 0; i++;
944 PUSH_NICKPUSHER(PUSHER_STRING
, nick
);
945 PUSH_NICKPUSHER(PUSHER_STRING
, ident
);
946 PUSH_NICKPUSHER(PUSHER_HOSTNAME
, host
);
947 PUSH_NICKPUSHER(PUSHER_REALNAME
, realname
);
948 PUSH_NICKPUSHER(PUSHER_STRING
, authname
);
949 PUSH_NICKPUSHER(PUSHER_IP
, ipnode
);
950 PUSH_NICKPUSHER(PUSHER_LONG
, numeric
);
951 PUSH_NICKPUSHER(PUSHER_LONG
, timestamp
);
952 PUSH_NICKPUSHER(PUSHER_LONG
, accountts
);
953 PUSH_NICKPUSHER(PUSHER_UMODES
, umodes
);
954 PUSH_NICKPUSHER_CUSTOM(PUSHER_COUNTRY
, "country");
957 nickpusher
[i
].argtype
= 0;
960 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
) {
966 if(!lua_istable(l
, index
) || (max
< 2))
973 while(lua_next(l
, index
)) {
974 if(lua_isint(l
, -1)) {
975 int index
= lua_toint(l
, -1);
976 if((index
>= 0) && (index
< pcount
))
977 lp
[current
++] = &pusherlist
[index
];
989 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
) {
993 void *offset
= (void *)np
+ (*lp
)->offset
;
995 switch((*lp
)->argtype
) {
997 lua_pushstring(l
, (char *)offset
);
999 case PUSHER_HOSTNAME
:
1000 lua_pushstring(l
, (*(host
**)offset
)->name
->content
);
1002 case PUSHER_REALNAME
:
1003 lua_pushstring(l
, (*(realname
**)offset
)->name
->content
);
1005 case PUSHER_SSTRING
:
1006 lua_pushstring(l
, (*((sstring
**)offset
))->content
);
1009 lua_pushlong(l
, *((long *)offset
));
1012 lua_pushstring(l
, IPtostr((*((patricia_node_t
**)offset
))->prefix
->sin
));
1014 case PUSHER_TOTALUSERS
:
1015 lua_pushint(l
, (*((channel
**)offset
))->users
->totalusers
);
1018 lua_pushstring(l
, printflags(*((flag_t
*)offset
), umodeflags
));
1021 if((*((channel
**)offset
))->topic
) {
1022 lua_pushstring(l
, (*((channel
**)offset
))->topic
->content
);
1027 case PUSHER_COUNTRY
:
1031 lua_pushint(l
, (long)((nick
*)offset
)->exts
[geoipext
]);
1043 void lua_initchanpusher(void) {
1046 #define PUSH_CHANPUSHER(F2, O2, N2) chanpusher[i].argtype = F2; chanpusher[i].structname = N2; chanpusher[i].offset = offsetof(chanindex, O2); i++;
1048 PUSH_CHANPUSHER(PUSHER_SSTRING
, name
, "name");
1049 PUSH_CHANPUSHER(PUSHER_TOTALUSERS
, channel
, "totalusers");
1050 PUSH_CHANPUSHER(PUSHER_TOPIC
, channel
, "topic");
1052 chanpushercount
= i
;
1053 chanpusher
[i
].argtype
= 0;