/******************************************************************************* * shroudBNC - an object-oriented framework for IRC * * Copyright (C) 2005-2011 Gunnar Beutner * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *******************************************************************************/ #include "StdAfx.h" IMPL_DNSEVENTPROXY(CClientConnection, AsyncDnsFinishedClient) /** * CClientConnection * * Constructs a new client connection object. * * @param Client the client socket * @param SSL whether to use SSL */ CClientConnection::CClientConnection(SOCKET Client, bool SSL) : CConnection(Client, SSL, Role_Server) { m_Nick = NULL; m_Password = NULL; m_Username = NULL; m_PeerName = NULL; m_PeerNameTemp = NULL; m_ClientLookup = NULL; m_CommandList = NULL; m_NamesXSupport = false; m_QuitReason = NULL; m_AuthTimer = NULL; m_PingTimer = NULL; m_DestroyClientTimer = NULL; if (Client != INVALID_SOCKET) { WriteLine(":shroudbnc.info NOTICE AUTH :*** shroudBNC %s - " "Copyright (C) 2005-2011 Gunnar Beutner", g_Bouncer->GetBouncerVersion()); m_ClientLookup = new CDnsQuery(this, USE_DNSEVENTPROXY(CClientConnection, AsyncDnsFinishedClient)); sockaddr *Remote = GetRemoteAddress(); if (Remote == NULL) { Kill("Internal error: GetRemoteAddress() failed. Could not look up your hostname."); return; } WriteLine(":shroudbnc.info NOTICE AUTH :*** Doing reverse DNS lookup on %s...", IpToString(Remote)); m_ClientLookup->GetHostByAddr(Remote); } if (m_Nick == NULL) { m_AuthTimer = new CTimer(30, false, ClientAuthTimer, this); } m_PingTimer = new CTimer(45, true, ClientPingTimer, this); m_LastResponse = g_CurrentTime; } /** * CClientConnection * * Constructs a new client connection object. This constructor should * only be used by ThawObject(). */ CClientConnection::CClientConnection() : CConnection(INVALID_SOCKET, false, Role_Server) { m_Nick = NULL; m_Password = NULL; m_Username = NULL; m_PeerName = NULL; // m_PreviousNick = NULL; m_ClientLookup = NULL; m_AuthTimer = NULL; m_CommandList = NULL; m_NamesXSupport = false; m_QuitReason = NULL; m_PingTimer = new CTimer(45, true, ClientPingTimer, this); } /** * ~CClientConnection * * Destructs a client connection object. */ CClientConnection::~CClientConnection() { free(m_Nick); free(m_Password); free(m_Username); free(m_PeerName); // free(m_PreviousNick); delete m_ClientLookup; delete m_AuthTimer; delete m_PingTimer; delete m_DestroyClientTimer; } /** * ProcessBncCommand * * Processes a bouncer command (i.e. /sbnc or /msg -sBNC ). * * @param Subcommand the command's name * @param argc number of parameters for the command * @param argv arguments for the command * @param NoticeUser whether to send replies as notices */ bool CClientConnection::ProcessBncCommand(const char *Subcommand, int argc, const char **argv, bool NoticeUser) { char *Out; const CVector *Modules; bool latchedRetVal = true; int rc; Modules = g_Bouncer->GetModules(); /** * SENDUSER * * Sends the specified text to the user. * * @param Text the text */ #define SENDUSER(Text) \ do { \ if (NoticeUser) { \ RealNotice(Text); \ } else { \ Privmsg(Text); \ } \ } while (0) if (argc < 1) { if (NoticeUser) { SENDUSER("You need to specify a command. Try /sbnc help"); } else { SENDUSER("You need to specify a command. Try /msg -sBNC help"); } return false; } if (strcasecmp(Subcommand, "help") == 0) { if (argc <= 1) { SENDUSER("--The following commands are available to you--"); SENDUSER("--Used as '/sbnc ', or '/msg -sbnc '"); } FlushCommands(&m_CommandList); if (GetOwner()->IsAdmin()) { AddCommand(&m_CommandList, "adduser", "Admin", "creates a new user", "Syntax: adduser [password]\nCreates a new user."); AddCommand(&m_CommandList, "deluser", "Admin", "removes a user", "Syntax: deluser \nDeletes a user."); AddCommand(&m_CommandList, "resetpass", "Admin", "sets a user's password", "Syntax: resetpass \nResets another user's password."); AddCommand(&m_CommandList, "who", "Admin", "shows users", "Syntax: who\nShows a list of all users.\nFlags (which are displayed in front of the username):\n" "@ user is an admin\n* user is currently logged in\n! user is suspended"); AddCommand(&m_CommandList, "admin", "Admin", "gives someone admin privileges", "Syntax: admin \nGives admin privileges to a user."); AddCommand(&m_CommandList, "unadmin", "Admin", "removes someone's admin privileges", "Syntax: unadmin \nRemoves someone's admin privileges."); AddCommand(&m_CommandList, "suspend", "Admin", "suspends a user", "Syntax: suspend [reason]\nSuspends an account. An optional reason can be specified."); AddCommand(&m_CommandList, "unsuspend", "Admin", "unsuspends a user", "Syntax: unsuspend \nRemoves a suspension from the specified account."); AddCommand(&m_CommandList, "lsmod", "Admin", "lists loaded modules", "Syntax: lsmod\nLists all currently loaded modules."); AddCommand(&m_CommandList, "insmod", "Admin", "loads a module", "Syntax: insmod \nLoads a module."); AddCommand(&m_CommandList, "rmmod", "Admin", "unloads a module", "Syntax: rmmod \nUnloads a module. Use the \"lsmod\" command to view a list of loaded modules."); AddCommand(&m_CommandList, "simul", "Admin", "simulates a command on another user's connection", "Syntax: simul \nExecutes a command in another user's context."); AddCommand(&m_CommandList, "broadcast", "Admin", "sends a global notice to all bouncer users", "Syntax: broadcast \nSends a notice to all currently connected users."); AddCommand(&m_CommandList, "kill", "Admin", "disconnects a user from the bouncer", "Syntax: kill \nDisconnects a user from the bouncer."); AddCommand(&m_CommandList, "disconnect", "Admin", "disconnects a user from the irc server", "Syntax: disconnect [username]\nDisconnects a user from the IRC server which he is currently connected to." " If you don't specify a username, your own IRC connection will be closed."); AddCommand(&m_CommandList, "playmainlog", "Admin", "plays the bouncer's log", "Syntax: playmainlog\nDisplays the bouncer's log."); AddCommand(&m_CommandList, "erasemainlog", "Admin", "erases the bouncer's log", "Syntax: erasemainlog\nErases the bouncer's log."); AddCommand(&m_CommandList, "globalset", "Admin", "sets global options", "Syntax: globalset [option] [value]\nDisplays or changed global options."); AddCommand(&m_CommandList, "globalunset", "Admin", "restores the default value of a global option", "Syntax: globalunset