]>
Commit | Line | Data |
---|---|---|
17358328 | 1 | /** |
2 | * SUSPENDCommand.cc | |
3 | * | |
4 | * 08/29/2005 - Reed Loden <reed@reedloden.com> | |
5 | * Initial Version | |
6 | * | |
7 | * Suspends a user indefinitely | |
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 | * | |
24 | * $Id$ | |
25 | */ | |
26 | ||
27 | #include "gnuworld_config.h" | |
28 | ||
29 | #include "chanfix.h" | |
530374e1 | 30 | #include "responses.h" |
17358328 | 31 | #include "StringTokenizer.h" |
13a50edb | 32 | #include "sqlcfUser.h" |
17358328 | 33 | |
34 | RCSTAG("$Id$"); | |
35 | ||
36 | namespace gnuworld | |
37 | { | |
1d54d2a1 | 38 | namespace cf |
39 | { | |
17358328 | 40 | |
13a50edb | 41 | void SUSPENDCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message) |
17358328 | 42 | { |
43 | StringTokenizer st(Message); | |
44 | ||
13a50edb | 45 | sqlcfUser* targetUser = bot->isAuthed(st[1]); |
17358328 | 46 | if (!targetUser) { |
530374e1 | 47 | bot->SendTo(theClient, |
48 | bot->getResponse(theUser, | |
49 | language::no_such_user, | |
50 | std::string("No such user %s.")).c_str(), st[1].c_str()); | |
17358328 | 51 | return; |
52 | } | |
53 | ||
f813bdeb | 54 | if (theUser == targetUser) { |
d4397486 | 55 | bot->SendTo(theClient, |
fa3ba3b3 | 56 | bot->getResponse(theUser, |
57 | language::user_cant_suspend_self, | |
58 | std::string("Suspending yourself is not a very wise thing to do.")).c_str()); | |
59 | return; | |
60 | } | |
61 | ||
62 | /* Can't suspend an owner unless you're an owner. */ | |
13a50edb | 63 | if (targetUser->getFlag(sqlcfUser::F_OWNER) && !theUser->getFlag(sqlcfUser::F_OWNER)) { |
fa3ba3b3 | 64 | bot->SendTo(theClient, |
65 | bot->getResponse(theUser, | |
66 | language::cant_suspend_an_owner, | |
67 | std::string("You cannot suspend an owner unless you're an owner.")).c_str()); | |
f813bdeb | 68 | return; |
69 | } | |
70 | ||
fa3ba3b3 | 71 | /* Can only suspend a user manager if you're an owner. */ |
13a50edb | 72 | if (targetUser->getFlag(sqlcfUser::F_USERMANAGER) && !theUser->getFlag(sqlcfUser::F_OWNER)) { |
fa3ba3b3 | 73 | bot->SendTo(theClient, |
74 | bot->getResponse(theUser, | |
75 | language::cant_suspend_manager, | |
76 | std::string("You cannot suspend a user manager unless you're an owner.")).c_str()); | |
77 | return; | |
78 | } | |
79 | ||
80 | ||
17358328 | 81 | /* A serveradmin can only suspend users in his/her own group. */ |
13a50edb | 82 | if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) && |
83 | !theUser->getFlag(sqlcfUser::F_USERMANAGER)) { | |
17358328 | 84 | if (targetUser->getGroup() != theUser->getGroup()) { |
530374e1 | 85 | bot->SendTo(theClient, |
fa3ba3b3 | 86 | bot->getResponse(theUser, |
87 | language::cant_suspend_diff_group, | |
88 | std::string("You cannot suspend a user in a different group.")).c_str()); | |
17358328 | 89 | return; |
90 | } | |
91 | } | |
92 | ||
93 | if (targetUser->getIsSuspended()) { | |
530374e1 | 94 | bot->SendTo(theClient, |
fa3ba3b3 | 95 | bot->getResponse(theUser, |
96 | language::user_already_suspended, | |
97 | std::string("User %s is already suspended.")).c_str(), | |
98 | targetUser->getUserName().c_str()); | |
17358328 | 99 | return; |
100 | } | |
101 | ||
102 | targetUser->setSuspended(true); | |
103 | targetUser->setLastUpdated(bot->currentTime()); | |
104 | targetUser->setLastUpdatedBy( std::string( "(" | |
105 | + theUser->getUserName() | |
106 | + ") " | |
107 | + theClient->getRealNickUserHost() ) ); | |
23cb8771 | 108 | targetUser->commit(bot->getLocalDBHandle()); |
17358328 | 109 | |
530374e1 | 110 | bot->SendTo(theClient, |
111 | bot->getResponse(theUser, | |
112 | language::user_suspended, | |
113 | std::string("Suspended user %s indefinitely.")).c_str(), | |
114 | targetUser->getUserName().c_str()); | |
87fb1731 | 115 | |
901a93e0 | 116 | bot->logAdminMessage("%s (%s) SUSPEND %s", |
87fb1731 | 117 | theUser->getUserName().c_str(), |
118 | theClient->getRealNickUserHost().c_str(), | |
119 | targetUser->getUserName().c_str()); | |
17358328 | 120 | |
25f00d30 | 121 | bot->logLastComMessage(theClient, Message); |
122 | ||
17358328 | 123 | return; |
124 | } //SUSPENDCommand::Exec | |
1d54d2a1 | 125 | } //Namespace cf |
17358328 | 126 | } //Namespace gnuworld |