struct channel *chan = findChannel(args[0]);
if (!chan)
return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
- if (!trie_get(&chan->members, client->key))
+ if (!map_get(&chan->members, client->key))
return err_notonchannel(client, chan), sendbuf(client), 0;
- if (trie_set(&chan->o, client->key, client, NULL) == -1)
+ if (map_set(&chan->o, client->key, client, NULL) == -1)
abort();
copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +o %s\r\n", chan->name, client->nick);
sendbuf_chan(chan);
channel_sendtopic(client, chan, 0);
} else {
// TODO: membership check, maybe?
- if (chan->dmode & DMODE_TOPICPROT && !trie_get(&chan->o, client->key))
+ if (chan->dmode & DMODE_TOPICPROT && !map_get(&chan->o, client->key))
return 0; // FIXME: error 482
free(chan->topic);
free(chan->topic_who);
if (!chan)
return err_nosuchchannel(client, args[1]), sendbuf(client), 0;
if (chan->dmode & DMODE_INVITEONLY) {
- if (!trie_get(&chan->o, client->key))
+ if (!map_get(&chan->o, client->key))
return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
} else {
- if (!trie_get(&chan->members, client->key))
+ if (!map_get(&chan->members, client->key))
return err_notonchannel(client, chan), sendbuf(client), 0;
}
struct client_data *cl = findClient(args[0]);
if (!cl)
return err_nosuchnick(client, args[0]), sendbuf(client), 0;
- if (trie_get(&chan->members, cl->key))
+ if (map_get(&chan->members, cl->key))
return err_useronchannel(client, cl->nick, chan), sendbuf(client), 0;
- if (trie_set(&chan->invitees, cl->nick, cl, NULL) == -1)
+ if (map_set(&chan->invitees, cl->nick, cl, NULL) == -1)
abort();
- if (trie_set(&cl->invites, chan->name, chan, NULL) == -1)
+ if (map_set(&cl->invites, chan->name, chan, NULL) == -1)
abort();
rpl_inviting(client, cl, chan);
sendbuf(client);
struct channel *chan = findChannel(args[0]);
if (!chan)
return err_nosuchchannel(client, args[0]), sendbuf(client), 0;
- if (!trie_get(&chan->o, client->key))
+ if (!map_get(&chan->o, client->key))
return err_chanoprivsneeded(client, chan), sendbuf(client), 0;
- if (!trie_get(&chan->members, client->key))
+ if (!map_get(&chan->members, client->key))
return err_notonchannel(client, chan), sendbuf(client), 0;
char *p = args[1];
do {
if (match_list(client, &chan->listb) && !match_list(client, &chan->liste))
return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
if (chan->dmode & DMODE_INVITEONLY
- && !trie_get(&chan->invitees, client->key) && !match_list(client, &chan->listI))
+ && !map_get(&chan->invitees, client->key) && !match_list(client, &chan->listI))
return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
- if (chan->dmode & DMODE_NOEXTERNAL && !trie_get(&chan->members, client->key))
+ if (chan->dmode & DMODE_NOEXTERNAL && !map_get(&chan->members, client->key))
return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
- if (chan->dmode & DMODE_MODERATED && !trie_get(&chan->v, client->key) && !trie_get(&chan->o, client->key))
+ if (chan->dmode & DMODE_MODERATED && !map_get(&chan->v, client->key) && !map_get(&chan->o, client->key))
return err_cannotsendtochan(client, chan->name), sendbuf(client), 0;
- if (!trie_get(&chan->v, client->key) && !trie_get(&chan->o, client->key) &&
+ if (!map_get(&chan->v, client->key) && !map_get(&chan->o, client->key) &&
(strstr(args[1], "irc.supernets.org") || strstr(args[1], "IRC.SUPERNETS.ORG"))) {
msg_quit(client, "Quit: eel bearing atlantean", "");
sendbuf_visible(client);
struct channel *chan = findChannel(nick);
if (!chan)
return err_nosuchchannel(client, nick), sendbuf(client), 0;
- if (!trie_get(&chan->o, client->key))
+ if (!map_get(&chan->o, client->key))
return 0; // TODO: error
if (argc == 2) { // Type A channel modes
struct trie_find *f = NULL;
if (strchr(mask, ' '))
break; // TODO: error msg
stringlower(mask);
- if (trie_set(list, mask, is_plus ? mask /* dummy */ : NULL, NULL) == -1)
+ if (map_set(list, mask, is_plus ? mask /* dummy */ : NULL, NULL) == -1)
abort();
char which[2] = {*p, 0};
copy_strf(&databuf, ":%s!%s@%s MODE %s %s%s %s\r\n",
err_nosuchnick(client, nick), sendbuf(client);
break;
}
- if (!trie_get(&chan->members, cl->key)) {
+ if (!map_get(&chan->members, cl->key)) {
err_usernotinchannel(client, cl->nick, chan), sendbuf(client);
break;
}
- if (trie_set(*p == 'o' ? &chan->o : &chan->v, cl->key, is_plus ? cl : NULL, NULL) == -1)
+ if (map_set(*p == 'o' ? &chan->o : &chan->v, cl->key, is_plus ? cl : NULL, NULL) == -1)
abort();
copy_strf(&databuf, ":%s!%s@%s MODE %s %s%s %s\r\n",
client->nick, client->username, client->hostname,
if (trie_findfirst(&f, &channel_map) == 1)
do {
struct channel *chan = f->n->value;
- if (!(chan->dmode & DMODE_SECRET) || trie_get(&chan->members, client->key))
+ if (!(chan->dmode & DMODE_SECRET) || map_get(&chan->members, client->key))
rpl_list(client, chan), sendbuf(client);
} while(trie_findnext(&f) == 1);
rpl_listend(client), sendbuf(client);
if ((p = strchr(channel, ',')))
*p++ = '\0';
struct channel *chan = findChannel(channel);
- if (chan && (!(chan->dmode & DMODE_SECRET) || trie_get(&chan->members, client->key))) {
+ if (chan && (!(chan->dmode & DMODE_SECRET) || map_get(&chan->members, client->key))) {
channel_sendnames(client, chan);
} else {
rpl_endofnames(client, channel);
if (trie_findfirst(&f, &cl->channels) == 1)
do {
struct channel *chan = f->n->value;
- if ((cl->umode & UMODE_INVISIBLE || chan->dmode & DMODE_SECRET) && !trie_get(&chan->members, client->key))
+ if ((cl->umode & UMODE_INVISIBLE || chan->dmode & DMODE_SECRET) && !map_get(&chan->members, client->key))
continue;
rpl_whoischannels(client, cl, chan), sendbuf(client);
} while (trie_findnext(&f) == 1);
memcpy(key, nickname, nicklen+1);
stringlower(key);
- if (trie_get(&client_map, key)) {
+ if (map_get(&client_map, key)) {
err_nicknameinuse(client, nickname), sendbuf(client);
return;
}
msg_nick(client, nickname);
sendbuf(client);
sendbuf_visible(client);
- trie_unset(&client_map, client->key, NULL);
+ map_unset(&client_map, client->key, NULL);
struct trie_find *f = NULL;
if (trie_findfirst(&f, &client->channels) == 1)
do {
struct channel *chan = f->n->value;
- trie_unset(&chan->members, client->key, NULL);
- if (trie_set(&chan->members, key, client, NULL) == -1)
+ map_unset(&chan->members, client->key, NULL);
+ if (map_set(&chan->members, key, client, NULL) == -1)
abort();
void *old;
- trie_unset(&chan->o, client->key, &old);
+ map_unset(&chan->o, client->key, &old);
if (old)
- if (trie_set(&chan->o, key, client, NULL) == -1)
+ if (map_set(&chan->o, key, client, NULL) == -1)
abort();
- trie_unset(&chan->v, client->key, &old);
+ map_unset(&chan->v, client->key, &old);
if (old)
- if (trie_set(&chan->v, key, client, NULL) == -1)
+ if (map_set(&chan->v, key, client, NULL) == -1)
abort();
} while(trie_findnext(&f) == 1);
free(client->nick);
client->key = mystrdup(key);
if (!client->key)
abort();
- if (trie_set(&client_map, client->key, client, 0) == -1)
+ if (map_set(&client_map, client->key, client, 0) == -1)
abort();
return;
char key[33];
memcpy(key, channel, chanlen+1);
stringlower(key);
- struct channel *chan = trie_get(&channel_map, key);
+ struct channel *chan = map_get(&channel_map, key);
int newchan = !chan;
if (!chan) {
chan = malloc(sizeof(struct channel));
if (!chan->key) abort();
chan->name = mystrdup(channel);
if (!chan->name) abort();
- if (trie_set(&channel_map, key, chan, NULL) == -1)
+ if (map_set(&channel_map, key, chan, NULL) == -1)
abort();
- if (trie_set(&chan->o, client->key, client, NULL) == -1)
+ if (map_set(&chan->o, client->key, client, NULL) == -1)
abort();
} else {
- if (trie_get(&chan->members, client->key))
+ if (map_get(&chan->members, client->key))
return;
if (chan->chankey && (!chankey || strcmp(chan->chankey, chankey) == 0))
return err_badchannelkey(client, chan), sendbuf(client);
if (match_list(client, &chan->listb) && !match_list(client, &chan->liste))
return err_bannedfromchan(client, chan), sendbuf(client);
if (chan->dmode & DMODE_INVITEONLY
- && !trie_get(&chan->invitees, client->key) && !match_list(client, &chan->listI))
+ && !map_get(&chan->invitees, client->key) && !match_list(client, &chan->listI))
return err_inviteonlychan(client, chan), sendbuf(client);
}
- if (trie_set(&chan->members, client->key, client, NULL) == -1)
+ if (map_set(&chan->members, client->key, client, NULL) == -1)
abort();
- if (trie_set(&client->channels, key, chan, NULL) == -1)
+ if (map_set(&client->channels, key, chan, NULL) == -1)
abort();
chan->member_count++;
// send JOIN to everyone
// TODO: send channel modes to the joining client
// apply +w modes
if (match_list(client, &chan->listwo)) {
- if (trie_set(&chan->o, client->key, client, NULL) == -1)
+ if (map_set(&chan->o, client->key, client, NULL) == -1)
abort();
copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +o %s\r\n", chan->name, client->nick);
sendbuf_chan(chan);
}
if (match_list(client, &chan->listwv)) {
- if (trie_set(&chan->v, client->key, client, NULL) == -1)
+ if (map_set(&chan->v, client->key, client, NULL) == -1)
abort();
copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +v %s\r\n", chan->name, client->nick);
sendbuf_chan(chan);
}
void channel_part(struct client_data *client, struct channel *chan, const char *reason, struct client_data *kicker)
{
- if (!trie_get(&chan->members, client->key))
+ if (!map_get(&chan->members, client->key))
return;
if (kicker) {
msg_kick(kicker, client, chan, reason);
msg_part(client, chan, *reason ? reason : NULL);
sendbuf_chan(chan);
}
- trie_unset(&client->channels, chan->key, NULL);
- trie_unset(&chan->members, client->key, NULL);
- trie_unset(&chan->o, client->key, NULL);
- trie_unset(&chan->v, client->key, NULL);
+ map_unset(&client->channels, chan->key, NULL);
+ map_unset(&chan->members, client->key, NULL);
+ map_unset(&chan->o, client->key, NULL);
+ map_unset(&chan->v, client->key, NULL);
chan->member_count--;
if (!chan->member_count && !(chan->dmode & DMODE_PERSIST))
channel_kill(chan);
}
void channel_kill(struct channel *chan)
{
- trie_unset(&channel_map, chan->key, NULL);
+ map_unset(&channel_map, chan->key, NULL);
struct trie_find *f = NULL;
if (trie_findfirst(&f, &chan->invitees) == 1)
do {
struct client_data *cl = f->n->value;
- trie_unset(&cl->invites, chan->key, NULL);
+ map_unset(&cl->invites, chan->key, NULL);
} while(trie_findnext(&f) == 1);
free(chan->key);
free(chan->name);
free(chan->topic);
free(chan->topic_who);
- trie_free(&chan->members);
- trie_free(&chan->o);
- trie_free(&chan->v);
- trie_free(&chan->listb);
- trie_free(&chan->liste);
- trie_free(&chan->listI);
- trie_free(&chan->listq);
- trie_free(&chan->listwo);
- trie_free(&chan->listwv);
- trie_free(&chan->invitees);
+ map_free(&chan->members);
+ map_free(&chan->o);
+ map_free(&chan->v);
+ map_free(&chan->listb);
+ map_free(&chan->liste);
+ map_free(&chan->listI);
+ map_free(&chan->listq);
+ map_free(&chan->listwo);
+ map_free(&chan->listwv);
+ map_free(&chan->invitees);
free(chan->chankey);
free(chan);
}
return NULL;
memcpy(key, nickname, len+1);
stringlower(key);
- return trie_get(&client_map, key);
+ return map_get(&client_map, key);
}
struct channel *findChannel(const char *channel)
{
char key[33];
memcpy(key, channel, chanlen+1);
stringlower(key);
- return trie_get(&channel_map, key);
+ return map_get(&channel_map, key);
}