]>
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
->ipaddress
));
258 snprintf(mask
, sizeof(mask
), "*@%s", IPtostr(target
->ipaddress
));
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
);
436 struct lua_pusher
*nickhashpusher
[MAX_PUSHER
];
438 static int lua_getnextnick(lua_State
*l
) {
439 if(!lasthashnick
&& (hashindex
!= -1))
445 if(hashindex
>= NICKHASHSIZE
)
447 lasthashnick
= nicktable
[hashindex
];
449 lasthashnick
= lasthashnick
->next
;
451 } while(!lasthashnick
);
453 return lua_usepusher(l
, nickhashpusher
, lasthashnick
);
456 static int lua_getfirstnick(lua_State
*l
) {
460 lua_setupnickpusher(l
, 1, nickhashpusher
, MAX_PUSHER
);
462 return lua_getnextnick(l
);
466 chanindex
*lasthashchan
;
468 struct lua_pusher
*chanhashpusher
[MAX_PUSHER
];
470 static int lua_getnextchan(lua_State
*l
) {
471 if(!lasthashchan
&& (chanhashindex
!= -1))
477 if(chanhashindex
>= CHANNELHASHSIZE
)
479 lasthashchan
= chantable
[chanhashindex
];
481 lasthashchan
= lasthashchan
->next
;
483 } while(!lasthashchan
|| !lasthashchan
->channel
);
485 return lua_usepusher(l
, chanhashpusher
, lasthashchan
);
488 static int lua_getfirstchan(lua_State
*l
) {
492 lua_setupchanpusher(l
, 1, chanhashpusher
, MAX_PUSHER
);
494 return lua_getnextchan(l
);
497 static int lua_getnickchancount(lua_State
*l
) {
500 if(!lua_islong(l
, 1))
503 np
= getnickbynumeric(lua_tolong(l
, 1));
507 lua_pushint(l
, np
->channels
->cursi
);
512 static int lua_gethostusers(lua_State
*l
) {
516 if(!lua_islong(l
, 1))
519 np
= getnickbynumeric(lua_tolong(l
, 1));
520 if(!np
|| !np
->host
|| !np
->host
->nicks
)
523 np
= np
->host
->nicks
;
524 count
= np
->host
->clonecount
;
534 static int lua_getnickcountry(lua_State
*l
) {
538 ext
= findnickext("geoip");
542 if(!lua_islong(l
, 1))
545 np
= getnickbynumeric(lua_tolong(l
, 1));
549 lua_pushint(l
, (int)np
->exts
[ext
]);
553 static int lua_chanfix(lua_State
*ps
) {
557 if(!lua_isstring(ps
, 1))
558 LUA_RETURN(ps
, LUA_FAIL
);
560 cp
= findchannel((char *)lua_tostring(ps
, 1));
561 if(!cp
|| !cp
->index
)
562 LUA_RETURN(ps
, LUA_FAIL
);
564 np
= getnickbynick(LUA_CHANFIXBOT
);
566 LUA_RETURN(ps
, LUA_FAIL
);
568 lua_message(np
, "chanfix %s", cp
->index
->name
->content
);
570 LUA_RETURN(ps
, LUA_OK
);
573 static int lua_clearmode(lua_State
*ps
) {
580 if(!lua_isstring(ps
, 1))
581 LUA_RETURN(ps
, LUA_FAIL
);
583 cp
= findchannel((char *)lua_tostring(ps
, 1));
584 if(!cp
|| !cp
->users
)
585 LUA_RETURN(ps
, LUA_FAIL
);
587 localsetmodeinit(&changes
, cp
, lua_nick
);
589 localdosetmode_key(&changes
, NULL
, MCB_DEL
);
590 localdosetmode_simple(&changes
, 0, CHANMODE_INVITEONLY
| CHANMODE_LIMIT
);
593 localdosetmode_ban(&changes
, bantostring(cp
->bans
), MCB_DEL
);
595 for(i
=0,lp
=cp
->users
->content
;i
<cp
->users
->hashsize
;i
++,lp
++)
596 if((*lp
!= nouser
) && (*lp
& CUMODE_OP
)) {
597 np
= getnickbynumeric(*lp
);
598 if(np
&& !IsService(np
))
599 localdosetmode_nick(&changes
, np
, MC_DEOP
);
602 localsetmodeflush(&changes
, 1);
604 LUA_RETURN(ps
, LUA_OK
);
607 static int lua_ban(lua_State
*ps
) {
613 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
614 LUA_RETURN(ps
, LUA_FAIL
);
616 if(lua_isboolean(ps
, 3) && lua_toboolean(ps
, 3))
619 cp
= findchannel((char *)lua_tostring(ps
, 1));
621 LUA_RETURN(ps
, LUA_FAIL
);
623 mask
= lua_tostring(ps
, 2);
624 if(!mask
|| !mask
[0] || !lua_lineok(mask
))
625 LUA_RETURN(ps
, LUA_FAIL
);
627 localsetmodeinit(&changes
, cp
, lua_nick
);
628 localdosetmode_ban(&changes
, mask
, dir
);
629 localsetmodeflush(&changes
, 1);
631 LUA_RETURN(ps
, LUA_OK
);
634 static int lua_topic(lua_State
*ps
) {
638 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
639 LUA_RETURN(ps
, LUA_FAIL
);
641 cp
= findchannel((char *)lua_tostring(ps
, 1));
643 LUA_RETURN(ps
, LUA_FAIL
);
645 topic
= (char *)lua_tostring(ps
, 2);
646 if(!topic
|| !lua_lineok(topic
))
647 LUA_RETURN(ps
, LUA_FAIL
);
649 localsettopic(lua_nick
, cp
, topic
);
651 LUA_RETURN(ps
, LUA_OK
);
654 static int lua_getuserchanmodes(lua_State
*l
) {
659 if(!lua_islong(l
, 1) || !lua_isstring(l
, 2))
662 np
= getnickbynumeric(lua_tolong(l
, 1));
666 cp
= findchannel((char *)lua_tostring(l
, 2));
667 if(!cp
|| !cp
->users
)
670 lp
= getnumerichandlefromchanhash(cp
->users
, np
->numeric
);
674 LUA_PUSHNICKCHANMODES(l
, lp
);
678 static int lua_getusermodes(lua_State
*l
) {
681 if(!lua_islong(l
, 1))
684 np
= getnickbynumeric(lua_tolong(l
, 1));
688 lua_pushstring(l
, printflags(np
->umodes
, umodeflags
));
692 static int lua_getnickbynick(lua_State
*l
) {
695 if(!lua_isstring(l
, 1))
698 np
= getnickbynick(lua_tostring(l
, 1));
706 static int lua_getnickbynumeric(lua_State
*l
) {
709 if(!lua_islong(l
, 1))
712 np
= getnickbynumeric(lua_tolong(l
, 1));
720 static int lua_fastgetnickbynumeric(lua_State
*l
) {
721 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
724 if(!lua_islong(l
, 1))
727 np
= getnickbynumeric(lua_tolong(l
, 1));
731 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
732 return lua_usepusher(l
, ourpusher
, np
);
735 int channelnicklistindex
, channelnicklistcount
= -1;
736 channel
*channelnicklist
;
738 struct lua_pusher
*channelnickpusher
[MAX_PUSHER
];
740 static int lua_getnextchannick(lua_State
*l
) {
744 channelnicklistindex
++;
746 if(channelnicklistindex
>= channelnicklistcount
)
748 } while((channelnicklist
->users
->content
[channelnicklistindex
] == nouser
) || !(np
= getnickbynumeric(channelnicklist
->users
->content
[channelnicklistindex
])));
750 return lua_usepusher(l
, channelnickpusher
, np
);
753 static int lua_getfirstchannick(lua_State
*l
) {
754 if(!lua_isstring(l
, 1))
757 channelnicklist
= findchannel((char *)lua_tostring(l
, 1));
758 if(!channelnicklist
|| !channelnicklist
->users
)
761 channelnicklistindex
= -1;
762 channelnicklistcount
= channelnicklist
->users
->hashsize
;
764 lua_setupnickpusher(l
, 2, channelnickpusher
, MAX_PUSHER
);
766 return lua_getnextchannick(l
);
769 static int lua_nickonchan(lua_State
*l
) {
771 if(lua_islong(l
, 1) && lua_isstring(l
, 2)) {
772 channel
*cp
= findchannel((char *)lua_tostring(l
, 2));
773 if(cp
&& cp
->users
) {
774 unsigned long *lp
= getnumerichandlefromchanhash(cp
->users
, lua_tolong(l
, 1));
780 lua_pushboolean(l
, success
);
784 static int lua_simplechanmode(lua_State
*ps
) {
787 flag_t add
= 0, del
= ~add
;
788 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
;
791 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
792 LUA_RETURN(ps
, LUA_FAIL
);
794 cp
= findchannel((char *)lua_tostring(ps
, 1));
796 LUA_RETURN(ps
, LUA_FAIL
);
798 modes
= (char *)lua_tostring(ps
, 2);
800 LUA_RETURN(ps
, LUA_FAIL
);
802 if(setflags(&add
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
803 LUA_RETURN(ps
, LUA_FAIL
);
805 if(setflags(&del
, permitted
, modes
, cmodeflags
, REJECT_DISALLOWED
|REJECT_UNKNOWN
) != REJECT_NONE
)
806 LUA_RETURN(ps
, LUA_FAIL
);
808 localsetmodeinit(&changes
, cp
, lua_nick
);
809 localdosetmode_simple(&changes
, add
, ~del
);
810 localsetmodeflush(&changes
, 1);
812 LUA_RETURN(ps
, LUA_OK
);
815 void lua_registercommands(lua_State
*l
) {
816 lua_register(l
, "irc_smsg", lua_smsg
);
817 lua_register(l
, "irc_skill", lua_skill
);
819 lua_register(l
, "chanmsg", lua_chanmsg
);
820 lua_register(l
, "versioninfo", lua_versioninfo
);
821 lua_register(l
, "basepath", lua_basepath
);
823 lua_register(l
, "irc_report", lua_chanmsg
);
824 lua_register(l
, "irc_ctcp", lua_ctcp
);
825 lua_register(l
, "irc_kill", lua_kill
);
826 lua_register(l
, "irc_kick", lua_kick
);
827 lua_register(l
, "irc_invite", lua_invite
);
828 lua_register(l
, "irc_gline", lua_gline
);
829 lua_register(l
, "irc_getchaninfo", lua_getchaninfo
);
830 lua_register(l
, "irc_counthost", lua_counthost
);
831 lua_register(l
, "irc_getuserbyauth", lua_getuserbyauth
);
832 lua_register(l
, "irc_notice", lua_noticecmd
);
833 lua_register(l
, "irc_privmsg", lua_privmsgcmd
);
834 lua_register(l
, "irc_opchan", lua_opchan
);
835 lua_register(l
, "irc_voicechan", lua_voicechan
);
836 lua_register(l
, "irc_chanfix", lua_chanfix
);
837 lua_register(l
, "irc_clearmode", lua_clearmode
);
838 lua_register(l
, "irc_ban", lua_ban
);
839 lua_register(l
, "irc_deopchan", lua_deopchan
);
840 lua_register(l
, "irc_topic", lua_topic
);
842 lua_register(l
, "irc_getnickbynick", lua_getnickbynick
);
843 lua_register(l
, "irc_getnickbynumeric", lua_getnickbynumeric
);
844 lua_register(l
, "irc_getfirstnick", lua_getfirstnick
);
845 lua_register(l
, "irc_getnextnick", lua_getnextnick
);
847 lua_register(l
, "irc_getnickchans", lua_getnickchans
);
848 lua_register(l
, "irc_getnickchanindex", lua_getnickchanindex
);
849 lua_register(l
, "irc_getnickchancount", lua_getnickchancount
);
851 lua_register(l
, "irc_getuserchanmodes", lua_getuserchanmodes
);
853 lua_register(l
, "irc_getfirstchannick", lua_getfirstchannick
);
854 lua_register(l
, "irc_getnextchannick", lua_getnextchannick
);
856 lua_register(l
, "irc_gethostusers", lua_gethostusers
);
857 lua_register(l
, "irc_getnickcountry", lua_getnickcountry
);
859 lua_register(l
, "irc_getfirstchan", lua_getfirstchan
);
860 lua_register(l
, "irc_getnextchan", lua_getnextchan
);
861 lua_register(l
, "irc_getusermodes", lua_getusermodes
);
862 lua_register(l
, "irc_nickonchan", lua_nickonchan
);
864 lua_register(l
, "irc_fastgetnickbynumeric", lua_fastgetnickbynumeric
);
866 lua_register(l
, "irc_simplechanmode", lua_simplechanmode
);
871 static int lua_smsg(lua_State
*ps
) {
872 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
873 LUA_RETURN(ps
, LUA_FAIL
);
875 LUA_RETURN(ps
, lua_cmsg((char *)lua_tostring(ps
, 2), "%s", lua_tostring(ps
, 1)));
878 static int lua_skill(lua_State
*ps
) {
882 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
883 LUA_RETURN(ps
, LUA_FAIL
);
885 n
= lua_tostring(ps
, 1);
886 msg
= lua_tostring(ps
, 2);
888 np
= getnickbynick(n
);
890 LUA_RETURN(ps
, LUA_FAIL
);
892 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
893 LUA_RETURN(ps
, LUA_FAIL
);
896 LUA_RETURN(ps
, LUA_FAIL
);
898 killuser(lua_nick
, np
, "%s", msg
);
900 LUA_RETURN(ps
, LUA_OK
);
903 #define PUSHER_STRING 1
904 #define PUSHER_REALNAME 2
906 #define PUSHER_LONG 4
907 #define PUSHER_HOSTNAME 5
908 #define PUSHER_SSTRING 6
909 #define PUSHER_TOTALUSERS 7
910 #define PUSHER_TOPIC 8
912 void lua_initnickpusher(void) {
915 #define PUSH_NICKPUSHER(F2, O2) nickpusher[i].argtype = F2; nickpusher[i].structname = #O2; nickpusher[i].offset = offsetof(nick, O2); i++;
917 PUSH_NICKPUSHER(PUSHER_STRING
, nick
);
918 PUSH_NICKPUSHER(PUSHER_STRING
, ident
);
919 PUSH_NICKPUSHER(PUSHER_HOSTNAME
, host
);
920 PUSH_NICKPUSHER(PUSHER_REALNAME
, realname
);
921 PUSH_NICKPUSHER(PUSHER_STRING
, authname
);
922 PUSH_NICKPUSHER(PUSHER_IP
, ipaddress
);
923 PUSH_NICKPUSHER(PUSHER_LONG
, numeric
);
926 nickpusher
[i
].argtype
= 0;
929 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
) {
935 if(!lua_istable(l
, index
) || (max
< 2))
942 while(lua_next(l
, index
)) {
943 if(lua_isint(l
, -1)) {
944 int index
= lua_toint(l
, -1);
945 if((index
>= 0) && (index
< pcount
))
946 lp
[current
++] = &pusherlist
[index
];
958 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
) {
962 void *offset
= (void *)np
+ (*lp
)->offset
;
964 switch((*lp
)->argtype
) {
966 lua_pushstring(l
, (char *)offset
);
968 case PUSHER_HOSTNAME
:
969 lua_pushstring(l
, (*(host
**)offset
)->name
->content
);
971 case PUSHER_REALNAME
:
972 lua_pushstring(l
, (*(realname
**)offset
)->name
->content
);
975 lua_pushstring(l
, (*((sstring
**)offset
))->content
);
978 lua_pushlong(l
, *((long *)offset
));
981 lua_pushstring(l
, IPtostr(*((long *)offset
)));
983 case PUSHER_TOTALUSERS
:
984 lua_pushint(l
, (*((channel
**)offset
))->users
->totalusers
);
987 if((*((channel
**)offset
))->topic
) {
988 lua_pushstring(l
, (*((channel
**)offset
))->topic
->content
);
1002 void lua_initchanpusher(void) {
1005 #define PUSH_CHANPUSHER(F2, O2, N2) chanpusher[i].argtype = F2; chanpusher[i].structname = N2; chanpusher[i].offset = offsetof(chanindex, O2); i++;
1007 PUSH_CHANPUSHER(PUSHER_SSTRING
, name
, "name");
1008 PUSH_CHANPUSHER(PUSHER_TOTALUSERS
, channel
, "totalusers");
1009 PUSH_CHANPUSHER(PUSHER_TOPIC
, channel
, "topic");
1011 chanpushercount
= i
;
1012 chanpusher
[i
].argtype
= 0;