]>
Commit | Line | Data |
---|---|---|
cf9e1bf3 C |
1 | /** |
2 | * ADDHOSTCommand.cc | |
3 | * | |
4 | * 08/26/2005 - Jimmy Lipham <music0m@alltel.net> | |
5 | * Initial Version | |
6 | * | |
17febc02 | 7 | * Adds this hostmask to 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 | 34 | RCSTAG("$Id$"); |
cf9e1bf3 C |
35 | |
36 | namespace gnuworld | |
37 | { | |
1d54d2a1 | 38 | namespace cf |
39 | { | |
13a50edb | 40 | void ADDHOSTCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message) |
cf9e1bf3 | 41 | { |
17febc02 | 42 | StringTokenizer st(Message); |
cf9e1bf3 | 43 | |
13a50edb | 44 | sqlcfUser* targetUser = bot->isAuthed(st[1]); |
17febc02 | 45 | if (!targetUser) { |
91c63299 | 46 | bot->SendTo(theClient, |
fa3ba3b3 | 47 | bot->getResponse(theUser, |
48 | language::no_such_user, | |
49 | std::string("No such user %s.")).c_str(), st[1].c_str()); | |
17febc02 | 50 | return; |
51 | } | |
52 | ||
fa3ba3b3 | 53 | /* Can't add a host to an owner unless you're an owner. */ |
13a50edb | 54 | if (targetUser->getFlag(sqlcfUser::F_OWNER) && !theUser->getFlag(sqlcfUser::F_OWNER)) { |
fa3ba3b3 | 55 | bot->SendTo(theClient, |
56 | bot->getResponse(theUser, | |
57 | language::cant_add_host_an_owner, | |
58 | std::string("You cannot add a host to an owner unless you're an owner.")).c_str()); | |
59 | return; | |
60 | } | |
61 | ||
62 | /* Can only add a host to a user manager if you're an owner. */ | |
13a50edb | 63 | if (targetUser->getFlag(sqlcfUser::F_USERMANAGER) && !theUser->getFlag(sqlcfUser::F_OWNER)) { |
fa3ba3b3 | 64 | bot->SendTo(theClient, |
65 | bot->getResponse(theUser, | |
66 | language::cant_add_host_manager, | |
67 | std::string("You cannot add a host to a user manager unless you're an owner.")).c_str()); | |
68 | return; | |
69 | } | |
70 | ||
71 | /* A serveradmin can only add hosts to users on his/her own group. */ | |
13a50edb | 72 | if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) && |
73 | !theUser->getFlag(sqlcfUser::F_USERMANAGER)) { | |
d939ef34 | 74 | if (targetUser->getGroup() != theUser->getGroup()) { |
91c63299 | 75 | bot->SendTo(theClient, |
fa3ba3b3 | 76 | bot->getResponse(theUser, |
77 | language::cant_add_host_diff_group, | |
78 | std::string("You cannot add a host to a user in a different group.")).c_str()); | |
d939ef34 | 79 | return; |
80 | } | |
17febc02 | 81 | } |
cf9e1bf3 | 82 | |
17febc02 | 83 | if (targetUser->matchHost(st[2].c_str())) { |
34cf18fe | 84 | if ((st[2] != "*!*@*") && targetUser->hasHost("*!*@*")) { |
23cb8771 | 85 | targetUser->delHost(bot->getLocalDBHandle(),"*!*@*"); |
34cf18fe | 86 | bot->SendTo(theClient, |
87 | bot->getResponse(theUser, | |
88 | language::removed_default_hostmask, | |
89 | std::string("Removed the default hostmask of *!*@* from user %s.")).c_str(), | |
90 | targetUser->getUserName().c_str()); | |
91 | } else { | |
92 | bot->SendTo(theClient, | |
93 | bot->getResponse(theUser, | |
94 | language::already_has_hostmask, | |
95 | std::string("User %s already has hostmask %s.")).c_str(), | |
96 | targetUser->getUserName().c_str(), | |
97 | st[2].c_str()); | |
98 | return; | |
99 | } | |
17febc02 | 100 | } |
101 | ||
23cb8771 | 102 | if (!targetUser->addHost(bot->getLocalDBHandle(),st[2].c_str())) { |
c2f14d27 | 103 | bot->SendTo(theClient, |
104 | bot->getResponse(theUser, | |
105 | language::failed_adding_hostmask, | |
106 | std::string("Failed adding hostmask %s to user %s.")).c_str(), | |
107 | st[2].c_str(), targetUser->getUserName().c_str()); | |
108 | return; | |
109 | } | |
110 | ||
17febc02 | 111 | targetUser->setLastUpdated(bot->currentTime()); |
112 | targetUser->setLastUpdatedBy( std::string( "(" | |
113 | + theUser->getUserName() | |
114 | + ") " | |
115 | + theClient->getRealNickUserHost() ) ); | |
23cb8771 | 116 | targetUser->commit(bot->getLocalDBHandle()); |
17febc02 | 117 | |
91c63299 | 118 | bot->SendTo(theClient, |
119 | bot->getResponse(theUser, | |
120 | language::adding_hostmask_to_user, | |
121 | std::string("Added hostmask %s to user %s.")).c_str(), | |
da505946 | 122 | st[2].c_str(), |
123 | targetUser->getUserName().c_str()); | |
124 | ||
901a93e0 | 125 | bot->logAdminMessage("%s (%s) ADDHOST %s %s", |
17febc02 | 126 | theUser->getUserName().c_str(), |
127 | theClient->getRealNickUserHost().c_str(), | |
87fb1731 | 128 | targetUser->getUserName().c_str(), st[2].c_str()); |
17febc02 | 129 | |
25f00d30 | 130 | bot->logLastComMessage(theClient, Message); |
131 | ||
17febc02 | 132 | return; |
cf9e1bf3 C |
133 | } |
134 | ||
1d54d2a1 | 135 | } //namespace cf |
cf9e1bf3 | 136 | } //namespace gnuworld |