]> jfr.im git - irc/evilnet/mod.chanfix.git/blame - DELHOSTCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / DELHOSTCommand.cc
CommitLineData
cf9e1bf3
C
1/**
2 * DELHOSTCommand.cc
3 *
4 * 08/26/2005 - Jimmy Lipham <music0m@alltel.net>
5 * Initial Version
6 *
17febc02 7 * Deletes this hostmask from the user's list of hostmasks
cf9e1bf3
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 *
17febc02 24 * $Id$
cf9e1bf3
C
25 */
26
27#include "gnuworld_config.h"
cf9e1bf3
C
28
29#include "chanfix.h"
91c63299 30#include "responses.h"
cf9e1bf3 31#include "StringTokenizer.h"
13a50edb 32#include "sqlcfUser.h"
cf9e1bf3 33
17febc02 34RCSTAG("$Id$");
cf9e1bf3
C
35
36namespace gnuworld
37{
1d54d2a1 38namespace cf
39{
cf9e1bf3 40
13a50edb 41void DELHOSTCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
cf9e1bf3 42{
17febc02 43StringTokenizer st(Message);
cf9e1bf3 44
13a50edb 45sqlcfUser* targetUser = bot->isAuthed(st[1]);
17febc02 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());
51 return;
52}
53
54/* Can't delete a host from an owner unless you're an owner. */
13a50edb 55if (targetUser->getFlag(sqlcfUser::F_OWNER) && !theUser->getFlag(sqlcfUser::F_OWNER)) {
fa3ba3b3 56 bot->SendTo(theClient,
57 bot->getResponse(theUser,
58 language::cant_del_host_an_owner,
59 std::string("You cannot delete a host from an owner unless you're an owner.")).c_str());
60 return;
61}
62
63/* Can only delete a host from a user manager if you're an owner. */
13a50edb 64if (targetUser->getFlag(sqlcfUser::F_USERMANAGER) && !theUser->getFlag(sqlcfUser::F_OWNER)) {
fa3ba3b3 65 bot->SendTo(theClient,
66 bot->getResponse(theUser,
67 language::cant_del_host_manager,
68 std::string("You cannot delete a host from a user manager unless you're an owner.")).c_str());
17febc02 69 return;
70}
71
d939ef34 72/* A serveradmin can only add flags to users on his/her own group. */
13a50edb 73if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) &&
74 !theUser->getFlag(sqlcfUser::F_USERMANAGER)) {
d939ef34 75 if (targetUser->getGroup() != theUser->getGroup()) {
91c63299 76 bot->SendTo(theClient,
fa3ba3b3 77 bot->getResponse(theUser,
78 language::cant_del_host_diff_group,
79 std::string("You cannot delete a host from a user in a different group.")).c_str());
d939ef34 80 return;
81 }
17febc02 82}
83
84if (!targetUser->hasHost(st[2].c_str())) {
91c63299 85 bot->SendTo(theClient,
fa3ba3b3 86 bot->getResponse(theUser,
87 language::user_doesnt_have_host,
88 std::string("User %s doesn't have hostmask %s.")).c_str(),
89 targetUser->getUserName().c_str(), st[2].c_str());
17febc02 90 return;
91}
92
23cb8771 93if (!targetUser->delHost(bot->getLocalDBHandle(),st[2].c_str())) {
c2f14d27 94 bot->SendTo(theClient,
95 bot->getResponse(theUser,
96 language::failed_deleting_host,
97 std::string("Failed deleting hostmask %s from user %s.")).c_str(),
98 st[2].c_str(), targetUser->getUserName().c_str());
99 return;
100}
101
17febc02 102targetUser->setLastUpdated(bot->currentTime());
103targetUser->setLastUpdatedBy( std::string( "("
104 + theUser->getUserName()
105 + ") "
106 + theClient->getRealNickUserHost() ) );
23cb8771 107targetUser->commit(bot->getLocalDBHandle());
17febc02 108
91c63299 109bot->SendTo(theClient,
110 bot->getResponse(theUser,
111 language::deleted_hostmask,
112 std::string("Deleted hostmask %s from user %s.")).c_str(),
113 st[2].c_str(), targetUser->getUserName().c_str());
87fb1731 114
901a93e0 115bot->logAdminMessage("%s (%s) DELHOST %s %s",
17febc02 116 theUser->getUserName().c_str(),
117 theClient->getRealNickUserHost().c_str(),
901a93e0 118 targetUser->getUserName().c_str(), st[2].c_str());
17febc02 119
25f00d30 120bot->logLastComMessage(theClient, Message);
121
17febc02 122return;
cf9e1bf3
C
123}
124
1d54d2a1 125} //namespace cf
cf9e1bf3 126} //namespace gnuworld