mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 23:01:30 +00:00
Merge pull request #48 from addtheice/master
Cleaned up Packet Handling in world/Client
This commit is contained in:
commit
9b015a2975
272
world/client.cpp
272
world/client.cpp
@ -368,46 +368,9 @@ void Client::SendPostEnterWorld() {
|
||||
safe_delete(outapp);
|
||||
}
|
||||
|
||||
bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
EmuOpcode opcode = app->GetOpcode();
|
||||
|
||||
clog(WORLD__CLIENT_TRACE,"Recevied EQApplicationPacket");
|
||||
_pkt(WORLD__CLIENT_TRACE,app);
|
||||
|
||||
bool ret = true;
|
||||
|
||||
if (!eqs->CheckState(ESTABLISHED)) {
|
||||
clog(WORLD__CLIENT,"Client disconnected (net inactive on send)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Voidd: Anti-GM Account hack, Checks source ip against valid GM Account IP Addresses
|
||||
if (RuleB(World, GMAccountIPList) && this->GetAdmin() >= (RuleI(World, MinGMAntiHackStatus))) {
|
||||
if(!database.CheckGMIPs(long2ip(this->GetIP()).c_str(), this->GetAccountID())) {
|
||||
clog(WORLD__CLIENT,"GM Account not permited from source address %s and accountid %i", long2ip(this->GetIP()).c_str(), this->GetAccountID());
|
||||
eqs->Close();
|
||||
}
|
||||
}
|
||||
|
||||
if (GetAccountID() == 0 && opcode != OP_SendLoginInfo) {
|
||||
// Got a packet other than OP_SendLoginInfo when not logged in
|
||||
clog(WORLD__CLIENT_ERR,"Expecting OP_SendLoginInfo, got %s", OpcodeNames[opcode]);
|
||||
return false;
|
||||
}
|
||||
else if (opcode == OP_AckPacket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(opcode)
|
||||
{
|
||||
case OP_CrashDump:
|
||||
break;
|
||||
case OP_SendLoginInfo:
|
||||
{
|
||||
bool Client::HandleSendLoginInfoPacket(const EQApplicationPacket *app) {
|
||||
if (app->size != sizeof(LoginInfo_Struct)) {
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
LoginInfo_Struct *li=(LoginInfo_Struct *)app->pBuffer;
|
||||
@ -421,8 +384,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
if (strlen(password) <= 1) {
|
||||
// TODO: Find out how to tell the client wrong username/password
|
||||
clog(WORLD__CLIENT_ERR,"Login without a password");
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
pZoning=(li->zoning==1);
|
||||
@ -447,8 +409,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
#else
|
||||
if (loginserverlist.Connected() == false && !pZoning) {
|
||||
clog(WORLD__CLIENT_ERR,"Error: Login server login while not connected to login server.");
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
if ((minilogin && (cle = client_list.CheckAuth(id,password,ip))) || (cle = client_list.CheckAuth(id, password)))
|
||||
#endif
|
||||
@ -459,8 +420,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
clog(WORLD__CLIENT_ERR,"If so you forget the minilogin variable...");
|
||||
else
|
||||
clog(WORLD__CLIENT_ERR,"Could not find a minilogin account, verify ip address logging into minilogin is the same that is in your account table.");
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
cle->SetOnline();
|
||||
@ -474,6 +434,9 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
else {
|
||||
clog(WORLD__CLIENT,"LS Account #%d",cle->LSID());
|
||||
}
|
||||
|
||||
const WorldConfig *Config=WorldConfig::get();
|
||||
|
||||
if(Config->UpdateStats){
|
||||
ServerPacket* pack = new ServerPacket;
|
||||
pack->opcode = ServerOP_LSPlayerJoinWorld;
|
||||
@ -503,22 +466,23 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
else {
|
||||
// TODO: Find out how to tell the client wrong username/password
|
||||
clog(WORLD__CLIENT_ERR,"Bad/Expired session key '%s'",name);
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cle)
|
||||
break;
|
||||
return true;
|
||||
|
||||
cle->SetIP(GetIP());
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
case OP_ApproveName: //Name approval
|
||||
{
|
||||
|
||||
bool Client::HandleNameApprovalPacket(const EQApplicationPacket *app) {
|
||||
|
||||
if (GetAccountID() == 0) {
|
||||
clog(WORLD__CLIENT_ERR,"Name approval request with no logged in account");
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
snprintf(char_name, 64, "%s", (char*)app->pBuffer);
|
||||
uchar race = app->pBuffer[64];
|
||||
uchar clas = app->pBuffer[68];
|
||||
@ -530,6 +494,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
outapp->SetOpcode(OP_ApproveName);
|
||||
outapp->pBuffer = new uchar[1];
|
||||
outapp->size = 1;
|
||||
|
||||
bool valid;
|
||||
if(!database.CheckNameFilter(char_name)) {
|
||||
valid = false;
|
||||
@ -552,10 +517,10 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
memset(char_name, 0, sizeof(char_name));
|
||||
}
|
||||
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
case OP_RandomNameGenerator:
|
||||
{
|
||||
|
||||
bool Client::HandleGenerateRandomNamePacket(const EQApplicationPacket *app) {
|
||||
// creates up to a 10 char name
|
||||
char vowels[18]="aeiouyaeiouaeioe";
|
||||
char cons[48]="bcdfghjklmnpqrstvwxzybcdgklmnprstvwbcdgkpstrkd";
|
||||
@ -630,16 +595,11 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
memset(ngs->name,0,64);
|
||||
strcpy(ngs->name,rndname);
|
||||
|
||||
// char names[8][64] = { "How", "About", "You", "Think", "Of", "Your", "Own", "Name" };
|
||||
// //Could have parts of the random name in this struct and they compile together
|
||||
// NameGeneration_Struct* ngs = (NameGeneration_Struct*)app->pBuffer;
|
||||
// strncpy(ngs->name,"Notcreated",64);
|
||||
|
||||
QueuePacket(app);
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
case OP_CharacterCreateRequest: {
|
||||
|
||||
bool Client::HandleCharacterCreateRequestPacket(const EQApplicationPacket *app) {
|
||||
// New OpCode in SoF
|
||||
uint32 allocs = character_create_allocations.size();
|
||||
uint32 combos = character_create_race_class_combos.size();
|
||||
@ -683,22 +643,22 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
|
||||
QueuePacket(outapp);
|
||||
safe_delete(outapp);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
case OP_CharacterCreate: //Char create
|
||||
{
|
||||
bool Client::HandleCharacterCreatePacket(const EQApplicationPacket *app) {
|
||||
if (GetAccountID() == 0)
|
||||
{
|
||||
clog(WORLD__CLIENT_ERR,"Account ID not set; unable to create character.");
|
||||
ret = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
else if (app->size != sizeof(CharCreate_Struct))
|
||||
{
|
||||
clog(WORLD__CLIENT_ERR,"Wrong size on OP_CharacterCreate. Got: %d, Expected: %d",app->size,sizeof(CharCreate_Struct));
|
||||
DumpPacket(app);
|
||||
break;
|
||||
// the previous behavior was essentially returning true here
|
||||
// but that seems a bit odd to me.
|
||||
return true;
|
||||
}
|
||||
|
||||
CharCreate_Struct *cc = (CharCreate_Struct*)app->pBuffer;
|
||||
@ -712,20 +672,23 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
}
|
||||
else
|
||||
SendCharInfo();
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
case OP_EnterWorld: // Enter world
|
||||
{
|
||||
|
||||
bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) {
|
||||
|
||||
if (GetAccountID() == 0) {
|
||||
clog(WORLD__CLIENT_ERR,"Enter world with no logged in account");
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(GetAdmin() < 0)
|
||||
{
|
||||
clog(WORLD__CLIENT,"Account banned or suspended.");
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RuleI(World, MaxClientsPerIP) >= 0) {
|
||||
@ -741,14 +704,14 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
if (charid == 0 || tmpaccid != GetAccountID()) {
|
||||
clog(WORLD__CLIENT_ERR,"Could not get CharInfo for '%s'",char_name);
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure this account owns this character
|
||||
if (tmpaccid != GetAccountID()) {
|
||||
clog(WORLD__CLIENT_ERR,"This account does not own the character named '%s'",char_name);
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!pZoning && ew->return_home)
|
||||
@ -765,7 +728,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
if(cs->gohome[x] == 1)
|
||||
{
|
||||
home_enabled = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -780,7 +743,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
clog(WORLD__CLIENT_ERR,"'%s' is trying to go home before they're able...",char_name);
|
||||
database.SetHackerFlag(GetAccountName(), char_name, "MQGoHome: player tried to go home before they were able.");
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -797,7 +760,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
if(cs->tutorial[x] == 1)
|
||||
{
|
||||
tutorial_enabled = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -813,7 +776,7 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
clog(WORLD__CLIENT_ERR,"'%s' is trying to go to tutorial but are not allowed...",char_name);
|
||||
database.SetHackerFlag(GetAccountName(), char_name, "MQTutorial: player tried to enter the tutorial without having tutorial enabled for this character.");
|
||||
eqs->Close();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -893,6 +856,9 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
|
||||
EQApplicationPacket *outapp2 = new EQApplicationPacket(OP_SetChatServer);
|
||||
char buffer[112];
|
||||
|
||||
const WorldConfig *Config = WorldConfig::get();
|
||||
|
||||
sprintf(buffer,"%s,%i,%s.%s,%c%08X",
|
||||
Config->ChatHost.c_str(),
|
||||
Config->ChatPort,
|
||||
@ -923,12 +889,12 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
safe_delete(outapp2);
|
||||
|
||||
EnterWorld();
|
||||
break;
|
||||
|
||||
return true;
|
||||
}
|
||||
case OP_LoginComplete:{
|
||||
break;
|
||||
}
|
||||
case OP_DeleteCharacter: {
|
||||
|
||||
bool Client::HandleDeleteCharacterPacket(const EQApplicationPacket *app) {
|
||||
|
||||
uint32 char_acct_id = database.GetAccountIDByChar((char*)app->pBuffer);
|
||||
if(char_acct_id == GetAccountID())
|
||||
{
|
||||
@ -936,51 +902,119 @@ bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
database.DeleteCharacter((char *)app->pBuffer);
|
||||
SendCharInfo();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OP_ApproveWorld:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case OP_WorldClientReady:{
|
||||
break;
|
||||
}
|
||||
case OP_World_Client_CRC1:
|
||||
case OP_World_Client_CRC2: {
|
||||
// There is no obvious entry in the CC struct to indicate that the 'Start Tutorial button
|
||||
// is selected when a character is created. I have observed that in this case, OP_EnterWorld is sent
|
||||
// before OP_World_Client_CRC1. Therefore, if we receive OP_World_Client_CRC1 before OP_EnterWorld,
|
||||
// then 'Start Tutorial' was not chosen.
|
||||
StartInTutorial = false;
|
||||
break;
|
||||
}
|
||||
case OP_WearChange: { // User has selected a different character
|
||||
break;
|
||||
}
|
||||
case OP_WorldComplete: {
|
||||
eqs->Close();
|
||||
break;
|
||||
}
|
||||
case OP_LoginUnknown1:
|
||||
case OP_LoginUnknown2:
|
||||
break;
|
||||
|
||||
case OP_ZoneChange:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandleZoneChangePacket(const EQApplicationPacket *app) {
|
||||
// HoT sends this to world while zoning and wants it echoed back.
|
||||
if(ClientVersionBit & BIT_RoFAndLater)
|
||||
{
|
||||
QueuePacket(app);
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::HandlePacket(const EQApplicationPacket *app) {
|
||||
|
||||
default: {
|
||||
EmuOpcode opcode = app->GetOpcode();
|
||||
|
||||
clog(WORLD__CLIENT_TRACE,"Recevied EQApplicationPacket");
|
||||
_pkt(WORLD__CLIENT_TRACE,app);
|
||||
|
||||
if (!eqs->CheckState(ESTABLISHED)) {
|
||||
clog(WORLD__CLIENT,"Client disconnected (net inactive on send)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Voidd: Anti-GM Account hack, Checks source ip against valid GM Account IP Addresses
|
||||
if (RuleB(World, GMAccountIPList) && this->GetAdmin() >= (RuleI(World, MinGMAntiHackStatus))) {
|
||||
if(!database.CheckGMIPs(long2ip(this->GetIP()).c_str(), this->GetAccountID())) {
|
||||
clog(WORLD__CLIENT,"GM Account not permited from source address %s and accountid %i", long2ip(this->GetIP()).c_str(), this->GetAccountID());
|
||||
eqs->Close();
|
||||
}
|
||||
}
|
||||
|
||||
if (GetAccountID() == 0 && opcode != OP_SendLoginInfo) {
|
||||
// Got a packet other than OP_SendLoginInfo when not logged in
|
||||
clog(WORLD__CLIENT_ERR,"Expecting OP_SendLoginInfo, got %s", OpcodeNames[opcode]);
|
||||
return false;
|
||||
}
|
||||
else if (opcode == OP_AckPacket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(opcode)
|
||||
{
|
||||
case OP_World_Client_CRC1:
|
||||
case OP_World_Client_CRC2:
|
||||
{
|
||||
// There is no obvious entry in the CC struct to indicate that the 'Start Tutorial button
|
||||
// is selected when a character is created. I have observed that in this case, OP_EnterWorld is sent
|
||||
// before OP_World_Client_CRC1. Therefore, if we receive OP_World_Client_CRC1 before OP_EnterWorld,
|
||||
// then 'Start Tutorial' was not chosen.
|
||||
StartInTutorial = false;
|
||||
return true;
|
||||
}
|
||||
case OP_SendLoginInfo:
|
||||
{
|
||||
return HandleSendLoginInfoPacket(app);
|
||||
}
|
||||
case OP_ApproveName: //Name approval
|
||||
{
|
||||
return HandleNameApprovalPacket(app);
|
||||
}
|
||||
case OP_RandomNameGenerator:
|
||||
{
|
||||
return HandleGenerateRandomNamePacket(app);
|
||||
}
|
||||
case OP_CharacterCreateRequest:
|
||||
{
|
||||
// New OpCode in SoF
|
||||
return HandleCharacterCreateRequestPacket(app);
|
||||
}
|
||||
case OP_CharacterCreate: //Char create
|
||||
{
|
||||
return HandleCharacterCreatePacket(app);
|
||||
}
|
||||
case OP_EnterWorld: // Enter world
|
||||
{
|
||||
return HandleEnterWorldPacket(app);
|
||||
}
|
||||
case OP_DeleteCharacter:
|
||||
{
|
||||
return HandleDeleteCharacterPacket(app);
|
||||
}
|
||||
case OP_WorldComplete:
|
||||
{
|
||||
eqs->Close();
|
||||
return true;
|
||||
}
|
||||
case OP_ZoneChange:
|
||||
{
|
||||
// HoT sends this to world while zoning and wants it echoed back.
|
||||
return HandleZoneChangePacket(app);
|
||||
}
|
||||
case OP_LoginUnknown1:
|
||||
case OP_LoginUnknown2:
|
||||
case OP_CrashDump:
|
||||
case OP_WearChange:
|
||||
case OP_LoginComplete:
|
||||
case OP_ApproveWorld:
|
||||
case OP_WorldClientReady:
|
||||
{
|
||||
// Essentially we are just 'eating' these packets, indicating
|
||||
// they are handled.
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
clog(WORLD__CLIENT_ERR,"Received unknown EQApplicationPacket");
|
||||
_pkt(WORLD__CLIENT_ERR,app);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::Process() {
|
||||
|
||||
@ -97,7 +97,17 @@ private:
|
||||
bool firstlogin;
|
||||
bool seencharsel;
|
||||
bool realfirstlogin;
|
||||
|
||||
bool HandlePacket(const EQApplicationPacket *app);
|
||||
bool HandleNameApprovalPacket(const EQApplicationPacket *app);
|
||||
bool HandleSendLoginInfoPacket(const EQApplicationPacket *app);
|
||||
bool HandleGenerateRandomNamePacket(const EQApplicationPacket *app);
|
||||
bool HandleCharacterCreateRequestPacket(const EQApplicationPacket *app);
|
||||
bool HandleCharacterCreatePacket(const EQApplicationPacket *app);
|
||||
bool HandleEnterWorldPacket(const EQApplicationPacket *app);
|
||||
bool HandleDeleteCharacterPacket(const EQApplicationPacket *app);
|
||||
bool HandleZoneChangePacket(const EQApplicationPacket *app);
|
||||
|
||||
EQStreamInterface* const eqs;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user