removed usewebapi

This commit is contained in:
CPunch 2020-09-21 14:49:08 -05:00
parent 5e0948ea93
commit b67a0b6946
4 changed files with 2 additions and 21 deletions

View File

@ -14,8 +14,6 @@ acceptallcustomnames=true
# how often should everything be flushed to the database?
# the default is 4 minutes
dbsaveinterval=240
# use the web API
usewebapi=false
# Shard Server configuration
[shard]

View File

@ -53,21 +53,14 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
else
{
std::unique_ptr<Database::Account> findUser = Database::findAccount(userLogin);
// if account not found
// if account not found, make new one
if (findUser == nullptr)
{
//web api takes care of registration
if (settings::USEWEBAPI)
errorCode = (int)LoginError::ID_DOESNT_EXIST;
//without web api, create new account
else
{
loginSessions[sock] = CNLoginData();
loginSessions[sock].userID = Database::addAccount(userLogin, userPassword);
loginSessions[sock].slot = 1;
success = true;
}
}
// if user exists, check if password is correct
else if (CNLoginServer::isPasswordCorrect(findUser->Password, userPassword))
{
@ -429,19 +422,12 @@ bool CNLoginServer::exitDuplicate(int accountId) {
bool CNLoginServer::isLoginDataGood(std::string login, std::string password) {
std::regex loginRegex("[a-zA-Z0-9_-]{4,32}");
//web api sends password hashed, so we don't check it
if (settings::USEWEBAPI)
return (std::regex_match(login, loginRegex));
//without web api
std::regex passwordRegex("[a-zA-Z0-9!@#$%^&*()_+]{8,32}");
return (std::regex_match(login, loginRegex) && std::regex_match(password, passwordRegex));
}
bool CNLoginServer::isPasswordCorrect(std::string actualPassword, std::string tryPassword) {
//web api sends password already hashed
if (settings::USEWEBAPI)
return actualPassword == tryPassword;
//without web api
return BCrypt::validatePassword(tryPassword, actualPassword);
}

View File

@ -7,7 +7,6 @@ int settings::VERBOSITY = 1;
int settings::LOGINPORT = 8001;
bool settings::APPROVEALLNAMES = true;
bool settings::USEWEBAPI = false;
int settings::DBSAVEINTERVAL = 240;
int settings::SHARDPORT = 8002;
@ -42,7 +41,6 @@ void settings::init() {
APPROVEALLNAMES = reader.GetBoolean("", "acceptallcustomnames", APPROVEALLNAMES);
VERBOSITY = reader.GetInteger("", "verbosity", VERBOSITY);
LOGINPORT = reader.GetInteger("login", "port", LOGINPORT);
USEWEBAPI = reader.GetBoolean("login", "usewebapi", USEWEBAPI);
SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT);
SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1");
DBSAVEINTERVAL = reader.GetInteger("shard", "dbsaveinterval", DBSAVEINTERVAL);

View File

@ -4,7 +4,6 @@ namespace settings {
extern int VERBOSITY;
extern int LOGINPORT;
extern bool APPROVEALLNAMES;
extern bool USEWEBAPI;
extern int DBSAVEINTERVAL;
extern int SHARDPORT;
extern std::string SHARDSERVERIP;