2005-12-16 18:10:38 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
2006-01-15 15:59:11 +00:00
|
|
|
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
|
2005-12-16 18:10:38 +00:00
|
|
|
* E-mail:
|
2006-01-15 15:59:11 +00:00
|
|
|
* <brain@chatspike.net>
|
|
|
|
* <Craig@chatspike.net>
|
2005-12-16 18:10:38 +00:00
|
|
|
*
|
|
|
|
* Written by Craig Edwards, Craig McLure, and others.
|
|
|
|
* This program is free but copyrighted software; see
|
|
|
|
* the file COPYING for details.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inspircd.h"
|
2006-04-08 17:05:48 +00:00
|
|
|
#include "configreader.h"
|
2005-12-16 18:10:38 +00:00
|
|
|
#include "users.h"
|
|
|
|
#include "modules.h"
|
2006-04-20 18:55:46 +00:00
|
|
|
#include "commands/cmd_quit.h"
|
2005-12-16 18:10:38 +00:00
|
|
|
|
2006-09-03 00:09:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" command_t* init_command(InspIRCd* Instance)
|
|
|
|
{
|
|
|
|
return new cmd_quit(Instance);
|
|
|
|
}
|
|
|
|
|
2006-09-06 17:21:59 +00:00
|
|
|
CmdResult cmd_quit::Handle (const char** parameters, int pcnt, userrec *user)
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
2006-08-09 16:35:24 +00:00
|
|
|
user_hash::iterator iter = ServerInstance->clientlist.find(user->nick);
|
2006-07-16 12:18:29 +00:00
|
|
|
char reason[MAXBUF];
|
2006-09-17 14:01:53 +00:00
|
|
|
std::string quitmsg = "Client exited";
|
2005-12-16 18:10:38 +00:00
|
|
|
|
2006-07-28 12:00:25 +00:00
|
|
|
if (user->registered == REG_ALL)
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
|
|
|
/* theres more to do here, but for now just close the socket */
|
|
|
|
if (pcnt == 1)
|
|
|
|
{
|
2006-03-07 11:55:22 +00:00
|
|
|
if (*parameters[0] == ':')
|
|
|
|
parameters[0]++;
|
|
|
|
|
2006-07-16 12:18:29 +00:00
|
|
|
strlcpy(reason, parameters[0],MAXQUIT-1);
|
2005-12-16 18:10:38 +00:00
|
|
|
|
|
|
|
/* We should only prefix the quit for a local user. Remote users have
|
|
|
|
* already been prefixed, where neccessary, by the upstream server.
|
|
|
|
*/
|
2006-08-18 01:08:14 +00:00
|
|
|
if (IS_LOCAL(user))
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
2006-09-17 14:01:53 +00:00
|
|
|
quitmsg = ServerInstance->Config->PrefixQuit;
|
|
|
|
quitmsg.append(parameters[0]);
|
|
|
|
user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,quitmsg.c_str());
|
|
|
|
ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,quitmsg.c_str());
|
|
|
|
user->WriteCommonExcept("QUIT :%s", quitmsg.c_str());
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-04 19:11:46 +00:00
|
|
|
ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,parameters[0]);
|
2006-08-08 20:08:02 +00:00
|
|
|
user->WriteCommonExcept("QUIT :%s",parameters[0]);
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
2006-08-09 11:33:10 +00:00
|
|
|
FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,std::string(ServerInstance->Config->PrefixQuit)+std::string(parameters[0])));
|
2005-12-16 18:10:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-31 22:27:54 +00:00
|
|
|
if (IS_LOCAL(user))
|
|
|
|
{
|
2006-09-17 14:01:53 +00:00
|
|
|
user->Write("ERROR :Closing link (%s@%s) []",user->ident,user->host);
|
2006-08-31 22:27:54 +00:00
|
|
|
ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [Client exited]",user->nick,user->ident,user->host);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-04 19:11:46 +00:00
|
|
|
ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [Client exited]",user->server,user->nick,user->ident,user->host);
|
2006-08-31 22:27:54 +00:00
|
|
|
}
|
2006-08-08 20:08:02 +00:00
|
|
|
user->WriteCommonExcept("QUIT :Client exited");
|
2005-12-26 17:26:16 +00:00
|
|
|
FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,"Client exited"));
|
2005-12-16 18:10:38 +00:00
|
|
|
|
|
|
|
}
|
2006-08-08 14:45:06 +00:00
|
|
|
user->AddToWhoWas();
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
|
|
|
|
2005-12-26 17:26:16 +00:00
|
|
|
FOREACH_MOD(I_OnUserDisconnect,OnUserDisconnect(user));
|
2005-12-16 18:10:38 +00:00
|
|
|
|
|
|
|
/* push the socket on a stack of sockets due to be closed at the next opportunity */
|
2006-08-18 01:08:14 +00:00
|
|
|
if (IS_LOCAL(user))
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
2006-08-18 01:08:14 +00:00
|
|
|
ServerInstance->SE->DelFd(user);
|
2006-08-09 17:52:10 +00:00
|
|
|
if (find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user) != ServerInstance->local_users.end())
|
2006-04-06 02:25:20 +00:00
|
|
|
{
|
2006-08-11 12:26:07 +00:00
|
|
|
ServerInstance->Log(DEBUG,"Delete local user");
|
2006-08-09 17:52:10 +00:00
|
|
|
ServerInstance->local_users.erase(find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user));
|
2006-04-06 02:25:20 +00:00
|
|
|
}
|
2005-12-16 18:10:38 +00:00
|
|
|
user->CloseSocket();
|
|
|
|
}
|
|
|
|
|
2006-08-09 16:35:24 +00:00
|
|
|
if (iter != ServerInstance->clientlist.end())
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
2006-08-09 16:35:24 +00:00
|
|
|
ServerInstance->clientlist.erase(iter);
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 12:00:25 +00:00
|
|
|
if (user->registered == REG_ALL) {
|
2006-08-10 14:43:29 +00:00
|
|
|
user->PurgeEmptyChannels();
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
2006-09-06 17:21:59 +00:00
|
|
|
|
2006-09-17 14:01:53 +00:00
|
|
|
if (IS_LOCAL(user))
|
|
|
|
{
|
|
|
|
std::string original_command = "QUIT :" + quitmsg;
|
|
|
|
FOREACH_MOD(I_OnPostCommand,OnPostCommand("QUIT", parameters, pcnt, user, CMD_SUCCESS, original_command));
|
|
|
|
}
|
|
|
|
|
2006-09-13 20:07:19 +00:00
|
|
|
DELETE(user);
|
|
|
|
return CMD_USER_DELETED;
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
2006-08-18 01:08:14 +00:00
|
|
|
|