Changes to make it actually sorta work

This commit is contained in:
KimLS 2017-12-11 18:38:04 -08:00
parent 5bbeec626c
commit 569a907e43
11 changed files with 75 additions and 76 deletions

View File

@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "login_structures.h" #include "login_structures.h"
#include "../common/misc_functions.h" #include "../common/misc_functions.h"
#include "../common/eqemu_logsys.h" #include "../common/eqemu_logsys.h"
#include "../common/string_util.h"
extern LoginServer server; extern LoginServer server;
@ -194,6 +195,7 @@ void Client::Handle_Login(const char* data, unsigned int size)
char *login_packet_buffer = nullptr; char *login_packet_buffer = nullptr;
unsigned int db_account_id = 0; unsigned int db_account_id = 0;
std::string db_loginserver = "eqemu";
std::string db_account_password_hash; std::string db_account_password_hash;
std::string outbuffer; std::string outbuffer;
@ -219,44 +221,38 @@ void Client::Handle_Login(const char* data, unsigned int size)
bool result = false; bool result = false;
if (outbuffer[0] == 0 && outbuffer[1] == 0) { if (outbuffer[0] == 0 && outbuffer[1] == 0) {
//if (server.options.IsTokenLoginAllowed()) { if (server.options.IsTokenLoginAllowed()) {
// cred = (&outbuffer[2 + user.length()]); cred = (&outbuffer[2 + user.length()]);
// result = server.db->GetLoginTokenDataFromToken(cred, connection->GetRemoteAddr(), db_account_id, user); result = server.db->GetLoginTokenDataFromToken(cred, connection->GetRemoteAddr(), db_account_id, db_loginserver, user);
//} }
} }
else { else {
//if (server.options.IsPasswordLoginAllowed()) { if (server.options.IsPasswordLoginAllowed()) {
// result = false; cred = (&outbuffer[1 + user.length()]);
// //cred = (&outbuffer[1 + user.length()]); auto components = SplitString(user, '.');
// //if (server.db->GetLoginDataFromAccountName(user, db_account_password_hash, db_account_id) == false) { if (components.size() == 2) {
// // /* If we have auto_create_accounts enabled in the login.ini, we will process the creation of an account on our own*/ db_loginserver = components[0];
// // if ( user = components[1];
// // server.options.CanAutoCreateAccounts() && }
// // server.db->CreateLoginData(user, eqcrypt_hash(user, cred, mode), db_account_id) == true
// // ) { if (server.db->GetLoginDataFromAccountInfo(user, db_loginserver, db_account_password_hash, db_account_id) == false) {
// // LogF(Logs::General, Logs::Error, "User {0} does not exist in the database, so we created it...", user);
// // result = true; }
// // } else {
// // else { if (eqcrypt_verify_hash(user, cred, db_account_password_hash, mode)) {
// // LogF(Logs::General, Logs::Error, "Error logging in, user {0} does not exist in the database.", user); result = true;
// // result = false; }
// // } else {
// //} result = false;
// //else { }
// // if (eqcrypt_verify_hash(user, cred, db_account_password_hash, mode)) { }
// // result = true; }
// // }
// // else {
// // result = false;
// // }
// //}
//}
} }
/* Login Accepted */ /* Login Accepted */
if (result) { if (result) {
server.client_manager->RemoveExistingClient(db_account_id); server.client_manager->RemoveExistingClient(db_account_id, db_loginserver);
in_addr in; in_addr in;
in.s_addr = connection->GetRemoteIP(); in.s_addr = connection->GetRemoteIP();
@ -266,6 +262,7 @@ void Client::Handle_Login(const char* data, unsigned int size)
account_id = db_account_id; account_id = db_account_id;
account_name = user; account_name = user;
loginserver_name = db_loginserver;
EQApplicationPacket *outapp = new EQApplicationPacket(OP_LoginAccepted, 10 + 80); EQApplicationPacket *outapp = new EQApplicationPacket(OP_LoginAccepted, 10 + 80);
const LoginLoginRequest_Struct* llrs = (const LoginLoginRequest_Struct *)data; const LoginLoginRequest_Struct* llrs = (const LoginLoginRequest_Struct *)data;
@ -358,7 +355,7 @@ void Client::Handle_Play(const char* data)
this->play_server_id = (unsigned int)play->ServerNumber; this->play_server_id = (unsigned int)play->ServerNumber;
play_sequence_id = sequence_in; play_sequence_id = sequence_in;
play_server_id = server_id_in; play_server_id = server_id_in;
server.server_manager->SendUserToWorldRequest(server_id_in, account_id); server.server_manager->SendUserToWorldRequest(server_id_in, account_id, loginserver_name);
} }
void Client::SendServerListPacket(uint32 seq) void Client::SendServerListPacket(uint32 seq)

View File

@ -96,6 +96,11 @@ public:
*/ */
unsigned int GetAccountID() const { return account_id; } unsigned int GetAccountID() const { return account_id; }
/**
* Gets the loginserver name of this client.
*/
std::string GetLoginServerName() const { return loginserver_name; }
/** /**
* Gets the account name of this client. * Gets the account name of this client.
*/ */

View File

@ -124,12 +124,12 @@ void ClientManager::ProcessDisconnect()
} }
} }
void ClientManager::RemoveExistingClient(unsigned int account_id) void ClientManager::RemoveExistingClient(unsigned int account_id, const std::string &loginserver)
{ {
auto iter = clients.begin(); auto iter = clients.begin();
while (iter != clients.end()) while (iter != clients.end())
{ {
if ((*iter)->GetAccountID() == account_id) if ((*iter)->GetAccountID() == account_id && (*iter)->GetLoginServerName().compare(loginserver) == 0)
{ {
Log(Logs::General, Logs::Login_Server, "Client attempting to log in and existing client already logged in, removing existing client."); Log(Logs::General, Logs::Login_Server, "Client attempting to log in and existing client already logged in, removing existing client.");
delete (*iter); delete (*iter);
@ -142,24 +142,17 @@ void ClientManager::RemoveExistingClient(unsigned int account_id)
} }
} }
Client *ClientManager::GetClient(unsigned int account_id) Client *ClientManager::GetClient(unsigned int account_id, const std::string &loginserver)
{ {
Client *cur = nullptr;
int count = 0;
auto iter = clients.begin(); auto iter = clients.begin();
while (iter != clients.end()) while (iter != clients.end())
{ {
if ((*iter)->GetAccountID() == account_id) if ((*iter)->GetAccountID() == account_id && (*iter)->GetLoginServerName().compare(loginserver) == 0)
{ {
cur = (*iter); return (*iter);
count++;
} }
++iter; ++iter;
} }
if (count > 1) return nullptr;
{
Log(Logs::General, Logs::Error, "More than one client with a given account_id existed in the client list.");
}
return cur;
} }

View File

@ -48,12 +48,12 @@ public:
/** /**
* Removes a client with a certain account id. * Removes a client with a certain account id.
*/ */
void RemoveExistingClient(unsigned int account_id); void RemoveExistingClient(unsigned int account_id, const std::string &loginserver);
/** /**
* Gets a client (if exists) by their account id. * Gets a client (if exists) by their account id.
*/ */
Client *GetClient(unsigned int account_id); Client *GetClient(unsigned int account_id, const std::string &loginserver);
private: private:
/** /**

View File

@ -41,7 +41,7 @@ public:
* Needed for client login procedure. * Needed for client login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id, std::string &loginserver) { return false; } virtual bool GetLoginDataFromAccountInfo(const std::string &name, const std::string &loginserver, std::string &password, unsigned int &id) { return false; }
virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user) { return false; } virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user) { return false; }

View File

@ -59,7 +59,7 @@ DatabaseMySQL::~DatabaseMySQL()
} }
} }
bool DatabaseMySQL::GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id, std::string &loginserver) bool DatabaseMySQL::GetLoginDataFromAccountInfo(const std::string &name, const std::string &loginserver, std::string &password, unsigned int &id)
{ {
if (!database) if (!database)
{ {
@ -70,7 +70,9 @@ bool DatabaseMySQL::GetLoginDataFromAccountName(std::string name, std::string &p
MYSQL_ROW row; MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out); std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT LoginServerID, AccountPassword FROM " << server.options.GetAccountTable() << " WHERE AccountName = '"; query << "SELECT LoginServerID, AccountPassword FROM " << server.options.GetAccountTable() << " WHERE AccountName = '";
query << name; query << EscapeString(name);
query << "' AND AccountLoginserver='";
query << EscapeString(loginserver);
query << "'"; query << "'";
if (mysql_query(database, query.str().c_str()) != 0) if (mysql_query(database, query.str().c_str()) != 0)

View File

@ -57,7 +57,7 @@ public:
* Needed for client login procedure. * Needed for client login procedure.
* Returns true if the record was found, false otherwise. * Returns true if the record was found, false otherwise.
*/ */
virtual bool GetLoginDataFromAccountName(std::string name, std::string &password, unsigned int &id, std::string &loginserver); virtual bool GetLoginDataFromAccountInfo(const std::string &name, const std::string &loginserver, std::string &password, unsigned int &id);
virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user); virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user);

View File

@ -206,18 +206,19 @@ EQApplicationPacket *ServerManager::CreateServerListPacket(Client *c, uint32 seq
return outapp; return outapp;
} }
void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id) void ServerManager::SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id, const std::string &client_loginserver)
{ {
auto iter = world_servers.begin(); auto iter = world_servers.begin();
bool found = false; bool found = false;
while (iter != world_servers.end()) { while (iter != world_servers.end()) {
if ((*iter)->GetRuntimeID() == server_id) { if ((*iter)->GetRuntimeID() == server_id) {
EQ::Net::DynamicPacket outapp; EQ::Net::DynamicPacket outapp;
outapp.Resize(sizeof(UsertoWorldRequestLegacy_Struct)); outapp.Resize(sizeof(UsertoWorldRequest_Struct));
UsertoWorldRequestLegacy_Struct *utwr = (UsertoWorldRequestLegacy_Struct*)outapp.Data(); UsertoWorldRequest_Struct *utwr = (UsertoWorldRequest_Struct*)outapp.Data();
utwr->worldid = server_id; utwr->worldid = server_id;
utwr->lsaccountid = client_account_id; utwr->lsaccountid = client_account_id;
(*iter)->GetConnection()->Send(ServerOP_UsertoWorldReqLeg, outapp); strncpy(utwr->login, &client_loginserver[0], 64);
(*iter)->GetConnection()->Send(ServerOP_UsertoWorldReq, outapp);
found = true; found = true;
if (server.options.IsDumpInPacketsOn()) { if (server.options.IsDumpInPacketsOn()) {

View File

@ -45,7 +45,7 @@ public:
/** /**
* Sends a request to world to see if the client is banned or suspended. * Sends a request to world to see if the client is banned or suspended.
*/ */
void SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id); void SendUserToWorldRequest(unsigned int server_id, unsigned int client_account_id, const std::string &client_loginserver);
/** /**
* Creates a server list packet for the client. * Creates a server list packet for the client.

View File

@ -146,7 +146,7 @@ void WorldServer::ProcessUsertoWorldRespLeg(uint16_t opcode, const EQ::Net::Pack
UsertoWorldResponseLegacy_Struct *utwr = (UsertoWorldResponseLegacy_Struct*)p.Data(); UsertoWorldResponseLegacy_Struct *utwr = (UsertoWorldResponseLegacy_Struct*)p.Data();
Log(Logs::General, Logs::Debug, "Trying to find client with user id of %u.", utwr->lsaccountid); Log(Logs::General, Logs::Debug, "Trying to find client with user id of %u.", utwr->lsaccountid);
Client *c = server.client_manager->GetClient(utwr->lsaccountid); Client *c = server.client_manager->GetClient(utwr->lsaccountid, "eqemu");
if (c) if (c)
{ {
Log(Logs::General, Logs::Debug, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str()); Log(Logs::General, Logs::Debug, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str());
@ -161,7 +161,7 @@ void WorldServer::ProcessUsertoWorldRespLeg(uint16_t opcode, const EQ::Net::Pack
if (utwr->response > 0) if (utwr->response > 0)
{ {
per->Allowed = 1; per->Allowed = 1;
SendClientAuth(c->GetConnection()->GetRemoteAddr(), c->GetAccountName(), c->GetKey(), c->GetAccountID()); SendClientAuth(c->GetConnection()->GetRemoteAddr(), c->GetAccountName(), c->GetKey(), c->GetAccountID(), c->GetLoginServerName());
} }
switch (utwr->response) switch (utwr->response)
@ -233,7 +233,7 @@ void WorldServer::ProcessUsertoWorldResp(uint16_t opcode, const EQ::Net::Packet
UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)p.Data(); UsertoWorldResponse_Struct *utwr = (UsertoWorldResponse_Struct*)p.Data();
Log(Logs::General, Logs::Debug, "Trying to find client with user id of %u.", utwr->lsaccountid); Log(Logs::General, Logs::Debug, "Trying to find client with user id of %u.", utwr->lsaccountid);
Client *c = server.client_manager->GetClient(utwr->lsaccountid); Client *c = server.client_manager->GetClient(utwr->lsaccountid, utwr->login);
if (c) if (c)
{ {
Log(Logs::General, Logs::Debug, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str()); Log(Logs::General, Logs::Debug, "Found client with user id of %u and account name of %s.", utwr->lsaccountid, c->GetAccountName().c_str());
@ -248,7 +248,7 @@ void WorldServer::ProcessUsertoWorldResp(uint16_t opcode, const EQ::Net::Packet
if (utwr->response > 0) if (utwr->response > 0)
{ {
per->Allowed = 1; per->Allowed = 1;
SendClientAuth(c->GetConnection()->GetRemoteAddr(), c->GetAccountName(), c->GetKey(), c->GetAccountID()); SendClientAuth(c->GetConnection()->GetRemoteAddr(), c->GetAccountName(), c->GetKey(), c->GetAccountID(), c->GetLoginServerName());
} }
switch (utwr->response) switch (utwr->response)
@ -586,16 +586,17 @@ void WorldServer::Handle_LSStatus(ServerLSStatus_Struct *s)
server_status = s->status; server_status = s->status;
} }
void WorldServer::SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id) void WorldServer::SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id, const std::string &loginserver_name)
{ {
EQ::Net::DynamicPacket outapp; EQ::Net::DynamicPacket outapp;
ClientAuthLegacy_Struct client_auth; ClientAuth_Struct client_auth;
client_auth.lsaccount_id = account_id; client_auth.lsaccount_id = account_id;
strncpy(client_auth.name, account.c_str(), 30); strncpy(client_auth.name, account.c_str(), 30);
strncpy(client_auth.key, key.c_str(), 30); strncpy(client_auth.key, key.c_str(), 30);
client_auth.lsadmin = 0; client_auth.lsadmin = 0;
client_auth.worldadmin = 0; client_auth.worldadmin = 0;
client_auth.ip = inet_addr(ip.c_str()); client_auth.ip = inet_addr(ip.c_str());
strncpy(client_auth.lsname, &loginserver_name[0], 64);
std::string client_address(ip); std::string client_address(ip);
std::string world_address(connection->Handle()->RemoteIP()); std::string world_address(connection->Handle()->RemoteIP());
@ -611,10 +612,10 @@ void WorldServer::SendClientAuth(std::string ip, std::string account, std::strin
} }
outapp.PutSerialize(0, client_auth); outapp.PutSerialize(0, client_auth);
connection->Send(ServerOP_LSClientAuthLeg, outapp); connection->Send(ServerOP_LSClientAuth, outapp);
if (server.options.IsDumpInPacketsOn()) if (server.options.IsDumpInPacketsOn())
{ {
DumpPacket(ServerOP_LSClientAuthLeg, outapp); DumpPacket(ServerOP_LSClientAuth, outapp);
} }
} }

View File

@ -124,7 +124,7 @@ public:
/** /**
* Informs world that there is a client incoming with the following data. * Informs world that there is a client incoming with the following data.
*/ */
void SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id); void SendClientAuth(std::string ip, std::string account, std::string key, unsigned int account_id, const std::string &loginserver_name);
private: private: