123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- */
- #include "../common/debug.h"
- #ifdef WIN32
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <winsock.h>
- #include <process.h>
- #else
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #endif
- #include <string.h>
- #include <iomanip>
- #include <stdlib.h>
- #include <assert.h>
- #include "net.h"
- #include "client.h"
- #include "../common/EQStream.h"
- #include "../common/packet_dump.h"
- #include "../common/packet_functions.h"
- #include "../common/emu_opcodes.h"
- #include "../common/MiscFunctions.h"
- #include "LWorld.h"
- #include "LoginDatabase.h"
- #include "../common/ConfigReader.h"
- #include "../common/Log.h"
- extern NetConnection net;
- extern LWorldList world_list;
- extern ClientList client_list;
- extern LoginDatabase database;
- extern map<int16,OpcodeManager*>EQOpcodeManager;
- extern ConfigReader configReader;
- using namespace std;
- Client::Client(EQStream* ieqnc) {
- eqnc = ieqnc;
- ip = eqnc->GetrIP();
- port = ntohs(eqnc->GetrPort());
- account_id = 0;
- lsadmin = 0;
- worldadmin = 0;
- lsstatus = 0;
- version = 0;
- kicked = false;
- verified = false;
- memset(bannedreason, 0, sizeof(bannedreason));
- //worldresponse_timer = new Timer(10000);
- //worldresponse_timer->Disable();
- memset(key,0,10);
- LoginMode = None;
- num_updates = 0;
- updatetimer = new Timer(500);
- updatelisttimer = new Timer(10000);
- //keepalive = new Timer(5000);
- //logintimer = new Timer(500); // Give time for the servers to send updates
- //keepalive->Start();
- //updatetimer->Start();
- //logintimer->Disable();
- disconnectTimer = 0;
- memset(ClientSession,0,25);
- request_num = 0;
- login_account = 0;
- createRequest = 0;
- playWaitTimer = NULL;
- start = false;
- update_position = 0;
- update_packets = 0;
- needs_world_list = true;
- }
- Client::~Client() {
- //safe_delete(worldresponse_timer);
- //safe_delete(logintimer);
- safe_delete(login_account);
- eqnc->Close();
- safe_delete(playWaitTimer);
- safe_delete(createRequest);
- safe_delete(disconnectTimer);
- safe_delete(updatetimer);
- }
- bool Client::Process() {
- if(!start && !eqnc->CheckActive()){
- if(!playWaitTimer)
- playWaitTimer = new Timer(5000);
- else if(playWaitTimer->Check()){
- safe_delete(playWaitTimer);
- return false;
- }
- return true;
- }
- else if(!start){
- safe_delete(playWaitTimer);
- start = true;
- }
-
- if (disconnectTimer && disconnectTimer->Check())
- {
- safe_delete(disconnectTimer);
- getConnection()->SendDisconnect();
- }
-
- if (!kicked) {
- /************ Get all packets from packet manager out queue and process them ************/
- EQApplicationPacket *app = 0;
- /*if(logintimer && logintimer->Check())
- {
- database.LoadCharacters(GetLoginAccount());
- SendLoginAccepted();
- logintimer->Disable();
- }*/
- /*if(worldresponse_timer && worldresponse_timer->Check())
- {
- FatalError(WorldDownErrorMessage);
- worldresponse_timer->Disable();
- }*/
-
- if(playWaitTimer != NULL && playWaitTimer->Check ( ) )
- {
- SendPlayFailed(PLAY_ERROR_SERVER_TIMEOUT);
- safe_delete(playWaitTimer);
- }
- if(!needs_world_list && updatetimer && updatetimer->Check()){
- if(updatelisttimer && updatelisttimer->Check()){
- if(num_updates >= 180){ //30 minutes
- getConnection()->SendDisconnect();
- }
- else{
- vector<PacketStruct*>::iterator itr;
- if(update_packets){
- for(itr = update_packets->begin(); itr != update_packets->end(); itr++){
- safe_delete(*itr);
- }
- }
- safe_delete(update_packets);
- update_packets = world_list.GetServerListUpdate(version);
- }
- num_updates++;
- }
- else{
- if(!update_packets){
- update_packets = world_list.GetServerListUpdate(version);
- }
- else{
- if(update_position < update_packets->size()){
- QueuePacket(update_packets->at(update_position)->serialize());
- update_position++;
- }
- else
- update_position = 0;
- }
- }
- }
- while(app = eqnc->PopPacket())
- {
- switch(app->GetOpcode())
- {
- case OP_LoginRequestMsg:{
- DumpPacket(app);
- PacketStruct* packet = configReader.getStruct("LS_LoginRequest", 1);
- if(packet && packet->LoadPacketData(app->pBuffer,app->size)){
- version = packet->getType_int16_ByName("version");
- LogWrite(LOGIN__DEBUG, 0, "Login", "Classic Client Version Provided: %i", version);
- if (version == 0 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0)
- {
- safe_delete(packet);
- packet = configReader.getStruct("LS_LoginRequest", 1208);
- if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
- version = packet->getType_int16_ByName("version");
- }
- else
- break;
- }
- //[7:19 PM] Kirmmin: Well, I very quickly learned that unknown3 in LS_LoginRequest packet is the same value as cl_eqversion in the eq2_defaults.ini file.
- LogWrite(LOGIN__DEBUG, 0, "Login", "New Client Version Provided: %i", version);
- if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
- LogWrite(LOGIN__ERROR, 0, "Login", "Incompatible client version provided: %i", version);
- SendLoginDenied();
- return false;
- }
-
- if(EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()){
- getConnection()->SetClientVersion(GetVersion());
- EQ2_16BitString username = packet->getType_EQ2_16BitString_ByName("username");
- EQ2_16BitString password = packet->getType_EQ2_16BitString_ByName("password");
- LoginAccount* acct = database.LoadAccount(username.data.c_str(),password.data.c_str(), net.IsAllowingAccountCreation());
- if(acct){
- Client* otherclient = client_list.FindByLSID(acct->getLoginAccountID());
- if(otherclient)
- otherclient->getConnection()->SendDisconnect(); // This person is already logged in, we don't want them logged in twice, kick the previous client as it might be a ghost
- }
- if(acct){
- SetAccountName(username.data.c_str());
- database.UpdateAccountIPAddress(acct->getLoginAccountID(), getConnection()->GetrIP());
- LogWrite(LOGIN__INFO, 0, "Login", "%s successfully logged in.", (char*)username.data.c_str());
- }
- else
- {
- if (username.size > 0)
- LogWrite(LOGIN__ERROR, 0, "Login", "%s login failed!", (char*)username.data.c_str());
- else
- LogWrite(LOGIN__ERROR, 0, "Login", "[UNKNOWN USER] login failed!");
- }
- if(!acct)
- SendLoginDenied();
- else{
- needs_world_list = true;
- SetLoginAccount(acct);
- SendLoginAccepted();
- }
- }
- else{
- cout << "Error bad version: " << version << endl;
- SendLoginDeniedBadVersion();
- }
- }
- else{
- cout << "Error loading LS_LoginRequest packet: \n";
- //DumpPacket(app);
- }
- safe_delete(packet);
- break;
- }
- case OP_KeymapLoadMsg:{
- // cout << "Received OP_KeymapNoneMsg\n";
- //dunno what this is for
- break;
- }
- case OP_AllWSDescRequestMsg:{
- SendWorldList();
- needs_world_list = false;
- database.LoadCharacters(GetLoginAccount(), GetVersion());
- SendCharList();
- break;
- }
- case OP_LsClientCrashlogReplyMsg:{
- // DumpPacket(app);
- SaveErrorsToDB(app, "Crash Log", GetVersion());
- break;
- }
- case OP_LsClientVerifylogReplyMsg:{
- // DumpPacket(app);
- SaveErrorsToDB(app, "Verify Log", GetVersion());
- break;
- }
- case OP_LsClientAlertlogReplyMsg:{
- // DumpPacket(app);
- SaveErrorsToDB(app, "Alert Log", GetVersion());
- break;
- }
- case OP_LsClientBaselogReplyMsg:{
- // DumpPacket(app);
- SaveErrorsToDB(app, "Base Log", GetVersion());
- break;
- }
- case OP_AllCharactersDescRequestMsg:{
- break;
- }
- case OP_CreateCharacterRequestMsg:{
- PacketStruct* packet = configReader.getStruct("CreateCharacter", GetVersion());
- DumpPacket(app);
- playWaitTimer = new Timer ( 15000 );
- playWaitTimer->Start ( );
- cout << "Char Create Request From: " << GetAccountName() << "....";
- if(packet->LoadPacketData(app->pBuffer,app->size)){
- cout << "Loaded Successfully\n";
- packet->setDataByName("account_id",GetAccountID());
- LWorld* world_server = world_list.FindByID(packet->getType_int32_ByName("server_id"));
- if(!world_server)
- {
- DumpPacket(app->pBuffer, app->size);
- cout << GetAccountName() << " attempted creation of character with an invalid server id of: " << packet->getType_int32_ByName("server_id") << "\n";
- break;
- }
- else
- {
- ServerPacket* outpack = new ServerPacket(ServerOP_CharacterCreate, app->size+sizeof(int16));
- int16 out_version = GetVersion();
- memcpy(outpack->pBuffer, &out_version, sizeof(int16));
- memcpy(outpack->pBuffer + sizeof(int16), app->pBuffer, app->size);
- uchar* tmp = outpack->pBuffer;
-
- if(out_version<=283)
- tmp+=2;
- else
- tmp += 7;
-
- int32 account_id = GetAccountID();
- memcpy(tmp, &account_id, sizeof(int32));
- world_server->SendPacket(outpack);
- safe_delete(outpack);
- createRequest = packet;
- }
- }
- else{
- cout << "Error loading Char Create Packet!!\n";
- safe_delete(packet);
- }
- // world_list.SendWorldChanged(create.profile.server_id, false, this);
- break;
- }
- case OP_PlayCharacterRequestMsg:{
- int32 char_id = 0;
- int32 server_id = 0;
- PacketStruct* request = configReader.getStruct("LS_PlayRequest",GetVersion());
- if(request && request->LoadPacketData(app->pBuffer,app->size)){
- char_id = request->getType_int32_ByName("char_id");
- if (GetVersion() <= 283) {
- server_id = database.GetServer(GetAccountID(), char_id, request->getType_EQ2_16BitString_ByName("name").data);
- }
- else {
- server_id = request->getType_int32_ByName("server_id");
- }
- LWorld* world = world_list.FindByID(server_id);
- string name = database.GetCharacterName(char_id,server_id);
- if(world && name.length() > 0){
- pending_play_char_id = char_id;
- ServerPacket* outpack = new ServerPacket(ServerOP_UsertoWorldReq, sizeof(UsertoWorldRequest_Struct));
- UsertoWorldRequest_Struct* req = (UsertoWorldRequest_Struct*)outpack->pBuffer;
- req->char_id = char_id;
- req->lsaccountid = GetAccountID();
- req->worldid = server_id;
- struct in_addr in;
- in.s_addr = GetIP();
- strcpy(req->ip_address, inet_ntoa(in));
- world->SendPacket(outpack);
- delete outpack;
- safe_delete(playWaitTimer);
- playWaitTimer = new Timer ( 5000 );
- playWaitTimer->Start ( );
- }
- else{
- cout << GetAccountName() << " sent invalid Play Request: \n";
- SendPlayFailed(PLAY_ERROR_PROBLEM);
- DumpPacket(app);
- }
- }
- safe_delete(request);
- break;
- }
- case OP_DeleteCharacterRequestMsg:{
- PacketStruct* request = configReader.getStruct("LS_DeleteCharacterRequest", GetVersion());
- PacketStruct* response = configReader.getStruct("LS_DeleteCharacterResponse", GetVersion());
- if(request && response && request->LoadPacketData(app->pBuffer,app->size)){
- EQ2_16BitString name = request->getType_EQ2_16BitString_ByName("name");
- int32 acct_id = GetAccountID();
- int32 char_id = request->getType_int32_ByName("char_id");
- int32 server_id = request->getType_int32_ByName("server_id");
- if(database.VerifyDelete(acct_id, char_id, name.data.c_str())){
- response->setDataByName("response", 1);
- GetLoginAccount()->removeCharacter((char*)name.data.c_str());
- LWorld* world_server = world_list.FindByID(server_id);
- if(world_server != NULL)
- world_server->SendDeleteCharacter ( char_id , acct_id );
- }
- else
- response->setDataByName("response", 0);
- response->setDataByName("server_id", server_id);
- response->setDataByName("char_id", char_id);
- response->setDataByName("account_id", account_id);
- response->setMediumStringByName("name", (char*)name.data.c_str());
- response->setDataByName("max_characters", 10);
- EQ2Packet* outapp = response->serialize();
- QueuePacket(outapp);
- this->SendCharList();
- }
- safe_delete(request);
- safe_delete(response);
- break;
- }
- default: {
- const char* name = app->GetOpcodeName();
- if (name)
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
- else
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
- }
- }
- delete app;
- }
- }
- if (!eqnc->CheckActive()) {
- return false;
- }
- return true;
- }
- void Client::SaveErrorsToDB(EQApplicationPacket* app, char* type, int32 version){
- int32 size = 0;
- z_stream zstream;
- if (version >= 284) {
- memcpy(&size, app->pBuffer + sizeof(int32), sizeof(int32));
- zstream.next_in = app->pBuffer + 8;
- zstream.avail_in = app->size - 8;
- }
- else { //box set
- size = 0xFFFF;
- zstream.next_in = app->pBuffer + 2;
- zstream.avail_in = app->size - 2;
- }
- size++;
- char* message = new char[size];
- memset(message, 0, size);
-
- int zerror = 0;
-
- zstream.next_out = (BYTE*)message;
- zstream.avail_out = size;
- zstream.zalloc = Z_NULL;
- zstream.zfree = Z_NULL;
- zstream.opaque = Z_NULL;
- zerror = inflateInit( &zstream);
- if(zerror != Z_OK) {
- safe_delete_array(message);
- return;
- }
- zerror = inflate( &zstream, 0 );
- if(message && strlen(message) > 0)
- database.SaveClientLog(type, message, GetLoginAccount()->getLoginName(), GetVersion());
- safe_delete_array(message);
- }
- void Client::CharacterApproved(int32 server_id,int32 char_id)
- {
- if(createRequest && server_id == createRequest->getType_int32_ByName("server_id")){
- LWorld* world_server = world_list.FindByID(server_id);
- if(!world_server)
- return;
- PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply", GetVersion());
- if(packet){
- packet->setDataByName("account_id", GetAccountID());
- packet->setDataByName("unknown", 0xFFFFFFFF);
- packet->setDataByName("response", CREATESUCCESS_REPLY);
- packet->setMediumStringByName("name", (char*)createRequest->getType_EQ2_16BitString_ByName("name").data.c_str());
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);
- database.SaveCharacter(createRequest, GetLoginAccount(),char_id, GetVersion());
- // refresh characters for this account
- database.LoadCharacters(GetLoginAccount(), GetVersion());
-
- SendCharList();
- if (GetVersion() <= 546)
- {
- pending_play_char_id = char_id;
- ServerPacket* outpack = new ServerPacket(ServerOP_UsertoWorldReq, sizeof(UsertoWorldRequest_Struct));
- UsertoWorldRequest_Struct* req = (UsertoWorldRequest_Struct*)outpack->pBuffer;
- req->char_id = char_id;
- req->lsaccountid = GetAccountID();
- req->worldid = server_id;
- struct in_addr in;
- in.s_addr = GetIP();
- strcpy(req->ip_address, inet_ntoa(in));
- world_server->SendPacket(outpack);
- delete outpack;
- }
- }
- }
- else{
- cout << GetAccountName() << " received invalid CharacterApproval from server: " << server_id << endl;
- }
- safe_delete(createRequest);
- }
- void Client::CharacterRejected(int8 reason_number)
- {
- PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply", GetVersion());
- if(createRequest && packet){
- packet->setDataByName("account_id", GetAccountID());
- int8 clientReasonNum = reason_number;
- // reason numbers change and instead of updating the world server
- // the login server will hold the up to date #'s
- /*
- switch(reason_number)
- {
- // these error codes seem to be removed now, they shutdown the client rather immediately
- // for now we are just going to play a joke on them and say they can't create a new character.
- case INVALIDRACE_REPLY:
- case INVALIDGENDER_REPLY:
- clientReasonNum = 8;
- break;
- case BADNAMELENGTH_REPLY:
- clientReasonNum = 9;
- break;
- case NAMEINVALID_REPLY:
- clientReasonNum = 10;
- break;
- case NAMEFILTER_REPLY:
- clientReasonNum = 11;
- break;
- case NAMETAKEN_REPLY:
- clientReasonNum = 12;
- break;
- case OVERLOADEDSERVER_REPLY:
- clientReasonNum = 13;
- break;
- }
- */
- packet->setDataByName("response", clientReasonNum);
- packet->setMediumStringByName("name", "");
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);
- }
- /*LS_CreateCharacterReply reply(GetAccountID(), reason_number, create.profile.name.data);
- EQ2Packet* outapp = reply.serialize();
- QueuePacket(outapp);
- create.Clear();*/
- }
- void Client::SendCharList(){
- /*PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply");
- packet->setDataByName("account_id", GetAccountID());
- packet->setDataByName("response", reason_number);
- packet->setDataByName("name", &create.profile.name);
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);*/
- LogWrite(LOGIN__INFO, 0, "Login", "[%s] sending character list.", GetAccountName());
- LS_CharSelectList list;
- list.loadData(GetAccountID(), GetLoginAccount()->charlist, GetVersion());
- EQ2Packet* outapp = list.serialize(GetVersion());
- DumpPacket(outapp->pBuffer, outapp->size);
- QueuePacket(outapp);
- }
- void Client::SendLoginDeniedBadVersion(){
- EQ2Packet* app = new EQ2Packet(OP_LoginReplyMsg, 0, sizeof(LS_LoginResponse));
- LS_LoginResponse* ls_response = (LS_LoginResponse*)app->pBuffer;
- ls_response->reply_code = 6;
- ls_response->unknown03 = 0xFFFFFFFF;
- ls_response->unknown04 = 0xFFFFFFFF;
- QueuePacket(app);
- StartDisconnectTimer();
- }
- void Client::SendLoginDenied(){
- EQ2Packet* app = new EQ2Packet(OP_LoginReplyMsg, 0, sizeof(LS_LoginResponse));
- LS_LoginResponse* ls_response = (LS_LoginResponse*)app->pBuffer;
- ls_response->reply_code = 1;
- ls_response->unknown03 = 0xFFFFFFFF;
- ls_response->unknown04 = 0xFFFFFFFF;
- QueuePacket(app);
- StartDisconnectTimer();
- }
- void Client::SendLoginAccepted() {
- PacketStruct* packet = configReader.getStruct("LS_LoginReplyMsg", GetVersion());
- int i = 0;
- if (packet)
- {
- packet->setDataByName("account_id", 1);
- //packet->setDataByName("login_response", 0);
- //packet->setDataByName("reset_appearance", 0);
- packet->setDataByName("do_not_force_soga", 1);
- //packet->setDataByName("race_unknown", 0x3F);
- //packet->setDataByName("unknown11", 2); // can be 7
- packet->setDataByName("sub_level", 2);
- packet->setDataByName("race_flag", 0x1FFFFF);
- packet->setDataByName("class_flag", 0x7FFFFFE);
- packet->setMediumStringByName("username", GetAccountName());
- packet->setMediumStringByName("password", GetAccountName());
- packet->setDataByName("unknown5", 0x7C);
- packet->setDataByName("unknown7", 0xFF6FFFBF);
- // Image 2020 Notes
- // Login Server only supports AoM at current time, but we will need to keep in mind the structure for 60100 or later calls for additional custom fields
- // >=60100
- packet->setDataByName("unknown11", 0x0E);
- packet->setDataByName("unknown7a", 0xFFFF);
- packet->setDataByName("unknown8", 0xFF, 1);
- EQ2Packet* outapp = packet->serialize();
- printf("Out struct:\n");
- DumpPacket(outapp->pBuffer, outapp->size);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- void Client::SendWorldList(){
- EQ2Packet* pack = world_list.MakeServerListPacket(lsadmin, version);
- EQ2Packet* dupe = pack->Copy();
- DumpPacket(dupe->pBuffer,dupe->size);
- QueuePacket(dupe);
- return;
- }
- void Client::QueuePacket(EQ2Packet* app){
- eqnc->EQ2QueuePacket(app);
- }
- void Client::WorldResponse(int32 worldid, int8 response, char* ip_address, int32 port, int32 access_key)
- {
- LWorld* world = world_list.FindByID(worldid);
- if(world == 0) {
- FatalError(0);
- return;
- }
- if(response != 1){
- if(response == PLAY_ERROR_CHAR_NOT_LOADED){
- string pending_play_char_name = database.GetCharacterName(pending_play_char_id, worldid);
- if(database.VerifyDelete(GetAccountID(), pending_play_char_id, pending_play_char_name.c_str())){
- GetLoginAccount()->removeCharacter((char*)pending_play_char_name.c_str());
- }
- }
- FatalError(response);
- return;
- }
- PacketStruct* response_packet = configReader.getStruct("LS_PlayResponse", GetVersion());
- if(response_packet){
- safe_delete(playWaitTimer);
- response_packet->setDataByName("response", 1);
- response_packet->setSmallStringByName("server", ip_address);
- response_packet->setDataByName("port", port);
- response_packet->setDataByName("account_id", GetAccountID());
- response_packet->setDataByName("access_code", access_key);
- EQ2Packet* outapp = response_packet->serialize();
- QueuePacket(outapp);
- safe_delete(response_packet);
- }
- return;
- }
- void Client::FatalError(int8 response) {
- safe_delete(playWaitTimer);
- SendPlayFailed(response);
- }
- void Client::SendPlayFailed(int8 response){
- PacketStruct* response_packet = configReader.getStruct("LS_PlayResponse", GetVersion());
- if(response_packet){
- response_packet->setDataByName("response", response);
- response_packet->setSmallStringByName("server", "");
- response_packet->setDataByName("port", 0);
- response_packet->setDataByName("account_id", GetAccountID());
- response_packet->setDataByName("access_code", 0);
- EQ2Packet* outapp = response_packet->serialize();
- QueuePacket(outapp);
- safe_delete(response_packet);
- }
- }
- void ClientList::Add(Client* client) {
- MClientList.writelock();
- client_list[client] = true;
- MClientList.releasewritelock();
- }
- Client* ClientList::Get(int32 ip, int16 port) {
- Client* ret = 0;
- map<Client*, bool>::iterator itr;
- MClientList.readlock();
- for(itr = client_list.begin(); itr != client_list.end(); itr++){
- if(itr->first->GetIP() == ip && itr->first->GetPort() == port){
- ret = itr->first;
- break;
- }
- }
- MClientList.releasereadlock();
- return ret;
- }
- void ClientList::FindByCreateRequest(){
- Client* client = 0;
- map<Client*, bool>::iterator itr;
- MClientList.readlock();
- for(itr = client_list.begin(); itr != client_list.end(); itr++){
- if(itr->first->AwaitingCharCreationRequest()){
- if(!client)
- client = itr->first;
- else{
- client = 0;//more than 1 character waiting, dont want to send rejection to wrong one
- break;
- }
- }
- }
- MClientList.releasereadlock();
- if(client)
- client->CharacterRejected(UNKNOWNERROR_REPLY);
- }
- Client* ClientList::FindByLSID(int32 lsaccountid) {
- Client* client = 0;
- map<Client*, bool>::iterator itr;
- MClientList.readlock();
- for(itr = client_list.begin(); itr != client_list.end(); itr++){
- if(itr->first->GetAccountID() == lsaccountid){
- client = itr->first;
- break;
- }
- }
- MClientList.releasereadlock();
- return client;
- }
- void ClientList::SendPacketToAllClients(EQ2Packet* app){
- Client* client = 0;
- map<Client*, bool>::iterator itr;
- MClientList.readlock();
- if(client_list.size() > 0){
- for(itr = client_list.begin(); itr != client_list.end(); itr++){
- itr->first->QueuePacket(app->Copy());
- }
- }
- safe_delete(app);
- MClientList.releasereadlock();
- }
- void ClientList::Process() {
- Client* client = 0;
- vector<Client*> erase_list;
- map<Client*, bool>::iterator itr;
- MClientList.readlock();
- for(itr = client_list.begin(); itr != client_list.end(); itr++){
- client = itr->first;
- if(!client->Process())
- erase_list.push_back(client);
- }
- MClientList.releasereadlock();
- if(erase_list.size() > 0){
- vector<Client*>::iterator erase_itr;
- MClientList.writelock();
- for(erase_itr = erase_list.begin(); erase_itr != erase_list.end(); erase_itr++){
- client = *erase_itr;
- struct in_addr in;
- in.s_addr = client->getConnection()->GetRemoteIP();
- net.numclients--;
- LogWrite(LOGIN__INFO, 0, "Login", "Removing client from ip: %s on port %i, Account Name: %s", inet_ntoa(in), ntohs(client->getConnection()->GetRemotePort()), client->GetAccountName());
- client->getConnection()->Close();
- net.UpdateWindowTitle();
- client_list.erase(client);
- }
- MClientList.releasewritelock();
- }
- }
- void Client::StartDisconnectTimer() {
- if (!disconnectTimer)
- {
- disconnectTimer = new Timer(1000);
- disconnectTimer->Start();
- }
- }
|