]>
Commit | Line | Data |
---|---|---|
dbbaed85 C |
1 | /** |
2 | * ADDFLAGCommand.cc | |
3 | * | |
dee49a74 | 4 | * 08/08/2005 - Jimmy Lipham <music0m@alltel.net> |
dbbaed85 C |
5 | * Initial Version |
6 | * | |
dee49a74 | 7 | * Adds this flag to the 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 C |
27 | #include "gnuworld_config.h" |
28 | #include "Network.h" | |
29 | ||
30 | #include "chanfix.h" | |
3935adc0 | 31 | #include "responses.h" |
dbbaed85 | 32 | #include "StringTokenizer.h" |
13a50edb | 33 | #include "sqlcfUser.h" |
dbbaed85 | 34 | |
dee49a74 | 35 | RCSTAG("$Id$"); |
dbbaed85 C |
36 | |
37 | namespace gnuworld | |
38 | { | |
1d54d2a1 | 39 | namespace cf |
40 | { | |
13a50edb | 41 | void ADDFLAGCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message) |
dbbaed85 | 42 | { |
dbbaed85 C |
43 | StringTokenizer st(Message); |
44 | ||
3e4d74fb | 45 | char flag = st[2][0]; |
dbbaed85 | 46 | if (st[2].size() > 1) { |
3e4d74fb | 47 | if (flag == '+') |
48 | flag = st[2][1]; | |
3935adc0 | 49 | else { |
50 | bot->SendTo(theClient, | |
51 | bot->getResponse(theUser, | |
52 | language::one_flag_per_addflag, | |
53 | std::string("You may only add one flag per ADDFLAG command.")).c_str()); | |
3e4d74fb | 54 | return; |
55 | } | |
dbbaed85 C |
56 | } |
57 | ||
dee49a74 | 58 | if (!bot->getFlagType(flag)) { |
dbbaed85 C |
59 | Usage(theClient); |
60 | return; | |
61 | } | |
62 | ||
13a50edb | 63 | sqlcfUser* targetUser = bot->isAuthed(st[1]); |
c06812cf | 64 | if (!targetUser) { |
3935adc0 | 65 | bot->SendTo(theClient, |
66 | bot->getResponse(theUser, | |
67 | language::no_such_user, | |
68 | std::string("No such user %s.")).c_str(), st[1].c_str()); | |
dee49a74 | 69 | return; |
70 | } | |
dbbaed85 | 71 | |
13a50edb | 72 | if (flag == bot->getFlagChar(sqlcfUser::F_OWNER) && |
73 | !theUser->getFlag(sqlcfUser::F_OWNER)) { | |
3935adc0 | 74 | bot->SendTo(theClient, |
75 | bot->getResponse(theUser, | |
4c59f7a3 | 76 | language::owner_add_owner_only, |
77 | std::string("Only an owner can add the owner flag.")).c_str()); | |
dbbaed85 C |
78 | return; |
79 | } | |
dee49a74 | 80 | |
13a50edb | 81 | if (flag == bot->getFlagChar(sqlcfUser::F_USERMANAGER) && |
82 | !theUser->getFlag(sqlcfUser::F_OWNER)) { | |
3935adc0 | 83 | bot->SendTo(theClient, |
84 | bot->getResponse(theUser, | |
85 | language::user_man_add_owner_only, | |
86 | std::string("Only an owner can add the user management flag.")).c_str()); | |
dbbaed85 C |
87 | return; |
88 | } | |
89 | ||
d939ef34 | 90 | /* A serveradmin can only add flags to users on his/her own group. */ |
13a50edb | 91 | if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) && |
92 | !theUser->getFlag(sqlcfUser::F_USERMANAGER)) { | |
c06812cf | 93 | if (targetUser->getGroup() != theUser->getGroup()) { |
3935adc0 | 94 | bot->SendTo(theClient, |
95 | bot->getResponse(theUser, | |
96 | language::cant_add_flag_diff_group, | |
97 | std::string("You cannot add a flag to a user in a different group.")).c_str()); | |
d939ef34 | 98 | return; |
99 | } | |
13a50edb | 100 | if (flag == bot->getFlagChar(sqlcfUser::F_BLOCK)) { |
3935adc0 | 101 | bot->SendTo(theClient, |
102 | bot->getResponse(theUser, | |
103 | language::cant_add_block_flag, | |
104 | std::string("You cannot add a block flag.")).c_str()); | |
dee49a74 | 105 | return; |
106 | } | |
13a50edb | 107 | if (flag == bot->getFlagChar(sqlcfUser::F_SERVERADMIN)) { |
3935adc0 | 108 | bot->SendTo(theClient, |
109 | bot->getResponse(theUser, | |
110 | language::cant_add_serveradmin_flag, | |
111 | std::string("You cannot add a serveradmin flag.")).c_str()); | |
dee49a74 | 112 | return; |
113 | } | |
114 | } | |
115 | ||
c06812cf | 116 | if (targetUser->getFlag(bot->getFlagType(flag))) { |
3935adc0 | 117 | bot->SendTo(theClient, |
118 | bot->getResponse(theUser, | |
119 | language::user_already_has_flag, | |
4c59f7a3 | 120 | std::string("User %s already has flag '%c'.")).c_str(), |
c06812cf | 121 | targetUser->getUserName().c_str(), flag); |
dbbaed85 C |
122 | return; |
123 | } | |
124 | ||
c06812cf | 125 | targetUser->setFlag(bot->getFlagType(flag)); |
126 | targetUser->setLastUpdated(bot->currentTime()); | |
127 | targetUser->setLastUpdatedBy( std::string( "(" | |
5b333029 | 128 | + theUser->getUserName() |
129 | + ") " | |
92b0a9b9 | 130 | + theClient->getRealNickUserHost() ) ); |
23cb8771 | 131 | targetUser->commit(bot->getLocalDBHandle()); |
3935adc0 | 132 | bot->SendTo(theClient, |
59e47d45 | 133 | bot->getResponse(theUser, |
134 | language::added_flag_to_user, | |
4c59f7a3 | 135 | std::string("Added flag '%c' to user %s.")).c_str(), |
59e47d45 | 136 | flag, |
c06812cf | 137 | targetUser->getUserName().c_str()); |
8de4dcba | 138 | |
139 | bot->logAdminMessage("%s (%s) ADDFLAG %s %c", | |
87fb1731 | 140 | theUser->getUserName().c_str(), |
141 | theClient->getRealNickUserHost().c_str(), | |
142 | targetUser->getUserName().c_str(), flag); | |
8de4dcba | 143 | |
25f00d30 | 144 | bot->logLastComMessage(theClient, Message); |
145 | ||
dbbaed85 | 146 | } //ADDFLAGCommand::Exec |
1d54d2a1 | 147 | } //Namespace cf |
dbbaed85 | 148 | } //Namespace gnuworld |