Add third parameter to OnUserQuit (quit reason for opers only) - bump api version

Add SetOperQuit and GetOperQuit methods to userrec
Add OPERQUIT command to protocol - bump protocol version
All this is to properly allow hidebans etc to work properly


git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6675 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2007-03-15 17:37:25 +00:00
parent d1dc60e83e
commit 38ca8be9a3
22 changed files with 79 additions and 22 deletions

View File

@ -75,7 +75,7 @@ enum MessageType {
* ipv4 servers, so this value will be ten times as
* high on ipv6 servers.
*/
#define NATIVE_API_VERSION 11017
#define NATIVE_API_VERSION 11018
#ifdef IPV6
#define API_VERSION (NATIVE_API_VERSION * 10)
#else
@ -471,9 +471,10 @@ class Module : public Extensible
* This event is only called when the user is fully registered when they quit. To catch
* raw disconnections, use the OnUserDisconnect method.
* @param user The user who is quitting
* @param message The user's quit message
* @param message The user's quit message (as seen by non-opers)
* @param oper_message The user's quit message (as seen by opers)
*/
virtual void OnUserQuit(userrec* user, const std::string &message);
virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message);
/** Called whenever a user's socket is closed.
* The details of the exiting user are available to you in the parameter userrec *user

View File

@ -283,6 +283,9 @@ class userrec : public connection
* mode characters this user is making use of.
*/
void DecrementModes();
char* operquit;
public:
/** Resolvers for looking up this users IP address
* This will occur if and when res_reverse completes.
@ -895,6 +898,13 @@ class userrec : public connection
*/
void ShowRULES();
/** Set oper-specific quit message shown to opers only when the user quits
* (overrides any sent by QuitUser)
*/
void SetOperQuit(const std::string &oquit);
const char* GetOperQuit();
/** Handle socket event.
* From EventHandler class.
* @param et Event type

View File

@ -87,8 +87,9 @@ int CullList::Apply()
user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
std::map<userrec*, userrec*>::iterator exemptiter = exempt.find(a->GetUser());
const char* preset_reason = a->GetUser()->GetOperQuit();
std::string reason = a->GetReason();
std::string oper_reason = a->GetOperReason();
std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
if (reason.length() > MAXQUIT - 1)
reason.resize(MAXQUIT - 1);
@ -110,7 +111,7 @@ int CullList::Apply()
{
a->GetUser()->PurgeEmptyChannels();
a->GetUser()->WriteCommonQuit(reason, oper_reason);
FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason));
FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason, oper_reason));
}
FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));

View File

@ -104,7 +104,7 @@ std::string Event::GetEventID()
Module::Module(InspIRCd* Me) : ServerInstance(Me) { }
Module::~Module() { }
void Module::OnUserConnect(userrec* user) { }
void Module::OnUserQuit(userrec* user, const std::string& message) { }
void Module::OnUserQuit(userrec* user, const std::string& message, const std::string &oper_message) { }
void Module::OnUserDisconnect(userrec* user) { }
void Module::OnUserJoin(userrec* user, chanrec* channel) { }
void Module::OnPostJoin(userrec* user, chanrec* channel) { }

View File

@ -291,7 +291,7 @@ class ModuleSQLLog : public Module
AddLogEntry(LT_CONNECT,user->nick,user->host,user->server);
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
AddLogEntry(LT_DISCONNECT,user->nick,user->host,user->server);
}

View File

@ -77,6 +77,7 @@ public:
virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
{
ServerInstance->Log(DEBUG, "*** " + ConvToStr( ( 20 * 100 / 26) ));
if (target_type == TYPE_CHANNEL)
{
if ((!IS_LOCAL(user)) || (text.length() < minlen))

View File

@ -235,7 +235,7 @@ public:
}
}
virtual void OnUserQuit(userrec* user, const std::string &message)
virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
OnCleanup(TYPE_USER, user);
}

View File

@ -272,7 +272,7 @@ class ModuleDCCAllow : public Module
Conf = new ConfigReader(ServerInstance);
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
dccallowlist* dl;

View File

@ -66,7 +66,7 @@ class ModuleFoobar : public Module
ServerInstance->Log(DEBUG,"Foobar: User connecting: "+b);
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
// method called when a user disconnects

View File

@ -203,7 +203,7 @@ class ModuleHttpStats : public Module
this->changed = true;
}
void OnUserQuit(userrec* user, const std::string &message)
void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
{

View File

@ -136,7 +136,7 @@ class ModuleNickLock : public Module
return 0;
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
user->Shrink("nick_locked");
}

View File

@ -233,7 +233,7 @@ class ModuleSafeList : public Module
output.append(" SAFELIST");
}
virtual void OnUserQuit(userrec* user, const std::string &message)
virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
this->OnCleanup(TYPE_USER,user);
}

View File

@ -243,7 +243,7 @@ class ModuleServicesAccount : public Module
}
// when a user quits, tidy up their metadata
virtual void OnUserQuit(userrec* user, const std::string &message)
virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
std::string* account;
user->GetExt("accountname", account);

View File

@ -142,7 +142,7 @@ class ModuleSilence : public Module
List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
// when the user quits tidy up any silence list they might have just to keep things tidy
// and to prevent a HONKING BIG MEMORY LEAK!

View File

@ -253,7 +253,7 @@ class ModuleSilence : public Module
List[I_OnBuildExemptList] = List[I_OnUserQuit] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = List[I_OnUserPreInvite] = 1;
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
// when the user quits tidy up any silence list they might have just to keep things tidy
silencelist* sl;

View File

@ -904,11 +904,18 @@ void ModuleSpanningTree::OnUserConnect(userrec* user)
}
}
void ModuleSpanningTree::OnUserQuit(userrec* user, const std::string &reason)
void ModuleSpanningTree::OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
{
std::deque<std::string> params;
if (oper_message != reason)
{
params.push_back(":"+oper_message);
Utils->DoOneToMany(user->nick,"OPERQUIT",params);
}
params.clear();
params.push_back(":"+reason);
Utils->DoOneToMany(user->nick,"QUIT",params);
}

View File

@ -13,7 +13,7 @@
* Failure to document your protocol changes will result in a painfully
* painful death by pain. You have been warned.
*/
const long ProtocolVersion = 1104;
const long ProtocolVersion = 1105;
/** Forward declarations
*/
@ -137,7 +137,7 @@ class ModuleSpanningTree : public Module
virtual void OnChangeName(userrec* user, const std::string &gecos);
virtual void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage);
virtual void OnUserConnect(userrec* user);
virtual void OnUserQuit(userrec* user, const std::string &reason);
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message);
virtual void OnUserPostNick(userrec* user, const std::string &oldnick);
virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason);
virtual void OnRemoteKill(userrec* source, userrec* dest, const std::string &reason);

View File

@ -240,6 +240,8 @@ class TreeSocket : public InspSocket
*/
bool ForceNick(const std::string &prefix, std::deque<std::string> &params);
bool OperQuit(const std::string &prefix, std::deque<std::string> &params);
/** Remote SQUIT (RSQUIT). Routing works similar to SVSNICK: Route it to the server that the target is connected to locally,
* then let that server do the dirty work (squit it!). Example:
* A -> B -> C -> D: oper on A squits D, A routes to B, B routes to C, C notices D connected locally, kills it. -- w00t

View File

@ -207,6 +207,21 @@ bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> &p
return true;
}
bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> &params)
{
if (params.size() < 1)
return true;
userrec* u = this->Instance->FindNick(prefix);
if (u)
{
Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
u->SetOperQuit(params[0]);
}
return true;
}
/*
* Remote SQUIT (RSQUIT). Routing works similar to SVSNICK: Route it to the server that the target is connected to locally,
* then let that server do the dirty work (squit it!). Example:
@ -1157,6 +1172,10 @@ bool TreeSocket::ProcessLine(std::string &line)
}
return this->ForceNick(prefix,params);
}
else if (command == "OPERQUIT")
{
return this->OperQuit(prefix,params);
}
else if (command == "RSQUIT")
{
return this->RemoteSquit(prefix, params);

View File

@ -141,7 +141,7 @@ class ModuleSWhois : public Module
}
// when a user quits, tidy up their metadata
virtual void OnUserQuit(userrec* user, const std::string &message)
virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
{
std::string* swhois;
user->GetExt("swhois", swhois);

View File

@ -306,7 +306,7 @@ class Modulewatch : public Module
List[I_OnGarbageCollect] = List[I_OnCleanup] = List[I_OnUserQuit] = List[I_OnPostConnect] = List[I_OnUserPostNick] = List[I_On005Numeric] = 1;
}
virtual void OnUserQuit(userrec* user, const std::string &reason)
virtual void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
{
watchentries::iterator x = whos_watching_me->find(user->nick);
if (x != whos_watching_me->end())

View File

@ -331,13 +331,15 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
memset(modes,0,sizeof(modes));
memset(snomasks,0,sizeof(snomasks));
/* Invalidate cache */
cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
}
userrec::~userrec()
{
this->InvalidateCache();
this->DecrementModes();
if (operquit)
free(operquit);
if (ip)
{
clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
@ -1914,3 +1916,17 @@ void userrec::HandleEvent(EventType et, int errornum)
}
}
void userrec::SetOperQuit(const std::string &oquit)
{
if (operquit)
return;
operquit = strdup(oquit.c_str());
}
const char* userrec::GetOperQuit()
{
return operquit ? operquit : "";
}