1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "m_spanningtree/treesocket.h"
18 #include "m_spanningtree/treeserver.h"
19 #include "m_spanningtree/utils.h"
21 /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */
25 * Yes, this function looks a little ugly.
26 * However, in some circumstances we may not have a User, so we need to do things this way.
27 * Returns 1 if colliding local client, 2 if colliding remote, 3 if colliding both.
28 * Sends SVSNICKs as appropriate and forces nickchanges too.
30 int TreeSocket::DoCollision(User *u, time_t remotets, const std::string &remoteident, const std::string &remoteip, const std::string &remoteuid)
33 * Under old protocol rules, we would have had to kill both clients.
35 * These days, we have UID. And, so what we do is, force nick change client(s)
36 * involved according to timestamp rules.
40 * Force nick change on OLDER timestamped client
42 * Force nick change on NEWER timestamped client
46 * This stops abusive use of collisions, simplifies problems with loops, and so on.
49 bool bChangeLocal = true;
50 bool bChangeRemote = true;
52 /* for brevity, don't use the User - use defines to avoid any copy */
53 #define localts u->age
54 #define localident u->ident
55 #define localip u->GetIPString()
57 /* mmk. let's do this again. */
58 if (remotets == localts)
60 /* equal. fuck them both! do nada, let the handler at the bottom figure this out. */
64 /* fuck. now it gets complex. */
66 /* first, let's see if ident@host matches. */
67 bool SamePerson = (localident == remoteident)
68 && (localip == remoteip);
71 * if ident@ip is equal, and theirs is newer, or
72 * ident@ip differ, and ours is newer
74 if((SamePerson && remotets < localts) ||
75 (!SamePerson && remotets > localts))
77 /* remote needs to change */
82 /* ours needs to change */
83 bChangeRemote = false;
90 u->ForceNickChange(u->uuid.c_str());
98 * Cheat a little here. Instead of a dedicated command to change UID,
99 * use SVSNICK and accept their client with it's UID (as we know the SVSNICK will
100 * not fail under any circumstances -- UIDs are netwide exclusive).
102 * This means that each side of a collide will generate one extra NICK back to where
103 * they have just linked (and where it got the SVSNICK from), however, it will
104 * be dropped harmlessly as it will come in as :928AAAB NICK 928AAAB, and we already
105 * have 928AAAB's nick set to that.
108 User *remote = this->ServerInstance->FindUUID(remoteuid);
112 /* buh.. nick change collide. force change their nick. */
113 remote->ForceNickChange(remote->uuid.c_str());
117 /* user has not been introduced yet, just inform their server */
118 this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" SVSNICK "+remoteuid+" " + remoteuid + " " + ConvToStr(remotets));