* @param src The source of the kick
* @param user The user being kicked (must be on this channel)
* @param reason The reason for the kick
- * @return The number of users left on the channel. If this is zero
- * when the method returns, you MUST delete the Channel immediately!
*/
void KickUser(User *src, User *user, const char* reason);
- /** Make the server kick user from this channel with the given reason.
- * @param user The user being kicked (must be on this channel)
- * @param reason The reason for the kick
- * @param triggerevents True if you wish this kick to trigger module events
- * @return The number of users left on the channel. If this is zero
- * when the method returns, you MUST delete the Channel immediately!
- */
- void ServerKickUser(User* user, const char* reason, const std::string& servername = "");
-
/** Part a user from this channel with the given reason.
* If the reason field is NULL, no reason will be sent.
* @param user The user who is parting (must be on this channel)
* @param reason The part reason
- * @return The number of users left on the channel. If this is zero
- * when the method returns, you MUST delete the Channel immediately!
*/
void PartUser(User *user, std::string &reason);
/** The user's unique identifier.
* This is the unique identifier which the user has across the network.
*/
- std::string uuid;
+ const std::string uuid;
/** The users ident reply.
* Two characters are added to the user-defined limit to compensate for the tilde etc.
/** The server the user is connected to.
*/
- std::string server;
+ const std::string server;
/** The user's away message.
* If this string is empty, the user is not marked as away.
* @throw CoreException if the UID allocated to the user already exists
* @param Instance Creator instance
* @param uid User UUID, or empty to allocate one automatically
+ * @param srv Server that this user is from
*/
- User(const std::string &uid);
+ User(const std::string &uid, const std::string& srv);
/** Check if the user matches a G or K line, and disconnect them if they do.
* @param doZline True if ZLines should be checked (if IP has changed since initial connect)
* on the server, in nick!ident&at;host form.
* @return The full masked host of the user
*/
- virtual const std::string GetFullHost();
+ virtual const std::string& GetFullHost();
/** Returns the full real host of the user
* This member function returns the hostname of the user as seen by other users
* e.g. through a module, then this method will ignore it and return the true hostname.
* @return The full real host of the user
*/
- virtual const std::string GetFullRealHost();
+ virtual const std::string& GetFullRealHost();
/** This clears any cached results that are used for GetFullRealHost() etc.
* The results of these calls are cached as generating them can be generally expensive.
class CoreExport RemoteUser : public User
{
public:
- RemoteUser(const std::string& uid) : User(uid)
+ RemoteUser(const std::string& uid, const std::string& srv) : User(uid, srv)
{
SetFd(FD_MAGIC_NUMBER);
}
class CoreExport FakeUser : public User
{
public:
- FakeUser(const std::string &uid) : User(uid)
+ FakeUser(const std::string &uid, const std::string& srv) : User(uid, srv)
{
SetFd(FD_FAKEUSER_NUMBER);
+ nick = srv;
}
+ virtual CullResult cull();
virtual void SendText(const std::string& line);
- virtual const std::string GetFullHost();
- virtual const std::string GetFullRealHost();
- void SetFakeServer(std::string name);
+ virtual const std::string& GetFullHost();
+ virtual const std::string& GetFullRealHost();
};
/* Faster than dynamic_cast */
this->DelUser(user);
}
-void Channel::ServerKickUser(User* user, const char* reason, const std::string& servername)
-{
- if (servername.empty() || !ServerInstance->Config->HideWhoisServer.empty())
- ServerInstance->FakeClient->server = ServerInstance->Config->ServerName;
- else
- ServerInstance->FakeClient->server = servername;
-
- KickUser(ServerInstance->FakeClient, user, reason);
-}
-
void Channel::KickUser(User *src, User *user, const char* reason)
{
if (!src || !user || !reason)
}
/* set up fake client again this time with the correct uid */
- this->FakeClient = new FakeUser("!");
- this->FakeClient->SetFakeServer(Config->ServerName);
+ this->FakeClient = new FakeUser(Config->sid, Config->ServerName);
// Get XLine to do it's thing.
this->XLines->CheckELines();
const UserMembList* users = c->GetUsers();
for(UserMembCIter j = users->begin(); j != users->end(); ++j)
if (IS_LOCAL(j->first))
- c->ServerKickUser(j->first, "Channel name no longer valid", NULL);
+ c->KickUser(ServerInstance->FakeClient, j->first, "Channel name no longer valid");
}
badchan = false;
}
char kickmessage[MAXBUF];
snprintf(kickmessage, MAXBUF, "Channel flood triggered (limit is %d lines in %d secs)", f->lines, f->secs);
- dest->ServerKickUser(user, kickmessage);
+ dest->KickUser(ServerInstance->FakeClient, user, kickmessage);
return MOD_RES_DENY;
}
User* dest = ServerInstance->FindNick(parameters[1]);
Channel* channel = ServerInstance->FindChan(parameters[0]);
const char* reason = "";
- const char* servername = NULL;
if (dest && channel)
{
*/
if (IS_LOCAL(dest))
{
- channel->ServerKickUser(dest, reason, servername);
+ channel->KickUser(ServerInstance->FakeClient, dest, reason);
Channel *n = ServerInstance->FindChan(parameters[1]);
if (n && n->HasUser(dest))
/** ENCAP */
-bool TreeSocket::Encap(const std::string &prefix, parameterlist ¶ms)
+void TreeSocket::Encap(User* who, parameterlist ¶ms)
{
if (params.size() > 1)
{
if (InspIRCd::Match(ServerInstance->Config->GetSID(), params[0]))
{
- User* who = ServerInstance->FindUUID(prefix);
- if (!who)
- who = Utils->ServerUser;
-
parameterlist plist(params.begin() + 2, params.end());
ServerInstance->CallCommandHandler(params[1].c_str(), plist, who);
// discard return value, ENCAP shall succeed even if the command does not exist
if (params[0].find('*') != std::string::npos)
{
- Utils->DoOneToAllButSender(prefix, "ENCAP", params, prefix);
+ Utils->DoOneToAllButSender(who->server, "ENCAP", params, who->server);
}
else
- Utils->DoOneToOne(prefix, "ENCAP", params, params[0]);
+ Utils->DoOneToOne(who->server, "ENCAP", params, params[0]);
}
- return true;
}
/** FJOIN, almost identical to TS6 SJOIN, except for nicklist handling. */
-bool TreeSocket::ForceJoin(const std::string &source, parameterlist ¶ms)
+void TreeSocket::ForceJoin(User* srcuser, parameterlist ¶ms)
{
/* 1.1 FJOIN works as follows:
*
* who succeed at internets. :-)
*/
if (params.size() < 3)
- return true;
+ return;
irc::modestacker modestack(true); /* Modes to apply from the users in the user list */
User* who = NULL; /* User we are currently checking */
if (params.size() > 3)
params[params.size() - 1] = ":" + params[params.size() - 1];
- Utils->DoOneToAllButSender(source,"FJOIN",params,source);
+ Utils->DoOneToAllButSender(srcuser->server,"FJOIN",params,srcuser->server);
if (!TS)
{
ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FJOIN. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
- ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FJOIN with a TS of zero. Total craq. Command was dropped.", source.c_str());
- return true;
+ ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FJOIN with a TS of zero. Total craq. Command was dropped.", srcuser->server.c_str());
+ return;
}
if (created)
ourTS = TS;
chan->age = TS;
param_list.push_back(channel);
- this->RemoveStatus(ServerInstance->Config->GetSID(), param_list);
+ this->RemoveStatus(ServerInstance->FakeClient, param_list);
}
// The silent case here is ourTS == TS, we don't need to remove modes here, just to merge them later on.
}
modelist.push_back(params[idx]);
}
- ServerInstance->SendMode(modelist, Utils->ServerUser);
+ ServerInstance->SendMode(modelist, srcuser);
}
/* Now, process every 'modes,nick' pair */
else
{
this->SendError(std::string("Unknown status mode '")+(*unparsedmodes)+"' in FJOIN");
- return false;
+ return;
}
usr++;
while (modestack.GetStackedLine(stackresult))
{
- ServerInstance->SendMode(stackresult, Utils->ServerUser);
+ ServerInstance->SendMode(stackresult, srcuser);
stackresult.erase(stackresult.begin() + 1, stackresult.end());
}
}
-
- return true;
}
-bool TreeSocket::RemoveStatus(const std::string &prefix, parameterlist ¶ms)
+void TreeSocket::RemoveStatus(User* srcuser, parameterlist ¶ms)
{
if (params.size() < 1)
- return true;
+ return;
Channel* c = ServerInstance->FindChan(params[0]);
while (stack.GetStackedLine(stackresult))
{
- ServerInstance->SendMode(stackresult, Utils->ServerUser);
+ ServerInstance->SendMode(stackresult, srcuser);
stackresult.erase(stackresult.begin() + 1, stackresult.end());
}
}
- return true;
}
/** FMODE command - server mode with timestamp checks */
-bool TreeSocket::ForceMode(const std::string &source, parameterlist ¶ms)
+void TreeSocket::ForceMode(User* who, parameterlist ¶ms)
{
/* Chances are this is a 1.0 FMODE without TS */
if (params.size() < 3)
{
/* No modes were in the command, probably a channel with no modes set on it */
- return true;
+ return;
}
- std::string sourceserv;
+ std::string sourceserv = who->server;
- /* Are we dealing with an FMODE from a user, or from a server? */
- User* who = ServerInstance->FindNick(source);
- if (who)
- {
- /* FMODE from a user, set sourceserv to the users server name */
- sourceserv = who->server;
- }
- else
- {
- /* FMODE from a server, use a fake user to receive mode feedback */
- who = Utils->ServerUser;
- sourceserv = source; /* Set sourceserv to the actual source string */
- }
std::vector<std::string> modelist;
time_t TS = 0;
for (unsigned int q = 0; (q < params.size()) && (q < 64); q++)
}
else
/* Oops, channel doesnt exist! */
- return true;
+ return;
}
if (!TS)
{
ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropped.");
ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq. Mode was dropped.", sourceserv.c_str());
- return true;
+ return;
}
/* TS is equal or less: Merge the mode changes into ours and pass on.
*/
if (TS <= ourTS)
{
- ServerInstance->Modes->Process(modelist, who, (who == Utils->ServerUser));
+ ServerInstance->Modes->Process(modelist, who, IS_SERVER(who));
/* HOT POTATO! PASS IT ON! */
- Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);
+ Utils->DoOneToAllButSender(sourceserv,"FMODE",params,sourceserv);
}
/* If the TS is greater than ours, we drop the mode and dont pass it anywhere.
*/
- return true;
}
{
Utils->DoOneToMany(source->uuid,"KICK",params);
}
- else if (IS_SERVER(source) && source != Utils->ServerUser)
+ else if (source == ServerInstance->FakeClient)
{
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"KICK",params);
}
routing = ROUTE_BROADCAST;
else
return;
- if (user == ServerUser)
+ if (IS_SERVER(user) && user != ServerInstance->FakeClient)
return;
}
else if (routing.type == ROUTE_TYPE_OPT_BCAST)
* no socket associated with it. Its version string is our own local version.
*/
TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id)
- : ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util)
+ : ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util), ServerUser(ServerInstance->FakeClient)
{
age = ServerInstance->Time();
bursting = false;
* its ping counters so that it will be pinged one minute from now.
*/
TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide)
- : Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), Hidden(Hide)
+ : Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), ServerUser(new FakeUser(id, Name)), Hidden(Hide)
{
age = ServerInstance->Time();
bursting = true;
return true;
}
+CullResult TreeServer::cull()
+{
+ if (ServerUser != ServerInstance->FakeClient)
+ ServerUser->cull();
+ return classbase::cull();
+}
+
TreeServer::~TreeServer()
{
/* We'd better tidy up after ourselves, eh? */
this->DelHashEntry();
+ if (ServerUser != ServerInstance->FakeClient)
+ delete ServerUser;
server_hash::iterator iter = Utils->sidlist.find(GetID());
if (iter != Utils->sidlist.end())
void SetID(const std::string &id);
public:
+ FakeUser* const ServerUser; /* User representing this server */
time_t age;
bool Warned; /* True if we've warned opers about high latency on this server */
/** Recursive call for child servers */
void FinishBurstInternal();
+ CullResult cull();
/** Destructor
*/
~TreeServer();
-
};
#endif
void Squit(TreeServer* Current, const std::string &reason);
/** FMODE command - server mode with timestamp checks */
- bool ForceMode(const std::string &source, parameterlist ¶ms);
+ void ForceMode(User* who, parameterlist ¶ms);
/** FTOPIC command */
bool ForceTopic(const std::string &source, parameterlist ¶ms);
/** FJOIN, similar to TS6 SJOIN, but not quite. */
- bool ForceJoin(const std::string &source, parameterlist ¶ms);
+ void ForceJoin(User* who, parameterlist ¶ms);
/* Used on nick collision ... XXX ugly function HACK */
int DoCollision(User *u, time_t remotets, const std::string &remoteident, const std::string &remoteip, const std::string &remoteuid);
/** ENCAP command
*/
- bool Encap(const std::string &prefix, parameterlist ¶ms);
+ void Encap(User* who, parameterlist ¶ms);
/** OPERQUIT command
*/
/** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
* This does not update the timestamp of the target channel, this must be done seperately.
*/
- bool RemoveStatus(const std::string &prefix, parameterlist ¶ms);
+ void RemoveStatus(User* source, parameterlist ¶ms);
/** <- (remote) <- SERVER
*/
SquitServer(from, Current);
Current->Tidy();
Current->GetParent()->DelChild(Current);
+ Current->cull();
delete Current;
if (LocalSquit)
ServerInstance->SNO->WriteToSnoMask('l', "Netsplit complete, lost \002%d\002 user%s on \002%d\002 server%s.", num_lost_users, num_lost_users != 1 ? "s" : "", num_lost_servers, num_lost_servers != 1 ? "s" : "");
if (ServerSource)
{
- who = Utils->ServerUser;
- Utils->ServerUser->SetFakeServer(ServerSource->GetName());
- Utils->ServerUser->uuid = ServerSource->GetID();
+ who = ServerSource->ServerUser;
direction = prefix;
}
else
}
else if (command == "FJOIN")
{
- this->ForceJoin(prefix,params);
+ this->ForceJoin(who,params);
}
else if (command == "STATS")
{
}
else if (command == "FMODE")
{
- this->ForceMode(prefix,params);
+ this->ForceMode(who,params);
}
else if (command == "FTOPIC")
{
}
else if (command == "ENCAP")
{
- this->Encap(prefix, params);
+ this->Encap(who, params);
}
else if (command == "NICK")
{
User* _new = NULL;
try
{
- _new = new RemoteUser(params[0]);
+ _new = new RemoteUser(params[0], remoteserver->GetName());
}
catch (...)
{
return false;
}
(*(ServerInstance->Users->clientlist))[params[2]] = _new;
- _new->SetFd(FD_MAGIC_NUMBER);
_new->nick.assign(params[2], 0, MAXBUF);
_new->host.assign(params[3], 0, 64);
_new->dhost.assign(params[4], 0, 64);
- _new->server = remoteserver->GetName();
_new->ident.assign(params[5], 0, MAXBUF);
_new->fullname.assign(params[params.size() - 1], 0, MAXBUF);
_new->registered = REG_ALL;
ServerInstance->Logs->Log("m_spanningtree",DEBUG,"***** Using SID for hash: %s *****", ServerInstance->Config->GetSID().c_str());
this->TreeRoot = new TreeServer(this, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc, ServerInstance->Config->GetSID());
- ServerUser = new FakeUser(TreeRoot->GetID());
-
this->ReadConfiguration();
}
TreeSocket* s = i->first;
ServerInstance->GlobalCulls.AddItem(s);
}
+ TreeRoot->cull();
- ServerUser->uuid = TreeRoot->GetID();
- ServerUser->cull();
- delete ServerUser;
return classbase::cull();
}
/** This variable represents the root of the server tree
*/
TreeServer *TreeRoot;
- /** Represents the server whose command we are processing
- */
- FakeUser *ServerUser;
/** IPs allowed to link to us
*/
std::vector<std::string> ValidIPs;
/* The users default nick is their UUID */
New->nick.assign(New->uuid, 0, ServerInstance->Config->Limits.NickMax);
- New->server = ServerInstance->Config->ServerName;
New->ident.assign("unknown");
New->registered = REG_NONE;
}
}
-User::User(const std::string &uid)
+User::User(const std::string &uid, const std::string& sid)
+ : uuid(uid), server(sid)
{
- server = ServerInstance->Config->ServerName;
age = ServerInstance->Time();
- signon = idle_lastmsg = registered = 0;
+ signon = idle_lastmsg = 0;
+ registered = 0;
quietquit = quitting = exempt = dns_done = false;
fd = -1;
- uuid = uid;
client_sa.sa.sa_family = AF_UNSPEC;
ServerInstance->Logs->Log("USERS", DEBUG, "New UUID for user: %s", uuid.c_str());
throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
}
-LocalUser::LocalUser() : User(ServerInstance->GetUID())
+LocalUser::LocalUser() : User(ServerInstance->GetUID(), ServerInstance->Config->ServerName)
{
bytes_in = bytes_out = cmds_in = cmds_out = 0;
server_sa.sa.sa_family = AF_UNSPEC;
User::~User()
{
- if (uuid.length())
+ if (ServerInstance->Users->uuidlist->find(uuid) != ServerInstance->Users->uuidlist->end())
ServerInstance->Logs->Log("USERS", ERROR, "User destructor for %s called without cull", uuid.c_str());
}
return this->cached_hostip;
}
-const std::string User::GetFullHost()
+const std::string& User::GetFullHost()
{
if (!this->cached_fullhost.empty())
return this->cached_fullhost;
return nresult;
}
-const std::string User::GetFullRealHost()
+const std::string& User::GetFullRealHost()
{
if (!this->cached_fullrealhost.empty())
return this->cached_fullrealhost;
{
if (!quitting)
ServerInstance->Users->QuitUser(this, "Culled without QuitUser");
- if (uuid.empty())
- {
- ServerInstance->Logs->Log("USERS", DEBUG, "User culled twice? UUID empty");
- return Extensible::cull();
- }
PurgeEmptyChannels();
if (IS_LOCAL(this) && fd != INT_MAX)
Close();
this->DecrementModes();
ServerInstance->Users->uuidlist->erase(uuid);
- uuid.clear();
return Extensible::cull();
}
return User::cull();
}
+CullResult FakeUser::cull()
+{
+ // Fake users don't quit, they just get culled.
+ quitting = true;
+ return User::cull();
+}
+
void User::Oper(OperInfo* info)
{
if (this->IsModeSet('o'))
this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
}
-void FakeUser::SetFakeServer(std::string name)
-{
- this->nick = name;
- this->server = name;
-}
-
-const std::string FakeUser::GetFullHost()
+const std::string& FakeUser::GetFullHost()
{
if (!ServerInstance->Config->HideWhoisServer.empty())
return ServerInstance->Config->HideWhoisServer;
- return nick;
+ return server;
}
-const std::string FakeUser::GetFullRealHost()
+const std::string& FakeUser::GetFullRealHost()
{
if (!ServerInstance->Config->HideWhoisServer.empty())
return ServerInstance->Config->HideWhoisServer;
- return nick;
+ return server;
}
ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)