client.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. */
  6. #include "../common/debug.h"
  7. #ifdef WIN32
  8. #define WIN32_LEAN_AND_MEAN
  9. #include <windows.h>
  10. #include <winsock.h>
  11. #include <process.h>
  12. #else
  13. #include <sys/socket.h>
  14. #include <netinet/in.h>
  15. #include <arpa/inet.h>
  16. #include <unistd.h>
  17. #endif
  18. #include <string.h>
  19. #include <iomanip>
  20. #include <stdlib.h>
  21. #include <assert.h>
  22. #include "net.h"
  23. #include "client.h"
  24. #include "../common/EQStream.h"
  25. #include "../common/packet_dump.h"
  26. #include "../common/packet_functions.h"
  27. #include "../common/emu_opcodes.h"
  28. #include "../common/MiscFunctions.h"
  29. #include "LWorld.h"
  30. #include "LoginDatabase.h"
  31. #include "../common/ConfigReader.h"
  32. #include "../common/Log.h"
  33. extern NetConnection net;
  34. extern LWorldList world_list;
  35. extern ClientList client_list;
  36. extern LoginDatabase database;
  37. extern map<int16,OpcodeManager*>EQOpcodeManager;
  38. extern ConfigReader configReader;
  39. using namespace std;
  40. Client::Client(EQStream* ieqnc) {
  41. eqnc = ieqnc;
  42. ip = eqnc->GetrIP();
  43. port = ntohs(eqnc->GetrPort());
  44. account_id = 0;
  45. lsadmin = 0;
  46. worldadmin = 0;
  47. lsstatus = 0;
  48. version = 0;
  49. kicked = false;
  50. verified = false;
  51. memset(bannedreason, 0, sizeof(bannedreason));
  52. //worldresponse_timer = new Timer(10000);
  53. //worldresponse_timer->Disable();
  54. memset(key,0,10);
  55. LoginMode = None;
  56. num_updates = 0;
  57. updatetimer = new Timer(500);
  58. updatelisttimer = new Timer(10000);
  59. //keepalive = new Timer(5000);
  60. //logintimer = new Timer(500); // Give time for the servers to send updates
  61. //keepalive->Start();
  62. //updatetimer->Start();
  63. //logintimer->Disable();
  64. disconnectTimer = 0;
  65. memset(ClientSession,0,25);
  66. request_num = 0;
  67. login_account = 0;
  68. createRequest = 0;
  69. playWaitTimer = NULL;
  70. start = false;
  71. update_position = 0;
  72. update_packets = 0;
  73. needs_world_list = true;
  74. }
  75. Client::~Client() {
  76. //safe_delete(worldresponse_timer);
  77. //safe_delete(logintimer);
  78. safe_delete(login_account);
  79. eqnc->Close();
  80. safe_delete(playWaitTimer);
  81. safe_delete(createRequest);
  82. safe_delete(disconnectTimer);
  83. safe_delete(updatetimer);
  84. }
  85. bool Client::Process() {
  86. if(!start && !eqnc->CheckActive()){
  87. if(!playWaitTimer)
  88. playWaitTimer = new Timer(5000);
  89. else if(playWaitTimer->Check()){
  90. safe_delete(playWaitTimer);
  91. return false;
  92. }
  93. return true;
  94. }
  95. else if(!start){
  96. safe_delete(playWaitTimer);
  97. start = true;
  98. }
  99. if (disconnectTimer && disconnectTimer->Check())
  100. {
  101. safe_delete(disconnectTimer);
  102. getConnection()->SendDisconnect();
  103. }
  104. if (!kicked) {
  105. /************ Get all packets from packet manager out queue and process them ************/
  106. EQApplicationPacket *app = 0;
  107. /*if(logintimer && logintimer->Check())
  108. {
  109. database.LoadCharacters(GetLoginAccount());
  110. SendLoginAccepted();
  111. logintimer->Disable();
  112. }*/
  113. /*if(worldresponse_timer && worldresponse_timer->Check())
  114. {
  115. FatalError(WorldDownErrorMessage);
  116. worldresponse_timer->Disable();
  117. }*/
  118. if(playWaitTimer != NULL && playWaitTimer->Check ( ) )
  119. {
  120. SendPlayFailed(PLAY_ERROR_SERVER_TIMEOUT);
  121. safe_delete(playWaitTimer);
  122. }
  123. if(!needs_world_list && updatetimer && updatetimer->Check()){
  124. if(updatelisttimer && updatelisttimer->Check()){
  125. if(num_updates >= 180){ //30 minutes
  126. getConnection()->SendDisconnect();
  127. }
  128. else{
  129. vector<PacketStruct*>::iterator itr;
  130. if(update_packets){
  131. for(itr = update_packets->begin(); itr != update_packets->end(); itr++){
  132. safe_delete(*itr);
  133. }
  134. }
  135. safe_delete(update_packets);
  136. update_packets = world_list.GetServerListUpdate(version);
  137. }
  138. num_updates++;
  139. }
  140. else{
  141. if(!update_packets){
  142. update_packets = world_list.GetServerListUpdate(version);
  143. }
  144. else{
  145. if(update_position < update_packets->size()){
  146. QueuePacket(update_packets->at(update_position)->serialize());
  147. update_position++;
  148. }
  149. else
  150. update_position = 0;
  151. }
  152. }
  153. }
  154. while(app = eqnc->PopPacket())
  155. {
  156. switch(app->GetOpcode())
  157. {
  158. case OP_LoginRequestMsg:{
  159. DumpPacket(app);
  160. PacketStruct* packet = configReader.getStruct("LS_LoginRequest", 1);
  161. if(packet && packet->LoadPacketData(app->pBuffer,app->size)){
  162. version = packet->getType_int16_ByName("version");
  163. LogWrite(LOGIN__DEBUG, 0, "Login", "Classic Client Version Provided: %i", version);
  164. if (version == 0 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0)
  165. {
  166. safe_delete(packet);
  167. packet = configReader.getStruct("LS_LoginRequest", 1208);
  168. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  169. version = packet->getType_int16_ByName("version");
  170. }
  171. else
  172. break;
  173. }
  174. //[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.
  175. LogWrite(LOGIN__DEBUG, 0, "Login", "New Client Version Provided: %i", version);
  176. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  177. LogWrite(LOGIN__ERROR, 0, "Login", "Incompatible client version provided: %i", version);
  178. SendLoginDenied();
  179. return false;
  180. }
  181. if(EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()){
  182. getConnection()->SetClientVersion(GetVersion());
  183. EQ2_16BitString username = packet->getType_EQ2_16BitString_ByName("username");
  184. EQ2_16BitString password = packet->getType_EQ2_16BitString_ByName("password");
  185. LoginAccount* acct = database.LoadAccount(username.data.c_str(),password.data.c_str(), net.IsAllowingAccountCreation());
  186. if(acct){
  187. Client* otherclient = client_list.FindByLSID(acct->getLoginAccountID());
  188. if(otherclient)
  189. 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
  190. }
  191. if(acct){
  192. SetAccountName(username.data.c_str());
  193. database.UpdateAccountIPAddress(acct->getLoginAccountID(), getConnection()->GetrIP());
  194. database.UpdateAccountClientDataVersion(acct->getLoginAccountID(), version);
  195. LogWrite(LOGIN__INFO, 0, "Login", "%s successfully logged in.", (char*)username.data.c_str());
  196. }
  197. else
  198. {
  199. if (username.size > 0)
  200. LogWrite(LOGIN__ERROR, 0, "Login", "%s login failed!", (char*)username.data.c_str());
  201. else
  202. LogWrite(LOGIN__ERROR, 0, "Login", "[UNKNOWN USER] login failed!");
  203. }
  204. if(!acct)
  205. SendLoginDenied();
  206. else{
  207. needs_world_list = true;
  208. SetLoginAccount(acct);
  209. SendLoginAccepted();
  210. }
  211. }
  212. else{
  213. cout << "Error bad version: " << version << endl;
  214. SendLoginDeniedBadVersion();
  215. }
  216. }
  217. else{
  218. cout << "Error loading LS_LoginRequest packet: \n";
  219. //DumpPacket(app);
  220. }
  221. safe_delete(packet);
  222. break;
  223. }
  224. case OP_KeymapLoadMsg:{
  225. // cout << "Received OP_KeymapNoneMsg\n";
  226. //dunno what this is for
  227. break;
  228. }
  229. case OP_AllWSDescRequestMsg:{
  230. SendWorldList();
  231. needs_world_list = false;
  232. database.LoadCharacters(GetLoginAccount(), GetVersion());
  233. SendCharList();
  234. break;
  235. }
  236. case OP_LsClientCrashlogReplyMsg:{
  237. // DumpPacket(app);
  238. SaveErrorsToDB(app, "Crash Log", GetVersion());
  239. break;
  240. }
  241. case OP_LsClientVerifylogReplyMsg:{
  242. // DumpPacket(app);
  243. SaveErrorsToDB(app, "Verify Log", GetVersion());
  244. break;
  245. }
  246. case OP_LsClientAlertlogReplyMsg:{
  247. // DumpPacket(app);
  248. SaveErrorsToDB(app, "Alert Log", GetVersion());
  249. break;
  250. }
  251. case OP_LsClientBaselogReplyMsg:{
  252. // DumpPacket(app);
  253. SaveErrorsToDB(app, "Base Log", GetVersion());
  254. break;
  255. }
  256. case OP_AllCharactersDescRequestMsg:{
  257. break;
  258. }
  259. case OP_CreateCharacterRequestMsg:{
  260. PacketStruct* packet = configReader.getStruct("CreateCharacter", GetVersion());
  261. DumpPacket(app);
  262. playWaitTimer = new Timer ( 15000 );
  263. playWaitTimer->Start ( );
  264. cout << "Char Create Request From: " << GetAccountName() << "....";
  265. if(packet->LoadPacketData(app->pBuffer,app->size)){
  266. cout << "Loaded Successfully\n";
  267. packet->setDataByName("account_id",GetAccountID());
  268. LWorld* world_server = world_list.FindByID(packet->getType_int32_ByName("server_id"));
  269. if(!world_server)
  270. {
  271. DumpPacket(app->pBuffer, app->size);
  272. cout << GetAccountName() << " attempted creation of character with an invalid server id of: " << packet->getType_int32_ByName("server_id") << "\n";
  273. break;
  274. }
  275. else
  276. {
  277. ServerPacket* outpack = new ServerPacket(ServerOP_CharacterCreate, app->size+sizeof(int16));
  278. int16 out_version = GetVersion();
  279. memcpy(outpack->pBuffer, &out_version, sizeof(int16));
  280. memcpy(outpack->pBuffer + sizeof(int16), app->pBuffer, app->size);
  281. uchar* tmp = outpack->pBuffer;
  282. if(out_version<=283)
  283. tmp+=2;
  284. else
  285. tmp += 7;
  286. int32 account_id = GetAccountID();
  287. memcpy(tmp, &account_id, sizeof(int32));
  288. world_server->SendPacket(outpack);
  289. safe_delete(outpack);
  290. createRequest = packet;
  291. }
  292. }
  293. else{
  294. cout << "Error loading Char Create Packet!!\n";
  295. safe_delete(packet);
  296. }
  297. // world_list.SendWorldChanged(create.profile.server_id, false, this);
  298. break;
  299. }
  300. case OP_PlayCharacterRequestMsg:{
  301. int32 char_id = 0;
  302. int32 server_id = 0;
  303. PacketStruct* request = configReader.getStruct("LS_PlayRequest",GetVersion());
  304. if(request && request->LoadPacketData(app->pBuffer,app->size)){
  305. char_id = request->getType_int32_ByName("char_id");
  306. if (GetVersion() <= 283) {
  307. server_id = database.GetServer(GetAccountID(), char_id, request->getType_EQ2_16BitString_ByName("name").data);
  308. }
  309. else {
  310. server_id = request->getType_int32_ByName("server_id");
  311. }
  312. LWorld* world = world_list.FindByID(server_id);
  313. string name = database.GetCharacterName(char_id,server_id,GetAccountID());
  314. if(world && name.length() > 0){
  315. pending_play_char_id = char_id;
  316. ServerPacket* outpack = new ServerPacket(ServerOP_UsertoWorldReq, sizeof(UsertoWorldRequest_Struct));
  317. UsertoWorldRequest_Struct* req = (UsertoWorldRequest_Struct*)outpack->pBuffer;
  318. req->char_id = char_id;
  319. req->lsaccountid = GetAccountID();
  320. req->worldid = server_id;
  321. struct in_addr in;
  322. in.s_addr = GetIP();
  323. strcpy(req->ip_address, inet_ntoa(in));
  324. world->SendPacket(outpack);
  325. delete outpack;
  326. safe_delete(playWaitTimer);
  327. playWaitTimer = new Timer ( 5000 );
  328. playWaitTimer->Start ( );
  329. }
  330. else{
  331. cout << GetAccountName() << " sent invalid Play Request: \n";
  332. SendPlayFailed(PLAY_ERROR_PROBLEM);
  333. DumpPacket(app);
  334. }
  335. }
  336. safe_delete(request);
  337. break;
  338. }
  339. case OP_DeleteCharacterRequestMsg:{
  340. PacketStruct* request = configReader.getStruct("LS_DeleteCharacterRequest", GetVersion());
  341. PacketStruct* response = configReader.getStruct("LS_DeleteCharacterResponse", GetVersion());
  342. if(request && response && request->LoadPacketData(app->pBuffer,app->size)){
  343. EQ2_16BitString name = request->getType_EQ2_16BitString_ByName("name");
  344. int32 acct_id = GetAccountID();
  345. int32 char_id = request->getType_int32_ByName("char_id");
  346. int32 server_id = request->getType_int32_ByName("server_id");
  347. if(database.VerifyDelete(acct_id, char_id, name.data.c_str())){
  348. response->setDataByName("response", 1);
  349. GetLoginAccount()->removeCharacter((char*)name.data.c_str());
  350. LWorld* world_server = world_list.FindByID(server_id);
  351. if(world_server != NULL)
  352. world_server->SendDeleteCharacter ( char_id , acct_id );
  353. }
  354. else
  355. response->setDataByName("response", 0);
  356. response->setDataByName("server_id", server_id);
  357. response->setDataByName("char_id", char_id);
  358. response->setDataByName("account_id", account_id);
  359. response->setMediumStringByName("name", (char*)name.data.c_str());
  360. response->setDataByName("max_characters", 10);
  361. EQ2Packet* outapp = response->serialize();
  362. QueuePacket(outapp);
  363. this->SendCharList();
  364. }
  365. safe_delete(request);
  366. safe_delete(response);
  367. break;
  368. }
  369. default: {
  370. const char* name = app->GetOpcodeName();
  371. if (name)
  372. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  373. else
  374. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  375. }
  376. }
  377. delete app;
  378. }
  379. }
  380. if (!eqnc->CheckActive()) {
  381. return false;
  382. }
  383. return true;
  384. }
  385. void Client::SaveErrorsToDB(EQApplicationPacket* app, char* type, int32 version){
  386. int32 size = 0;
  387. z_stream zstream;
  388. if (version >= 284) {
  389. memcpy(&size, app->pBuffer + sizeof(int32), sizeof(int32));
  390. zstream.next_in = app->pBuffer + 8;
  391. zstream.avail_in = app->size - 8;
  392. }
  393. else { //box set
  394. size = 0xFFFF;
  395. zstream.next_in = app->pBuffer + 2;
  396. zstream.avail_in = app->size - 2;
  397. }
  398. size++;
  399. char* message = new char[size];
  400. memset(message, 0, size);
  401. int zerror = 0;
  402. zstream.next_out = (BYTE*)message;
  403. zstream.avail_out = size;
  404. zstream.zalloc = Z_NULL;
  405. zstream.zfree = Z_NULL;
  406. zstream.opaque = Z_NULL;
  407. zerror = inflateInit( &zstream);
  408. if(zerror != Z_OK) {
  409. safe_delete_array(message);
  410. return;
  411. }
  412. zerror = inflate( &zstream, 0 );
  413. if(message && strlen(message) > 0)
  414. database.SaveClientLog(type, message, GetLoginAccount()->getLoginName(), GetVersion());
  415. safe_delete_array(message);
  416. }
  417. void Client::CharacterApproved(int32 server_id,int32 char_id)
  418. {
  419. if(createRequest && server_id == createRequest->getType_int32_ByName("server_id")){
  420. LWorld* world_server = world_list.FindByID(server_id);
  421. if(!world_server)
  422. return;
  423. PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply", GetVersion());
  424. if(packet){
  425. packet->setDataByName("account_id", GetAccountID());
  426. packet->setDataByName("unknown", 0xFFFFFFFF);
  427. packet->setDataByName("response", CREATESUCCESS_REPLY);
  428. packet->setMediumStringByName("name", (char*)createRequest->getType_EQ2_16BitString_ByName("name").data.c_str());
  429. EQ2Packet* outapp = packet->serialize();
  430. QueuePacket(outapp);
  431. safe_delete(packet);
  432. database.SaveCharacter(createRequest, GetLoginAccount(),char_id, GetVersion());
  433. // refresh characters for this account
  434. database.LoadCharacters(GetLoginAccount(), GetVersion());
  435. SendCharList();
  436. if (GetVersion() <= 546)
  437. {
  438. pending_play_char_id = char_id;
  439. ServerPacket* outpack = new ServerPacket(ServerOP_UsertoWorldReq, sizeof(UsertoWorldRequest_Struct));
  440. UsertoWorldRequest_Struct* req = (UsertoWorldRequest_Struct*)outpack->pBuffer;
  441. req->char_id = char_id;
  442. req->lsaccountid = GetAccountID();
  443. req->worldid = server_id;
  444. struct in_addr in;
  445. in.s_addr = GetIP();
  446. strcpy(req->ip_address, inet_ntoa(in));
  447. world_server->SendPacket(outpack);
  448. delete outpack;
  449. }
  450. }
  451. }
  452. else{
  453. cout << GetAccountName() << " received invalid CharacterApproval from server: " << server_id << endl;
  454. }
  455. safe_delete(createRequest);
  456. }
  457. void Client::CharacterRejected(int8 reason_number)
  458. {
  459. PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply", GetVersion());
  460. if(createRequest && packet){
  461. packet->setDataByName("account_id", GetAccountID());
  462. int8 clientReasonNum = reason_number;
  463. // reason numbers change and instead of updating the world server
  464. // the login server will hold the up to date #'s
  465. /*
  466. switch(reason_number)
  467. {
  468. // these error codes seem to be removed now, they shutdown the client rather immediately
  469. // for now we are just going to play a joke on them and say they can't create a new character.
  470. case INVALIDRACE_REPLY:
  471. case INVALIDGENDER_REPLY:
  472. clientReasonNum = 8;
  473. break;
  474. case BADNAMELENGTH_REPLY:
  475. clientReasonNum = 9;
  476. break;
  477. case NAMEINVALID_REPLY:
  478. clientReasonNum = 10;
  479. break;
  480. case NAMEFILTER_REPLY:
  481. clientReasonNum = 11;
  482. break;
  483. case NAMETAKEN_REPLY:
  484. clientReasonNum = 12;
  485. break;
  486. case OVERLOADEDSERVER_REPLY:
  487. clientReasonNum = 13;
  488. break;
  489. }
  490. */
  491. packet->setDataByName("response", clientReasonNum);
  492. packet->setMediumStringByName("name", "");
  493. EQ2Packet* outapp = packet->serialize();
  494. QueuePacket(outapp);
  495. safe_delete(packet);
  496. }
  497. /*LS_CreateCharacterReply reply(GetAccountID(), reason_number, create.profile.name.data);
  498. EQ2Packet* outapp = reply.serialize();
  499. QueuePacket(outapp);
  500. create.Clear();*/
  501. }
  502. void Client::SendCharList(){
  503. /*PacketStruct* packet = configReader.getStruct("LS_CreateCharacterReply");
  504. packet->setDataByName("account_id", GetAccountID());
  505. packet->setDataByName("response", reason_number);
  506. packet->setDataByName("name", &create.profile.name);
  507. EQ2Packet* outapp = packet->serialize();
  508. QueuePacket(outapp);
  509. safe_delete(packet);*/
  510. LogWrite(LOGIN__INFO, 0, "Login", "[%s] sending character list.", GetAccountName());
  511. LS_CharSelectList list;
  512. list.loadData(GetAccountID(), GetLoginAccount()->charlist, GetVersion());
  513. EQ2Packet* outapp = list.serialize(GetVersion());
  514. DumpPacket(outapp->pBuffer, outapp->size);
  515. QueuePacket(outapp);
  516. }
  517. void Client::SendLoginDeniedBadVersion(){
  518. EQ2Packet* app = new EQ2Packet(OP_LoginReplyMsg, 0, sizeof(LS_LoginResponse));
  519. LS_LoginResponse* ls_response = (LS_LoginResponse*)app->pBuffer;
  520. ls_response->reply_code = 6;
  521. ls_response->unknown03 = 0xFFFFFFFF;
  522. ls_response->unknown04 = 0xFFFFFFFF;
  523. QueuePacket(app);
  524. StartDisconnectTimer();
  525. }
  526. void Client::SendLoginDenied(){
  527. EQ2Packet* app = new EQ2Packet(OP_LoginReplyMsg, 0, sizeof(LS_LoginResponse));
  528. LS_LoginResponse* ls_response = (LS_LoginResponse*)app->pBuffer;
  529. ls_response->reply_code = 1;
  530. // reply_codes for AoM:
  531. /* 1 = Login rejected: Invalid username or password. Please try again.
  532. 2 = Login rejected: Server thinks your account is currently playing; you may have to wait "
  533. "a few minutes for it to clear, then try again
  534. 6 = Login rejected: The client's version does not match the server's. Please re-run the patcher.
  535. 7 = Login rejected: You have no scheduled playtimes.
  536. 8 = Your account does not have the features required to play on this server.
  537. 11 = The client's build does not match the server's. Please re-run the patcher.
  538. 12 = You must update your password in order to log in. Pressing OK will op"
  539. "en your web browser to the SOE password management page
  540. Other Value > 1 = Login rejected for an unknown reason.
  541. */
  542. ls_response->unknown03 = 0xFFFFFFFF;
  543. ls_response->unknown04 = 0xFFFFFFFF;
  544. QueuePacket(app);
  545. StartDisconnectTimer();
  546. }
  547. void Client::SendLoginAccepted(int32 account_id, int8 login_response) {
  548. PacketStruct* packet = configReader.getStruct("LS_LoginReplyMsg", GetVersion());
  549. int i = 0;
  550. if (packet)
  551. {
  552. packet->setDataByName("account_id", account_id);
  553. packet->setDataByName("login_response", login_response);
  554. packet->setDataByName("do_not_force_soga", 1);
  555. // sub_level 0xFFFFFFFF = blacks out all portraits for class alignments, considered non membership
  556. // sub_level > 0 = class alignments still required, but portraits are viewable and race selectable
  557. // sub_level = 2 membership, you can 'create characters on time locked servers' vs standard
  558. // sub_level = 0 forces popup on close to web browser
  559. packet->setDataByName("sub_level", net.GetDefaultSubscriptionLevel());
  560. packet->setDataByName("race_flag", 0x1FFFFF);
  561. packet->setDataByName("class_flag", 0x7FFFFFE);
  562. packet->setMediumStringByName("username", GetAccountName());
  563. packet->setMediumStringByName("password", GetAccountName());
  564. // unknown5
  565. // full support = 0x7CFF
  566. // 1 << 12 (-4096) = missing echoes of faydwer, disables Fae and Arasai (black portraits) and kelethin as starting city
  567. // 1 << 13 (-8192) = disables sarnak (black portraits) and gorowyn as starting city
  568. packet->setDataByName("unknown5", net.GetExpansionFlag());
  569. packet->setDataByName("unknown6", 0xFF);
  570. packet->setDataByName("unknown6", 0xFF, 1);
  571. packet->setDataByName("unknown6", 0xFF, 2);
  572. // controls class access / playable characters
  573. packet->setDataByName("unknown10", 0xFF);
  574. // packet->setDataByName("unknown7a", 0x0101);
  575. // packet->setDataByName("race_unknown", 0x01);
  576. packet->setDataByName("unknown7", net.GetEnabledRaces()); // 0x01-0xFF disable extra races FAE(16) ARASAI (17) SARNAK (18) -- with 4096/8192 flags, no visibility of portraits
  577. packet->setDataByName("unknown7a", 0xEE);
  578. packet->setDataByName("unknown8", net.GetCitiesFlag(), 1); // dword_1ECBA18 operand for race flag packs (sublevel 0,1,2?) -- (sublevel -1) controls starting zones omission 0xEE vs 0xCF (CF misses halas)
  579. /*
  580. 1 = city of qeynos
  581. 2 = city of freeport
  582. 4 = city of kelethin
  583. 8 = city of neriak
  584. 16 = gorowyn
  585. 32 = new halas
  586. 64 = queens colony
  587. 128 = outpost overlord
  588. */
  589. EQ2Packet* outapp = packet->serialize();
  590. QueuePacket(outapp);
  591. safe_delete(packet);
  592. }
  593. }
  594. void Client::SendWorldList(){
  595. EQ2Packet* pack = world_list.MakeServerListPacket(lsadmin, version);
  596. EQ2Packet* dupe = pack->Copy();
  597. DumpPacket(dupe->pBuffer,dupe->size);
  598. QueuePacket(dupe);
  599. SendLoginAccepted(0, 10); // triggers a different code path in the client to set certain flags
  600. return;
  601. }
  602. void Client::QueuePacket(EQ2Packet* app){
  603. eqnc->EQ2QueuePacket(app);
  604. }
  605. void Client::WorldResponse(int32 worldid, int8 response, char* ip_address, int32 port, int32 access_key)
  606. {
  607. LWorld* world = world_list.FindByID(worldid);
  608. if(world == 0) {
  609. FatalError(0);
  610. return;
  611. }
  612. if(response != 1){
  613. if(response == PLAY_ERROR_CHAR_NOT_LOADED){
  614. string pending_play_char_name = database.GetCharacterName(pending_play_char_id, worldid, GetAccountID());
  615. if(database.VerifyDelete(GetAccountID(), pending_play_char_id, pending_play_char_name.c_str())){
  616. GetLoginAccount()->removeCharacter((char*)pending_play_char_name.c_str());
  617. }
  618. }
  619. FatalError(response);
  620. return;
  621. }
  622. PacketStruct* response_packet = configReader.getStruct("LS_PlayResponse", GetVersion());
  623. if(response_packet){
  624. safe_delete(playWaitTimer);
  625. response_packet->setDataByName("response", 1);
  626. response_packet->setSmallStringByName("server", ip_address);
  627. response_packet->setDataByName("port", port);
  628. response_packet->setDataByName("account_id", GetAccountID());
  629. response_packet->setDataByName("access_code", access_key);
  630. EQ2Packet* outapp = response_packet->serialize();
  631. QueuePacket(outapp);
  632. safe_delete(response_packet);
  633. }
  634. return;
  635. }
  636. void Client::FatalError(int8 response) {
  637. safe_delete(playWaitTimer);
  638. SendPlayFailed(response);
  639. }
  640. void Client::SendPlayFailed(int8 response){
  641. PacketStruct* response_packet = configReader.getStruct("LS_PlayResponse", GetVersion());
  642. if(response_packet){
  643. response_packet->setDataByName("response", response);
  644. response_packet->setSmallStringByName("server", "");
  645. response_packet->setDataByName("port", 0);
  646. response_packet->setDataByName("account_id", GetAccountID());
  647. response_packet->setDataByName("access_code", 0);
  648. EQ2Packet* outapp = response_packet->serialize();
  649. QueuePacket(outapp);
  650. safe_delete(response_packet);
  651. }
  652. }
  653. void ClientList::Add(Client* client) {
  654. MClientList.writelock();
  655. client_list[client] = true;
  656. MClientList.releasewritelock();
  657. }
  658. Client* ClientList::Get(int32 ip, int16 port) {
  659. Client* ret = 0;
  660. map<Client*, bool>::iterator itr;
  661. MClientList.readlock();
  662. for(itr = client_list.begin(); itr != client_list.end(); itr++){
  663. if(itr->first->GetIP() == ip && itr->first->GetPort() == port){
  664. ret = itr->first;
  665. break;
  666. }
  667. }
  668. MClientList.releasereadlock();
  669. return ret;
  670. }
  671. void ClientList::FindByCreateRequest(){
  672. Client* client = 0;
  673. map<Client*, bool>::iterator itr;
  674. MClientList.readlock();
  675. for(itr = client_list.begin(); itr != client_list.end(); itr++){
  676. if(itr->first->AwaitingCharCreationRequest()){
  677. if(!client)
  678. client = itr->first;
  679. else{
  680. client = 0;//more than 1 character waiting, dont want to send rejection to wrong one
  681. break;
  682. }
  683. }
  684. }
  685. MClientList.releasereadlock();
  686. if(client)
  687. client->CharacterRejected(UNKNOWNERROR_REPLY);
  688. }
  689. Client* ClientList::FindByLSID(int32 lsaccountid) {
  690. Client* client = 0;
  691. map<Client*, bool>::iterator itr;
  692. MClientList.readlock();
  693. for(itr = client_list.begin(); itr != client_list.end(); itr++){
  694. if(itr->first->GetAccountID() == lsaccountid){
  695. client = itr->first;
  696. break;
  697. }
  698. }
  699. MClientList.releasereadlock();
  700. return client;
  701. }
  702. void ClientList::SendPacketToAllClients(EQ2Packet* app){
  703. Client* client = 0;
  704. map<Client*, bool>::iterator itr;
  705. MClientList.readlock();
  706. if(client_list.size() > 0){
  707. for(itr = client_list.begin(); itr != client_list.end(); itr++){
  708. itr->first->QueuePacket(app->Copy());
  709. }
  710. }
  711. safe_delete(app);
  712. MClientList.releasereadlock();
  713. }
  714. void ClientList::Process() {
  715. Client* client = 0;
  716. vector<Client*> erase_list;
  717. map<Client*, bool>::iterator itr;
  718. MClientList.readlock();
  719. for(itr = client_list.begin(); itr != client_list.end(); itr++){
  720. client = itr->first;
  721. if(!client->Process())
  722. erase_list.push_back(client);
  723. }
  724. MClientList.releasereadlock();
  725. if(erase_list.size() > 0){
  726. vector<Client*>::iterator erase_itr;
  727. MClientList.writelock();
  728. for(erase_itr = erase_list.begin(); erase_itr != erase_list.end(); erase_itr++){
  729. client = *erase_itr;
  730. struct in_addr in;
  731. in.s_addr = client->getConnection()->GetRemoteIP();
  732. net.numclients--;
  733. 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());
  734. client->getConnection()->Close();
  735. net.UpdateWindowTitle();
  736. client_list.erase(client);
  737. }
  738. MClientList.releasewritelock();
  739. }
  740. }
  741. void Client::StartDisconnectTimer() {
  742. if (!disconnectTimer)
  743. {
  744. disconnectTimer = new Timer(1000);
  745. disconnectTimer->Start();
  746. }
  747. }