mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
Working on login / world connection mostly there, fixed a few crashes with encryption on 0 length packets
This commit is contained in:
+98
-91
@@ -53,95 +53,102 @@ LoginServer::LoginServer(const char* iAddress, uint16 iPort, const char* Account
|
||||
LoginServer::~LoginServer() {
|
||||
}
|
||||
|
||||
void LoginServer::ProcessPacket(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
void LoginServer::ProcessUsertoWorldReq(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
/************ Get all packets from packet manager out queue and process them ************/
|
||||
Log.Out(Logs::Detail, Logs::World_Server,"Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
UsertoWorldRequest_Struct* utwr = (UsertoWorldRequest_Struct*)p.Data();
|
||||
uint32 id = database.GetAccountIDFromLSID(utwr->lsaccountid);
|
||||
int16 status = database.CheckStatus(id);
|
||||
|
||||
switch(opcode) {
|
||||
case ServerOP_UsertoWorldReq: {
|
||||
UsertoWorldRequest_Struct* utwr = (UsertoWorldRequest_Struct*)p.Data();
|
||||
uint32 id = database.GetAccountIDFromLSID(utwr->lsaccountid);
|
||||
int16 status = database.CheckStatus(id);
|
||||
auto outpack = new ServerPacket;
|
||||
outpack->opcode = ServerOP_UsertoWorldResp;
|
||||
outpack->size = sizeof(UsertoWorldResponse_Struct);
|
||||
outpack->pBuffer = new uchar[outpack->size];
|
||||
memset(outpack->pBuffer, 0, outpack->size);
|
||||
UsertoWorldResponse_Struct* utwrs = (UsertoWorldResponse_Struct*)outpack->pBuffer;
|
||||
utwrs->lsaccountid = utwr->lsaccountid;
|
||||
utwrs->ToID = utwr->FromID;
|
||||
|
||||
auto outpack = new ServerPacket;
|
||||
outpack->opcode = ServerOP_UsertoWorldResp;
|
||||
outpack->size = sizeof(UsertoWorldResponse_Struct);
|
||||
outpack->pBuffer = new uchar[outpack->size];
|
||||
memset(outpack->pBuffer, 0, outpack->size);
|
||||
UsertoWorldResponse_Struct* utwrs = (UsertoWorldResponse_Struct*) outpack->pBuffer;
|
||||
utwrs->lsaccountid = utwr->lsaccountid;
|
||||
utwrs->ToID = utwr->FromID;
|
||||
|
||||
if(Config->Locked == true)
|
||||
{
|
||||
if((status == 0 || status < 100) && (status != -2 || status != -1))
|
||||
utwrs->response = 0;
|
||||
if(status >= 100)
|
||||
utwrs->response = 1;
|
||||
}
|
||||
else {
|
||||
utwrs->response = 1;
|
||||
}
|
||||
|
||||
int32 x = Config->MaxClients;
|
||||
if( (int32)numplayers >= x && x != -1 && x != 255 && status < 80)
|
||||
utwrs->response = -3;
|
||||
|
||||
if(status == -1)
|
||||
utwrs->response = -1;
|
||||
if(status == -2)
|
||||
utwrs->response = -2;
|
||||
|
||||
utwrs->worldid = utwr->worldid;
|
||||
SendPacket(outpack);
|
||||
delete outpack;
|
||||
break;
|
||||
}
|
||||
case ServerOP_LSClientAuth: {
|
||||
ClientAuth_Struct* slsca = (ClientAuth_Struct*)p.Data();
|
||||
|
||||
if (RuleI(World, AccountSessionLimit) >= 0) {
|
||||
// Enforce the limit on the number of characters on the same account that can be
|
||||
// online at the same time.
|
||||
client_list.EnforceSessionLimit(slsca->lsaccount_id);
|
||||
}
|
||||
|
||||
client_list.CLEAdd(slsca->lsaccount_id, slsca->name, slsca->key, slsca->worldadmin, inet_addr(slsca->ip), slsca->local);
|
||||
break;
|
||||
}
|
||||
case ServerOP_LSFatalError: {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Login server responded with FatalError.");
|
||||
if (p.Length() > 1) {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, " %s", (const char*)p.Data());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ServerOP_SystemwideMessage: {
|
||||
ServerSystemwideMessage* swm = (ServerSystemwideMessage*)p.Data();
|
||||
zoneserver_list.SendEmoteMessageRaw(0, 0, 0, swm->type, swm->message);
|
||||
break;
|
||||
}
|
||||
case ServerOP_LSRemoteAddr: {
|
||||
if (!Config->WorldAddress.length()) {
|
||||
WorldConfig::SetWorldAddress((char *)p.Data());
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Loginserver provided %s as world address", (const char*)p.Data());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ServerOP_LSAccountUpdate: {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Received ServerOP_LSAccountUpdate packet from loginserver");
|
||||
CanAccountUpdate = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Unknown LSOpCode: 0x%04x size=%d",(int)opcode, p.Length());
|
||||
Log.OutF(Logs::General, Logs::Login_Server, "{0}", p.ToString());
|
||||
break;
|
||||
}
|
||||
if (Config->Locked == true)
|
||||
{
|
||||
if ((status == 0 || status < 100) && (status != -2 || status != -1))
|
||||
utwrs->response = 0;
|
||||
if (status >= 100)
|
||||
utwrs->response = 1;
|
||||
}
|
||||
else {
|
||||
utwrs->response = 1;
|
||||
}
|
||||
|
||||
int32 x = Config->MaxClients;
|
||||
if ((int32)numplayers >= x && x != -1 && x != 255 && status < 80)
|
||||
utwrs->response = -3;
|
||||
|
||||
if (status == -1)
|
||||
utwrs->response = -1;
|
||||
if (status == -2)
|
||||
utwrs->response = -2;
|
||||
|
||||
utwrs->worldid = utwr->worldid;
|
||||
SendPacket(outpack);
|
||||
delete outpack;
|
||||
}
|
||||
|
||||
void LoginServer::ProcessLSClientAuth(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
try {
|
||||
auto slsca = p.GetSerialize<ClientAuth_Struct>(0);
|
||||
|
||||
if (RuleI(World, AccountSessionLimit) >= 0) {
|
||||
// Enforce the limit on the number of characters on the same account that can be
|
||||
// online at the same time.
|
||||
client_list.EnforceSessionLimit(slsca.lsaccount_id);
|
||||
}
|
||||
|
||||
client_list.CLEAdd(slsca.lsaccount_id, slsca.name.c_str(), slsca.key.c_str(), slsca.worldadmin, inet_addr(slsca.ip.c_str()), slsca.local);
|
||||
}
|
||||
catch (std::exception &ex) {
|
||||
Log.OutF(Logs::General, Logs::Error, "Error parsing LSClientAuth packet from world.\n{0}", ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
void LoginServer::ProcessLSFatalError(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Login server responded with FatalError.");
|
||||
if (p.Length() > 1) {
|
||||
Log.Out(Logs::Detail, Logs::World_Server, " %s", (const char*)p.Data());
|
||||
}
|
||||
}
|
||||
|
||||
void LoginServer::ProcessSystemwideMessage(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
ServerSystemwideMessage* swm = (ServerSystemwideMessage*)p.Data();
|
||||
zoneserver_list.SendEmoteMessageRaw(0, 0, 0, swm->type, swm->message);
|
||||
}
|
||||
|
||||
void LoginServer::ProcessLSRemoteAddr(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
if (!Config->WorldAddress.length()) {
|
||||
WorldConfig::SetWorldAddress((char *)p.Data());
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Loginserver provided %s as world address", (const char*)p.Data());
|
||||
}
|
||||
}
|
||||
|
||||
void LoginServer::ProcessLSAccountUpdate(uint16_t opcode, EQ::Net::Packet &p) {
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Recevied ServerPacket from LS OpCode 0x04x", opcode);
|
||||
|
||||
Log.Out(Logs::Detail, Logs::World_Server, "Received ServerOP_LSAccountUpdate packet from loginserver");
|
||||
CanAccountUpdate = true;
|
||||
}
|
||||
|
||||
bool LoginServer::Connect() {
|
||||
@@ -189,12 +196,12 @@ bool LoginServer::Connect() {
|
||||
}
|
||||
});
|
||||
|
||||
client->OnMessage(ServerOP_UsertoWorldReq, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSClientAuth, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSFatalError, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_SystemwideMessage, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSRemoteAddr, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSAccountUpdate, std::bind(&LoginServer::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_UsertoWorldReq, std::bind(&LoginServer::ProcessUsertoWorldReq, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSClientAuth, std::bind(&LoginServer::ProcessLSClientAuth, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSFatalError, std::bind(&LoginServer::ProcessLSFatalError, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_SystemwideMessage, std::bind(&LoginServer::ProcessSystemwideMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSRemoteAddr, std::bind(&LoginServer::ProcessLSRemoteAddr, this, std::placeholders::_1, std::placeholders::_2));
|
||||
client->OnMessage(ServerOP_LSAccountUpdate, std::bind(&LoginServer::ProcessLSAccountUpdate, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
void LoginServer::SendInfo() {
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
LoginServer(const char*, uint16, const char*, const char*);
|
||||
~LoginServer();
|
||||
|
||||
void ProcessPacket(uint16_t opcode, EQ::Net::Packet &p);
|
||||
bool Connect();
|
||||
|
||||
void SendInfo();
|
||||
@@ -47,6 +46,13 @@ public:
|
||||
bool CanUpdate() { return CanAccountUpdate; }
|
||||
|
||||
private:
|
||||
void ProcessUsertoWorldReq(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void ProcessLSClientAuth(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void ProcessLSFatalError(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void ProcessSystemwideMessage(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void ProcessLSRemoteAddr(uint16_t opcode, EQ::Net::Packet &p);
|
||||
void ProcessLSAccountUpdate(uint16_t opcode, EQ::Net::Packet &p);
|
||||
|
||||
bool minilogin;
|
||||
std::unique_ptr<EQ::Net::ServertalkClient> client;
|
||||
std::unique_ptr<EQ::Timer> statusupdate_timer;
|
||||
|
||||
@@ -415,28 +415,6 @@ int main(int argc, char** argv) {
|
||||
Log.OutF(Logs::Detail, Logs::World_Server, "New connection from IP {0}:{1}", stream->RemoteEndpoint(), ntohs(stream->GetRemotePort()));
|
||||
});
|
||||
|
||||
EQ::Net::ServertalkServer server;
|
||||
EQ::Net::ServertalkServerOptions stopts;
|
||||
stopts.port = 5999;
|
||||
stopts.credentials = "User:Root;Password:1234567890";
|
||||
stopts.encrypted = true;
|
||||
server.Listen(stopts);
|
||||
|
||||
server.OnConnectionIdentified("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> conn) {
|
||||
Log.Out(Logs::General, Logs::Debug, "New QueryServ Connection....");
|
||||
EQ::Net::WritablePacket out;
|
||||
out.PutCString(0, "Hello");
|
||||
conn->Send(1, out);
|
||||
|
||||
conn->OnMessage(2, [&](uint16_t opcode, EQ::Net::Packet &p) {
|
||||
Log.OutF(Logs::General, Logs::Debug, "Server got message of type {0}\n{1}", opcode, p.ToString());
|
||||
});
|
||||
});
|
||||
|
||||
server.OnConnectionRemoved("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> conn) {
|
||||
Log.Out(Logs::General, Logs::Debug, "Lost QueryServ connection.");
|
||||
});
|
||||
|
||||
while(RunLoops) {
|
||||
Timer::SetCurrentTime();
|
||||
eqs = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user