]>
jfr.im git - irc/evilnet/mod.auth.git/blob - auth.cc
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 #include "StringTokenizer.h"
34 * Exported function used by moduleLoader to gain an
35 * instance of this module.
40 xClient
* _gnuwinit(const std::string
& args
)
42 return new auth( args
);
48 * This constructor calls the base class constructor. The xClient
49 * constructor will open the configuration file given and retrieve
50 * basic client info (nick/user/host/etc).
51 * Any additional processing must be done here.
53 auth::auth( const std::string
& configFileName
)
54 : xClient( configFileName
)
56 /* Load the config file */
57 EConfig
authConfig(configFileName
);
59 /* Load any settings we have */
60 maxAccountLen
= ::atoi(authConfig
.Require("maxAccountLen")->second
.c_str());
61 operOnly
= ::atoi(authConfig
.Require("operOnly")->second
.c_str());
62 secureOnly
= ::atoi(authConfig
.Require("secureOnly")->second
.c_str());
67 /* No heap space allocated */
70 void auth::OnPrivateMessage( iClient
* theClient
,
71 const std::string
& Message
, bool secure
)
73 if (operOnly
&& !theClient
->isOper()) {
74 // if the client is not oper'd we act as the clientExample ;)
75 Notice(theClient
, "You must be an IRC Operator to use this service.");
79 if (secureOnly
&& !secure
) {
80 Notice(theClient
, "You must /msg %s@%s", nickName
.c_str(),
81 getUplinkName().c_str());
85 StringTokenizer
st(Message
);
89 std::string
account(st
[0]);
90 if (!validAccount(account
)) {
91 Notice(theClient
, "%s is not a valid account name.", account
.c_str());
94 iClient
* receiver
= NULL
;
96 if (!(receiver
= Network
->findNick(st
[1]))) {
97 Notice(theClient
, "Unable to find nickname %s", st
[1].c_str());
102 if (!theClient
->isModeR()) {
104 MyUplink
->UserLogin(receiver
, account
, this);
105 Notice(theClient
, "%s is now authenticated as %s.",
106 receiver
->getNickName().c_str(), account
.c_str());
107 Notice(receiver
, "You have been authenticated as %s by %s.",
108 account
.c_str(), theClient
->getNickName().c_str());
110 MyUplink
->UserLogin(theClient
, account
, this);
111 Notice(theClient
, "You are now authenticated as %s.",
115 Notice(theClient
, "You are already authenticated as %s!",
116 theClient
->getAccount().c_str());
121 // Burst any channels.
122 void auth::BurstChannels()
124 xClient::BurstChannels();
127 bool auth::validAccount(const std::string
& account
) const
129 if (account
.empty() || account
.size() > maxAccountLen
)
134 * Nickname characters are in range 'A'..'}', '_', '-', '0'..'9'
135 * anything outside the above set will terminate nickname.
136 * In addition, the first character cannot be '-' or a Digit.
138 if (isdigit(account
[0]))
141 for ( std::string::const_iterator sItr
= account
.begin();
142 sItr
!= account
.end() ; ++sItr
) {
143 if ( *sItr
>= 'A' && *sItr
<= '}' )
146 if ( '_' == *sItr
|| '-' == *sItr
)
149 if ( *sItr
>= '0' && *sItr
<= '9' )
158 } // namespace gnuworld