/* ProcessAction.cpp Process actions performed by the client and respond accordingly Written by scottgl */ /* #include "Main.h" void Instance::ProcessSetSecondary(int ID, unsigned char *d, int dataSize) { //just for debugging, response packet not yet implemented if (dataSize == 7) { gCoreLog.Write(OPT_DEBUG_LEVEL, "Setting secondary profession to: "); switch (d[6]) { case 0: gCoreLog.debug("none"); break; case 1: gCoreLog.debug("Warrior"); break; case 3: gCoreLog.debug("Monk"); break; case 4: gCoreLog.debug("Necromancer"); break; case 5: gCoreLog.debug("Mesmer"); break; case 6: gCoreLog.debug("Elementalist"); break; } } } // add or remove gold amount to/from client's inventory // if add == true, add amount. if add == false, remove amount // STATUS: working void Instance::ProcessGold(unsigned int amount, unsigned char inventoryID, int ID, bool add) { unsigned char retp[22]; memset(&retp[0], 0, 22); if (add == true) // add gold to inventory { retp[0x00] = WITHDRAW_GOLD_SVR1; retp[0x08] = WITHDRAW_GOLD_SVR2; } else // remove gold from inventory { retp[0x00] = DEPOSIT_GOLD_SVR1; retp[0x08] = DEPOSIT_GOLD_SVR2; } // this is the byte used in packet headers throughout CharInfo, the format is // 17 01 XX 00 where XX is the byte that is assigned below. I think it is for // inventory identification, and is used in trading in a district. retp[0x02] = retp[0x0A] = inventoryID; retp[0x01] = retp[0x09] = 0x01; // amount is a 4-byte value which says how much gold to add or remove memcpy(&retp[0x04], &amount, 4); memcpy(&retp[0x0C], &amount, 4); // below is for CUP packet appended to the end retp[0x10] = 0x10; retp[0x12] = 0xFA; NetMessage s(retp, 22, ID); gpGameServer->SendData(&s); } // process item deletion from inventory (possibly from storage also) // packet received from client = 6 bytes, sent to client = 14 bytes // STATUS: working void Instance::ProcessItemDelete(unsigned char inventoryID, int ID, unsigned char *d, int size) { unsigned char retp[14]; memset(retp, 0, 14); memcpy(&retp[3], &d[1], 5); // packet from client is used to build return packet // return packet header retp[0x0] = DELETE_ITEM_SVR; retp[0x1] = 0x01; // this is the byte used in packet headers throughout CharInfo, the format is // 17 01 XX 00 where XX is the byte that is assigned below. I think it is for // inventory identification, and is used in trading in a district. retp[0x2] = inventoryID; // below is for CUP packet appended to the end retp[0x8] = 0x10; retp[0xA] = 0xFA; NetMessage s(retp, 14, ID); gpGameServer->SendData(&s); } // process item move in the inventory (possibly in storage also) // packet received from client = 9 bytes, sent to client = 17 bytes // STATUS: working void Instance::ProcessItemMove(unsigned char inventoryID, int ID, unsigned char *d, int size) { unsigned char retp[17]; memset(retp, 0, 17); memcpy(&retp[3], &d[1], 8); // packet from client is used to build return packet // return packet header retp[0x0] = MOVE_ITEM_SVR; retp[0x1] = 0x01; // this is the byte used in packet headers throughout CharInfo, the format is // 17 01 XX 00 where XX is the byte that is assigned below. I think it is for // inventory identification, and is used in trading in a district. retp[0x2] = inventoryID; // below is for CUP packet appended to the end retp[0xB] = 0x10; retp[0xD] = 0xFA; NetMessage s(retp, 17, ID); gpGameServer->SendData(&s); } // Process movement of skills // STATUS: working void Instance::ProcessSkillMove(int ID, unsigned char *d, int dataSize) { if (dataSize != 18) return; unsigned char retp[19]; memset(&retp[0], 0, 19); //copy relevant data from received packet memcpy(&retp[0], &d[0], 7); memcpy(&retp[0x7], &d[0xA], 8); retp[0x00] = MOVE_SKILL_SVR; // below is for CUP packet appended to the end retp[0xD] = 0x10; retp[0xF] = 0xFA; NetMessage s = NetMessage(retp, 19, ID); gpGameServer->SendData(&s); } // Process movement of the player // STATUS: partially working void Instance::ProcessMove(int ID, unsigned char *d, int size, unsigned short zone, unsigned char localID, unsigned long spawnID) {/* if (spawnID == -1) return; int pos = this->FindPlayerByNID(ID); Player *p = &this->players[pos]; NetMessage s; s.ID = ID; unsigned char retp[29]; memset(&retp[0], 0, 29); unsigned short cup_rate = 500; float posx, posy, posz; float deltax, deltay, deltaz; float destx, desty, destz; switch (d[0]) { case MOVE_UPDATE: // periodically updated while client is moving, working memcpy(&posx, &d[0x2], 4); memcpy(&posy, &d[0x6], 4); memcpy(&posz, &d[0xA], 4); memcpy(&deltax, &d[0xE], 4); memcpy(&deltay, &d[0x12], 4); memcpy(&deltaz, &d[0x16], 4); destx = posx + deltax; desty = posy + deltay; destz = posz + deltaz; memcpy(&retp[0x2], &spawnID, 4); memcpy(&retp[0x6], &destx, 4); memcpy(&retp[0xA], &desty, 4); memcpy(&retp[0xE], &destz, 4); retp[0] = MOVE_UPDATE_SVR; retp[0x12] = 0x01; s.data = retp; s.dataSize = 20; CoreLog.LogUnknownPacket(s.data, s.dataSize); GameServer->SendData(&s); CoreLog.debug("Updating client position"); break; // move to location clicked by mouse, working case MOVE_TO_CLICK: memcpy(&retp[0xC], &d[2], 12); retp[0x00] = UPDATE_CLIENT_SVR; //this is probably the cup rate memcpy(&retp[2], &cup_rate, 2); //below seems to be static (signifies a move command) retp[6] = 0x1B; //these two bytes are the zone ID //memcpy(&retp[7], &zone, 2); //retp[7] = 0x00; //retp[8] = 0x49; /*0x33;*/ //NPC ID /* retp[7] = 0x00; memcpy(&retp[8], &spawnID, 4); s.data = retp; s.dataSize = 24; GameServer->SendData(&s); CoreLog.debug("Moving to location clicked by mouse"); break; case MOVE_ROTATE: retp[0] = MOVE_ROTATE_SVR; memcpy(&retp[2], &spawnID, 4); memcpy(&retp[6], &d[2], 4); //below seems to be static (not sure what it means) retp[0xA] = 0x92; retp[0xB] = 0x0A; retp[0xC] = 0x06; retp[0xD] = 0x40; s.data = retp; s.dataSize = 14; CoreLog.LogUnknownPacket(s.data, s.dataSize); GameServer->SendData(&s); CoreLog.debug("Client is performing a rotation"); break; // let the server know the player has released a key (working) case MOVE_RELEASE: retp[0] = MOVE_RELEASE_SVR; //below seems to be static (not sure what it means) retp[8] = 0x80; retp[9] = 0x3F; retp[10] = 0x09; retp[11] = 0x1B; memcpy(&retp[2], &spawnID, 4); memcpy(&retp[13], &spawnID, 4); memcpy(&retp[17], &d[2], 12); s.data = retp; s.dataSize = 29; CoreLog.LogUnknownPacket(s.data, s.dataSize); GameServer->SendData(&s); break; } */ //} /* void Instance::ProcessTargetNPC(int ID, unsigned char *d, int dataSize, int localID) { gCoreLog.debug("Selecting NPC with ID: %d", d[2]); if (dataSize != 6) { //send out the "I'm talking to X" message in team chat unsigned char *retp = new unsigned char[dataSize+5]; memset(&retp[0], 0, dataSize+5); retp[0] = CHAT_RESPONSE_SVR; memcpy(&retp[2], &d[8], 16); retp[0x12] = CHAT_RESPONSE_CMD; retp[0x14] = localID; retp[0x16] = TEAM_CHAT; //data below is appended to the end of most action return packets retp[0x17] = 0x10; retp[0x19] = 0xFA; NetMessage s(retp, dataSize + 5, ID); gpGameServer->SendData(&s); Sleep(10); delete retp; } } // Process compass ping and distribute to team members // STATUS: working (only debug output for now) void Instance::ProcessCompass(unsigned char action, int ID, int x, int y, int countdown) { gCoreLog.debug("Compass ping, countdown: %d", countdown); //positioning is relative to north gCoreLog.debug("X position: %d Y position: %d", x, y); } // client is sending an attribute to team chat such as health, energy weapon stats, skill list // STATUS: working void Instance::ProcessTeamAction(int ID, unsigned char localID, int dataSize, unsigned char *d) { NetMessage s; CompiledPacket pck; unsigned char pktend[11]; memset(pktend, 0, 11); //response packet is for team chat d[0] = CHAT_RESPONSE_SVR; // build the data appended to the end of the received packet pktend[0] = CHAT_RESPONSE_CMD; pktend[2] = localID; pktend[4] = TEAM_CHAT; // below is for CUP packet appended to the end pktend[5] = 0x10; pktend[7] = 0xFA; // data appended to the received packet has a different offset if the user // requested energy or health, so move pktend back by 6 if (dataSize == ATTRIB_TEAM_EORH) { memcpy(&d[dataSize-6], pktend, 6); pck.Add(d, dataSize, false); pck.Add(&pktend[6], 11-6, false); } // if the received request is not for health or energy, then append pktend // to the very end of the received packet else { pck.Add(d, dataSize, false); pck.Add(pktend, 11, false); } s.networkId = ID; s.pData=pck.GetString(&s.dataSize); gpGameServer->SendData(&s); //sending some attribute to team chat such as health, energy, exp, or weapon (for debugging) switch (dataSize) { case ATTRIB_TEAM_EXP: //send exp info gCoreLog.debug("Experience"); break; case ATTRIB_TEAM_EORH: //send health or energy info switch (d[6]) { case ATTRIB_TEAM_ENERGY: // sent energy amount gCoreLog.debug("Energy"); break; case ATTRIB_TEAM_HEALTH: // sent Health amount gCoreLog.debug("Health"); break; } gCoreLog.debug("Sending from Player ID: %d", localID); break; default: //sent weapon attributes or skill list (dynamic packet size) gCoreLog.debug("Weapon attributes or skill list"); break; } } // client is attempting a map travel, currently does not work // STATUS: not working void Instance::ProcessMapTravel(unsigned char action, int ID) { gCoreLog.debug("attempting map travel"); unsigned char retp[10] = {0x03, 0, 0x06, 0, 0, 0, 0, 0, 0, 0}; NetMessage s(retp, 10, ID); gpGameServer->SendData(&s); } // process action which involves local district // STATUS: working (only displays debug info for now) void Instance::ProcessLocalAction(unsigned char action, int ID, unsigned char type, unsigned char dataSize, char *str) { if (action == SEEK_PARTY) { gCoreLog.Write(OPT_DEBUG_LEVEL, "seeking party, type: "); switch (type) { case SEEK_PARTY_HUNT: gCoreLog.debug("Hunting"); break; case SEEK_PARTY_MISSION: gCoreLog.debug("Mission"); break; case SEEK_PARTY_QUEST: gCoreLog.debug("Quest"); break; case SEEK_PARTY_TRADE: gCoreLog.debug("Trade"); break; case SEEK_PARTY_GUILD: gCoreLog.debug("Guild"); break; } gCoreLog.debug("String length: "); gCoreLog.debug("Description: "); if (dataSize == 7){/* log << "(description is empty)" << ;*///} /*else { Util::StripUnicode(str); } } // 2 byte packet else if (action == UNSEEK_PARTY) { gCoreLog.debug("no longer seeking party"); } } */