]> jfr.im git - irc/evilnet/mod.chanfix.git/blame - DELUSERCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / DELUSERCommand.cc
CommitLineData
dbbaed85
C
1/**
2 * DELUSERCommand.cc
3 *
dee49a74 4 * 08/08/2005 - Jimmy Lipham <music0m@alltel.net>
dbbaed85
C
5 * Initial Version
6 *
87fb1731 7 * Deletes a user
dbbaed85
C
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 * USA.
23 *
dee49a74 24 * $Id$
dbbaed85
C
25 */
26
dbbaed85 27#include "gnuworld_config.h"
dbbaed85
C
28
29#include "chanfix.h"
91c63299 30#include "responses.h"
dbbaed85 31#include "StringTokenizer.h"
13a50edb 32#include "sqlcfUser.h"
dbbaed85 33
dee49a74 34RCSTAG("$Id$");
dbbaed85
C
35
36namespace gnuworld
37{
1d54d2a1 38namespace cf
39{
dbbaed85 40
13a50edb 41void DELUSERCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
dbbaed85 42{
dbbaed85
C
43StringTokenizer st(Message);
44
13a50edb 45sqlcfUser* targetUser = bot->isAuthed(st[1]);
c06812cf 46if (!targetUser) {
91c63299 47 bot->SendTo(theClient,
fa3ba3b3 48 bot->getResponse(theUser,
49 language::no_such_user,
50 std::string("No such user %s.")).c_str(), st[1].c_str());
dbbaed85
C
51 return;
52}
53
fa3ba3b3 54/* Can't delete an owner unless you're an owner. */
13a50edb 55if (targetUser->getFlag(sqlcfUser::F_OWNER) && !theUser->getFlag(sqlcfUser::F_OWNER)) {
91c63299 56 bot->SendTo(theClient,
fa3ba3b3 57 bot->getResponse(theUser,
58 language::cant_delete_an_owner,
59 std::string("You cannot delete an owner unless you're an owner.")).c_str());
dbbaed85
C
60 return;
61}
62
fa3ba3b3 63/* Can only delete a user manager if you're an owner. */
13a50edb 64if (targetUser->getFlag(sqlcfUser::F_USERMANAGER) && !theUser->getFlag(sqlcfUser::F_OWNER)) {
91c63299 65 bot->SendTo(theClient,
fa3ba3b3 66 bot->getResponse(theUser,
67 language::cant_delete_manager,
68 std::string("You cannot delete a user manager unless you're an owner.")).c_str());
dbbaed85
C
69 return;
70}
71
17358328 72/* A serveradmin can only delete users in his/her own group. */
13a50edb 73if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) &&
74 !theUser->getFlag(sqlcfUser::F_USERMANAGER)) {
c06812cf 75 if (targetUser->getGroup() != theUser->getGroup()) {
91c63299 76 bot->SendTo(theClient,
fa3ba3b3 77 bot->getResponse(theUser,
78 language::cant_delete_from_diff_group,
79 std::string("You cannot delete a user in a different group.")).c_str());
d939ef34 80 return;
81 }
82}
dbbaed85 83
23cb8771 84if (targetUser->Delete(bot->getLocalDBHandle())) {
c2f14d27 85 bot->usersMap.erase(bot->usersMap.find(targetUser->getUserName()));
86 bot->SendTo(theClient,
87 bot->getResponse(theUser,
dbbf1647 88 language::deleted_user,
c06812cf 89 std::string("Deleted user %s.")).c_str(), targetUser->getUserName().c_str());
901a93e0 90 bot->logAdminMessage("%s (%s) DELUSER %s",
c2f14d27 91 theClient->getAccount().c_str(),
92 theClient->getRealNickUserHost().c_str(),
93 targetUser->getUserName().c_str());
94 delete targetUser; targetUser = 0;
95} else {
96 bot->SendTo(theClient,
97 bot->getResponse(theUser,
98 language::error_deleting_user,
99 std::string("Error deleting user %s.")).c_str(), st[1].c_str());
100}
dbbf1647 101
25f00d30 102bot->logLastComMessage(theClient, Message);
103
dbbf1647 104return;
c2f14d27 105} //DELUSERCommand::Exec
1d54d2a1 106
107} //namespace cf
c2f14d27 108} //namespace gnuworld