-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathADDFLAGCommand.cc
148 lines (133 loc) · 4.68 KB
/
ADDFLAGCommand.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* ADDFLAGCommand.cc
*
* 08/08/2005 - Jimmy Lipham <[email protected]>
* Initial Version
*
* Adds this flag to the user
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id$
*/
#include "gnuworld_config.h"
#include "Network.h"
#include "chanfix.h"
#include "responses.h"
#include "StringTokenizer.h"
#include "sqlcfUser.h"
RCSTAG("$Id$");
namespace gnuworld
{
namespace cf
{
void ADDFLAGCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
{
StringTokenizer st(Message);
char flag = st[2][0];
if (st[2].size() > 1) {
if (flag == '+')
flag = st[2][1];
else {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::one_flag_per_addflag,
std::string("You may only add one flag per ADDFLAG command.")).c_str());
return;
}
}
if (!bot->getFlagType(flag)) {
Usage(theClient);
return;
}
sqlcfUser* targetUser = bot->isAuthed(st[1]);
if (!targetUser) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::no_such_user,
std::string("No such user %s.")).c_str(), st[1].c_str());
return;
}
if (flag == bot->getFlagChar(sqlcfUser::F_OWNER) &&
!theUser->getFlag(sqlcfUser::F_OWNER)) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::owner_add_owner_only,
std::string("Only an owner can add the owner flag.")).c_str());
return;
}
if (flag == bot->getFlagChar(sqlcfUser::F_USERMANAGER) &&
!theUser->getFlag(sqlcfUser::F_OWNER)) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::user_man_add_owner_only,
std::string("Only an owner can add the user management flag.")).c_str());
return;
}
/* A serveradmin can only add flags to users on his/her own group. */
if (theUser->getFlag(sqlcfUser::F_SERVERADMIN) &&
!theUser->getFlag(sqlcfUser::F_USERMANAGER)) {
if (targetUser->getGroup() != theUser->getGroup()) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::cant_add_flag_diff_group,
std::string("You cannot add a flag to a user in a different group.")).c_str());
return;
}
if (flag == bot->getFlagChar(sqlcfUser::F_BLOCK)) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::cant_add_block_flag,
std::string("You cannot add a block flag.")).c_str());
return;
}
if (flag == bot->getFlagChar(sqlcfUser::F_SERVERADMIN)) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::cant_add_serveradmin_flag,
std::string("You cannot add a serveradmin flag.")).c_str());
return;
}
}
if (targetUser->getFlag(bot->getFlagType(flag))) {
bot->SendTo(theClient,
bot->getResponse(theUser,
language::user_already_has_flag,
std::string("User %s already has flag '%c'.")).c_str(),
targetUser->getUserName().c_str(), flag);
return;
}
targetUser->setFlag(bot->getFlagType(flag));
targetUser->setLastUpdated(bot->currentTime());
targetUser->setLastUpdatedBy( std::string( "("
+ theUser->getUserName()
+ ") "
+ theClient->getRealNickUserHost() ) );
targetUser->commit(bot->getLocalDBHandle());
bot->SendTo(theClient,
bot->getResponse(theUser,
language::added_flag_to_user,
std::string("Added flag '%c' to user %s.")).c_str(),
flag,
targetUser->getUserName().c_str());
bot->logAdminMessage("%s (%s) ADDFLAG %s %c",
theUser->getUserName().c_str(),
theClient->getRealNickUserHost().c_str(),
targetUser->getUserName().c_str(), flag);
bot->logLastComMessage(theClient, Message);
} //ADDFLAGCommand::Exec
} //Namespace cf
} //Namespace gnuworld