5 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup);
6 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan);
8 struct neonserv_cmd_peek_cache {
9 struct ClientSocket *client, *textclient;
10 struct UserNode *user;
13 static CMD_BIND(neonserv_cmd_peek) {
14 struct neonserv_cmd_peek_cache *cache = malloc(sizeof(*cache));
16 perror("malloc() failed");
19 cache->client = client;
20 cache->textclient = getTextBot();
22 get_userlist_with_invisible(chan, neonserv_cmd_peek_userlist_lookup, cache);
25 static USERLIST_CALLBACK(neonserv_cmd_peek_userlist_lookup) {
26 struct neonserv_cmd_peek_cache *cache = data;
27 neonserv_cmd_peek_async1(cache->client, cache->textclient, cache->user, chan);
31 static void neonserv_cmd_peek_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan) {
32 reply(textclient, user, "NS_PEEK_HEADER", chan->name);
33 reply(textclient, user, "NS_PEEK_TOPIC", chan->topic);
35 getModeString(chan->modes, tmpStr);
36 reply(textclient, user, "NS_PEEK_MODES", tmpStr);
37 struct ChanUser *chanuser;
38 int op_count = 0, voice_count = 0, normal_count = 0, invi_count = 0;
39 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
40 if(chanuser->flags & CHANUSERFLAG_OPPED)
42 else if(chanuser->flags & CHANUSERFLAG_VOICED)
44 else if(chanuser->flags & CHANUSERFLAG_VOICED)
49 reply(textclient, user, "NS_PEEK_USERS", op_count+voice_count+invi_count+normal_count, op_count, voice_count, normal_count, invi_count);
51 int headerlen = 10 + strlen(user->nick);
52 for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
53 if(chanuser->flags & CHANUSERFLAG_OPPED) {
54 if(tmpStrPos + headerlen + strlen(chanuser->user->nick) + 2 >= 512) {
56 reply(textclient, user, "%s", tmpStr);
59 tmpStrPos += sprintf(tmpStr + tmpStrPos, (tmpStrPos ? ", %s" : "%s"), chanuser->user->nick);
63 reply(textclient, user, "%s", tmpStr);