2 #include "cmd_neonserv.h"
7 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup);
8 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan);
10 struct neonserv_cmd_peek_cache {
11 struct ClientSocket *client, *textclient;
12 struct UserNode *user;
15 CMD_BIND(neonserv_cmd_peek) {
16 struct neonserv_cmd_peek_cache *cache = malloc(sizeof(*cache));
18 perror("malloc() failed");
21 cache->client = client;
22 cache->textclient = getTextBot();
24 get_userlist_with_invisible(chan, neonserv_cmd_peek_userlist_lookup, cache);
27 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup) {
28 struct neonserv_cmd_peek_cache *cache = data;
29 neonserv_cmd_peek_async1(cache->client, cache->textclient, cache->user, chan);
33 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan) {
34 reply(textclient, user, "NS_PEEK_HEADER", chan->name);
35 reply(textclient, user, "NS_PEEK_TOPIC", chan->topic);
37 getModeString(chan->modes, tmpStr);
38 reply(textclient, user, "NS_PEEK_MODES", tmpStr);
39 struct ChanUser *chanuser;
40 int op_count = 0, voice_count = 0, normal_count = 0, invi_count = 0;
41 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
42 if(chanuser->flags & CHANUSERFLAG_OPPED)
44 else if(chanuser->flags & CHANUSERFLAG_VOICED)
46 else if(chanuser->flags & CHANUSERFLAG_VOICED)
51 reply(textclient, user, "NS_PEEK_USERS", op_count+voice_count+invi_count+normal_count, op_count, voice_count, normal_count, invi_count);
53 int headerlen = 10 + strlen(user->nick);
54 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
55 if(chanuser->flags & CHANUSERFLAG_OPPED) {
56 if(tmpStrPos + headerlen + strlen(chanuser->user->nick) + 2 >= 512) {
58 reply(textclient, user, "%s", tmpStr);
61 tmpStrPos += sprintf(tmpStr + tmpStrPos, (tmpStrPos ? ", %s" : "%s"), chanuser->user->nick);
65 reply(textclient, user, "%s", tmpStr);