1 /* cmd_neonserv_peek.c - NeonServ v5.1
2 * Copyright (C) 2011 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonserv.h"
23 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup);
24 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan);
26 struct neonserv_cmd_peek_cache {
27 struct ClientSocket *client, *textclient;
28 struct UserNode *user;
31 CMD_BIND(neonserv_cmd_peek) {
32 struct neonserv_cmd_peek_cache *cache = malloc(sizeof(*cache));
34 perror("malloc() failed");
37 cache->client = client;
38 cache->textclient = getTextBot();
40 get_userlist_with_invisible(chan, neonserv_cmd_peek_userlist_lookup, cache);
43 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup) {
44 struct neonserv_cmd_peek_cache *cache = data;
45 neonserv_cmd_peek_async1(cache->client, cache->textclient, cache->user, chan);
49 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan) {
50 reply(textclient, user, "NS_PEEK_HEADER", chan->name);
51 reply(textclient, user, "NS_PEEK_TOPIC", chan->topic);
53 getModeString(chan->modes, tmpStr);
54 reply(textclient, user, "NS_PEEK_MODES", tmpStr);
55 struct ChanUser *chanuser;
56 int op_count = 0, voice_count = 0, normal_count = 0, invi_count = 0;
57 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
58 if(chanuser->flags & CHANUSERFLAG_OPPED)
60 else if(chanuser->flags & CHANUSERFLAG_VOICED)
62 else if(chanuser->flags & CHANUSERFLAG_VOICED)
67 reply(textclient, user, "NS_PEEK_USERS", op_count+voice_count+invi_count+normal_count, op_count, voice_count, normal_count, invi_count);
69 int headerlen = 10 + strlen(user->nick);
70 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
71 if(chanuser->flags & CHANUSERFLAG_OPPED) {
72 if(tmpStrPos + headerlen + strlen(chanuser->user->nick) + 2 >= 512) {
74 reply(textclient, user, "%s", tmpStr);
77 tmpStrPos += sprintf(tmpStr + tmpStrPos, (tmpStrPos ? ", %s" : "%s"), chanuser->user->nick);
81 reply(textclient, user, "%s", tmpStr);