|
Флудильня Разговоры на любые темы. Мы устаем постоянно работать. Иногда надо где-то немного отдохнуть. Пожалуйста, не надо здесь устраивать бардак. |
|
Опции темы | Поиск в этой теме | Опции просмотра |
30.11.2010, 09:34 | #1 |
Гость
Сообщений: n/a
|
[patch] Auto_reg
Искал по всюду, ни где нет на версии 3.3.5...
Нашел только это Код:
# HG changeset patch # User max_ru # Date 1257256570 -10800 # Branch trunk # Node ID 86f10a53a8c936c57a28ed5b95d9ed4213692a1e # Parent 527883bf47d868bc30dcd7144993075e66c8b813 autoreg diff -r 527883bf47d8 -r 86f10a53a8c9 src/trinityrealm/AuthSocket.cpp --- a/src/trinityrealm/AuthSocket.cpp Tue Nov 03 13:37:54 2009 +0100 +++ b/src/trinityrealm/AuthSocket.cpp Tue Nov 03 16:56:10 2009 +0300 @@ -30,6 +30,7 @@ #include "RealmList.h" #include "AuthSocket.h" #include "AuthCodes.h" +#include <cwctype> // needs for towupper #include <openssl/md5.h> #include "Auth/Sha1.h" //#include "Util.h" -- for commented utf8ToUpperOnlyLatin @@ -229,6 +230,9 @@ #define AUTH_TOTAL_COMMANDS sizeof(table)/sizeof(AuthHandler) +// check used symbols in account name at creating +std::string notAllowedChars = "\t\v\b\f\a\n\r\\\"\'\? <>[](){}_=+-|/!@#$%^&*~`.,\0"; + ///Holds the MD5 hash of client patches present on the server Patcher PatchesCache; @@ -238,6 +242,7 @@ N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB 3C82872A3E9BB7"); g.SetDword(7); _authed = false; + _autoreg = sConfig.GetBoolDefault("UseAutoReg", false); pPatch = NULL; _accountSecurityLevel = SEC_PLAYER; @@ -526,13 +531,80 @@ _localizationName[i] = ch->country[4-i-1]; sLog.outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)); + + // user authenticated => turn off autoreg, thus account creating + _autoreg = false; } } delete result; } - else //no account + else if(_autoreg) // no account { - pkt<< (uint8) REALM_AUTH_NO_MATCH; + // check username + if(_safelogin.find_first_of(notAllowedChars)!=_saf elogin.npos || _safelogin.length()<4) + _autoreg = false; + // check IP + else if(uint32 amountip = sConfig.GetIntDefault("AmountIP", 0)) + { + QueryResult *result2 = loginDatabase.PQuery("SELECT COUNT(last_ip) FROM account WHERE last_ip = '%s'", GetRemoteAddress().c_str()); + if (result2 && (*result2)[0].GetUInt8() >= amountip) + { + _autoreg = false; + delete result2; + } + } + + // still all ok + if(_autoreg) + { + ///- Get the password from the account table, upper it, and make the SRP6 calculation + std::transform(_safelogin.begin(), _safelogin.end(), _safelogin.begin(), std::towupper); + Sha1Hash sha; + std::string sI = _safelogin + ":" + _safelogin; + sha.UpdateData(sI); + sha.Finalize(); + + BigNumber bn; + bn.SetBinary(sha.GetDigest(), sha.GetLength()); + uint8 *val = bn.AsByteArray(); + std::reverse(val, val+bn.GetNumBytes()); + bn.SetBinary(val, bn.GetNumBytes()); + + const char* rI = bn.AsHexStr(); + _SetVSFields(rI); + OPENSSL_free((void*)rI); + + b.SetRand(19 * 8); + BigNumber gmod=g.ModExp(b, N); + B = ((v * 3) + gmod) % N; + + if (B.GetNumBytes() < 32) + sLog.outDetail("Interesting, calculation of B in realmd is < 32."); + + ASSERT(gmod.GetNumBytes() <= 32); + + BigNumber unk3; + unk3.SetRand(16*8); + + ///- Fill the response packet with the result + pkt << (uint8)REALM_AUTH_SUCCESS; + pkt.append(B.AsByteArray(), 32); + pkt << (uint8)1; + pkt.append(g.AsByteArray(), 1); + pkt << (uint8)32; + pkt.append(N.AsByteArray(), 32); + pkt.append(s.AsByteArray(), s.GetNumBytes()); + pkt.append(unk3.AsByteArray(), 16); + pkt << (uint8)0; // Added in 1.12.x client branch + } + else + // username and/or IP is bad + pkt << (uint8) REALM_AUTH_NO_MATCH; + } + else + { + // autoreg off in config, account is wrong + pkt << (uint8) REALM_AUTH_NO_MATCH; } } SendBuf((char const*)pkt.contents(), pkt.size()); @@ -693,6 +765,13 @@ ///- Check if SRP6 results match (password is correct), else send an error if (!memcmp(M.AsByteArray(), lp.M1, 20)) { + //create new account if use autoreg + if(_autoreg) + { + loginDatabase.PExecute("INSERT IGNORE INTO account (username,sha_pass_hash,joindate) VALUES ('%s',SHA1(CONCAT(UPPER('%s'),':',UPPER('%s'))),NO W())",_safelogin.c_str(),_safelogin.c_str(),_safelogin. c_str()); + sLog.outBasic("New account [%s] created successfully", _login.c_str()); + } + sLog.outBasic("User '%s' successfully authenticated", _login.c_str()); ///- Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account Последний раз редактировалось Konctantin; 30.11.2010 в 20:35. Причина: tegs code |
30.11.2010, 16:53 | #2 |
Forum bot
Регистрация: 01.02.2010
Адрес: пусто
Сообщений: 841
Сказал(а) спасибо: 286
Поблагодарили 418 раз(а) в 190 сообщениях
Записей в дневнике: 60
|
Здесь форум мангос, под тринь ищите в ином местею
__________________
Совершенно безопасен для людей, обладающих хотя бы некоторыми минимальными зачатками интеллекта, и способными строить причинно-следственные цепочки. |