ClientPacketFunctions.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "ClientPacketFunctions.h"
  17. #include "WorldDatabase.h"
  18. #include "../common/ConfigReader.h"
  19. #include "Variables.h"
  20. #include "World.h"
  21. #include "classes.h"
  22. #include "../common/Log.h"
  23. #include "Traits/Traits.h"
  24. extern Classes classes;
  25. extern Commands commands;
  26. extern WorldDatabase database;
  27. extern ConfigReader configReader;
  28. extern MasterSpellList master_spell_list;
  29. extern MasterTraitList master_trait_list;
  30. extern Variables variables;
  31. extern World world;
  32. void ClientPacketFunctions::SendFinishedEntitiesList ( Client* client ){
  33. EQ2Packet* finishedEntitiesApp = new EQ2Packet(OP_DoneSendingInitialEntitiesMsg, 0, 0);
  34. client->QueuePacket(finishedEntitiesApp);
  35. }
  36. void ClientPacketFunctions::SendSkillSlotMappings(Client* client){
  37. EQ2Packet* app = client->GetPlayer()->GetSpellSlotMappingPacket(client->GetVersion());
  38. if(app)
  39. client->QueuePacket(app);
  40. }
  41. void ClientPacketFunctions::SendLoginDenied ( Client* client ){
  42. PacketStruct* packet = configReader.getStruct("LS_LoginResponse", 1);
  43. if(packet){
  44. packet->setDataByName("reply_code", 1);
  45. packet->setDataByName("unknown03", 0xFFFFFFFF);
  46. packet->setDataByName("unknown04", 0xFFFFFFFF);
  47. EQ2Packet* app = packet->serialize();
  48. client->QueuePacket(app);
  49. safe_delete(packet);
  50. }
  51. }
  52. void ClientPacketFunctions::SendLoginAccepted ( Client* client ){
  53. LogWrite(PACKET__DEBUG, 0, "Packet", "Sending Login Accepted packet (LS_LoginResponse, %i)", client->GetVersion());
  54. PacketStruct* response_packet = configReader.getStruct("LS_LoginResponse", client->GetVersion());
  55. if(response_packet){
  56. response_packet->setDataByName("unknown02", 1);
  57. response_packet->setDataByName("unknown05", -959971393);
  58. response_packet->setDataByName("unknown08", 2);
  59. response_packet->setDataByName("unknown09", 585);
  60. response_packet->setDataByName("unknown10", 1597830);
  61. response_packet->setDataByName("accountid", 3); //client->GetAccountID());
  62. EQ2Packet* outapp = response_packet->serialize();
  63. client->QueuePacket(outapp);
  64. safe_delete(response_packet);
  65. }
  66. }
  67. void ClientPacketFunctions::SendCommandList ( Client* client ){
  68. EQ2Packet* app = commands.GetRemoteCommands()->serialize();
  69. client->QueuePacket(app);
  70. }
  71. void ClientPacketFunctions::SendGameWorldTime ( Client* client ){
  72. PacketStruct* packet = world.GetWorldTime(client->GetVersion());
  73. if(packet){
  74. client->QueuePacket(packet->serialize());
  75. safe_delete(packet);
  76. }
  77. //opcode 501 was the selection display opcode
  78. }
  79. void ClientPacketFunctions::SendCharacterData ( Client* client ){
  80. client->GetPlayer()->SetCharacterID(client->GetCharacterID());
  81. if(!client->IsReloadingZone()) {
  82. EQ2Packet* outapp = client->GetPlayer()->serialize(client->GetPlayer(), client->GetVersion());
  83. //DumpPacket(outapp);
  84. client->QueuePacket(outapp);
  85. }
  86. }
  87. void ClientPacketFunctions::SendCharacterSheet ( Client* client ){
  88. EQ2Packet* app = client->GetPlayer()->GetPlayerInfo()->serialize(client->GetVersion());
  89. client->QueuePacket(app);
  90. if (client->GetVersion() >= 1188) {
  91. EQ2Packet* app2 = client->GetPlayer()->GetPlayerInfo()->serializePet(client->GetVersion());
  92. if (app2)
  93. client->QueuePacket(app2);
  94. }
  95. }
  96. void ClientPacketFunctions::SendSkillBook ( Client* client ){
  97. EQ2Packet* app = client->GetPlayer()->skill_list.GetSkillPacket(client->GetVersion());
  98. if(app)
  99. client->QueuePacket(app);
  100. }
  101. // Jabantiz: Attempt to get the char trait list working
  102. void ClientPacketFunctions::SendTraitList(Client* client) {
  103. if (client->GetVersion() >= 547) {
  104. EQ2Packet* traitApp = master_trait_list.GetTraitListPacket(client);
  105. //DumpPacket(traitApp);
  106. if (traitApp) {
  107. client->QueuePacket(traitApp);
  108. }
  109. }
  110. }
  111. void ClientPacketFunctions::SendAbilities ( Client* client ){
  112. LogWrite(MISC__TODO, 1, "TODO", " Add SendAbilities functionality\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  113. // this is the featherfall ability data
  114. // later this would loop through and send all abilities
  115. /*uchar abilityData[] ={0x11,0x00,0x00,0x00,0xff,0x15,0x02,0x00,0x0b,0x00,0x46,0x65,0x61,0x74
  116. ,0x68,0x65,0x72,0x66,0x61,0x6c,0x6c};
  117. EQ2Packet* abilityApp = new EQ2Packet(OP_ClientCmdMsg, abilityData, sizeof(abilityData));
  118. client->QueuePacket(abilityApp);*/
  119. }
  120. void ClientPacketFunctions::SendCommandNamePacket ( Client* client ){
  121. LogWrite(MISC__TODO, 1, "TODO", " fix, this is actually quest/collection information\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  122. /*
  123. PacketStruct* command_packet = configReader.getStruct("WS_CommandName", client->GetVersion());
  124. if(command_packet){
  125. command_packet->setDataByName("unknown03", 0x221bfb47);
  126. char* charName = { "BogusName" };
  127. command_packet->setMediumStringByName("character_name",charName);
  128. EQ2Packet* outapp = command_packet->serialize();
  129. client->QueuePacket(outapp);
  130. safe_delete(command_packet);
  131. }
  132. */
  133. }
  134. void ClientPacketFunctions::SendQuickBarInit ( Client* client ){
  135. int32 count = database.LoadPlayerSkillbar(client);
  136. if(count == 0) {
  137. LogWrite(PACKET__DEBUG, 0, "Packet", "No character quickbar found!");
  138. database.UpdateStartingSkillbar(client->GetCharacterID(), client->GetPlayer()->GetAdventureClass(), client->GetPlayer()->GetRace());
  139. database.LoadPlayerSkillbar(client);
  140. }
  141. EQ2Packet* quickbarApp = client->GetPlayer()->GetQuickbarPacket(client->GetVersion());
  142. if(quickbarApp)
  143. client->QueuePacket(quickbarApp);
  144. }
  145. void ClientPacketFunctions::SendCharacterMacros(Client* client) {
  146. LogWrite(PACKET__DEBUG, 0, "Packet", "Sending Character Macro packet (WS_MacroInit, %i)", client->GetVersion());
  147. map<int8, vector<MacroData*> >* macros = database.LoadCharacterMacros(client->GetCharacterID());
  148. if (macros) {
  149. PacketStruct* macro_packet = configReader.getStruct("WS_MacroInit", client->GetVersion());
  150. if (macro_packet) {
  151. map<int8, vector<MacroData*> >::iterator itr;
  152. macro_packet->setArrayLengthByName("macro_count", macros->size());
  153. int8 x = 0;
  154. for (itr = macros->begin(); itr != macros->end(); itr++, x++) {
  155. macro_packet->setArrayDataByName("number", itr->first, x);
  156. if (itr->second.size() > 0) {
  157. LogWrite(PACKET__DEBUG, 5, "Packet", "Loading Macro %i, name: %s", itr->first, itr->second[0]->name.c_str());
  158. macro_packet->setArrayDataByName("name", itr->second[0]->name.c_str(), x);
  159. }
  160. if (client->GetVersion() > 283) {
  161. char tmp_details_count[25] = { 0 };
  162. sprintf(tmp_details_count, "macro_details_count_%i", x);
  163. macro_packet->setArrayLengthByName(tmp_details_count, itr->second.size());
  164. for (int8 i = 0; i < itr->second.size(); i++) {
  165. char tmp_command[15] = { 0 };
  166. sprintf(tmp_command, "command%i", x);
  167. LogWrite(PACKET__DEBUG, 5, "Packet", "\tLoading Command %i: %s", itr->first, x, itr->second[i]->text.c_str());
  168. macro_packet->setArrayDataByName(tmp_command, itr->second[i]->text.c_str(), i);
  169. if ( i > 0 ) // itr->second[0] used below, we will delete it later
  170. safe_delete(itr->second[i]); // delete MacroData*
  171. }
  172. macro_packet->setArrayDataByName("unknown2", 2, x);
  173. macro_packet->setArrayDataByName("unknown3", 0xFFFFFFFF, x);
  174. }
  175. else {
  176. if (itr->second.size() > 0)
  177. macro_packet->setArrayDataByName("command", itr->second[0]->text.c_str(), x);
  178. }
  179. macro_packet->setArrayDataByName("icon", itr->second[0]->icon, x);
  180. client->GetPlayer()->macro_icons[itr->first] = itr->second[0]->icon;
  181. // remove itr->second[0] now that we are done with it
  182. safe_delete(itr->second[0]); // delete MacroData*
  183. }
  184. EQ2Packet* packet = macro_packet->serialize();
  185. client->QueuePacket(packet);
  186. safe_delete(macro_packet);
  187. }
  188. safe_delete(macros);
  189. }
  190. }
  191. void ClientPacketFunctions::SendMOTD ( Client* client ){
  192. const char* motd = 0;
  193. // fetch MOTD from `variables` table
  194. Variable* var = variables.FindVariable("motd");
  195. if( var == NULL || strlen (var->GetValue()) == 0) {
  196. LogWrite(WORLD__WARNING, 0, "World", "No MOTD set. Sending generic message...");
  197. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Message of the Day: Welcome to EQ2Emulator! Customize this message in the `variables`.`motd` data!");
  198. }
  199. else {
  200. motd = var->GetValue();
  201. LogWrite(WORLD__DEBUG, 0, "World", "Send MOTD...");
  202. client->SimpleMessage(CHANNEL_COLOR_YELLOW, motd);
  203. }
  204. }
  205. void ClientPacketFunctions::SendUpdateSpellBook ( Client* client ){
  206. if(client->IsReadyForSpawns()){
  207. EQ2Packet* app = client->GetPlayer()->GetSpellBookUpdatePacket(client->GetVersion());
  208. if(app)
  209. client->QueuePacket(app);
  210. }
  211. client->GetPlayer()->UnlockAllSpells(true);
  212. }
  213. void ClientPacketFunctions::SendServerControlFlagsClassic(Client* client, int32 param, int32 value) {
  214. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  215. if(packet) {
  216. packet->setDataByName("parameter", param);
  217. packet->setDataByName("value", value);
  218. client->QueuePacket(packet->serialize());
  219. }
  220. safe_delete(packet);
  221. }
  222. void ClientPacketFunctions::SendServerControlFlags(Client* client, int8 param, int8 param_val, int8 value) {
  223. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  224. if(packet) {
  225. if(client->GetVersion() <= 546 && param == 1 && !value) {
  226. param_val = 0;
  227. }
  228. if (param == 1)
  229. packet->setDataByName("parameter1", param_val);
  230. else if (param == 2)
  231. packet->setDataByName("parameter2", param_val);
  232. else if (param == 3)
  233. packet->setDataByName("parameter3", param_val);
  234. else if (param == 4)
  235. packet->setDataByName("parameter4", param_val);
  236. else if (param == 5)
  237. packet->setDataByName("parameter5", param_val);
  238. else {
  239. safe_delete(packet);
  240. return;
  241. }
  242. packet->setDataByName("value", value);
  243. client->QueuePacket(packet->serialize());
  244. /*
  245. Some other values for this packet
  246. first param:
  247. 01 flymode
  248. 02 collisons off
  249. 04 unknown
  250. 08 heading movement only
  251. 16 forward/reverse movement only
  252. 32 low gravity
  253. 64 sit
  254. second
  255. 2 crouch
  256. third:
  257. 04 float when trying to jump, no movement
  258. 08 jump high, no movement
  259. 128 walk underwater
  260. fourth:
  261. 01 moon jump underwater
  262. 04 fear
  263. 16 moon jumps
  264. 32 safe fall (float to ground)
  265. 64 cant move
  266. fifth:
  267. 01 die
  268. 08 hover (fae)
  269. 32 flymode2?
  270. */
  271. }
  272. safe_delete(packet);
  273. }
  274. void ClientPacketFunctions::SendInstanceList(Client* client) {
  275. if (client->GetPlayer()->GetCharacterInstances()->GetInstanceCount() > 0) {
  276. PacketStruct* packet = configReader.getStruct("WS_InstanceCreated", client->GetVersion());
  277. if (packet) {
  278. vector<InstanceData> persist = client->GetPlayer()->GetCharacterInstances()->GetPersistentInstances();
  279. vector<InstanceData> lockout = client->GetPlayer()->GetCharacterInstances()->GetLockoutInstances();
  280. packet->setArrayLengthByName("num_instances", lockout.size());
  281. for (int32 i = 0; i < lockout.size(); i++) {
  282. InstanceData data = lockout.at(i);
  283. packet->setArrayDataByName("unknown1", data.db_id, i); // unique id per player
  284. packet->setArrayDataByName("instance_zone_name", data.zone_name.c_str(), i);
  285. packet->setArrayDataByName("unknown2", 0x0B, i); // Always set to 0x0B on live packets
  286. packet->setArrayDataByName("success_last", data.last_success_timestamp, i);
  287. packet->setArrayDataByName("last_failure", data.last_failure_timestamp, i);
  288. packet->setArrayDataByName("failure", data.failure_lockout_time, i);
  289. packet->setArrayDataByName("success", data.success_lockout_time, i);
  290. }
  291. packet->setArrayLengthByName("num_persistent", persist.size());
  292. for (int32 i = 0; i < persist.size(); i++) {
  293. InstanceData data = persist.at(i);
  294. packet->setArrayDataByName("unknown1a", data.db_id, i); // unique id per player
  295. packet->setArrayDataByName("persistent_zone_name", data.zone_name.c_str(), i);
  296. packet->setArrayDataByName("unknown2a", 0x0B, i); // set to 0x0B in all live packets
  297. packet->setArrayDataByName("persist_success_timestamp", data.last_success_timestamp, i);
  298. packet->setArrayDataByName("persist_failure_timestamp", data.last_failure_timestamp, i);
  299. // Check min duration (last success + failure)
  300. //if (Timer::GetUnixTimeStamp() < data.last_success_timestamp + data.failure_lockout_time*/)
  301. //packet->setArrayDataByName("unknown3b", 1, i);
  302. packet->setArrayDataByName("unknown3b", 1, i);
  303. packet->setArrayDataByName("minimum_duration", data.failure_lockout_time, i);
  304. packet->setArrayDataByName("maximum_duration", data.success_lockout_time, i);
  305. packet->setArrayDataByName("unknown4a", 1800, i); // All live logs have 0x0708
  306. }
  307. client->QueuePacket(packet->serialize());
  308. }
  309. safe_delete(packet);
  310. }
  311. }
  312. void ClientPacketFunctions::SendMaintainedExamineUpdate(Client* client, int8 slot_pos, int32 update_value, int8 update_type){
  313. if (!client)
  314. return;
  315. PacketStruct* packet = configReader.getStruct("WS_UpdateMaintainedExamine", client->GetVersion());
  316. if (packet){
  317. packet->setSubstructDataByName("info_header", "show_name", 1);
  318. packet->setSubstructDataByName("info_header", "packettype", 19710);
  319. packet->setSubstructDataByName("info_header", "packetsubtype", 5);
  320. packet->setDataByName("time_stamp", Timer::GetCurrentTime2());
  321. packet->setDataByName("slot_pos", slot_pos);
  322. packet->setDataByName("update_value", update_value > 0 ? update_value : 0xFFFFFFFF);
  323. packet->setDataByName("update_type", update_type);
  324. client->QueuePacket(packet->serialize());
  325. safe_delete(packet);
  326. }
  327. }
  328. void ClientPacketFunctions::SendZoneChange(Client* client, char* zone_ip, int16 zone_port, int32 key) {
  329. if (!client)
  330. return;
  331. PacketStruct* packet = configReader.getStruct("WS_ZoneChangeMsg", client->GetVersion());
  332. if (packet) {
  333. packet->setDataByName("account_id", client->GetAccountID());
  334. packet->setDataByName("key", key);
  335. packet->setDataByName("ip_address", zone_ip);
  336. packet->setDataByName("port", zone_port);
  337. client->QueuePacket(packet->serialize());
  338. }
  339. safe_delete(packet);
  340. }
  341. void ClientPacketFunctions::SendStateCommand(Client* client, int32 spawn_id, int32 state) {
  342. if (!client || !spawn_id) {
  343. return;
  344. }
  345. PacketStruct* packet = configReader.getStruct("WS_StateCmd", client->GetVersion());
  346. if (packet) {
  347. packet->setDataByName("spawn_id", spawn_id);
  348. packet->setDataByName("state", state);
  349. client->QueuePacket(packet->serialize());
  350. }
  351. safe_delete(packet);
  352. }
  353. void ClientPacketFunctions::SendFlyMode(Client* client, int8 flymode, bool updateCharProperty)
  354. {
  355. if (updateCharProperty)
  356. database.insertCharacterProperty(client, CHAR_PROPERTY_FLYMODE, (char*)std::to_string(flymode).c_str());
  357. if(client->GetVersion() <= 546) {
  358. if(flymode) {
  359. // old flymode
  360. SendServerControlFlagsClassic(client, flymode, 1);
  361. if(flymode == 1) {
  362. // disable noclip
  363. SendServerControlFlagsClassic(client, 2, 0);
  364. }
  365. }
  366. else {
  367. // disable flymode and noclip
  368. SendServerControlFlagsClassic(client, 2, 0);
  369. SendServerControlFlagsClassic(client, 1, 0);
  370. }
  371. }
  372. else {
  373. if(flymode == 2) {
  374. // new flymode + noclip
  375. SendServerControlFlags(client, 5, 32, 1);
  376. SendServerControlFlags(client, 1, 2, 1);
  377. }
  378. else if(flymode == 1) {
  379. // new flymode
  380. SendServerControlFlags(client, 5, 32, 1);
  381. SendServerControlFlags(client, 1, 2, 0);
  382. }
  383. else {
  384. // disable flymode and noclip
  385. SendServerControlFlags(client, 5, 32, 0);
  386. SendServerControlFlags(client, 1, 2, 0);
  387. }
  388. }
  389. client->Message(CHANNEL_STATUS, "Flymode %s, No Clip %s", flymode > 0 ? "on" : "off", flymode > 1 ? "on" : "off");
  390. /*
  391. CLASSIC/DOF ONLY HAS THE FIRST SET OF FLAGS
  392. Some other values for this packet
  393. first param:
  394. 01 flymode
  395. 02 collisons off
  396. 04 unknown
  397. 08 forward movement
  398. 16 heading movement
  399. 32 low gravity
  400. 64 sit
  401. EVERYTHING BELOW NOT SUPPORTED BY CLASSIC/DOF
  402. second
  403. 2 crouch
  404. third:
  405. 04 float when trying to jump, no movement
  406. 08 jump high, no movement
  407. fourth:
  408. 04 autorun (fear?)
  409. 16 moon jumps
  410. 32 safe fall (float to ground)
  411. 64 cant move
  412. fifth:
  413. 01 die
  414. 08 hover (fae)
  415. 32 flymode2?
  416. */
  417. }