]>
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_fastgetchaninfo(lua_State
*ps
) {
266 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
269 if(!lua_isstring(ps
, 1))
272 cp
= findchannel((char *)lua_tostring(ps
, 1));
273 if(!cp
|| cp
->index
->channel
!= cp
)
276 lua_setupchanpusher(ps
, 2, ourpusher
, MAX_PUSHER
);
277 return lua_usepusher(ps
, ourpusher
, cp
->index
);
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
)) {
385 lua_pushnumeric(l
, np
->numeric
);
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
;
529 lua_pushnumeric(l
, np
->numeric
);
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_fastgetnickbynumeric(lua_State
*l
) {
695 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
698 if(!lua_islong(l
, 1))
701 np
= getnickbynumeric(lua_tolong(l
, 1));
705 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
706 return lua_usepusher(l
, ourpusher
, np
);
709 static int lua_fastgetnickbynick(lua_State
*l
) {
710 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
713 if(!lua_isstring(l
, 1))
716 np
= getnickbynick((char *)lua_tostring(l
, 1));
720 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
721 return lua_usepusher(l
, ourpusher
, np
);
724 int channelnicklistindex
, channelnicklistcount
= -1;
725 channel
*channelnicklist
;
727 struct lua_pusher
*channelnickpusher
[MAX_PUSHER
];
729 static int lua_getnextchannick(lua_State
*l
) {
733 channelnicklistindex
++;
735 if(channelnicklistindex
>= channelnicklistcount
)
737 } while((channelnicklist
->users
->content
[channelnicklistindex
] == nouser
) || !(np
= getnickbynumeric(channelnicklist
->users
->content
[channelnicklistindex
])));
739 return lua_usepusher(l
, channelnickpusher
, np
);
742 static int lua_getfirstchannick(lua_State
*l
) {
743 if(!lua_isstring(l
, 1))
746 channelnicklist
= findchannel((char *)lua_tostring(l
, 1));
747 if(!channelnicklist
|| !channelnicklist
->users
)
750 channelnicklistindex
= -1;
751 channelnicklistcount
= channelnicklist
->users
->hashsize
;
753 lua_setupnickpusher(l
, 2, channelnickpusher
, MAX_PUSHER
);
755 return lua_getnextchannick(l
);
758 static int lua_nickonchan(lua_State
*l
) {
760 if(lua_islong(l
, 1) && lua_isstring(l
, 2)) {
761 channel
*cp
= findchannel((char *)lua_tostring(l
, 2));
762 if(cp
&& cp
->users
) {
763 unsigned long *lp
= getnumerichandlefromchanhash(cp
->users
, lua_tolong(l
, 1));
769 lua_pushboolean(l
, success
);
773 static int lua_simplechanmode(lua_State
*ps
) {
776 flag_t add
= 0, del
= ~add
;
777 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
;
780 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
781 LUA_RETURN(ps
, LUA_FAIL
);
783 cp
= findchannel((char *)lua_tostring(ps
, 1));
785 LUA_RETURN(ps
, LUA_FAIL
);
787 modes
= (char *)lua_tostring(ps
, 2);
789 LUA_RETURN(ps
, LUA_FAIL
);
791 if(setflags(&add
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
792 LUA_RETURN(ps
, LUA_FAIL
);
794 if(setflags(&del
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
795 LUA_RETURN(ps
, LUA_FAIL
);
797 localsetmodeinit(&changes
, cp
, lua_nick
);
798 localdosetmode_simple(&changes
, add
, ~del
);
799 localsetmodeflush(&changes
, 1);
801 LUA_RETURN(ps
, LUA_OK
);
804 static int lua_sethost(lua_State
*ps
) {
808 if(!lua_islong(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
809 LUA_RETURN(ps
, LUA_FAIL
);
811 np
= getnickbynumeric(lua_tolong(ps
, 1));
813 LUA_RETURN(ps
, LUA_FAIL
);
815 ident
= (char *)lua_tostring(ps
, 2);
816 host
= (char *)lua_tostring(ps
, 3);
817 if(!lua_lineok(ident
) || !lua_lineok(host
))
818 LUA_RETURN(ps
, LUA_FAIL
);
820 sethostuser(np
, ident
, host
);
822 LUA_RETURN(ps
, LUA_OK
);
825 void lua_registercommands(lua_State
*l
) {
826 lua_register(l
, "irc_smsg", lua_smsg
);
827 lua_register(l
, "irc_skill", lua_skill
);
829 lua_register(l
, "chanmsg", lua_chanmsg
);
830 lua_register(l
, "versioninfo", lua_versioninfo
);
831 lua_register(l
, "basepath", lua_basepath
);
833 lua_register(l
, "irc_report", lua_chanmsg
);
834 lua_register(l
, "irc_ctcp", lua_ctcp
);
835 lua_register(l
, "irc_kill", lua_kill
);
836 lua_register(l
, "irc_kick", lua_kick
);
837 lua_register(l
, "irc_invite", lua_invite
);
838 lua_register(l
, "irc_gline", lua_gline
);
839 lua_register(l
, "irc_counthost", lua_counthost
);
840 lua_register(l
, "irc_getuserbyauth", lua_getuserbyauth
);
841 lua_register(l
, "irc_notice", lua_noticecmd
);
842 lua_register(l
, "irc_privmsg", lua_privmsgcmd
);
843 lua_register(l
, "irc_opchan", lua_opchan
);
844 lua_register(l
, "irc_voicechan", lua_voicechan
);
845 lua_register(l
, "irc_chanfix", lua_chanfix
);
846 lua_register(l
, "irc_clearmode", lua_clearmode
);
847 lua_register(l
, "irc_ban", lua_ban
);
848 lua_register(l
, "irc_deopchan", lua_deopchan
);
849 lua_register(l
, "irc_topic", lua_topic
);
851 lua_register(l
, "irc_getfirstnick", lua_getfirstnick
);
852 lua_register(l
, "irc_getnextnick", lua_getnextnick
);
854 lua_register(l
, "irc_getnickchans", lua_getnickchans
);
855 lua_register(l
, "irc_getnickchanindex", lua_getnickchanindex
);
856 lua_register(l
, "irc_getnickchancount", lua_getnickchancount
);
858 lua_register(l
, "irc_getuserchanmodes", lua_getuserchanmodes
);
860 lua_register(l
, "irc_getfirstchannick", lua_getfirstchannick
);
861 lua_register(l
, "irc_getnextchannick", lua_getnextchannick
);
863 lua_register(l
, "irc_gethostusers", lua_gethostusers
);
864 lua_register(l
, "irc_getnickcountry", lua_getnickcountry
);
866 lua_register(l
, "irc_getfirstchan", lua_getfirstchan
);
867 lua_register(l
, "irc_getnextchan", lua_getnextchan
);
868 lua_register(l
, "irc_getusermodes", lua_getusermodes
);
869 lua_register(l
, "irc_nickonchan", lua_nickonchan
);
871 lua_register(l
, "irc_fastgetnickbynumeric", lua_fastgetnickbynumeric
);
872 lua_register(l
, "irc_fastgetnickbynick", lua_fastgetnickbynick
);
873 lua_register(l
, "irc_fastgetchaninfo", lua_fastgetchaninfo
);
875 lua_register(l
, "irc_simplechanmode", lua_simplechanmode
);
876 lua_register(l
, "irc_sethost", lua_sethost
);
881 static int lua_smsg(lua_State
*ps
) {
882 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
883 LUA_RETURN(ps
, LUA_FAIL
);
885 LUA_RETURN(ps
, lua_cmsg((char *)lua_tostring(ps
, 2), "%s", lua_tostring(ps
, 1)));
888 static int lua_skill(lua_State
*ps
) {
892 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
893 LUA_RETURN(ps
, LUA_FAIL
);
895 n
= lua_tostring(ps
, 1);
896 msg
= lua_tostring(ps
, 2);
898 np
= getnickbynick(n
);
900 LUA_RETURN(ps
, LUA_FAIL
);
902 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
903 LUA_RETURN(ps
, LUA_FAIL
);
906 LUA_RETURN(ps
, LUA_FAIL
);
908 killuser(lua_nick
, np
, "%s", msg
);
910 LUA_RETURN(ps
, LUA_OK
);
913 #define PUSHER_STRING 1
914 #define PUSHER_REALNAME 2
916 #define PUSHER_LONG 4
917 #define PUSHER_HOSTNAME 5
918 #define PUSHER_SSTRING 6
919 #define PUSHER_TOTALUSERS 7
920 #define PUSHER_TOPIC 8
921 #define PUSHER_UMODES 9
922 #define PUSHER_COUNTRY 10
923 #define PUSHER_REALUSERS 11
924 #define PUSHER_CHANMODES 12
925 #define PUSHER_TIMESTAMP 13
927 void lua_initnickpusher(void) {
930 #define PUSH_NICKPUSHER(F2, O2) nickpusher[i].argtype = F2; nickpusher[i].structname = #O2; nickpusher[i].offset = offsetof(nick, O2); i++;
931 #define PUSH_NICKPUSHER_CUSTOM(F2, custom) nickpusher[i].argtype = F2; nickpusher[i].structname = custom; nickpusher[i].offset = 0; i++;
933 PUSH_NICKPUSHER(PUSHER_STRING
, nick
);
934 PUSH_NICKPUSHER(PUSHER_STRING
, ident
);
935 PUSH_NICKPUSHER(PUSHER_HOSTNAME
, host
);
936 PUSH_NICKPUSHER(PUSHER_REALNAME
, realname
);
937 PUSH_NICKPUSHER(PUSHER_STRING
, authname
);
938 PUSH_NICKPUSHER(PUSHER_IP
, ipnode
);
939 PUSH_NICKPUSHER(PUSHER_LONG
, numeric
);
940 PUSH_NICKPUSHER(PUSHER_LONG
, timestamp
);
941 PUSH_NICKPUSHER(PUSHER_LONG
, accountts
);
942 PUSH_NICKPUSHER(PUSHER_UMODES
, umodes
);
943 PUSH_NICKPUSHER_CUSTOM(PUSHER_COUNTRY
, "country");
946 nickpusher
[i
].argtype
= 0;
949 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
) {
955 if(!lua_istable(l
, index
) || (max
< 2))
962 while(lua_next(l
, index
)) {
963 if(lua_isint(l
, -1)) {
964 int index
= lua_toint(l
, -1);
965 if((index
>= 0) && (index
< pcount
))
966 lp
[current
++] = &pusherlist
[index
];
978 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
) {
982 void *offset
= (void *)np
+ (*lp
)->offset
;
984 switch((*lp
)->argtype
) {
986 lua_pushstring(l
, (char *)offset
);
988 case PUSHER_HOSTNAME
:
989 lua_pushstring(l
, (*(host
**)offset
)->name
->content
);
991 case PUSHER_REALNAME
:
992 lua_pushstring(l
, (*(realname
**)offset
)->name
->content
);
995 lua_pushstring(l
, (*((sstring
**)offset
))->content
);
998 lua_pushlong(l
, *((long *)offset
));
1000 case PUSHER_TIMESTAMP
:
1001 lua_pushlong(l
, (*((channel
**)offset
))->timestamp
);
1004 lua_pushstring(l
, IPtostr((*((patricia_node_t
**)offset
))->prefix
->sin
));
1006 case PUSHER_TOTALUSERS
:
1007 lua_pushint(l
, (*((channel
**)offset
))->users
->totalusers
);
1009 case PUSHER_CHANMODES
:
1010 lua_pushstring(l
, printallmodes(*((channel
**)offset
)));
1012 case PUSHER_REALUSERS
:
1014 channel
*cp
= *((channel
**)offset
);
1016 int i
, currentusers
= countuniquehosts(cp
);
1017 for(i
=0;i
<cp
->users
->hashsize
;i
++) {
1018 if(cp
->users
->content
[i
]==nouser
)
1021 if((np2
=getnickbynumeric(cp
->users
->content
[i
]))==NULL
) {
1022 Error("lua", ERR_ERROR
, "Found unknown numeric %u on channel %s", cp
->users
->content
[i
], cp
->index
->name
->content
);
1026 if (IsXOper(np2
) || IsService(np2
))
1029 lua_pushint(l
, currentusers
);
1033 lua_pushstring(l
, printflags(*((flag_t
*)offset
), umodeflags
));
1036 if((*((channel
**)offset
))->topic
) {
1037 lua_pushstring(l
, (*((channel
**)offset
))->topic
->content
);
1042 case PUSHER_COUNTRY
:
1046 lua_pushint(l
, (long)((nick
*)offset
)->exts
[geoipext
]);
1058 void lua_initchanpusher(void) {
1061 #define PUSH_CHANPUSHER(F2, O2, N2) chanpusher[i].argtype = F2; chanpusher[i].structname = N2; chanpusher[i].offset = offsetof(chanindex, O2); i++;
1063 PUSH_CHANPUSHER(PUSHER_SSTRING
, name
, "name");
1064 PUSH_CHANPUSHER(PUSHER_TOTALUSERS
, channel
, "totalusers");
1065 PUSH_CHANPUSHER(PUSHER_TOPIC
, channel
, "topic");
1066 PUSH_CHANPUSHER(PUSHER_REALUSERS
, channel
, "realusers");
1067 PUSH_CHANPUSHER(PUSHER_TIMESTAMP
, channel
, "timestamp");
1068 PUSH_CHANPUSHER(PUSHER_CHANMODES
, channel
, "modes");
1070 chanpushercount
= i
;
1071 chanpusher
[i
].argtype
= 0;