]> jfr.im git - irc/evilnet/mod.chanfix.git/blame - WHOISCommand.cc
Fixed missing include, corebug fix was already applied here.
[irc/evilnet/mod.chanfix.git] / WHOISCommand.cc
CommitLineData
43236e25
C
1/**
2 * WHOISCommand.cc
3 *
4 * 08/07/2005 - Jimmy Lipham <music0m@alltel.net>
5 * Initial Version
6 *
dee49a74 7 * Shows information about this user
43236e25
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$
43236e25
C
25 */
26
43236e25 27#include "gnuworld_config.h"
c169a3ca 28#include "Network.h"
43236e25
C
29
30#include "chanfix.h"
530374e1 31#include "responses.h"
43236e25 32#include "StringTokenizer.h"
13a50edb 33#include "sqlcfUser.h"
43236e25 34
69d8a8b3 35RCSTAG("$Id$");
43236e25
C
36
37namespace gnuworld
38{
1d54d2a1 39namespace cf
40{
43236e25 41
13a50edb 42void WHOISCommand::Exec(iClient* theClient, sqlcfUser* theUser, const std::string& Message)
43236e25
C
43{
44StringTokenizer st(Message);
8de4dcba 45
46bot->logAdminMessage("%s (%s) WHOIS %s",
87fb1731 47 theUser->getUserName().c_str(),
48 theClient->getRealNickUserHost().c_str(),
49 st[1].c_str());
8de4dcba 50
92b0a9b9 51if (st[1] == "*") {
34cf18fe 52 unsigned int numUsers = 0;
530374e1 53 bot->SendTo(theClient,
54 bot->getResponse(theUser,
55 language::list_of_all_users,
56 std::string("List of all users:")).c_str());
2e3ba7bc 57 chanfix::usersIterator ptr = bot->usersMap_begin();
92b0a9b9 58 while (ptr != bot->usersMap_end()) {
13a50edb 59 sqlcfUser* tmpUser = ptr->second;
530374e1 60 bot->SendTo(theClient,
d8674157 61 bot->getResponse(theUser,
62 language::user_flags_group,
63 std::string("User: %s, Flags: %s, Group: %s")).c_str(),
64 tmpUser->getUserName().c_str(),
65 (tmpUser->getFlags()) ? std::string("+" + bot->getFlagsString(tmpUser->getFlags())).c_str() : "None",
66 tmpUser->getGroup().c_str());
92b0a9b9 67 ptr++;
34cf18fe 68 numUsers++;
92b0a9b9 69 }
530374e1 70 bot->SendTo(theClient,
34cf18fe 71 bot->getResponse(theUser,
72 language::number_of_users,
73 std::string("Number of users: %d.")).c_str(),
74 numUsers);
92b0a9b9 75 return;
76}
77
13a50edb 78sqlcfUser* theUser2 = bot->isAuthed(st[1]);
c169a3ca 79
80const char* username = st[1].c_str();
81if (username[0] == '=') {
82 /* Skip the '='. */
83 ++username;
84 iClient* theClient2 = Network->findNick(username);
85 if (theClient2)
86 theUser2 = bot->isAuthed(theClient2->getAccount());
87}
88
530374e1 89if (!theUser2)
43236e25 90{
530374e1 91 bot->SendTo(theClient,
92 bot->getResponse(theUser,
93 language::no_such_user,
f813bdeb 94 std::string("No such user %s.")).c_str(),
c169a3ca 95 username);
43236e25
C
96 return;
97}
dee49a74 98
f813bdeb 99bot->SendTo(theClient, "*** \002%s\002 ***", theUser2->getUserName().c_str());
100
101if (theUser2->getIsSuspended())
102 bot->SendTo(theClient,
103 bot->getResponse(theUser,
104 language::whois_suspended,
105 std::string("--SUSPENDED--")).c_str());
106
530374e1 107if (!theUser2->getFlags())
108 bot->SendTo(theClient,
109 bot->getResponse(theUser,
110 language::whois_flags_none,
111 std::string("Flags: none.")).c_str());
dee49a74 112else
530374e1 113 bot->SendTo(theClient,
114 bot->getResponse(theUser,
115 language::whois_flags,
116 std::string("Flags: +%s")).c_str(),
117 bot->getFlagsString(theUser2->getFlags()).c_str());
cf9e1bf3 118
530374e1 119bot->SendTo(theClient,
120 bot->getResponse(theUser,
121 language::whois_group,
f813bdeb 122 std::string("Group: %s")).c_str(),
123 theUser2->getGroup().c_str());
124
125std::string langName = "Unknown";
126std::string langCode = "UN";
127for( chanfix::languageTableType::iterator ptr = bot->languageTable.begin() ;
128 ptr != bot->languageTable.end() ; ++ptr )
129 {
130 if ((unsigned int)ptr->second.first == theUser2->getLanguageId())
131 {
132 langName = ptr->second.second;
133 langCode = ptr->first;
134 break;
135 }
136}
137
138bot->SendTo(theClient,
139 bot->getResponse(theUser,
140 language::whois_lang,
141 std::string("Language: %s (%s)")).c_str(),
142 langName.c_str(), langCode.c_str());
143
144if (theUser2->getNeedOper())
4ed0862b
C
145 bot->SendTo(theClient,
146 bot->getResponse(theUser,
147 language::whois_needoper_yes,
148 std::string("NeedOper: Yes")).c_str());
f813bdeb 149else
4ed0862b
C
150 bot->SendTo(theClient,
151 bot->getResponse(theUser,
152 language::whois_needoper_no,
153 std::string("NeedOper: No")).c_str());
154
c169a3ca 155if (theUser != theUser2) {
156 if (theUser2->getLastSeen() > 0)
157 bot->SendTo(theClient,
158 bot->getResponse(theUser,
159 language::whois_lastused,
160 std::string("Last used the service: %s ago")).c_str(),
161 bot->prettyDuration(theUser2->getLastSeen()).c_str());
162 else
163 bot->SendTo(theClient,
164 bot->getResponse(theUser,
165 language::whois_lastused_never,
166 std::string("Last used the service: Never")).c_str());
167}
168
d8674157 169if (st.size() > 2 && string_upper(st[2]) == "-MODIF")
4ed0862b 170 bot->SendTo(theClient,
d8674157 171 bot->getResponse(theUser,
172 language::whois_modif,
82f09291 173 std::string("Last modified: %s (%s ago)")).c_str(),
174 theUser2->getLastUpdatedBy().c_str(),
175 bot->prettyDuration(theUser2->getLastUpdated()).c_str());
d939ef34 176
25f00d30 177bot->logLastComMessage(theClient, Message);
178
d939ef34 179return;
f813bdeb 180} //WHOISCommand::Exec
1d54d2a1 181} //namespace cf
43236e25 182} //namespace gnuworld