Refactor client cross zone message helpers

Remove extra cross zone message server opcode and struct. Existing
function already exists for normal messages

Group CZClientMessageString struct with other CZ structs
This commit is contained in:
hg 2020-06-30 21:34:50 -04:00
parent e99528fe73
commit 184ea679f2
9 changed files with 54 additions and 75 deletions

View File

@ -282,8 +282,7 @@
#define ServerOP_CZTaskRemoveGroup 0x4560 #define ServerOP_CZTaskRemoveGroup 0x4560
#define ServerOP_CZTaskRemoveRaid 0x4561 #define ServerOP_CZTaskRemoveRaid 0x4561
#define ServerOP_CZTaskRemoveGuild 0x4562 #define ServerOP_CZTaskRemoveGuild 0x4562
#define ServerOP_CZClientMessage 0x4563 #define ServerOP_CZClientMessageString 0x4563
#define ServerOP_CZClientMessageString 0x4564
#define ServerOP_WWAssignTask 0x4750 #define ServerOP_WWAssignTask 0x4750
#define ServerOP_WWCastSpell 0x4751 #define ServerOP_WWCastSpell 0x4751
@ -1460,6 +1459,14 @@ struct CZNPCSignal_Struct {
uint32 signal; uint32 signal;
}; };
struct CZClientMessageString_Struct {
uint32 string_id;
uint16 chat_type;
char character_name[64];
uint32 args_size;
char args[1]; // null delimited
};
struct CZClientSignalByName_Struct { struct CZClientSignalByName_Struct {
char character_name[64]; char character_name[64];
uint32 signal; uint32 signal;
@ -1985,21 +1992,6 @@ struct UCSServerStatus_Struct {
}; };
}; };
struct ServerCZClientMessage_Struct {
uint16 chat_type;
char character_name[64];
uint32 message_size;
char message[1];
};
struct ServerCZClientMessageString_Struct {
uint32 string_id;
uint16 chat_type;
char character_name[64];
uint32 string_params_size;
char string_params[1]; // null delimited
};
struct ServerExpeditionID_Struct { struct ServerExpeditionID_Struct {
uint32 expedition_id; uint32 expedition_id;
uint32 sender_zone_id; uint32 sender_zone_id;

View File

@ -1356,15 +1356,9 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) {
cle->ProcessTellQueue(); cle->ProcessTellQueue();
break; break;
} }
case ServerOP_CZClientMessage:
{
auto buf = reinterpret_cast<ServerCZClientMessage_Struct*>(pack->pBuffer);
client_list.SendPacket(buf->character_name, pack);
break;
}
case ServerOP_CZClientMessageString: case ServerOP_CZClientMessageString:
{ {
auto buf = reinterpret_cast<ServerCZClientMessageString_Struct*>(pack->pBuffer); auto buf = reinterpret_cast<CZClientMessageString_Struct*>(pack->pBuffer);
client_list.SendPacket(buf->character_name, pack); client_list.SendPacket(buf->character_name, pack);
break; break;
} }

View File

@ -3207,22 +3207,22 @@ void Client::MessageString(uint32 type, uint32 string_id, const char* message1,
safe_delete(outapp); safe_delete(outapp);
} }
void Client::MessageString(const ServerCZClientMessageString_Struct* msg) void Client::MessageString(const CZClientMessageString_Struct* msg)
{ {
if (msg) if (msg)
{ {
if (msg->string_params_size == 0) if (msg->args_size == 0)
{ {
MessageString(msg->chat_type, msg->string_id); MessageString(msg->chat_type, msg->string_id);
} }
else else
{ {
uint32_t outsize = sizeof(FormattedMessage_Struct) + msg->string_params_size; uint32_t outsize = sizeof(FormattedMessage_Struct) + msg->args_size;
auto outapp = std::unique_ptr<EQApplicationPacket>(new EQApplicationPacket(OP_FormattedMessage, outsize)); auto outapp = std::unique_ptr<EQApplicationPacket>(new EQApplicationPacket(OP_FormattedMessage, outsize));
auto outbuf = reinterpret_cast<FormattedMessage_Struct*>(outapp->pBuffer); auto outbuf = reinterpret_cast<FormattedMessage_Struct*>(outapp->pBuffer);
outbuf->string_id = msg->string_id; outbuf->string_id = msg->string_id;
outbuf->type = msg->chat_type; outbuf->type = msg->chat_type;
memcpy(outbuf->message, msg->string_params, msg->string_params_size); memcpy(outbuf->message, msg->args, msg->args_size);
QueuePacket(outapp.get()); QueuePacket(outapp.get());
} }
} }
@ -9496,7 +9496,7 @@ void Client::SendCrossZoneMessage(
Client* client, const std::string& character_name, uint16_t chat_type, const std::string& message) Client* client, const std::string& character_name, uint16_t chat_type, const std::string& message)
{ {
// if client is null, falls back to sending a cross zone message by name // if client is null, falls back to sending a cross zone message by name
if (!client) if (!client && !character_name.empty())
{ {
client = entity_list.GetClientByName(character_name.c_str()); client = entity_list.GetClientByName(character_name.c_str());
} }
@ -9505,16 +9505,14 @@ void Client::SendCrossZoneMessage(
{ {
client->Message(chat_type, message.c_str()); client->Message(chat_type, message.c_str());
} }
else if (message.size() > 0) else if (!character_name.empty() && !message.empty())
{ {
uint32_t msg_size = static_cast<uint32_t>(message.size()) + 1; uint32_t pack_size = sizeof(CZMessagePlayer_Struct);
uint32_t pack_size = sizeof(ServerCZClientMessage_Struct) + msg_size; auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_CZMessagePlayer, pack_size));
auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_CZClientMessage, pack_size)); auto buf = reinterpret_cast<CZMessagePlayer_Struct*>(pack->pBuffer);
auto buf = reinterpret_cast<ServerCZClientMessage_Struct*>(pack->pBuffer); buf->type = chat_type;
buf->chat_type = chat_type;
strn0cpy(buf->character_name, character_name.c_str(), sizeof(buf->character_name)); strn0cpy(buf->character_name, character_name.c_str(), sizeof(buf->character_name));
buf->message_size = msg_size; strn0cpy(buf->message, message.c_str(), sizeof(buf->message));
strn0cpy(buf->message, message.c_str(), buf->message_size);
worldserver.SendPacket(pack.get()); worldserver.SendPacket(pack.get());
} }
@ -9522,32 +9520,35 @@ void Client::SendCrossZoneMessage(
void Client::SendCrossZoneMessageString( void Client::SendCrossZoneMessageString(
Client* client, const std::string& character_name, uint16_t chat_type, Client* client, const std::string& character_name, uint16_t chat_type,
uint32_t string_id, const std::initializer_list<std::string>& parameters) uint32_t string_id, const std::initializer_list<std::string>& arguments)
{ {
// if client is null, falls back to sending a cross zone message by name // if client is null, falls back to sending a cross zone message by name
SerializeBuffer parameter_buffer; if (!client && !character_name.empty()) // double check client isn't in this zone
for (const auto& parameter : parameters)
{
parameter_buffer.WriteString(parameter);
}
uint32_t pack_size = sizeof(ServerCZClientMessageString_Struct) + static_cast<uint32_t>(parameter_buffer.size());
auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_CZClientMessageString, pack_size));
auto buf = reinterpret_cast<ServerCZClientMessageString_Struct*>(pack->pBuffer);
buf->string_id = string_id;
buf->chat_type = chat_type;
strn0cpy(buf->character_name, character_name.c_str(), sizeof(buf->character_name));
buf->string_params_size = static_cast<uint32_t>(parameter_buffer.size());
buf->string_params[0] = '\0';
if (parameter_buffer.size()) {
memcpy(buf->string_params, parameter_buffer.buffer(), parameter_buffer.size());
}
if (!client) // double check client isn't in this zone
{ {
client = entity_list.GetClientByName(character_name.c_str()); client = entity_list.GetClientByName(character_name.c_str());
} }
if (!client && character_name.empty())
{
return;
}
SerializeBuffer argument_buffer;
for (const auto& argument : arguments)
{
argument_buffer.WriteString(argument);
}
uint32_t args_size = static_cast<uint32_t>(argument_buffer.size());
uint32_t pack_size = sizeof(CZClientMessageString_Struct) + args_size;
auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_CZClientMessageString, pack_size));
auto buf = reinterpret_cast<CZClientMessageString_Struct*>(pack->pBuffer);
buf->string_id = string_id;
buf->chat_type = chat_type;
strn0cpy(buf->character_name, character_name.c_str(), sizeof(buf->character_name));
buf->args_size = args_size;
memcpy(buf->args, argument_buffer.buffer(), argument_buffer.size());
if (client) if (client)
{ {
client->MessageString(buf); client->MessageString(buf);

View File

@ -288,7 +288,7 @@ public:
uint8 SlotConvert(uint8 slot,bool bracer=false); uint8 SlotConvert(uint8 slot,bool bracer=false);
void MessageString(uint32 type, uint32 string_id, uint32 distance = 0); void MessageString(uint32 type, uint32 string_id, uint32 distance = 0);
void MessageString(uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0); void MessageString(uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0);
void MessageString(const ServerCZClientMessageString_Struct* msg); void MessageString(const CZClientMessageString_Struct* msg);
bool FilteredMessageCheck(Mob *sender, eqFilterType filter); bool FilteredMessageCheck(Mob *sender, eqFilterType filter);
void FilteredMessageString(Mob *sender, uint32 type, eqFilterType filter, uint32 string_id); void FilteredMessageString(Mob *sender, uint32 type, eqFilterType filter, uint32 string_id);
void FilteredMessageString(Mob *sender, uint32 type, eqFilterType filter, void FilteredMessageString(Mob *sender, uint32 type, eqFilterType filter,
@ -1115,7 +1115,7 @@ public:
Client* client, const std::string& client_name, uint16_t chat_type, const std::string& message); Client* client, const std::string& client_name, uint16_t chat_type, const std::string& message);
static void SendCrossZoneMessageString( static void SendCrossZoneMessageString(
Client* client, const std::string& client_name, uint16_t chat_type, Client* client, const std::string& client_name, uint16_t chat_type,
uint32_t string_id, const std::initializer_list<std::string>& parameters = {}); uint32_t string_id, const std::initializer_list<std::string>& arguments = {});
void AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db = false, bool update_client = true); void AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db = false, bool update_client = true);
void AddNewExpeditionLockout( void AddNewExpeditionLockout(

View File

@ -682,9 +682,9 @@ void Expedition::SendClientExpeditionInvite(
} }
void Expedition::SendLeaderMessage( void Expedition::SendLeaderMessage(
Client* leader_client, uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& parameters) Client* leader_client, uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& args)
{ {
Client::SendCrossZoneMessageString(leader_client, m_leader.name, chat_type, string_id, parameters); Client::SendCrossZoneMessageString(leader_client, m_leader.name, chat_type, string_id, args);
} }
bool Expedition::ProcessAddConflicts(Client* leader_client, Client* add_client, bool swapping) bool Expedition::ProcessAddConflicts(Client* leader_client, Client* add_client, bool swapping)

View File

@ -157,7 +157,8 @@ private:
void SaveLockouts(ExpeditionRequest& request); void SaveLockouts(ExpeditionRequest& request);
void SaveMembers(ExpeditionRequest& request); void SaveMembers(ExpeditionRequest& request);
void SendClientExpeditionInvite(Client* client, const std::string& inviter_name, const std::string& swap_remove_name); void SendClientExpeditionInvite(Client* client, const std::string& inviter_name, const std::string& swap_remove_name);
void SendLeaderMessage(Client* leader_client, uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& parameters = {}); void SendLeaderMessage(Client* leader_client, uint16_t chat_type, uint32_t string_id,
const std::initializer_list<std::string>& args = {});
void SendUpdatesToZoneMembers(bool clear = false, bool message_on_clear = true); void SendUpdatesToZoneMembers(bool clear = false, bool message_on_clear = true);
void SendWorldDzLocationUpdate(uint16_t server_opcode, const DynamicZoneLocation& location); void SendWorldDzLocationUpdate(uint16_t server_opcode, const DynamicZoneLocation& location);
void SendWorldExpeditionUpdate(uint16_t server_opcode); void SendWorldExpeditionUpdate(uint16_t server_opcode);

View File

@ -285,11 +285,11 @@ bool ExpeditionRequest::CheckMembersForConflicts(const std::vector<std::string>&
} }
void ExpeditionRequest::SendLeaderMessage( void ExpeditionRequest::SendLeaderMessage(
uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& parameters) uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& args)
{ {
if (!m_disable_messages) if (!m_disable_messages)
{ {
Client::SendCrossZoneMessageString(m_leader, m_leader_name, chat_type, string_id, parameters); Client::SendCrossZoneMessageString(m_leader, m_leader_name, chat_type, string_id, args);
} }
} }

View File

@ -63,7 +63,7 @@ private:
void SendLeaderMemberInExpedition(const std::string& member_name, bool is_solo); void SendLeaderMemberInExpedition(const std::string& member_name, bool is_solo);
void SendLeaderMemberReplayLockout(const std::string& member_name, const ExpeditionLockoutTimer& lockout, bool is_solo); void SendLeaderMemberReplayLockout(const std::string& member_name, const ExpeditionLockoutTimer& lockout, bool is_solo);
void SendLeaderMemberEventLockout(const std::string& member_name, const ExpeditionLockoutTimer& lockout); void SendLeaderMemberEventLockout(const std::string& member_name, const ExpeditionLockoutTimer& lockout);
void SendLeaderMessage(uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& parameters = {}); void SendLeaderMessage(uint16_t chat_type, uint32_t string_id, const std::initializer_list<std::string>& args = {});
Client* m_requester = nullptr; Client* m_requester = nullptr;
Client* m_leader = nullptr; Client* m_leader = nullptr;

View File

@ -2881,18 +2881,9 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
} }
break; break;
} }
case ServerOP_CZClientMessage:
{
auto buf = reinterpret_cast<ServerCZClientMessage_Struct*>(pack->pBuffer);
Client* client = entity_list.GetClientByName(buf->character_name);
if (client) {
client->Message(buf->chat_type, buf->message);
}
break;
}
case ServerOP_CZClientMessageString: case ServerOP_CZClientMessageString:
{ {
auto buf = reinterpret_cast<ServerCZClientMessageString_Struct*>(pack->pBuffer); auto buf = reinterpret_cast<CZClientMessageString_Struct*>(pack->pBuffer);
Client* client = entity_list.GetClientByName(buf->character_name); Client* client = entity_list.GetClientByName(buf->character_name);
if (client) { if (client) {
client->MessageString(buf); client->MessageString(buf);