void Database::SendBody(Client *c, int MessageNumber) { int CharacterID = FindCharacter(c->MailBoxName().c_str()); _log(UCS__TRACE, "SendBody: MsgID %i, to %s, CharID is %i", MessageNumber, c->MailBoxName().c_str(), CharacterID); if(CharacterID <= 0) return; char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; MYSQL_RES *result; MYSQL_ROW row; if (!RunQuery(query,MakeAnyLenString(&query, "select `msgid`, `body`, `to` from `mail` " "where `charid`=%i and `msgid`=%i", CharacterID, MessageNumber), errbuf, &result)){ safe_delete_array(query); return ; } safe_delete_array(query); if (mysql_num_rows(result) != 1) { mysql_free_result(result); return; } row = mysql_fetch_row(result); _log(UCS__TRACE, "Message: %i body (%i bytes)", MessageNumber, strlen(row[1])); int PacketLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]); EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailSendBody,PacketLength); char *PacketBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber()); VARSTRUCT_ENCODE_STRING(PacketBuffer,row[0]); VARSTRUCT_ENCODE_STRING(PacketBuffer,row[1]); VARSTRUCT_ENCODE_STRING(PacketBuffer,"1"); VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0); VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0x0a); VARSTRUCT_ENCODE_STRING(PacketBuffer, "TO:"); PacketBuffer--; VARSTRUCT_ENCODE_STRING(PacketBuffer, row[2]); PacketBuffer--; // Overwrite the null terminator VARSTRUCT_ENCODE_TYPE(uint8, PacketBuffer, 0x0a); mysql_free_result(result); _pkt(UCS__PACKETS, outapp); c->QueuePacket(outapp); safe_delete(outapp); }
void Database::SendBody(Client *client, int messageNumber) { int characterID = FindCharacter(client->MailBoxName().c_str()); _log(UCS__TRACE, "SendBody: MsgID %i, to %s, CharID is %i", messageNumber, client->MailBoxName().c_str(), characterID); if(characterID <= 0) return; std::string query = StringFormat("SELECT `msgid`, `body`, `to` FROM `mail` " "WHERE `charid`=%i AND `msgid`=%i", characterID, messageNumber); auto results = QueryDatabase(query); if (!results.Success()) return; if (results.RowCount() != 1) return; auto row = results.begin(); _log(UCS__TRACE, "Message: %i body (%i bytes)", messageNumber, strlen(row[1])); int packetLength = 12 + strlen(row[0]) + strlen(row[1]) + strlen(row[2]); EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailSendBody,packetLength); char *packetBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber()); VARSTRUCT_ENCODE_STRING(packetBuffer,row[0]); VARSTRUCT_ENCODE_STRING(packetBuffer,row[1]); VARSTRUCT_ENCODE_STRING(packetBuffer,"1"); VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0); VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a); VARSTRUCT_ENCODE_STRING(packetBuffer, "TO:"); packetBuffer--; VARSTRUCT_ENCODE_STRING(packetBuffer, row[2]); packetBuffer--; // Overwrite the null terminator VARSTRUCT_ENCODE_TYPE(uint8, packetBuffer, 0x0a); _pkt(UCS__PACKETS, outapp); client->QueuePacket(outapp); safe_delete(outapp); }
void Database::SendHeaders(Client *c) { int UnknownField2 = 25015275; int UnknownField3 = 1; int CharacterID = FindCharacter(c->MailBoxName().c_str()); _log(UCS__TRACE, "Sendheaders for %s, CharID is %i", c->MailBoxName().c_str(), CharacterID); if(CharacterID <= 0) return; char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; MYSQL_RES *result; MYSQL_ROW row; if (!RunQuery(query,MakeAnyLenString(&query, "select `msgid`,`timestamp`,`from`,`subject`, `status` from `mail` " "where `charid`=%i", CharacterID),errbuf,&result)){ safe_delete_array(query); return ; } safe_delete_array(query); char Buf[100]; uint32 NumRows = mysql_num_rows(result); int HeaderCountPacketLength = 0; sprintf(Buf, "%i", c->GetMailBoxNumber()); HeaderCountPacketLength += (strlen(Buf) + 1); sprintf(Buf, "%i", UnknownField2); HeaderCountPacketLength += (strlen(Buf) + 1); sprintf(Buf, "%i", UnknownField3); HeaderCountPacketLength += (strlen(Buf) + 1); sprintf(Buf, "%i", NumRows); HeaderCountPacketLength += (strlen(Buf) + 1); EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailHeaderCount, HeaderCountPacketLength); char *PacketBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber()); VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField2); VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField3); VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, NumRows); _pkt(UCS__PACKETS, outapp); c->QueuePacket(outapp); safe_delete(outapp); int RowNum = 0; while((row = mysql_fetch_row(result))) { int HeaderPacketLength = 0; sprintf(Buf, "%i", c->GetMailBoxNumber()); HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1; sprintf(Buf, "%i", UnknownField2); HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1; sprintf(Buf, "%i", RowNum); HeaderPacketLength = HeaderPacketLength + strlen(Buf) + 1; HeaderPacketLength = HeaderPacketLength + strlen(row[0]) + 1; HeaderPacketLength = HeaderPacketLength + strlen(row[1]) + 1; HeaderPacketLength = HeaderPacketLength + strlen(row[4]) + 1; HeaderPacketLength = HeaderPacketLength + GetMailPrefix().length() + strlen(row[2]) + 1; HeaderPacketLength = HeaderPacketLength + strlen(row[3]) + 1; outapp = new EQApplicationPacket(OP_MailHeader, HeaderPacketLength); PacketBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, c->GetMailBoxNumber()); VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, UnknownField2); VARSTRUCT_ENCODE_INTSTRING(PacketBuffer, RowNum); VARSTRUCT_ENCODE_STRING(PacketBuffer, row[0]); VARSTRUCT_ENCODE_STRING(PacketBuffer, row[1]); VARSTRUCT_ENCODE_STRING(PacketBuffer, row[4]); VARSTRUCT_ENCODE_STRING(PacketBuffer, GetMailPrefix().c_str()); PacketBuffer--; VARSTRUCT_ENCODE_STRING(PacketBuffer, row[2]); VARSTRUCT_ENCODE_STRING(PacketBuffer, row[3]); _pkt(UCS__PACKETS, outapp); c->QueuePacket(outapp); safe_delete(outapp); RowNum++; } mysql_free_result(result); }
void Database::SendHeaders(Client *client) { int unknownField2 = 25015275; int unknownField3 = 1; int characterID = FindCharacter(client->MailBoxName().c_str()); _log(UCS__TRACE, "Sendheaders for %s, CharID is %i", client->MailBoxName().c_str(), characterID); if(characterID <= 0) return; std::string query = StringFormat("SELECT `msgid`,`timestamp`, `from`, `subject`, `status` " "FROM `mail` WHERE `charid`=%i", characterID); auto results = QueryDatabase(query); if (!results.Success()) return; char buffer[100]; int headerCountPacketLength = 0; sprintf(buffer, "%i", client->GetMailBoxNumber()); headerCountPacketLength += (strlen(buffer) + 1); sprintf(buffer, "%i", unknownField2); headerCountPacketLength += (strlen(buffer) + 1); sprintf(buffer, "%i", unknownField3); headerCountPacketLength += (strlen(buffer) + 1); sprintf(buffer, "%i", results.RowCount()); headerCountPacketLength += (strlen(buffer) + 1); EQApplicationPacket *outapp = new EQApplicationPacket(OP_MailHeaderCount, headerCountPacketLength); char *packetBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber()); VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2); VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField3); VARSTRUCT_ENCODE_INTSTRING(packetBuffer, results.RowCount()); _pkt(UCS__PACKETS, outapp); client->QueuePacket(outapp); safe_delete(outapp); int rowIndex = 0; for(auto row = results.begin(); row != results.end(); ++row, ++rowIndex) { int headerPacketLength = 0; sprintf(buffer, "%i", client->GetMailBoxNumber()); headerPacketLength += strlen(buffer) + 1; sprintf(buffer, "%i", unknownField2); headerPacketLength += strlen(buffer) + 1; sprintf(buffer, "%i", rowIndex); headerPacketLength += strlen(buffer) + 1; headerPacketLength += strlen(row[0]) + 1; headerPacketLength += strlen(row[1]) + 1; headerPacketLength += strlen(row[4]) + 1; headerPacketLength += GetMailPrefix().length() + strlen(row[2]) + 1; headerPacketLength += strlen(row[3]) + 1; outapp = new EQApplicationPacket(OP_MailHeader, headerPacketLength); packetBuffer = (char *)outapp->pBuffer; VARSTRUCT_ENCODE_INTSTRING(packetBuffer, client->GetMailBoxNumber()); VARSTRUCT_ENCODE_INTSTRING(packetBuffer, unknownField2); VARSTRUCT_ENCODE_INTSTRING(packetBuffer, rowIndex); VARSTRUCT_ENCODE_STRING(packetBuffer, row[0]); VARSTRUCT_ENCODE_STRING(packetBuffer, row[1]); VARSTRUCT_ENCODE_STRING(packetBuffer, row[4]); VARSTRUCT_ENCODE_STRING(packetBuffer, GetMailPrefix().c_str()); packetBuffer--; VARSTRUCT_ENCODE_STRING(packetBuffer, row[2]); VARSTRUCT_ENCODE_STRING(packetBuffer, row[3]); _pkt(UCS__PACKETS, outapp); client->QueuePacket(outapp); safe_delete(outapp); } }