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 * ---------------------------------------------------
15 #include "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
20 #include "transport.h"
22 #include "socketengine.h"
24 #include "m_spanningtree/main.h"
25 #include "m_spanningtree/utils.h"
26 #include "m_spanningtree/treeserver.h"
27 #include "m_spanningtree/link.h"
28 #include "m_spanningtree/treesocket.h"
29 #include "m_spanningtree/resolvers.h"
30 #include "m_spanningtree/handshaketimer.h"
32 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_hash.h */
35 * Yes, this function looks a little ugly.
36 * However, in some circumstances we may not have a User, so we need to do things this way.
37 * Returns 1 if colliding local client, 2 if colliding remote, 3 if colliding both.
38 * Sends SVSNICKs as appropriate and forces nickchanges too.
40 int TreeSocket::DoCollision(User *u, time_t remotets, const char *remoteident, const char *remoteip, const char *remoteuid)
43 * Under old protocol rules, we would have had to kill both clients.
45 * These days, we have UID. And, so what we do is, force nick change client(s)
46 * involved according to timestamp rules.
50 * Force nick change on OLDER timestamped client
52 * Force nick change on NEWER timestamped client
56 * This stops abusive use of collisions, simplifies problems with loops, and so on.
59 bool bChangeLocal = true;
60 bool bChangeRemote = true;
62 /* for brevity, don't use the User */
63 time_t localts = u->age;
64 const char *localident = u->ident;
65 const char *localip = u->GetIPString();
67 /* mmk. let's do this again. */
68 if (remotets == localts)
70 /* equal. fuck them both! do nada, let the handler at the bottom figure this out. */
74 /* fuck. now it gets complex. */
76 /* first, let's see if ident@host matches. */
77 bool SamePerson = !strcmp(localident, remoteident)
78 && !strcmp(localip, remoteip);
81 * if ident@ip is equal, and theirs is newer, or
82 * ident@ip differ, and ours is newer
84 if((SamePerson && remotets < localts) ||
85 (!SamePerson && remotets > localts))
87 /* remote needs to change */
92 /* ours needs to change */
93 bChangeRemote = false;
100 u->ForceNickChange(u->uuid);
108 * Cheat a little here. Instead of a dedicated command to change UID,
109 * use SVSNICK and accept their client with it's UID (as we know the SVSNICK will
110 * not fail under any circumstances -- UIDs are netwide exclusive).
112 * This means that each side of a collide will generate one extra NICK back to where
113 * they have just linked (and where it got the SVSNICK from), however, it will
114 * be dropped harmlessly as it will come in as :928AAAB NICK 928AAAB, and we already
115 * have 928AAAB's nick set to that.
118 User *remote = this->Instance->FindUUID(remoteuid);
122 /* buh.. nick change collide. force change their nick. */
123 remote->ForceNickChange(remote->uuid);
127 /* user has not been introduced yet, just inform their server */
128 this->WriteLine(std::string(":")+this->Instance->Config->GetSID()+" SVSNICK "+remoteuid+" " + remoteuid + " " + ConvToStr(remotets));