Replace the usage of RakString (#648)

This commit is contained in:
Jett 2022-07-17 04:40:46 +01:00 committed by GitHub
parent 9287e5bc4b
commit 77d35019cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 91 additions and 48 deletions

View File

@ -123,7 +123,7 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
requestee.reset(new PlayerData()); requestee.reset(new PlayerData());
// Setup the needed info since you can add a best friend offline. // Setup the needed info since you can add a best friend offline.
requestee->playerID = friendDataCandidate.friendID; requestee->playerID = friendDataCandidate.friendID;
requestee->playerName = RakNet::RakString(friendDataCandidate.friendName.c_str()); requestee->playerName = friendDataCandidate.friendName;
requestee->zoneID = LWOZONEID(); requestee->zoneID = LWOZONEID();
FriendData requesteeFriendData{}; FriendData requesteeFriendData{};
@ -147,7 +147,7 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
std::unique_ptr<sql::ResultSet> result(nameQuery->executeQuery()); std::unique_ptr<sql::ResultSet> result(nameQuery->executeQuery());
requestee.reset(new PlayerData()); requestee.reset(new PlayerData());
requestee->playerName = RakNet::RakString(playerName.c_str()); requestee->playerName = playerName;
SendFriendResponse(requestor, requestee.get(), result->next() ? AddFriendResponseType::NOTONLINE : AddFriendResponseType::INVALIDCHARACTER); SendFriendResponse(requestor, requestee.get(), result->next() ? AddFriendResponseType::NOTONLINE : AddFriendResponseType::INVALIDCHARACTER);
return; return;
@ -384,7 +384,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet)
if (playerContainer.GetIsMuted(sender)) return; if (playerContainer.GetIsMuted(sender)) return;
const auto senderName = std::string(sender->playerName.C_String()); const auto senderName = std::string(sender->playerName.c_str());
inStream.SetReadOffset(0x14 * 8); inStream.SetReadOffset(0x14 * 8);
@ -407,7 +407,7 @@ void ChatPacketHandler::HandleChatMessage(Packet* packet)
if (otherMember == nullptr) return; if (otherMember == nullptr) return;
const auto otherName = std::string(otherMember->playerName.C_String()); const auto otherName = std::string(otherMember->playerName.c_str());
CBITSTREAM; CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_ROUTE_TO_PLAYER); PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_ROUTE_TO_PLAYER);
@ -443,8 +443,8 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
if (playerContainer.GetIsMuted(goonA)) return; if (playerContainer.GetIsMuted(goonA)) return;
std::string goonAName = goonA->playerName.C_String(); std::string goonAName = goonA->playerName.c_str();
std::string goonBName = goonB->playerName.C_String(); std::string goonBName = goonB->playerName.c_str();
//To the sender: //To the sender:
{ {
@ -720,7 +720,7 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet)
playerContainer.TeamStatusUpdate(team); playerContainer.TeamStatusUpdate(team);
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.C_String())); const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.c_str()));
for (const auto memberId : team->memberIDs) for (const auto memberId : team->memberIDs)
{ {
@ -750,7 +750,7 @@ void ChatPacketHandler::SendTeamInvite(PlayerData* receiver, PlayerData* sender)
//portion that will get routed: //portion that will get routed:
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_TEAM_INVITE); PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_TEAM_INVITE);
PacketUtils::WritePacketWString(sender->playerName.C_String(), 33, &bitStream); PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
bitStream.Write(sender->playerID); bitStream.Write(sender->playerID);
SystemAddress sysAddr = receiver->sysAddr; SystemAddress sysAddr = receiver->sysAddr;
@ -936,7 +936,7 @@ void ChatPacketHandler::SendFriendUpdate(PlayerData* friendData, PlayerData* pla
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_UPDATE_FRIEND_NOTIFY); PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_UPDATE_FRIEND_NOTIFY);
bitStream.Write<uint8_t>(notifyType); bitStream.Write<uint8_t>(notifyType);
std::string playerName = playerData->playerName.C_String(); std::string playerName = playerData->playerName.c_str();
PacketUtils::WritePacketWString(playerName, 33, &bitStream); PacketUtils::WritePacketWString(playerName, 33, &bitStream);
@ -976,7 +976,7 @@ void ChatPacketHandler::SendFriendRequest(PlayerData* receiver, PlayerData* send
//portion that will get routed: //portion that will get routed:
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_ADD_FRIEND_REQUEST); PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_ADD_FRIEND_REQUEST);
PacketUtils::WritePacketWString(sender->playerName.C_String(), 33, &bitStream); PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
bitStream.Write<uint8_t>(0); // This is a BFF flag however this is unused in live and does not have an implementation client side. bitStream.Write<uint8_t>(0); // This is a BFF flag however this is unused in live and does not have an implementation client side.
SystemAddress sysAddr = receiver->sysAddr; SystemAddress sysAddr = receiver->sysAddr;
@ -996,7 +996,7 @@ void ChatPacketHandler::SendFriendResponse(PlayerData* receiver, PlayerData* sen
// For all requests besides accepted, write a flag that says whether or not we are already best friends with the receiver. // For all requests besides accepted, write a flag that says whether or not we are already best friends with the receiver.
bitStream.Write<uint8_t>(responseCode != AddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender->sysAddr != UNASSIGNED_SYSTEM_ADDRESS); bitStream.Write<uint8_t>(responseCode != AddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender->sysAddr != UNASSIGNED_SYSTEM_ADDRESS);
// Then write the player name // Then write the player name
PacketUtils::WritePacketWString(sender->playerName.C_String(), 33, &bitStream); PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
// Then if this is an acceptance code, write the following extra info. // Then if this is an acceptance code, write the following extra info.
if (responseCode == AddFriendResponseType::ACCEPTED) { if (responseCode == AddFriendResponseType::ACCEPTED) {
bitStream.Write(sender->playerID); bitStream.Write(sender->playerID);

View File

@ -20,17 +20,25 @@ PlayerContainer::~PlayerContainer() {
void PlayerContainer::InsertPlayer(Packet* packet) { void PlayerContainer::InsertPlayer(Packet* packet) {
CINSTREAM; CINSTREAM;
PlayerData* data = new PlayerData(); PlayerData* data = new PlayerData();
inStream.SetReadOffset(inStream.GetReadOffset() + 64);
inStream.Read(data->playerID); inStream.Read(data->playerID);
inStream.Read(data->playerID);
inStream.Read(data->playerName); uint32_t len;
inStream.Read<uint32_t>(len);
for (int i = 0; i < len; i++) {
char character; inStream.Read<char>(character);
data->playerName += character;
}
inStream.Read(data->zoneID); inStream.Read(data->zoneID);
inStream.Read(data->muteExpire); inStream.Read(data->muteExpire);
data->sysAddr = packet->systemAddress; data->sysAddr = packet->systemAddress;
mNames[data->playerID] = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.C_String())); mNames[data->playerID] = GeneralUtils::ASCIIToUTF16(std::string(data->playerName.c_str()));
mPlayers.insert(std::make_pair(data->playerID, data)); mPlayers.insert(std::make_pair(data->playerID, data));
Game::logger->Log("PlayerContainer", "Added user: %s (%llu), zone: %i\n", data->playerName.C_String(), data->playerID, data->zoneID.GetMapID()); Game::logger->Log("PlayerContainer", "Added user: %s (%llu), zone: %i\n", data->playerName.c_str(), data->playerID, data->zoneID.GetMapID());
auto* insertLog = Database::CreatePreppedStmt("INSERT INTO activity_log (character_id, activity, time, map_id) VALUES (?, ?, ?, ?);"); auto* insertLog = Database::CreatePreppedStmt("INSERT INTO activity_log (character_id, activity, time, map_id) VALUES (?, ?, ?, ?);");
@ -64,7 +72,7 @@ void PlayerContainer::RemovePlayer(Packet* packet) {
if (team != nullptr) if (team != nullptr)
{ {
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(player->playerName.C_String())); const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(player->playerName.c_str()));
for (const auto memberId : team->memberIDs) for (const auto memberId : team->memberIDs)
{ {
@ -232,8 +240,8 @@ void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID)
if (leader == nullptr || member == nullptr) return; if (leader == nullptr || member == nullptr) return;
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.C_String())); const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.c_str()));
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(member->playerName.C_String())); const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(member->playerName.c_str()));
ChatPacketHandler::SendTeamInviteConfirm(member, false, leader->playerID, leader->zoneID, team->lootFlag, 0, 0, leaderName); ChatPacketHandler::SendTeamInviteConfirm(member, false, leader->playerID, leader->zoneID, team->lootFlag, 0, 0, leaderName);
@ -337,7 +345,7 @@ void PlayerContainer::DisbandTeam(TeamData* team)
if (otherMember == nullptr) continue; if (otherMember == nullptr) continue;
const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(otherMember->playerName.C_String())); const auto memberName = GeneralUtils::ASCIIToUTF16(std::string(otherMember->playerName.c_str()));
ChatPacketHandler::SendTeamSetLeader(otherMember, LWOOBJID_EMPTY); ChatPacketHandler::SendTeamSetLeader(otherMember, LWOOBJID_EMPTY);
ChatPacketHandler::SendTeamRemovePlayer(otherMember, true, false, false, team->local, team->leaderID, otherMember->playerID, memberName); ChatPacketHandler::SendTeamRemovePlayer(otherMember, true, false, false, team->local, team->leaderID, otherMember->playerID, memberName);
@ -360,7 +368,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team)
if (leader == nullptr) return; if (leader == nullptr) return;
const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.C_String())); const auto leaderName = GeneralUtils::ASCIIToUTF16(std::string(leader->playerName.c_str()));
for (const auto memberId : team->memberIDs) for (const auto memberId : team->memberIDs)
{ {

View File

@ -9,7 +9,7 @@
struct PlayerData { struct PlayerData {
LWOOBJID playerID; LWOOBJID playerID;
RakNet::RakString playerName; std::string playerName;
SystemAddress sysAddr; SystemAddress sysAddr;
LWOZONEID zoneID; LWOZONEID zoneID;
std::vector<FriendData> friends; std::vector<FriendData> friends;
@ -46,7 +46,7 @@ public:
PlayerData* GetPlayerData(const std::string& playerName) { PlayerData* GetPlayerData(const std::string& playerName) {
for (auto player : mPlayers) { for (auto player : mPlayers) {
if (player.second) { if (player.second) {
std::string pn = player.second->playerName.C_String(); std::string pn = player.second->playerName.c_str();
if (pn == playerName) return player.second; if (pn == playerName) return player.second;
} }
} }

View File

@ -2017,11 +2017,15 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std::
CBITSTREAM; CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_ANNOUNCEMENT); PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_ANNOUNCEMENT);
RakNet::RakString rsTitle(title.c_str()); bitStream.Write<uint32_t>(title.size());
RakNet::RakString rsMsg(message.c_str()); for (auto character : title) {
bitStream.Write<char>(character);
}
bitStream.Write(rsTitle); bitStream.Write<uint32_t>(message.size());
bitStream.Write(rsMsg); for (auto character : message) {
bitStream.Write<char>(character);
}
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
} }

View File

@ -497,7 +497,10 @@ void HandlePacket(Packet* packet) {
CBITSTREAM; CBITSTREAM;
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_NEW_SESSION_ALERT); PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_NEW_SESSION_ALERT);
bitStream.Write(sessionKey); bitStream.Write(sessionKey);
bitStream.Write(RakNet::RakString(username.c_str())); bitStream.Write<uint32_t>(username.size());
for (auto character : username) {
bitStream.Write(character);
}
SEND_PACKET_BROADCAST; SEND_PACKET_BROADCAST;
break; break;
@ -572,14 +575,20 @@ void HandlePacket(Packet* packet) {
uint32_t mapId; uint32_t mapId;
LWOCLONEID cloneId; LWOCLONEID cloneId;
RakNet::RakString password; std::string password;
inStream.Read(mapId); inStream.Read(mapId);
inStream.Read(cloneId); inStream.Read(cloneId);
inStream.Read(password);
Game::im->CreatePrivateInstance(mapId, cloneId, uint32_t len;
password.C_String()); inStream.Read<uint32_t>(len);
for (int i = 0; len > i; i++) {
char character;
inStream.Read<char>(character);
password += character;
}
Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
break; break;
} }
@ -591,15 +600,22 @@ void HandlePacket(Packet* packet) {
uint64_t requestID = 0; uint64_t requestID = 0;
uint8_t mythranShift = false; uint8_t mythranShift = false;
RakNet::RakString password; std::string password;
inStream.Read(requestID); inStream.Read(requestID);
inStream.Read(mythranShift); inStream.Read(mythranShift);
inStream.Read(password);
auto* instance = Game::im->FindPrivateInstance(password.C_String()); uint32_t len;
inStream.Read<uint32_t>(len);
Game::logger->Log( "MasterServer", "Join private zone: %llu %d %s %p\n", requestID, mythranShift, password.C_String(), instance); for (int i = 0; i < len; i++) {
char character; inStream.Read<char>(character);
password += character;
}
auto* instance = Game::im->FindPrivateInstance(password.c_str());
Game::logger->Log( "MasterServer", "Join private zone: %llu %d %s %p\n", requestID, mythranShift, password.c_str(), instance);
if (instance == nullptr) { if (instance == nullptr) {
return; return;

View File

@ -43,8 +43,10 @@ void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint
bitStream.Write(zoneID); bitStream.Write(zoneID);
bitStream.Write(cloneID); bitStream.Write(cloneID);
RakNet::RakString passwd(password.c_str()); bitStream.Write<uint32_t>(password.size());
bitStream.Write(passwd); for (auto character : password) {
bitStream.Write<char>(character);
}
server->SendToMaster(&bitStream); server->SendToMaster(&bitStream);
} }
@ -56,8 +58,10 @@ void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID,
bitStream.Write(requestID); bitStream.Write(requestID);
bitStream.Write(static_cast<uint8_t>(mythranShift)); bitStream.Write(static_cast<uint8_t>(mythranShift));
RakNet::RakString passwd(password.c_str()); bitStream.Write<uint32_t>(password.size());
bitStream.Write(passwd); for (auto character : password) {
bitStream.Write<char>(character);
}
server->SendToMaster(&bitStream); server->SendToMaster(&bitStream);
} }

View File

@ -546,18 +546,31 @@ void HandlePacketChat(Packet* packet) {
LWOOBJID header; LWOOBJID header;
inStream.Read(header); inStream.Read(header);
RakNet::RakString title; std::string title;
RakNet::RakString msg; std::string msg;
inStream.Read(title); uint32_t len;
inStream.Read(msg); inStream.Read<uint32_t>(len);
for (int i = 0; len > i; i++) {
char character;
inStream.Read<char>(character);
title += character;
}
len = 0;
inStream.Read<uint32_t>(len);
for (int i = 0; len > i; i++) {
char character;
inStream.Read<char>(character);
msg += character;
}
//Send to our clients: //Send to our clients:
AMFArrayValue args; AMFArrayValue args;
auto* titleValue = new AMFStringValue(); auto* titleValue = new AMFStringValue();
titleValue->SetStringValue(title.C_String()); titleValue->SetStringValue(title.c_str());
auto* messageValue = new AMFStringValue(); auto* messageValue = new AMFStringValue();
messageValue->SetStringValue(msg.C_String()); messageValue->SetStringValue(msg.c_str());
args.InsertValue("title", titleValue); args.InsertValue("title", titleValue);
args.InsertValue("message", messageValue); args.InsertValue("message", messageValue);
@ -1122,14 +1135,12 @@ void HandlePacket(Packet* packet) {
CBITSTREAM; CBITSTREAM;
PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_PLAYER_ADDED_NOTIFICATION); PacketUtils::WriteHeader(bitStream, CHAT_INTERNAL, MSG_CHAT_INTERNAL_PLAYER_ADDED_NOTIFICATION);
bitStream.Write(player->GetObjectID()); bitStream.Write(player->GetObjectID());
bitStream.Write<uint16_t>(playerName.size()); bitStream.Write<uint32_t>(playerName.size());
for (size_t i = 0; i < playerName.size(); i++) for (size_t i = 0; i < playerName.size(); i++)
{ {
bitStream.Write(playerName[i]); bitStream.Write(playerName[i]);
} }
//bitStream.Write(playerName);
auto zone = dZoneManager::Instance()->GetZone()->GetZoneID(); auto zone = dZoneManager::Instance()->GetZone()->GetZoneID();
bitStream.Write(zone.GetMapID()); bitStream.Write(zone.GetMapID());
bitStream.Write(zone.GetInstanceID()); bitStream.Write(zone.GetInstanceID());