]>
jfr.im git - irc/quakenet/newserv.git/blob - lua/luacommands.c
1 /* Copyright (C) Chris Porter 2005-2006 */
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"
27 static int lua_smsg(lua_State
*ps
);
28 static int lua_skill(lua_State
*ps
);
30 typedef struct lua_pusher
{
33 const char *structname
;
36 struct lua_pusher nickpusher
[MAX_PUSHER
];
37 struct lua_pusher chanpusher
[MAX_PUSHER
];
38 int nickpushercount
, chanpushercount
;
40 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
);
41 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
);
43 void lua_initnickpusher(void);
44 void lua_initchanpusher(void);
46 #define lua_setupnickpusher(L2, I2, P2, M2) lua_setuppusher(&nickpusher[0], L2, I2, P2, M2, nickpushercount)
47 #define lua_setupchanpusher(L2, I2, P2, M2) lua_setuppusher(&chanpusher[0], L2, I2, P2, M2, chanpushercount)
49 int lua_cmsg(char *channell
, char *message
, ...) {
54 va_start(va
, message
);
55 vsnprintf(buf
, sizeof(buf
), message
, va
);
58 cp
= findchannel(channell
);
65 lua_channelmessage(cp
, "%s", buf
);
70 static int lua_chanmsg(lua_State
*ps
) {
71 if(!lua_isstring(ps
, 1))
72 LUA_RETURN(ps
, LUA_FAIL
);
74 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua: %s", lua_tostring(ps
, 1)));
77 static int lua_ctcp(lua_State
*ps
) {
81 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
82 LUA_RETURN(ps
, LUA_FAIL
);
84 n
= lua_tostring(ps
, 1);
85 msg
= lua_tostring(ps
, 2);
87 np
= getnickbynick(n
);
88 if(!np
|| !lua_lineok(msg
))
89 LUA_RETURN(ps
, LUA_FAIL
);
91 lua_message(np
, "\001%s\001", msg
);
93 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-ctcp: %s (%s)", np
->nick
, msg
));
96 static int lua_noticecmd(lua_State
*ps
) {
100 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
101 LUA_RETURN(ps
, LUA_FAIL
);
103 n
= lua_tostring(ps
, 1);
104 msg
= lua_tostring(ps
, 2);
106 np
= getnickbynick(n
);
107 if(!np
|| !lua_lineok(msg
))
108 LUA_RETURN(ps
, LUA_FAIL
);
110 lua_notice(np
, "%s", msg
);
112 LUA_RETURN(ps
, LUA_OK
);
115 static int lua_privmsgcmd(lua_State
*ps
) {
119 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
120 LUA_RETURN(ps
, LUA_FAIL
);
122 n
= lua_tostring(ps
, 1);
123 msg
= lua_tostring(ps
, 2);
125 np
= getnickbynick(n
);
126 if(!np
|| !lua_lineok(msg
))
127 LUA_RETURN(ps
, LUA_FAIL
);
129 lua_message(np
, "%s", msg
);
131 LUA_RETURN(ps
, LUA_OK
);
134 static int lua_kill(lua_State
*ps
) {
138 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
139 LUA_RETURN(ps
, LUA_FAIL
);
141 n
= lua_tostring(ps
, 1);
142 msg
= lua_tostring(ps
, 2);
144 np
= getnickbynick(n
);
146 LUA_RETURN(ps
, LUA_FAIL
);
148 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
149 LUA_RETURN(ps
, LUA_FAIL
);
152 LUA_RETURN(ps
, LUA_FAIL
);
154 killuser(lua_nick
, np
, "%s", msg
);
156 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-KILL: %s (%s)", np
->nick
, msg
));
159 static int lua_kick(lua_State
*ps
) {
160 const char *n
, *msg
, *chan
;
165 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2) || !lua_isstring(ps
, 3))
166 LUA_RETURN(ps
, LUA_FAIL
);
168 chan
= lua_tostring(ps
, 1);
169 n
= lua_tostring(ps
, 2);
170 msg
= lua_tostring(ps
, 3);
172 if(lua_isboolean(ps
, 4) && !lua_toboolean(ps
, 4))
175 np
= getnickbynick(n
);
177 LUA_RETURN(ps
, LUA_FAIL
);
179 if(dochecks
&& (IsOper(np
) || IsXOper(np
) || IsService(np
)))
180 LUA_RETURN(ps
, LUA_FAIL
);
182 cp
= findchannel((char *)chan
);
184 LUA_RETURN(ps
, LUA_FAIL
);
187 LUA_RETURN(ps
, LUA_FAIL
);
189 localkickuser(lua_nick
, cp
, np
, msg
);
191 LUA_RETURN(ps
, LUA_OK
);
194 static int lua_invite(lua_State
*ps
) {
198 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
199 LUA_RETURN(ps
, LUA_FAIL
);
201 np
= getnickbynick((char *)lua_tostring(ps
, 1));
203 LUA_RETURN(ps
, LUA_FAIL
);
205 cp
= findchannel((char *)lua_tostring(ps
, 2));
207 LUA_RETURN(ps
, LUA_FAIL
);
209 localinvite(lua_nick
, cp
, np
);
211 LUA_RETURN(ps
, LUA_OK
);
214 static int lua_gline(lua_State
*ps
) {
218 int duration
, usercount
= 0;
221 if(!lua_isstring(ps
, 1) || !lua_isint(ps
, 2) || !lua_isstring(ps
, 3))
222 LUA_RETURN(ps
, LUA_FAIL
);
224 duration
= lua_toint(ps
, 2);
225 if((duration
< 1) || (duration
> 31 * 86400))
226 LUA_RETURN(ps
, LUA_FAIL
);
228 reason
= lua_tostring(ps
, 3);
229 if(!lua_lineok(reason
) || !reason
)
230 LUA_RETURN(ps
, LUA_FAIL
);
232 target
= getnickbynick(lua_tostring(ps
, 1));
233 if(!target
|| (IsOper(target
) || IsXOper(target
) || IsService(target
)))
234 LUA_RETURN(ps
, LUA_FAIL
);
238 LUA_RETURN(ps
, LUA_FAIL
);
240 usercount
= hp
->clonecount
;
241 if(usercount
> 10) { /* (decent) trusted host */
247 for (j
=0;j
<NICKHASHSIZE
;j
++)
248 for (np
=nicktable
[j
];np
;np
=np
->next
)
249 if (np
&& (np
->host
== hp
) && (!ircd_strcmp(np
->ident
, target
->ident
)))
253 LUA_RETURN(ps
, LUA_FAIL
);
255 snprintf(mask
, sizeof(mask
), "*%s@%s", target
->ident
, IPtostr(target
->ipaddress
));
257 snprintf(mask
, sizeof(mask
), "*@%s", IPtostr(target
->ipaddress
));
260 irc_send("%s GL * +%s %d :%s", mynumeric
->content
, mask
, duration
, reason
);
261 LUA_RETURN(ps
, lua_cmsg(LUA_PUKECHAN
, "lua-GLINE: %s (%d users, %d seconds -- %s)", mask
, usercount
, duration
, reason
));
264 static int lua_getchaninfo(lua_State
*ps
) {
267 if(!lua_isstring(ps
, 1))
270 cp
= findchannel((char *)lua_tostring(ps
, 1));
274 LUA_PUSHCHAN(ps
, cp
);
279 static int lua_opchan(lua_State
*ps
) {
283 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
284 LUA_RETURN(ps
, LUA_FAIL
);
286 cp
= findchannel((char *)lua_tostring(ps
, 1));
288 LUA_RETURN(ps
, LUA_FAIL
);
290 np
= getnickbynick((char *)lua_tostring(ps
, 2));
292 LUA_RETURN(ps
, LUA_FAIL
);
294 localsetmodes(lua_nick
, cp
, np
, MC_OP
);
295 LUA_RETURN(ps
, LUA_OK
);
298 static int lua_deopchan(lua_State
*ps
) {
302 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
303 LUA_RETURN(ps
, LUA_FAIL
);
305 cp
= findchannel((char *)lua_tostring(ps
, 1));
307 LUA_RETURN(ps
, LUA_FAIL
);
309 np
= getnickbynick((char *)lua_tostring(ps
, 2));
311 LUA_RETURN(ps
, LUA_FAIL
);
313 localsetmodes(lua_nick
, cp
, np
, MC_DEOP
);
314 LUA_RETURN(ps
, LUA_OK
);
317 static int lua_voicechan(lua_State
*ps
) {
321 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
322 LUA_RETURN(ps
, LUA_FAIL
);
324 cp
= findchannel((char *)lua_tostring(ps
, 1));
326 LUA_RETURN(ps
, LUA_FAIL
);
328 np
= getnickbynick((char *)lua_tostring(ps
, 2));
330 LUA_RETURN(ps
, LUA_FAIL
);
332 localsetmodes(lua_nick
, cp
, np
, MC_VOICE
);
333 LUA_RETURN(ps
, LUA_OK
);
336 static int lua_counthost(lua_State
*ps
) {
340 if(!lua_islong(ps
, 1))
343 numeric
= lua_tolong(ps
, 1);
345 np
= getnickbynumeric(numeric
);
349 lua_pushint(ps
, np
->host
->clonecount
);
353 static int lua_versioninfo(lua_State
*ps
) {
354 lua_pushstring(ps
, LUA_VERSION
);
355 lua_pushstring(ps
, LUA_BOTVERSION
);
356 lua_pushstring(ps
, __DATE__
);
357 lua_pushstring(ps
, __TIME__
);
359 lua_pushstring(ps
, LUA_AUXVERSION
);
364 static int lua_basepath(lua_State
*ps
) {
365 lua_pushfstring(ps
, "%s/", cpath
->content
);
371 static int lua_getuserbyauth(lua_State
*l
) {
376 if(!lua_isstring(l
, 1))
379 acc
= lua_tostring(l
, 1);
381 for(i
=0;i
<NICKHASHSIZE
;i
++) {
382 for(np
=nicktable
[i
];np
;np
=np
->next
) {
383 if(np
&& np
->authname
&& !ircd_strcmp(np
->authname
, acc
)) {
393 static int lua_getnickchans(lua_State
*l
) {
398 if(!lua_islong(l
, 1))
401 np
= getnickbynumeric(lua_tolong(l
, 1));
405 channels
= (channel
**)np
->channels
->content
;
406 for(i
=0;i
<np
->channels
->cursi
;i
++)
407 lua_pushstring(l
, channels
[i
]->index
->name
->content
);
409 return np
->channels
->cursi
;
412 static int lua_getnickchanindex(lua_State
*l
) {
416 if(!lua_islong(l
, 1) || !lua_isint(l
, 2))
419 np
= getnickbynumeric(lua_tolong(l
, 1));
423 offset
= lua_toint(l
, 2);
424 if((offset
< 0) || (offset
>= np
->channels
->cursi
))
427 lua_pushstring(l
, ((channel
**)np
->channels
->content
)[offset
]->index
->name
->content
);
435 struct lua_pusher
*nickhashpusher
[MAX_PUSHER
];
437 static int lua_getnextnick(lua_State
*l
) {
438 if(!lasthashnick
&& (hashindex
!= -1))
444 if(hashindex
>= NICKHASHSIZE
)
446 lasthashnick
= nicktable
[hashindex
];
448 lasthashnick
= lasthashnick
->next
;
450 } while(!lasthashnick
);
452 return lua_usepusher(l
, nickhashpusher
, lasthashnick
);
455 static int lua_getfirstnick(lua_State
*l
) {
459 lua_setupnickpusher(l
, 1, nickhashpusher
, MAX_PUSHER
);
461 return lua_getnextnick(l
);
465 chanindex
*lasthashchan
;
467 struct lua_pusher
*chanhashpusher
[MAX_PUSHER
];
469 static int lua_getnextchan(lua_State
*l
) {
470 if(!lasthashchan
&& (chanhashindex
!= -1))
476 if(chanhashindex
>= CHANNELHASHSIZE
)
478 lasthashchan
= chantable
[chanhashindex
];
480 lasthashchan
= lasthashchan
->next
;
482 } while(!lasthashchan
|| !lasthashchan
->channel
);
484 return lua_usepusher(l
, chanhashpusher
, lasthashchan
);
487 static int lua_getfirstchan(lua_State
*l
) {
491 lua_setupchanpusher(l
, 1, chanhashpusher
, MAX_PUSHER
);
493 return lua_getnextchan(l
);
496 static int lua_getnickchancount(lua_State
*l
) {
499 if(!lua_islong(l
, 1))
502 np
= getnickbynumeric(lua_tolong(l
, 1));
506 lua_pushint(l
, np
->channels
->cursi
);
511 static int lua_gethostusers(lua_State
*l
) {
515 if(!lua_islong(l
, 1))
518 np
= getnickbynumeric(lua_tolong(l
, 1));
519 if(!np
|| !np
->host
|| !np
->host
->nicks
)
522 np
= np
->host
->nicks
;
523 count
= np
->host
->clonecount
;
533 static int lua_getnickcountry(lua_State
*l
) {
537 ext
= findnickext("geoip");
541 if(!lua_islong(l
, 1))
544 np
= getnickbynumeric(lua_tolong(l
, 1));
548 lua_pushint(l
, (int)np
->exts
[ext
]);
552 static int lua_chanfix(lua_State
*ps
) {
556 if(!lua_isstring(ps
, 1))
557 LUA_RETURN(ps
, LUA_FAIL
);
559 cp
= findchannel((char *)lua_tostring(ps
, 1));
560 if(!cp
|| !cp
->index
)
561 LUA_RETURN(ps
, LUA_FAIL
);
563 np
= getnickbynick(LUA_CHANFIXBOT
);
565 LUA_RETURN(ps
, LUA_FAIL
);
567 lua_message(np
, "chanfix %s", cp
->index
->name
->content
);
569 LUA_RETURN(ps
, LUA_OK
);
572 static int lua_clearmode(lua_State
*ps
) {
579 if(!lua_isstring(ps
, 1))
580 LUA_RETURN(ps
, LUA_FAIL
);
582 cp
= findchannel((char *)lua_tostring(ps
, 1));
583 if(!cp
|| !cp
->users
)
584 LUA_RETURN(ps
, LUA_FAIL
);
586 localsetmodeinit(&changes
, cp
, lua_nick
);
588 localdosetmode_key(&changes
, NULL
, MCB_DEL
);
589 localdosetmode_simple(&changes
, 0, CHANMODE_INVITEONLY
| CHANMODE_LIMIT
);
592 localdosetmode_ban(&changes
, bantostring(cp
->bans
), MCB_DEL
);
594 for(i
=0,lp
=cp
->users
->content
;i
<cp
->users
->hashsize
;i
++,lp
++)
595 if((*lp
!= nouser
) && (*lp
& CUMODE_OP
)) {
596 np
= getnickbynumeric(*lp
);
597 if(np
&& !IsService(np
))
598 localdosetmode_nick(&changes
, np
, MC_DEOP
);
601 localsetmodeflush(&changes
, 1);
603 LUA_RETURN(ps
, LUA_OK
);
606 static int lua_ban(lua_State
*ps
) {
612 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
613 LUA_RETURN(ps
, LUA_FAIL
);
615 if(lua_isboolean(ps
, 3) && lua_toboolean(ps
, 3))
618 cp
= findchannel((char *)lua_tostring(ps
, 1));
620 LUA_RETURN(ps
, LUA_FAIL
);
622 mask
= lua_tostring(ps
, 2);
623 if(!mask
|| !mask
[0] || !lua_lineok(mask
))
624 LUA_RETURN(ps
, LUA_FAIL
);
626 localsetmodeinit(&changes
, cp
, lua_nick
);
627 localdosetmode_ban(&changes
, mask
, dir
);
628 localsetmodeflush(&changes
, 1);
630 LUA_RETURN(ps
, LUA_OK
);
633 static int lua_topic(lua_State
*ps
) {
637 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
638 LUA_RETURN(ps
, LUA_FAIL
);
640 cp
= findchannel((char *)lua_tostring(ps
, 1));
642 LUA_RETURN(ps
, LUA_FAIL
);
644 topic
= (char *)lua_tostring(ps
, 2);
645 if(!topic
|| !lua_lineok(topic
))
646 LUA_RETURN(ps
, LUA_FAIL
);
648 localsettopic(lua_nick
, cp
, topic
);
650 LUA_RETURN(ps
, LUA_OK
);
653 static int lua_getuserchanmodes(lua_State
*l
) {
658 if(!lua_islong(l
, 1) || !lua_isstring(l
, 2))
661 np
= getnickbynumeric(lua_tolong(l
, 1));
665 cp
= findchannel((char *)lua_tostring(l
, 2));
666 if(!cp
|| !cp
->users
)
669 lp
= getnumerichandlefromchanhash(cp
->users
, np
->numeric
);
673 LUA_PUSHNICKCHANMODES(l
, lp
);
677 static int lua_getusermodes(lua_State
*l
) {
680 if(!lua_islong(l
, 1))
683 np
= getnickbynumeric(lua_tolong(l
, 1));
687 lua_pushstring(l
, printflags(np
->umodes
, umodeflags
));
691 static int lua_getnickbynick(lua_State
*l
) {
694 if(!lua_isstring(l
, 1))
697 np
= getnickbynick(lua_tostring(l
, 1));
705 static int lua_getnickbynumeric(lua_State
*l
) {
708 if(!lua_islong(l
, 1))
711 np
= getnickbynumeric(lua_tolong(l
, 1));
719 static int lua_fastgetnickbynumeric(lua_State
*l
) {
720 static struct lua_pusher
*ourpusher
[MAX_PUSHER
];
723 if(!lua_islong(l
, 1))
726 np
= getnickbynumeric(lua_tolong(l
, 1));
730 lua_setupnickpusher(l
, 2, ourpusher
, MAX_PUSHER
);
731 return lua_usepusher(l
, ourpusher
, np
);
734 int channelnicklistindex
, channelnicklistcount
= -1;
735 channel
*channelnicklist
;
737 struct lua_pusher
*channelnickpusher
[MAX_PUSHER
];
739 static int lua_getnextchannick(lua_State
*l
) {
743 channelnicklistindex
++;
745 if(channelnicklistindex
>= channelnicklistcount
)
747 } while((channelnicklist
->users
->content
[channelnicklistindex
] == nouser
) || !(np
= getnickbynumeric(channelnicklist
->users
->content
[channelnicklistindex
])));
749 return lua_usepusher(l
, channelnickpusher
, np
);
752 static int lua_getfirstchannick(lua_State
*l
) {
753 if(!lua_isstring(l
, 1))
756 channelnicklist
= findchannel((char *)lua_tostring(l
, 1));
757 if(!channelnicklist
|| !channelnicklist
->users
)
760 channelnicklistindex
= -1;
761 channelnicklistcount
= channelnicklist
->users
->hashsize
;
763 lua_setupnickpusher(l
, 2, channelnickpusher
, MAX_PUSHER
);
765 return lua_getnextchannick(l
);
768 static int lua_nickonchan(lua_State
*l
) {
770 if(lua_islong(l
, 1) && lua_isstring(l
, 2)) {
771 channel
*cp
= findchannel((char *)lua_tostring(l
, 2));
772 if(cp
&& cp
->users
) {
773 unsigned long *lp
= getnumerichandlefromchanhash(cp
->users
, lua_tolong(l
, 1));
779 lua_pushboolean(l
, success
);
783 void lua_registercommands(lua_State
*l
) {
784 lua_register(l
, "irc_smsg", lua_smsg
);
785 lua_register(l
, "irc_skill", lua_skill
);
787 lua_register(l
, "chanmsg", lua_chanmsg
);
788 lua_register(l
, "versioninfo", lua_versioninfo
);
789 lua_register(l
, "basepath", lua_basepath
);
791 lua_register(l
, "irc_report", lua_chanmsg
);
792 lua_register(l
, "irc_ctcp", lua_ctcp
);
793 lua_register(l
, "irc_kill", lua_kill
);
794 lua_register(l
, "irc_kick", lua_kick
);
795 lua_register(l
, "irc_invite", lua_invite
);
796 lua_register(l
, "irc_gline", lua_gline
);
797 lua_register(l
, "irc_getchaninfo", lua_getchaninfo
);
798 lua_register(l
, "irc_counthost", lua_counthost
);
799 lua_register(l
, "irc_getuserbyauth", lua_getuserbyauth
);
800 lua_register(l
, "irc_notice", lua_noticecmd
);
801 lua_register(l
, "irc_privmsg", lua_privmsgcmd
);
802 lua_register(l
, "irc_opchan", lua_opchan
);
803 lua_register(l
, "irc_voicechan", lua_voicechan
);
804 lua_register(l
, "irc_chanfix", lua_chanfix
);
805 lua_register(l
, "irc_clearmode", lua_clearmode
);
806 lua_register(l
, "irc_ban", lua_ban
);
807 lua_register(l
, "irc_deopchan", lua_deopchan
);
808 lua_register(l
, "irc_topic", lua_topic
);
810 lua_register(l
, "irc_getnickbynick", lua_getnickbynick
);
811 lua_register(l
, "irc_getnickbynumeric", lua_getnickbynumeric
);
812 lua_register(l
, "irc_getfirstnick", lua_getfirstnick
);
813 lua_register(l
, "irc_getnextnick", lua_getnextnick
);
815 lua_register(l
, "irc_getnickchans", lua_getnickchans
);
816 lua_register(l
, "irc_getnickchanindex", lua_getnickchanindex
);
817 lua_register(l
, "irc_getnickchancount", lua_getnickchancount
);
819 lua_register(l
, "irc_getuserchanmodes", lua_getuserchanmodes
);
821 lua_register(l
, "irc_getfirstchannick", lua_getfirstchannick
);
822 lua_register(l
, "irc_getnextchannick", lua_getnextchannick
);
824 lua_register(l
, "irc_gethostusers", lua_gethostusers
);
825 lua_register(l
, "irc_getnickcountry", lua_getnickcountry
);
827 lua_register(l
, "irc_getfirstchan", lua_getfirstchan
);
828 lua_register(l
, "irc_getnextchan", lua_getnextchan
);
829 lua_register(l
, "irc_getusermodes", lua_getusermodes
);
830 lua_register(l
, "irc_nickonchan", lua_nickonchan
);
832 lua_register(l
, "irc_fastgetnickbynumeric", lua_fastgetnickbynumeric
);
837 static int lua_smsg(lua_State
*ps
) {
838 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
839 LUA_RETURN(ps
, LUA_FAIL
);
841 LUA_RETURN(ps
, lua_cmsg((char *)lua_tostring(ps
, 2), "%s", lua_tostring(ps
, 1)));
844 static int lua_skill(lua_State
*ps
) {
848 if(!lua_isstring(ps
, 1) || !lua_isstring(ps
, 2))
849 LUA_RETURN(ps
, LUA_FAIL
);
851 n
= lua_tostring(ps
, 1);
852 msg
= lua_tostring(ps
, 2);
854 np
= getnickbynick(n
);
856 LUA_RETURN(ps
, LUA_FAIL
);
858 if(IsOper(np
) || IsService(np
) || IsXOper(np
))
859 LUA_RETURN(ps
, LUA_FAIL
);
862 LUA_RETURN(ps
, LUA_FAIL
);
864 killuser(lua_nick
, np
, "%s", msg
);
866 LUA_RETURN(ps
, LUA_OK
);
869 #define PUSHER_STRING 1
870 #define PUSHER_REALNAME 2
872 #define PUSHER_LONG 4
873 #define PUSHER_HOSTNAME 5
874 #define PUSHER_SSTRING 6
875 #define PUSHER_TOTALUSERS 7
876 #define PUSHER_TOPIC 8
878 void lua_initnickpusher(void) {
881 #define PUSH_NICKPUSHER(F2, O2) nickpusher[i].argtype = F2; nickpusher[i].structname = #O2; nickpusher[i].offset = offsetof(nick, O2); i++;
883 PUSH_NICKPUSHER(PUSHER_STRING
, nick
);
884 PUSH_NICKPUSHER(PUSHER_STRING
, ident
);
885 PUSH_NICKPUSHER(PUSHER_HOSTNAME
, host
);
886 PUSH_NICKPUSHER(PUSHER_REALNAME
, realname
);
887 PUSH_NICKPUSHER(PUSHER_STRING
, authname
);
888 PUSH_NICKPUSHER(PUSHER_IP
, ipaddress
);
889 PUSH_NICKPUSHER(PUSHER_LONG
, numeric
);
892 nickpusher
[i
].argtype
= 0;
895 INLINE
void lua_setuppusher(struct lua_pusher
*pusherlist
, lua_State
*l
, int index
, struct lua_pusher
**lp
, int max
, int pcount
) {
901 if(!lua_istable(l
, index
) || (max
< 2))
908 while(lua_next(l
, index
)) {
909 if(lua_isint(l
, -1)) {
910 int index
= lua_toint(l
, -1);
911 if((index
>= 0) && (index
< pcount
))
912 lp
[current
++] = &pusherlist
[index
];
924 INLINE
int lua_usepusher(lua_State
*l
, struct lua_pusher
**lp
, void *np
) {
928 void *offset
= (void *)np
+ (*lp
)->offset
;
930 switch((*lp
)->argtype
) {
932 lua_pushstring(l
, (char *)offset
);
934 case PUSHER_HOSTNAME
:
935 lua_pushstring(l
, (*(host
**)offset
)->name
->content
);
937 case PUSHER_REALNAME
:
938 lua_pushstring(l
, (*(realname
**)offset
)->name
->content
);
941 lua_pushstring(l
, (*((sstring
**)offset
))->content
);
944 lua_pushlong(l
, *((long *)offset
));
947 lua_pushstring(l
, IPtostr(*((long *)offset
)));
949 case PUSHER_TOTALUSERS
:
950 lua_pushint(l
, (*((channel
**)offset
))->users
->totalusers
);
953 if((*((channel
**)offset
))->topic
) {
954 lua_pushstring(l
, (*((channel
**)offset
))->topic
->content
);
968 void lua_initchanpusher(void) {
971 #define PUSH_CHANPUSHER(F2, O2, N2) chanpusher[i].argtype = F2; chanpusher[i].structname = N2; chanpusher[i].offset = offsetof(chanindex, O2); i++;
973 PUSH_CHANPUSHER(PUSHER_SSTRING
, name
, "name");
974 PUSH_CHANPUSHER(PUSHER_TOTALUSERS
, channel
, "totalusers");
975 PUSH_CHANPUSHER(PUSHER_TOPIC
, channel
, "topic");
978 chanpusher
[i
].argtype
= 0;