summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/channels.h8
-rw-r--r--src/channels.cpp32
2 files changed, 25 insertions, 15 deletions
diff --git a/include/channels.h b/include/channels.h
index b9983ed88..3c95bb7fb 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -374,6 +374,14 @@ class CoreExport Channel : public Extensible
*/
static Channel* JoinUser(InspIRCd* ServerInstance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS = 0);
+ /*
+ * Create a channel record, and insert it into the hash.
+ * @param name The channel name
+ * @param ts The channel timestamp
+ * @return A pointer to the newly created Channel object.
+ */
+ static Channel *CreateChannel(InspIRCd *ServerInstance, const std::string &name, time_t ts = 0);
+
/** Write to a channel, from a user, using va_args for text
* @param user User whos details to prefix the line with
* @param text A printf-style format string which builds the output line without prefix
diff --git a/src/channels.cpp b/src/channels.cpp
index 14f0f55f1..e252100f1 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -271,21 +271,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
return NULL;
}
- /* create a new one */
- Ptr = new Channel(Instance);
- (*(Instance->chanlist))[cname] = Ptr;
-
- strlcpy(Ptr->name, cname,CHANMAX);
-
- /* As spotted by jilles, dont bother to set this on remote users */
- if (IS_LOCAL(user))
- Ptr->SetDefaultModes();
-
- Ptr->created = TS ? TS : Instance->Time();
- Ptr->age = Ptr->created;
- *Ptr->topic = 0;
- *Ptr->setby = 0;
- Ptr->topicset = 0;
+ Ptr = Channel::CreateChannel(Instance, cname, TS);
}
else
{
@@ -359,9 +345,25 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
}
}
+ /* As spotted by jilles, dont bother to set this on remote users */
+ if (IS_LOCAL(user) && Ptr->GetUserCounter() == 1)
+ Ptr->SetDefaultModes();
+
return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
}
+Channel *Channel::CreateChannel(InspIRCd *ServerInstance, const std::string &name, time_t ts)
+{
+ /* create a new one */
+ Channel *c = new Channel(ServerInstance);
+ (*(ServerInstance->chanlist))[name.c_str()] = c;
+
+ strlcpy(c->name, name.c_str(), CHANMAX);
+ c->created = ts ? ts : ServerInstance->Time();
+ c->age = c->created;
+ return c;
+}
+
Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
{
std::string nick = user->nick;