aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/m_spanningtree/treesocket2.cpp
diff options
context:
space:
mode:
authorGravatar Attila Molnar2014-07-05 13:29:16 +0200
committerGravatar Attila Molnar2014-07-05 13:29:16 +0200
commit85e8c259de499f76eab01b77901af37f4c15efce (patch)
tree0d39228a9521b8e522c559df37983693b364dc4b /src/modules/m_spanningtree/treesocket2.cpp
parentm_spanningtree Fix fake direction detection for commands (diff)
downloadinspircd++-85e8c259de499f76eab01b77901af37f4c15efce.tar.gz
inspircd++-85e8c259de499f76eab01b77901af37f4c15efce.tar.bz2
inspircd++-85e8c259de499f76eab01b77901af37f4c15efce.zip
m_spanningtree Extract logic that finds the source user for an incoming command into a function
Diffstat (limited to 'src/modules/m_spanningtree/treesocket2.cpp')
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp72
1 files changed, 39 insertions, 33 deletions
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index d16e55702..3df0bdee8 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -226,46 +226,52 @@ void TreeSocket::ProcessLine(std::string &line)
}
}
-void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
+User* TreeSocket::FindSource(const std::string& prefix, const std::string& command)
{
+ // Empty prefix means the source is the directly connected server that sent this command
+ if (prefix.empty())
+ return MyRoot->ServerUser;
+
+ // If the prefix string is a uuid or a sid FindUUID() returns the appropriate User object
User* who = ServerInstance->FindUUID(prefix);
+ if (who)
+ return who;
- if (!who)
+ // Some implementations wrongly send a server name as prefix occasionally, handle that too for now
+ TreeServer* const server = Utils->FindServer(prefix);
+ if (server)
+ return server->ServerUser;
+
+ /* It is important that we don't close the link here, unknown prefix can occur
+ * due to various race conditions such as the KILL message for a user somehow
+ * crossing the users QUIT further upstream from the server. Thanks jilles!
+ */
+
+ if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (isdigit(prefix[0])) &&
+ ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
{
- TreeServer* ServerSource = Utils->FindServer(prefix);
- if (prefix.empty())
- ServerSource = MyRoot;
+ /* Special case, we cannot drop these commands as they've been committed already on a
+ * part of the network by the time we receive them, so in this scenario pretend the
+ * command came from a server to avoid desync.
+ */
- if (ServerSource)
- {
- who = ServerSource->ServerUser;
- }
- else
- {
- /* It is important that we don't close the link here, unknown prefix can occur
- * due to various race conditions such as the KILL message for a user somehow
- * crossing the users QUIT further upstream from the server. Thanks jilles!
- */
+ who = ServerInstance->FindUUID(prefix.substr(0, 3));
+ if (who)
+ return who;
+ return this->MyRoot->ServerUser;
+ }
- if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (isdigit(prefix[0])) &&
- ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
- {
- /* Special case, we cannot drop these commands as they've been committed already on a
- * part of the network by the time we receive them, so in this scenario pretend the
- * command came from a server to avoid desync.
- */
+ // Unknown prefix
+ return NULL;
+}
- who = ServerInstance->FindUUID(prefix.substr(0, 3));
- if (!who)
- who = this->MyRoot->ServerUser;
- }
- else
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
- command.c_str(), prefix.c_str());
- return;
- }
- }
+void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
+{
+ User* who = FindSource(prefix, command);
+ if (!who)
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.", command.c_str(), prefix.c_str());
+ return;
}
/*