mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 06:28:55 +02:00
Upgrade channels structure.
This commit is contained in:
parent
271aa22aee
commit
9835d43977
|
@ -44,7 +44,7 @@ eb_canjoin(const char *data, struct Client *client_p, chan::chan *chptr, mode::t
|
|||
return INVALID;
|
||||
if (data == NULL)
|
||||
return INVALID;
|
||||
chptr2 = find_channel(data);
|
||||
chptr2 = chan::get(data, std::nothrow);
|
||||
/* must exist, and no point doing this with the same channel */
|
||||
if (chptr2 == NULL || chptr2 == chptr)
|
||||
return INVALID;
|
||||
|
|
|
@ -41,7 +41,7 @@ static int eb_channel(const char *data, struct Client *client_p,
|
|||
if (data == NULL)
|
||||
return INVALID;
|
||||
|
||||
chptr2 = find_channel(data);
|
||||
chptr2 = chan::get(data, std::nothrow);
|
||||
if (chptr2 == NULL)
|
||||
return INVALID;
|
||||
/* require consistent target */
|
||||
|
|
|
@ -52,7 +52,7 @@ m_findforwards(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *
|
|||
/* Allow ircops to search for forwards to nonexistent channels */
|
||||
if(!IsOper(source_p))
|
||||
{
|
||||
if((chptr = find_channel(parv[1])) == NULL || (msptr = get(chptr->members, *source_p, std::nothrow)) == NULL)
|
||||
if((chptr = chan::get(parv[1], std::nothrow)) == NULL || (msptr = get(chptr->members, *source_p, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOTONCHANNEL,
|
||||
form_str(ERR_NOTONCHANNEL), parv[1]);
|
||||
|
@ -76,9 +76,9 @@ m_findforwards(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *
|
|||
last_used = rb_current_time();
|
||||
}
|
||||
|
||||
RB_DLINK_FOREACH(ptr, chan::global_channel_list.head)
|
||||
for(const auto &pit : chan::chans)
|
||||
{
|
||||
chptr = (chan::chan *)ptr->data;
|
||||
chptr = pit.second.get();
|
||||
if(!irccmp(chptr->mode.forward, parv[1]))
|
||||
{
|
||||
if(p + chptr->name.size() >= end - 13)
|
||||
|
|
|
@ -55,7 +55,7 @@ mo_ojoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
move_me = 1;
|
||||
}
|
||||
|
||||
if((chptr = find_channel(parv[1])) == NULL)
|
||||
if((chptr = chan::get(parv[1], std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), parv[1]);
|
||||
|
|
|
@ -75,7 +75,7 @@ mo_okick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
|
||||
name = LOCAL_COPY(parv[1]);
|
||||
|
||||
chptr = find_channel(name);
|
||||
chptr = chan::get(name, std::nothrow);
|
||||
if(!chptr)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
|
||||
|
|
|
@ -66,7 +66,7 @@ mo_omode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
return;
|
||||
}
|
||||
|
||||
chptr = find_channel(parv[1]);
|
||||
chptr = chan::get(parv[1], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ mo_opme(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
return;
|
||||
}
|
||||
|
||||
if((chptr = find_channel(parv[1])) == NULL)
|
||||
if((chptr = chan::get(parv[1], std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), parv[1]);
|
||||
|
|
|
@ -71,7 +71,7 @@ m_remove(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
|
||||
name = parv[1];
|
||||
|
||||
chptr = find_channel(name);
|
||||
chptr = chan::get(name, std::nothrow);
|
||||
if(chptr == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
|
||||
|
|
|
@ -133,7 +133,7 @@ m_displaymsg(struct MsgBuf *msgbuf_p, struct Client *source_p, const char *chann
|
|||
if(!IsFloodDone(source_p))
|
||||
flood_endgrace(source_p);
|
||||
|
||||
if((chptr = find_channel(channel)) == NULL)
|
||||
if((chptr = chan::get(channel, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), channel);
|
||||
|
@ -203,7 +203,7 @@ me_roleplay(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou
|
|||
|
||||
/* Don't segfault if we get ROLEPLAY with an invalid channel.
|
||||
* This shouldn't happen but it's best to be on the safe side. */
|
||||
if((chptr = find_channel(parv[1])) == NULL)
|
||||
if((chptr = chan::get(parv[1], std::nothrow)) == NULL)
|
||||
return;
|
||||
|
||||
sendto_channel_local(chan::ALL_MEMBERS, chptr, ":%s!%s@npc.fakeuser.invalid PRIVMSG %s :%s", parv[2], source_p->name, parv[1], parv[3]);
|
||||
|
|
|
@ -171,8 +171,6 @@ struct chan
|
|||
mode::type last_checked_type;
|
||||
bool last_checked_result;
|
||||
|
||||
rb_dlink_node node = {0};
|
||||
|
||||
chan(const std::string &name);
|
||||
~chan() noexcept;
|
||||
};
|
||||
|
@ -244,18 +242,45 @@ const char * get_extban_string(void);
|
|||
int get_channel_access(client *source, chan *, membership *, int dir, const char *modestr);
|
||||
void send_join(chan &, client &);
|
||||
|
||||
//extern std::map<std::string, std::unique_ptr<chan>> chans;
|
||||
extern rb_dlink_list global_channel_list;
|
||||
|
||||
// Add and remove clients from channels
|
||||
auto empty(const chan &);
|
||||
auto local_size(const chan &);
|
||||
auto size(const chan &);
|
||||
void add(chan &, client &, const int &flags = PEON);
|
||||
void del(chan &, client &);
|
||||
void del(client &); // remove from all channels
|
||||
|
||||
// Channels
|
||||
extern std::map<const std::string *, std::unique_ptr<chan>, rfc1459::less> chans;
|
||||
|
||||
bool exists(const std::string &name);
|
||||
chan *get(const std::string &name, std::nothrow_t);
|
||||
chan &get(const std::string &name);
|
||||
chan &add(const std::string &name, client &); // get or add (but does not join the client)
|
||||
bool del(const std::string &name);
|
||||
bool del(const chan &);
|
||||
|
||||
// Initialize subsystem
|
||||
void init();
|
||||
|
||||
|
||||
inline auto
|
||||
size(const chan &chan)
|
||||
{
|
||||
return size(chan.members);
|
||||
}
|
||||
|
||||
inline auto
|
||||
local_size(const chan &chan)
|
||||
{
|
||||
return local_size(chan.members);
|
||||
}
|
||||
|
||||
inline auto
|
||||
empty(const chan &chan)
|
||||
{
|
||||
return empty(chan.members);
|
||||
}
|
||||
|
||||
inline bool
|
||||
is_secret(const chan &c)
|
||||
{
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace ircd {
|
|||
|
||||
extern rb_dictionary *nd_dict;
|
||||
extern rb_radixtree *resv_tree;
|
||||
extern rb_radixtree *channel_tree;
|
||||
|
||||
/* Magic value for FNV hash functions */
|
||||
#define FNV1_32_INIT 0x811c9dc5UL
|
||||
|
@ -80,10 +79,6 @@ extern void add_to_id_hash(const char *, struct Client *);
|
|||
extern void del_from_id_hash(const char *name, struct Client *client);
|
||||
extern struct Client *find_id(const char *name);
|
||||
|
||||
extern chan::chan *get_or_create_channel(struct Client *client_p, const char *chname, bool *isnew);
|
||||
extern void del_from_channel_hash(const char *name, chan::chan *chan);
|
||||
extern chan::chan *find_channel(const char *name);
|
||||
|
||||
extern void add_to_hostname_hash(const char *, struct Client *);
|
||||
extern void del_from_hostname_hash(const char *, struct Client *);
|
||||
extern rb_dlink_node *find_hostname(const char *);
|
||||
|
|
|
@ -29,12 +29,9 @@ using namespace ircd;
|
|||
int h_can_join;
|
||||
int h_can_send;
|
||||
int h_get_channel_access;
|
||||
|
||||
struct config_channel_entry ircd::ConfigChannel;
|
||||
|
||||
|
||||
rb_dlink_list chan::global_channel_list;
|
||||
//std::map<std::string, std::unique_ptr<chan::chan>> chan::chans;
|
||||
std::map<const std::string *, std::unique_ptr<chan::chan>, rfc1459::less> chan::chans;
|
||||
|
||||
void
|
||||
chan::init()
|
||||
|
@ -44,6 +41,79 @@ chan::init()
|
|||
h_get_channel_access = register_hook("get_channel_access");
|
||||
}
|
||||
|
||||
bool
|
||||
chan::del(const chan &chan)
|
||||
{
|
||||
return del(name(chan));
|
||||
}
|
||||
|
||||
bool
|
||||
chan::del(const std::string &name)
|
||||
{
|
||||
return chans.erase(&name);
|
||||
}
|
||||
|
||||
chan::chan &
|
||||
chan::add(const std::string &name,
|
||||
client &client)
|
||||
{
|
||||
if (name.empty())
|
||||
throw invalid_argument();
|
||||
|
||||
if (name.size() > CHANNELLEN && IsServer(&client))
|
||||
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
||||
"*** Long channel name from %s (%lu > %d): %s",
|
||||
client.name,
|
||||
name.size(),
|
||||
CHANNELLEN,
|
||||
name.c_str());
|
||||
|
||||
if (name.size() > CHANNELLEN)
|
||||
throw invalid_argument();
|
||||
|
||||
const auto it(chans.lower_bound(&name));
|
||||
if (it != end(chans))
|
||||
{
|
||||
auto &chan(*it->second);
|
||||
if (irccmp(chan.name, name) == 0)
|
||||
return chan;
|
||||
}
|
||||
|
||||
auto chan(std::make_unique<chan>(name));
|
||||
const auto name_p(&chan->name);
|
||||
const auto iit(chans.emplace_hint(it, name_p, std::move(chan)));
|
||||
return *iit->second;
|
||||
}
|
||||
|
||||
chan::chan &
|
||||
chan::get(const std::string &name)
|
||||
try
|
||||
{
|
||||
return *chans.at(&name);
|
||||
}
|
||||
catch(const std::out_of_range &e)
|
||||
{
|
||||
throw not_found();
|
||||
}
|
||||
|
||||
chan::chan *
|
||||
chan::get(const std::string &name,
|
||||
std::nothrow_t)
|
||||
{
|
||||
const auto it(chans.find(&name));
|
||||
if (it == end(chans))
|
||||
return nullptr;
|
||||
|
||||
const auto &ptr(it->second);
|
||||
return ptr.get();
|
||||
}
|
||||
|
||||
bool
|
||||
chan::exists(const std::string &name)
|
||||
{
|
||||
return chans.count(&name);
|
||||
}
|
||||
|
||||
chan::chan::chan(const std::string &name)
|
||||
:name{name}
|
||||
,mode{}
|
||||
|
@ -57,7 +127,7 @@ chan::chan::chan(const std::string &name)
|
|||
,first_received_message_time{0}
|
||||
,last_knock{0}
|
||||
,bants{0}
|
||||
,channelts{0}
|
||||
,channelts{rb_current_time()}
|
||||
,last_checked_ts{0}
|
||||
,last_checked_client{nullptr}
|
||||
,last_checked_type{mode::type(0)}
|
||||
|
@ -69,8 +139,6 @@ chan::chan::~chan()
|
|||
noexcept
|
||||
{
|
||||
clear_invites(*this);
|
||||
rb_dlinkDelete(&node, &global_channel_list);
|
||||
del_from_channel_hash(name.c_str(), this);
|
||||
}
|
||||
|
||||
/* remove_user_from_channels()
|
||||
|
@ -94,8 +162,8 @@ chan::del(client &client)
|
|||
chan.members.global.erase(member.git);
|
||||
chan.invites.erase(&client);
|
||||
|
||||
if (empty(chan.members) && ~chan.mode & mode::PERMANENT)
|
||||
delete &chan;
|
||||
if (empty(chan) && ~chan.mode & mode::PERMANENT)
|
||||
del(chan);
|
||||
}
|
||||
|
||||
client_chans.clear();
|
||||
|
@ -123,8 +191,8 @@ chan::del(chan &chan,
|
|||
chan.members.global.erase(member.git); // The member is destroyed at this point.
|
||||
client_chans.erase(it);
|
||||
|
||||
if (empty(chan.members) && ~chan.mode & mode::PERMANENT)
|
||||
delete &chan;
|
||||
if (empty(chan) && ~chan.mode & mode::PERMANENT)
|
||||
del(chan);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -154,13 +222,12 @@ chan::add(chan &chan,
|
|||
// Add iterator (pointer to the element) for constant time lookup/removal
|
||||
member.git = iit.first;
|
||||
|
||||
// Add channel to client's channel map, pointing to the membership;
|
||||
client_chans.emplace(&chan, &member);
|
||||
|
||||
// Add membership to a local list which can be iterated for local IO;
|
||||
// iterator to this element is saved more crucially here to prevent linear removal
|
||||
if (my(client))
|
||||
member.lit = local.emplace(end(local), &member);
|
||||
|
||||
// Add channel to client's channel map, pointing to the membership;
|
||||
client_chans.emplace(&chan, &member);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1282,7 +1349,7 @@ chan::resv_chan_forcepart(const char *name, const char *reason, int temp_time)
|
|||
/* for each user on our server in the channel list
|
||||
* send them a PART, and notify opers.
|
||||
*/
|
||||
chptr = find_channel(name);
|
||||
chptr = get(name, std::nothrow);
|
||||
if(chptr != NULL)
|
||||
{
|
||||
// Iterate a copy of the local list while all of this is going on
|
||||
|
|
|
@ -427,7 +427,7 @@ check_forward(Client *source_p, chan::chan *chptr, const char *forward)
|
|||
form_str(ERR_BADCHANNAME), forward);
|
||||
return false;
|
||||
}
|
||||
if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
|
||||
if(MyClient(source_p) && (targptr = chan::get(forward, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), forward);
|
||||
|
|
88
ircd/hash.cc
88
ircd/hash.cc
|
@ -28,7 +28,6 @@ rb_dictionary *client_connid_tree = NULL;
|
|||
rb_radixtree *client_id_tree = NULL;
|
||||
rb_radixtree *client_name_tree = NULL;
|
||||
|
||||
rb_radixtree *channel_tree = NULL;
|
||||
rb_radixtree *resv_tree = NULL;
|
||||
rb_radixtree *hostname_tree = NULL;
|
||||
|
||||
|
@ -47,7 +46,6 @@ init_hash(void)
|
|||
client_id_tree = rb_radixtree_create("client id", NULL);
|
||||
client_name_tree = rb_radixtree_create("client name", irccasecanon);
|
||||
|
||||
channel_tree = rb_radixtree_create("channel", irccasecanon);
|
||||
resv_tree = rb_radixtree_create("resv", irccasecanon);
|
||||
|
||||
hostname_tree = rb_radixtree_create("hostname", irccasecanon);
|
||||
|
@ -213,22 +211,6 @@ del_from_client_hash(const char *name, struct Client *client_p)
|
|||
rb_radixtree_delete(client_name_tree, name);
|
||||
}
|
||||
|
||||
/* del_from_channel_hash()
|
||||
*
|
||||
* removes a channel from the channel hash table
|
||||
*/
|
||||
void
|
||||
del_from_channel_hash(const char *name, chan::chan *chptr)
|
||||
{
|
||||
s_assert(name != NULL);
|
||||
s_assert(chptr != NULL);
|
||||
|
||||
if(EmptyString(name) || chptr == NULL)
|
||||
return;
|
||||
|
||||
rb_radixtree_delete(channel_tree, name);
|
||||
}
|
||||
|
||||
/* del_from_hostname_hash()
|
||||
*
|
||||
* removes a client entry from the hostname hash table
|
||||
|
@ -364,76 +346,6 @@ find_hostname(const char *hostname)
|
|||
return hlist->head;
|
||||
}
|
||||
|
||||
/* find_channel()
|
||||
*
|
||||
* finds a channel from the channel hash table
|
||||
*/
|
||||
chan::chan *
|
||||
find_channel(const char *name)
|
||||
{
|
||||
s_assert(name != NULL);
|
||||
if(EmptyString(name))
|
||||
return NULL;
|
||||
|
||||
return (chan::chan *)rb_radixtree_retrieve(channel_tree, name);
|
||||
}
|
||||
|
||||
/*
|
||||
* get_or_create_channel
|
||||
* inputs - client pointer
|
||||
* - channel name
|
||||
* - pointer to int flag whether channel was newly created or not
|
||||
* output - returns channel block or NULL if illegal name
|
||||
* - also modifies *isnew
|
||||
*
|
||||
* Get Channel block for chname (and allocate a new channel
|
||||
* block, if it didn't exist before).
|
||||
*/
|
||||
chan::chan *
|
||||
get_or_create_channel(struct Client *client_p, const char *chname, bool *isnew)
|
||||
{
|
||||
chan::chan *chptr;
|
||||
int len;
|
||||
const char *s = chname;
|
||||
|
||||
if(EmptyString(s))
|
||||
return NULL;
|
||||
|
||||
len = strlen(s);
|
||||
if(len > CHANNELLEN)
|
||||
{
|
||||
char *t;
|
||||
if(IsServer(client_p))
|
||||
{
|
||||
sendto_realops_snomask(SNO_DEBUG, L_ALL,
|
||||
"*** Long channel name from %s (%d > %d): %s",
|
||||
client_p->name, len, CHANNELLEN, s);
|
||||
}
|
||||
len = CHANNELLEN;
|
||||
t = LOCAL_COPY(s);
|
||||
*(t + CHANNELLEN) = '\0';
|
||||
s = t;
|
||||
}
|
||||
|
||||
chptr = (chan::chan *)rb_radixtree_retrieve(channel_tree, s);
|
||||
if (chptr != NULL)
|
||||
{
|
||||
if (isnew != NULL)
|
||||
*isnew = false;
|
||||
return chptr;
|
||||
}
|
||||
|
||||
if(isnew != NULL)
|
||||
*isnew = true;
|
||||
|
||||
chptr = new chan::chan(s);
|
||||
chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */
|
||||
|
||||
rb_dlinkAdd(chptr, &chptr->node, &chan::global_channel_list);
|
||||
rb_radixtree_add(channel_tree, chptr->name.c_str(), chptr);
|
||||
|
||||
return chptr;
|
||||
}
|
||||
|
||||
/* hash_find_resv()
|
||||
*
|
||||
|
|
|
@ -472,7 +472,7 @@ do_numeric(int numeric, struct Client *client_p, struct Client *source_p, int pa
|
|||
get_id(target_p, target_p), buffer);
|
||||
return;
|
||||
}
|
||||
else if((chptr = find_channel(parv[1])) != NULL)
|
||||
else if((chptr = chan::get(parv[1], std::nothrow)) != NULL)
|
||||
sendto_channel_flags(client_p, chan::ALL_MEMBERS, source_p, chptr,
|
||||
"%03d %s%s",
|
||||
numeric, chptr->name.c_str(), buffer);
|
||||
|
|
|
@ -633,9 +633,10 @@ burst_TS6(struct Client *client_p)
|
|||
call_hook(h_burst_client, &hclientinfo);
|
||||
}
|
||||
|
||||
RB_DLINK_FOREACH(ptr, chan::global_channel_list.head)
|
||||
|
||||
for(const auto &pit : chan::chans)
|
||||
{
|
||||
chptr = (chan::chan *)ptr->data;
|
||||
const auto &chptr(pit.second.get());
|
||||
|
||||
if(chptr->name[0] != '#')
|
||||
continue;
|
||||
|
|
|
@ -134,10 +134,10 @@ show_lusers(struct Client *source_p)
|
|||
form_str(RPL_LUSERUNKNOWN),
|
||||
(int)rb_dlink_list_length(&unknown_list));
|
||||
|
||||
if(rb_dlink_list_length(&chan::global_channel_list) > 0)
|
||||
if(!chan::chans.empty())
|
||||
sendto_one_numeric(source_p, RPL_LUSERCHANNELS,
|
||||
form_str(RPL_LUSERCHANNELS),
|
||||
rb_dlink_list_length(&chan::global_channel_list));
|
||||
chan::chans.size());
|
||||
|
||||
sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME),
|
||||
(int)rb_dlink_list_length(&lclient_list),
|
||||
|
|
|
@ -92,7 +92,7 @@ check_forward(struct Client *source_p, chan::chan *chptr,
|
|||
if (next == NULL)
|
||||
return NULL;
|
||||
|
||||
chptr = find_channel(next);
|
||||
chptr = chan::get(next, std::nothrow);
|
||||
/* Can only forward to existing channels */
|
||||
if (chptr == NULL)
|
||||
return NULL;
|
||||
|
@ -229,7 +229,7 @@ m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
|
|||
}
|
||||
|
||||
/* look for the channel */
|
||||
if((chptr = find_channel(name)) != NULL)
|
||||
if((chptr = chan::get(name, std::nothrow)) != NULL)
|
||||
{
|
||||
if(is_member(chptr, source_p))
|
||||
continue;
|
||||
|
@ -276,16 +276,17 @@ m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
|
|||
continue;
|
||||
}
|
||||
|
||||
if(chptr == NULL) /* If I already have a chptr, no point doing this */
|
||||
if(chptr == NULL) try // If I already have a chptr, no point doing this
|
||||
{
|
||||
chptr = get_or_create_channel(source_p, name, NULL);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
||||
me.name, source_p->name, name);
|
||||
continue;
|
||||
}
|
||||
chptr = &chan::add(name, *source_p);
|
||||
}
|
||||
catch(const chan::error &e)
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
||||
me.name,
|
||||
source_p->name,
|
||||
name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */
|
||||
|
@ -415,8 +416,15 @@ ms_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
mode.key[0] = mode.forward[0] = '\0';
|
||||
mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
|
||||
|
||||
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
|
||||
try
|
||||
{
|
||||
chptr = &chan::add(parv[2], *source_p);
|
||||
isnew = size(*chptr) == 0;
|
||||
}
|
||||
catch(chan::error &e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
newts = atol(parv[1]);
|
||||
oldts = chptr->channelts;
|
||||
|
@ -595,9 +603,15 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
else
|
||||
s = "";
|
||||
|
||||
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
|
||||
try
|
||||
{
|
||||
chptr = &chan::add(parv[2], *source_p);
|
||||
isnew = size(*chptr) == 0;
|
||||
}
|
||||
catch(chan::error &e)
|
||||
{
|
||||
return; /* channel name too long? */
|
||||
|
||||
}
|
||||
|
||||
oldts = chptr->channelts;
|
||||
oldmode = &chptr->mode;
|
||||
|
@ -656,8 +670,15 @@ ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
if (l == 0)
|
||||
{
|
||||
/* Channel was emptied, create a new one */
|
||||
if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
|
||||
try
|
||||
{
|
||||
chptr = &chan::add(parv[2], *source_p);
|
||||
isnew = size(*chptr) == 0;
|
||||
}
|
||||
catch(chan::error &e)
|
||||
{
|
||||
return; /* oops! */
|
||||
}
|
||||
|
||||
oldmode = &chptr->mode;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ m_kick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
|
|||
|
||||
name = parv[1];
|
||||
|
||||
chptr = find_channel(name);
|
||||
chptr = chan::get(name, std::nothrow);
|
||||
if(chptr == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
|
||||
|
|
|
@ -256,7 +256,7 @@ build_target_list(enum message_type msgtype, struct Client *client_p,
|
|||
if(IsServer(client_p) && *nick == '&')
|
||||
continue;
|
||||
|
||||
if((chptr = find_channel(nick)) != NULL)
|
||||
if((chptr = chan::get(nick, std::nothrow)) != NULL)
|
||||
{
|
||||
if(!duplicate_ptr(chptr))
|
||||
{
|
||||
|
@ -332,7 +332,7 @@ build_target_list(enum message_type msgtype, struct Client *client_p,
|
|||
* if the channel is found, fine, if not report an error
|
||||
*/
|
||||
|
||||
if((chptr = find_channel(nick)) != NULL)
|
||||
if((chptr = chan::get(nick, std::nothrow)) != NULL)
|
||||
{
|
||||
chan::membership *msptr;
|
||||
|
||||
|
@ -372,7 +372,7 @@ build_target_list(enum message_type msgtype, struct Client *client_p,
|
|||
if(IsServer(client_p) && *nick == '=' && nick[1] == '#')
|
||||
{
|
||||
nick++;
|
||||
if((chptr = find_channel(nick)) != NULL)
|
||||
if((chptr = chan::get(nick, std::nothrow)) != NULL)
|
||||
{
|
||||
if(!duplicate_ptr(chptr))
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@ m_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
|
|||
return;
|
||||
}
|
||||
|
||||
chptr = find_channel(dest);
|
||||
chptr = chan::get(dest, std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ ms_mode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
{
|
||||
chan::chan *chptr;
|
||||
|
||||
chptr = find_channel(parv[1]);
|
||||
chptr = chan::get(parv[1], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ ms_tmode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
return;
|
||||
}
|
||||
|
||||
chptr = find_channel(parv[2]);
|
||||
chptr = chan::get(parv[2], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
return;
|
||||
}
|
||||
|
||||
chptr = find_channel(parv[2]);
|
||||
chptr = chan::get(parv[2], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
@ -273,7 +273,7 @@ ms_bmask(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
if(!rfc1459::is_chan_prefix(parv[2][0]) || !chan::valid_name(parv[2]))
|
||||
return;
|
||||
|
||||
if((chptr = find_channel(parv[2])) == NULL)
|
||||
if((chptr = chan::get(parv[2], std::nothrow)) == NULL)
|
||||
return;
|
||||
|
||||
/* TS is higher, drop it. */
|
||||
|
|
|
@ -89,7 +89,7 @@ part_one_client(struct Client *client_p, struct Client *source_p, char *name, co
|
|||
chan::chan *chptr;
|
||||
chan::membership *msptr;
|
||||
|
||||
if((chptr = find_channel(name)) == NULL)
|
||||
if((chptr = chan::get(name, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
|
||||
return;
|
||||
|
|
|
@ -232,7 +232,7 @@ m_chantrace(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou
|
|||
}
|
||||
}
|
||||
|
||||
if((chptr = find_channel(name)) == NULL)
|
||||
if((chptr = chan::get(name, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL),
|
||||
name);
|
||||
|
|
|
@ -105,7 +105,7 @@ m_invite(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
return;
|
||||
}
|
||||
|
||||
if((chptr = find_channel(parv[2])) == NULL)
|
||||
if((chptr = chan::get(parv[2], std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), parv[2]);
|
||||
|
|
|
@ -81,7 +81,7 @@ m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
if((p = strchr(name, ',')))
|
||||
*p = '\0';
|
||||
|
||||
if((chptr = find_channel(name)) == NULL)
|
||||
if((chptr = chan::get(name, std::nothrow)) == NULL)
|
||||
{
|
||||
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
||||
form_str(ERR_NOSUCHCHANNEL), name);
|
||||
|
|
|
@ -389,7 +389,7 @@ static void safelist_channel_named(struct Client *source_p, const char *name, in
|
|||
return;
|
||||
}
|
||||
|
||||
chptr = find_channel(name);
|
||||
chptr = chan::get(name, std::nothrow);
|
||||
|
||||
if (chptr == NULL)
|
||||
{
|
||||
|
@ -450,21 +450,19 @@ static void safelist_one_channel(struct Client *source_p, chan::chan *chptr, str
|
|||
*/
|
||||
static void safelist_iterate_client(struct Client *source_p)
|
||||
{
|
||||
rb_radixtree_iteration_state iter;
|
||||
|
||||
void *elem;
|
||||
RB_RADIXTREE_FOREACH_FROM(elem, &iter, channel_tree, source_p->localClient->safelist_data->chname)
|
||||
std::string chname(source_p->localClient->safelist_data->chname);
|
||||
auto it(chan::chans.lower_bound(&chname));
|
||||
for (; it != end(chan::chans); ++it)
|
||||
{
|
||||
const auto chptr(reinterpret_cast<chan::chan *>(elem));
|
||||
auto &chan(*it->second);
|
||||
if (safelist_sendq_exceeded(source_p->from))
|
||||
{
|
||||
rb_free(source_p->localClient->safelist_data->chname);
|
||||
source_p->localClient->safelist_data->chname = rb_strdup(chptr->name.c_str());
|
||||
|
||||
chname = rb_strdup(name(chan).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
safelist_one_channel(source_p, chptr, source_p->localClient->safelist_data);
|
||||
safelist_one_channel(source_p, &chan, source_p->localClient->safelist_data);
|
||||
}
|
||||
|
||||
safelist_client_release(source_p);
|
||||
|
|
|
@ -68,7 +68,7 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
return;
|
||||
}
|
||||
|
||||
if((chptr = find_channel(p)) != NULL)
|
||||
if((chptr = chan::get(p, std::nothrow)) != NULL)
|
||||
channel_member_names(chptr, source_p, 1);
|
||||
else
|
||||
sendto_one(source_p, form_str(RPL_ENDOFNAMES),
|
||||
|
@ -117,9 +117,9 @@ names_global(struct Client *source_p)
|
|||
char *t;
|
||||
|
||||
/* first do all visible channels */
|
||||
RB_DLINK_FOREACH(ptr, chan::global_channel_list.head)
|
||||
for(const auto &pit : chan::chans)
|
||||
{
|
||||
chptr = (chan::chan *)ptr->data;
|
||||
chptr = pit.second.get();
|
||||
channel_member_names(chptr, source_p, 0);
|
||||
}
|
||||
cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY),
|
||||
|
|
|
@ -1346,9 +1346,9 @@ stats_memory (struct Client *source_p)
|
|||
}
|
||||
|
||||
/* Count up all channels, ban lists, except lists, Invex lists */
|
||||
RB_DLINK_FOREACH(ptr, chan::global_channel_list.head)
|
||||
for(const auto &pit : chan::chans)
|
||||
{
|
||||
chptr = (chan::chan *)ptr->data;
|
||||
chptr = pit.second.get();
|
||||
channel_count++;
|
||||
channel_memory += (strlen(chptr->name.c_str()) + sizeof(chan::chan));
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ ms_tb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
|||
time_t newtopicts;
|
||||
struct Client *fakesource_p;
|
||||
|
||||
chptr = find_channel(parv[1]);
|
||||
chptr = chan::get(parv[1], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
return;
|
||||
|
@ -131,7 +131,7 @@ ms_etb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
|
|||
int textchange, can_use_tb, member;
|
||||
|
||||
channelts = atol(parv[1]);
|
||||
chptr = find_channel(parv[2]);
|
||||
chptr = chan::get(parv[2], std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
return;
|
||||
|
|
|
@ -73,7 +73,7 @@ m_topic(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
|
|||
if(MyClient(source_p) && !IsFloodDone(source_p))
|
||||
flood_endgrace(source_p);
|
||||
|
||||
chptr = find_channel(name);
|
||||
chptr = chan::get(name, std::nothrow);
|
||||
|
||||
if(chptr == NULL)
|
||||
{
|
||||
|
@ -182,7 +182,7 @@ ms_topic(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
|
|||
{
|
||||
chan::chan *chptr = NULL;
|
||||
|
||||
if((chptr = find_channel(parv[1])) == NULL)
|
||||
if((chptr = chan::get(parv[1], std::nothrow)) == NULL)
|
||||
return;
|
||||
|
||||
set_channel_topic(chptr, parv[4], parv[2], atoi(parv[3]));
|
||||
|
|
|
@ -172,7 +172,7 @@ m_who(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
|
|||
if(chan::has_prefix(mask))
|
||||
{
|
||||
/* List all users on a given channel */
|
||||
chptr = find_channel(parv[1] + operspy);
|
||||
chptr = chan::get(parv[1] + operspy, std::nothrow);
|
||||
|
||||
if(chptr != NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue