1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "treesocket.h"
18 #include "treeserver.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 SAVEs 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;
88 * Cheat a little here. Instead of a dedicated command to change UID,
89 * use SAVE and accept the losing client with its UID (as we know the SAVE will
90 * not fail under any circumstances -- UIDs are netwide exclusive).
92 * This means that each side of a collide will generate one extra NICK back to where
93 * they have just linked (and where it got the SAVE from), however, it will
94 * be dropped harmlessly as it will come in as :928AAAB NICK 928AAAB, and we already
95 * have 928AAAB's nick set to that.
102 * Local-side nick needs to change. Just in case we are hub, and
103 * this "local" nick is actually behind us, send an SAVE out.
105 parameterlist params;
106 params.push_back(u->uuid);
107 params.push_back(ConvToStr(u->age));
108 Utils->DoOneToMany(ServerInstance->Config->GetSID(),"SAVE",params);
110 u->ForceNickChange(u->uuid.c_str());
117 User *remote = ServerInstance->FindUUID(remoteuid);
119 * remote side needs to change. If this happens, we will modify
120 * the UID or halt the propagation of the nick change command,
121 * so other servers don't need to see the SAVE
123 WriteLine(std::string(":")+ServerInstance->Config->GetSID()+" SAVE "+remoteuid+" "+ ConvToStr(remotets));
127 /* nick change collide. Force change their nick. */
128 remote->ForceNickChange(remoteuid.c_str());