4 * 12/28/2005 - Reed Loden <reed@reedloden.com>
7 * Shows all the host entries assigned to an oper
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.
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.
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,
27 #include "gnuworld_config.h"
30 #include "responses.h"
31 #include "StringTokenizer.h"
32 #include "sqlcfUser.h"
41 void LISTHOSTSCommand::Exec(iClient
* theClient
, sqlcfUser
* theUser
, const std::string
& Message
)
43 StringTokenizer
st(Message
);
45 sqlcfUser
* targetUser
;
47 targetUser
= bot
->isAuthed(st
[1]);
52 bot
->SendTo(theClient
,
53 bot
->getResponse(theUser
,
54 language::no_such_user
,
55 std::string("No such user %s.")).c_str(),
60 sqlcfUser::flagType requiredFlags
= sqlcfUser::F_USERMANAGER
| sqlcfUser::F_SERVERADMIN
;
61 if ((targetUser
!= theUser
) && !theUser
->getFlag(requiredFlags
)) {
62 bot
->SendTo(theClient
,
63 bot
->getResponse(theUser
,
64 language::requires_auth_and_flags
,
65 std::string("This command requires authentication and one of these flags: \"%s\".")).c_str(),
66 bot
->getFlagsString(requiredFlags
).c_str());
70 /* A serveradmin can only view hosts of users in his/her own group. */
71 if (theUser
->getFlag(sqlcfUser::F_SERVERADMIN
) &&
72 !theUser
->getFlag(sqlcfUser::F_USERMANAGER
)) {
73 if (targetUser
->getGroup() != theUser
->getGroup()) {
74 bot
->SendTo(theClient
,
75 bot
->getResponse(theUser
,
76 language::cant_view_hosts_diff_group
,
77 std::string("You cannot view hosts of a user in a different group.")).c_str());
82 bot
->SendTo(theClient
,
83 bot
->getResponse(theUser
,
84 language::host_list_header
,
85 std::string("Host list for %s:")).c_str(),
86 targetUser
->getUserName().c_str());
88 sqlcfUser::hostListType sqlHostList
= targetUser
->getHostList();
89 if (!sqlHostList
.empty()) {
90 for (sqlcfUser::hostListType::iterator itr
= sqlHostList
.begin();
91 itr
!= sqlHostList
.end(); ++itr
)
92 bot
->SendTo(theClient
, *itr
);
94 bot
->SendTo(theClient
, "None.");
97 bot
->SendTo(theClient
,
98 bot
->getResponse(theUser
,
99 language::host_list_footer
,
100 std::string("End of host list.")).c_str());
102 bot
->logAdminMessage("%s (%s) LISTHOSTS %s",
103 theUser
->getUserName().c_str(),
104 theClient
->getRealNickUserHost().c_str(),
105 targetUser
->getUserName().c_str());
107 bot
->logLastComMessage(theClient
, Message
);
110 } //LISTHOSTSCommand::Exec
113 } //namespace gnuworld