From 5f4765ea4b9699e2f5556946d7d7efccac546888 Mon Sep 17 00:00:00 2001 From: Cekis Date: Fri, 26 Nov 2021 01:52:23 -0500 Subject: [PATCH 1/5] Fix /emptyMail (Add UpdatePersistentMessages Handling) --- src/stationapi/Node.hpp | 1 + src/stationchat/CMakeLists.txt | 1 + src/stationchat/GatewayClient.cpp | 4 ++ src/stationchat/PersistentMessageService.cpp | 29 ++++++++ src/stationchat/PersistentMessageService.hpp | 3 + src/stationchat/protocol/Protocol.cpp | 9 +++ .../protocol/UpdatePersistentMessages.hpp | 67 +++++++++++++++++++ 7 files changed, 114 insertions(+) create mode 100755 src/stationchat/protocol/UpdatePersistentMessages.hpp diff --git a/src/stationapi/Node.hpp b/src/stationapi/Node.hpp index 6ce98a3..be5235c 100644 --- a/src/stationapi/Node.hpp +++ b/src/stationapi/Node.hpp @@ -8,6 +8,7 @@ #include #include #include +#include template class Node : public UdpManagerHandler { diff --git a/src/stationchat/CMakeLists.txt b/src/stationchat/CMakeLists.txt index b2e335e..b2c53d0 100644 --- a/src/stationchat/CMakeLists.txt +++ b/src/stationchat/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(stationchat protocol/SetApiVersion.hpp protocol/SetAvatarAttributes.hpp protocol/UpdatePersistentMessage.hpp + protocol/UpdatePersistentMessages.hpp ChatAvatar.cpp ChatAvatar.hpp diff --git a/src/stationchat/GatewayClient.cpp b/src/stationchat/GatewayClient.cpp index 8a6d521..7ee4723 100644 --- a/src/stationchat/GatewayClient.cpp +++ b/src/stationchat/GatewayClient.cpp @@ -42,6 +42,7 @@ #include "protocol/SetApiVersion.hpp" #include "protocol/SetAvatarAttributes.hpp" #include "protocol/UpdatePersistentMessage.hpp" +#include "protocol/UpdatePersistentMessages.hpp" #include "easylogging++.h" @@ -138,6 +139,9 @@ void GatewayClient::OnIncoming(std::istringstream& istream) { case ChatRequestType::UPDATEPERSISTENTMESSAGE: HandleIncomingMessage(istream); break; + case ChatRequestType::UPDATEPERSISTENTMESSAGES: + HandleIncomingMessage(istream); + break; case ChatRequestType::IGNORESTATUS: HandleIncomingMessage(istream); break; diff --git a/src/stationchat/PersistentMessageService.cpp b/src/stationchat/PersistentMessageService.cpp index 3f22d3d..fe2f34a 100644 --- a/src/stationchat/PersistentMessageService.cpp +++ b/src/stationchat/PersistentMessageService.cpp @@ -208,3 +208,32 @@ void PersistentMessageService::UpdateMessageStatus( sqlite3_finalize(stmt); } + +void PersistentMessageService::BulkUpdateMessageStatus( + uint32_t avatarId, const std::u16string& category, PersistentState newStatus) +{ + sqlite3_stmt* stmt; + + char sql[] = "UPDATE persistent_message SET status = @status WHERE avatar_id = @avatar_id AND " + "category = @category"; + + auto result = sqlite3_prepare_v2(db_, sql, -1, &stmt, 0); + if (result != SQLITE_OK) { + throw SQLite3Exception{result, sqlite3_errmsg(db_)}; + } + + int statusIdx = sqlite3_bind_parameter_index(stmt, "@status"); + int avatarIdIdx = sqlite3_bind_parameter_index(stmt, "@avatar_id"); + int categoryIdx = sqlite3_bind_parameter_index(stmt, "@category"); + + sqlite3_bind_int(stmt, statusIdx, static_cast(newStatus)); + sqlite3_bind_int(stmt, avatarIdIdx, avatarId); + std::string cat = FromWideString(category); + sqlite3_bind_text(stmt, categoryIdx, cat.c_str(), -1, nullptr); + + result = sqlite3_step(stmt); + if (result != SQLITE_DONE) { + throw SQLite3Exception{result, sqlite3_errmsg(db_)}; + } + sqlite3_finalize(stmt); +} diff --git a/src/stationchat/PersistentMessageService.hpp b/src/stationchat/PersistentMessageService.hpp index a61a812..6a8b1bc 100644 --- a/src/stationchat/PersistentMessageService.hpp +++ b/src/stationchat/PersistentMessageService.hpp @@ -25,6 +25,9 @@ class PersistentMessageService { void UpdateMessageStatus( uint32_t avatarId, uint32_t messageId, PersistentState status); + void BulkUpdateMessageStatus( + uint32_t avatarId, const std::u16string& category, PersistentState newStatus); + private: sqlite3* db_; }; diff --git a/src/stationchat/protocol/Protocol.cpp b/src/stationchat/protocol/Protocol.cpp index 8fa6188..bedb370 100644 --- a/src/stationchat/protocol/Protocol.cpp +++ b/src/stationchat/protocol/Protocol.cpp @@ -43,6 +43,7 @@ #include "protocol/SetApiVersion.hpp" #include "protocol/SetAvatarAttributes.hpp" #include "protocol/UpdatePersistentMessage.hpp" +#include "protocol/UpdatePersistentMessages.hpp" #include "easylogging++.h" @@ -729,3 +730,11 @@ UpdatePersistentMessage::UpdatePersistentMessage(GatewayClient* client, const Re messageService_->UpdateMessageStatus( request.srcAvatarId, request.messageId, request.status); } + +UpdatePersistentMessages::UpdatePersistentMessages(GatewayClient *client, const RequestType &request, ResponseType &response) + : messageService_{client->GetNode()->GetMessageService()} +{ + LOG(INFO) << "UPDATEPERSISTENTMESSAGES request received"; + messageService_->BulkUpdateMessageStatus( + request.srcAvatarId, request.category, request.newStatus); +} diff --git a/src/stationchat/protocol/UpdatePersistentMessages.hpp b/src/stationchat/protocol/UpdatePersistentMessages.hpp new file mode 100755 index 0000000..f271086 --- /dev/null +++ b/src/stationchat/protocol/UpdatePersistentMessages.hpp @@ -0,0 +1,67 @@ +/** + * UpdatePersistentMessages.hpp + * Specific handling for bulk-message update requests + * e.g. for use with /emptyMail command + * + * SWG Source Addition - 2021 + * Authors: Aconite + */ + +#pragma once + +#include "ChatEnums.hpp" +#include "PersistentMessage.hpp" + +class PersistentMessageService; +class GatewayClient; + +/** Begin UpdatePersistentMessages Request */ + +struct ReqUpdatePersistentMessages { + const ChatRequestType type = ChatRequestType::UPDATEPERSISTENTMESSAGES; + uint32_t track; + uint32_t srcAvatarId; + PersistentState currentStatus; + PersistentState newStatus; + std::u16string category; +}; + +template +void read(StreamT& ar, ReqUpdatePersistentMessages& data) { + read(ar, data.track); + read(ar, data.srcAvatarId); + read(ar, data.currentStatus); + read(ar, data.newStatus); + read(ar, data.category); +} + +/** Begin UpdatePersistentMessages Response */ + +struct ResUpdatePersistentMessages { + ResUpdatePersistentMessages(uint32_t track_) + : track{track_} + , result{ChatResultCode::SUCCESS} {} + + const ChatResponseType type = ChatResponseType::UPDATEPERSISTENTMESSAGES; + uint32_t track; + ChatResultCode result; +}; + +template +void write(StreamT& ar, const ResUpdatePersistentMessages& data) { + write(ar, data.type); + write(ar, data.track); + write(ar, data.result); +} + +class UpdatePersistentMessages { +public: + using RequestType = ReqUpdatePersistentMessages; + using ResponseType = ResUpdatePersistentMessages; + + UpdatePersistentMessages(GatewayClient* client, const RequestType& request, ResponseType& response); + +private: + PersistentMessageService* messageService_; +}; + From 60e4f7f8561bd774642aa321dd7f7dc7ef0ab8ff Mon Sep 17 00:00:00 2001 From: Cekis Date: Fri, 26 Nov 2021 02:12:08 -0500 Subject: [PATCH 2/5] Added extra logging detail to Exception messages - Aconite --- src/stationchat/protocol/Protocol.cpp | 98 ++++++++++++++------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/stationchat/protocol/Protocol.cpp b/src/stationchat/protocol/Protocol.cpp index bedb370..35324d4 100644 --- a/src/stationchat/protocol/Protocol.cpp +++ b/src/stationchat/protocol/Protocol.cpp @@ -57,18 +57,19 @@ AddBan::AddBan(GatewayClient* client, const RequestType& request, ResponseType& auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto bannedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!bannedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -83,12 +84,12 @@ AddFriend::AddFriend(GatewayClient* client, const RequestType& request, Response << FromWideString(request.srcAddress); auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->AddFriend(destAvatar); @@ -105,12 +106,12 @@ AddIgnore::AddIgnore(GatewayClient* client, const RequestType& request, Response << FromWideString(request.srcAddress); auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->AddIgnore(destAvatar); @@ -126,18 +127,18 @@ AddInvite::AddInvite(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto invitedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!invitedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -156,18 +157,18 @@ AddModerator::AddModerator( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto moderatorAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!moderatorAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -193,7 +194,7 @@ DestroyAvatar::DestroyAvatar( , roomService_{client->GetNode()->GetRoomService()} { auto avatar = avatarService_->GetAvatar(request.avatarId); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.avatarId).c_str()}; } // Remove From All Rooms @@ -217,12 +218,12 @@ DestroyRoom::DestroyRoom(GatewayClient* client, const RequestType& request, Resp auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException(ChatResultCode::ADDRESSNOTROOM); + throw ChatResultException(ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()); } auto addresses = room->GetRemoteAddresses(); @@ -244,12 +245,12 @@ EnterRoom::EnterRoom(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.room = roomService_->GetRoom(request.roomAddress); if (!response.room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()}; } response.roomId = response.room->GetRoomId(); @@ -297,7 +298,7 @@ FriendStatus::FriendStatus( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.srcAvatar = srcAvatar; @@ -311,7 +312,8 @@ GetAnyAvatar::GetAnyAvatar( auto avatar = avatarService_->GetAvatar(request.name, request.address); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, (FromWideString(request.name) + " : " + + FromWideString(request.address)).c_str()}; } response.isOnline = avatar->IsOnline(); @@ -343,7 +345,7 @@ GetRoom::GetRoom(GatewayClient* client, const RequestType& request, ResponseType auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSDOESNTEXIST}; + throw ChatResultException{ChatResultCode::ADDRESSDOESNTEXIST, FromWideString(request.roomAddress).c_str()}; } response.room = room; @@ -367,7 +369,7 @@ IgnoreStatus::IgnoreStatus( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } response.srcAvatar = srcAvatar; @@ -382,17 +384,17 @@ KickAvatar::KickAvatar(GatewayClient* client, const RequestType& request, Respon auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -408,12 +410,12 @@ LeaveRoom::LeaveRoom(GatewayClient* client, const RequestType& request, Response , roomService_{client->GetNode()->GetRoomService()} { auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto room = roomService_->GetRoom(request.roomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.roomAddress).c_str()}; } response.roomId = room->GetRoomId(); @@ -490,18 +492,18 @@ RemoveBan::RemoveBan(GatewayClient* client, const RequestType& request, Response auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto bannedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!bannedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -518,12 +520,12 @@ RemoveFriend::RemoveFriend( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->RemoveFriend(destAvatar); @@ -537,12 +539,12 @@ RemoveIgnore::RemoveIgnore(GatewayClient* client, const RequestType& request, Re auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } srcAvatar->RemoveIgnore(destAvatar); @@ -559,18 +561,18 @@ RemoveInvite::RemoveInvite( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto invitedAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!invitedAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -586,17 +588,17 @@ RemoveModerator::RemoveModerator(GatewayClient* client, const RequestType& reque auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } auto moderatorAvatar = avatarService_->GetAvatar(request.destAvatarName, request.destAvatarAddress); if (!moderatorAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destAvatarName) + " : " + FromWideString(request.destAvatarAddress)).c_str()}; } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException{ChatResultCode::ADDRESSNOTROOM}; + throw ChatResultException{ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()}; } response.destRoomId = room->GetRoomId(); @@ -613,12 +615,12 @@ SendInstantMessage::SendInstantMessage( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException(ChatResultCode::DESTAVATARDOESNTEXIST); + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } if (destAvatar->IsIgnored(srcAvatar)) { @@ -635,7 +637,7 @@ SendPersistentMessage::SendPersistentMessage(GatewayClient* client, const Reques auto destAvatar = avatarService_->GetAvatar(request.destName, request.destAddress); if (!destAvatar) { - throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::DESTAVATARDOESNTEXIST, (FromWideString(request.destName) + " : " + FromWideString(request.destAddress)).c_str()}; } PersistentMessage message; @@ -643,11 +645,11 @@ SendPersistentMessage::SendPersistentMessage(GatewayClient* client, const Reques if (request.avatarPresence) { auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()}; } if (destAvatar->IsIgnored(srcAvatar)) { - throw ChatResultException(ChatResultCode::IGNORING); + throw ChatResultException(ChatResultCode::IGNORING, (std::to_string(destAvatar->GetAvatarId()) + " : " + std::to_string(srcAvatar->GetAvatarId())).c_str()); } message.header.fromName = srcAvatar->GetName(); @@ -681,12 +683,12 @@ SendRoomMessage::SendRoomMessage( auto srcAvatar = avatarService_->GetAvatar(request.srcAvatarId); if (!srcAvatar) { - throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST); + throw ChatResultException(ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.srcAvatarId).c_str()); } auto room = roomService_->GetRoom(request.destRoomAddress); if (!room) { - throw ChatResultException(ChatResultCode::ADDRESSNOTROOM); + throw ChatResultException(ChatResultCode::ADDRESSNOTROOM, FromWideString(request.destRoomAddress).c_str()); } response.roomId = room->GetRoomId(); @@ -710,7 +712,7 @@ SetAvatarAttributes::SetAvatarAttributes(GatewayClient* client, const RequestTyp auto avatar = avatarService_->GetAvatar(request.avatarId); if (!avatar) { - throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST}; + throw ChatResultException{ChatResultCode::SRCAVATARDOESNTEXIST, std::to_string(request.avatarId).c_str()}; } response.avatar = avatar; From 66dc49f7dffebad5e017eb843e486e71fe8e0951 Mon Sep 17 00:00:00 2001 From: Cekis Date: Fri, 26 Nov 2021 15:51:24 -0500 Subject: [PATCH 3/5] Added check for logged out client to prevent erase on erased pointer --- src/stationapi/Node.hpp | 2 +- src/stationchat/ChatAvatarService.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stationapi/Node.hpp b/src/stationapi/Node.hpp index be5235c..08248f8 100644 --- a/src/stationapi/Node.hpp +++ b/src/stationapi/Node.hpp @@ -38,7 +38,7 @@ class Node : public UdpManagerHandler { auto remove_iter = std::remove_if(std::begin(clients_), std::end(clients_), [](auto& client) { - return client->GetConnection()->GetStatus() == UdpConnection::cStatusDisconnected; + return client->GetConnection()->GetStatus() == UdpConnection::cStatusDisconnected || client == std::end(clients_); }); if (remove_iter != std::end(clients_)) diff --git a/src/stationchat/ChatAvatarService.cpp b/src/stationchat/ChatAvatarService.cpp index 0de85a3..746dc32 100644 --- a/src/stationchat/ChatAvatarService.cpp +++ b/src/stationchat/ChatAvatarService.cpp @@ -72,6 +72,7 @@ void ChatAvatarService::LoginAvatar(ChatAvatar* avatar) { } void ChatAvatarService::LogoutAvatar(ChatAvatar* avatar) { + if(!avatar->isOnline_) return; avatar->isOnline_ = false; onlineAvatars_.erase(std::remove_if( From 13a9a808805673846a7803a3b3ef9542836a686b Mon Sep 17 00:00:00 2001 From: Cekis Date: Sat, 27 Nov 2021 12:14:31 -0500 Subject: [PATCH 4/5] Reverted udplibrary changes in CMake files. --- src/stationapi/CMakeLists.txt | 34 +++++++++++++++++----------------- src/stationchat/CMakeLists.txt | 1 + 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/stationapi/CMakeLists.txt b/src/stationapi/CMakeLists.txt index b04caea..9503000 100644 --- a/src/stationapi/CMakeLists.txt +++ b/src/stationapi/CMakeLists.txt @@ -1,19 +1,19 @@ -add_library( - stationapi - Node.hpp - NodeClient.cpp - NodeClient.hpp - Serialization.hpp - SQLite3.hpp - StreamUtils.cpp - StreamUtils.hpp - StringUtils.cpp - StringUtils.hpp) -target_include_directories( - stationapi - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/externals/catch - ${PROJECT_SOURCE_DIR}/externals/easyloggingpp ${Boost_INCLUDE_DIRS} - ${SQLite3_INCLUDE_DIR}) +add_library(stationapi + Node.hpp + NodeClient.cpp + NodeClient.hpp + Serialization.hpp + SQLite3.hpp + StreamUtils.cpp + StreamUtils.hpp + StringUtils.cpp + StringUtils.hpp) -target_link_libraries(stationapi udplibrary) +target_include_directories(stationapi PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/externals/catch + ${PROJECT_SOURCE_DIR}/externals/easyloggingpp + ${PROJECT_SOURCE_DIR}/externals/udplibrary + ${Boost_INCLUDE_DIRS} + ${SQLite3_INCLUDE_DIR}) \ No newline at end of file diff --git a/src/stationchat/CMakeLists.txt b/src/stationchat/CMakeLists.txt index e594d09..c2796dc 100644 --- a/src/stationchat/CMakeLists.txt +++ b/src/stationchat/CMakeLists.txt @@ -65,6 +65,7 @@ add_executable( # cmake-format: off target_link_libraries(stationchat stationapi + udplibrary ${Boost_LIBRARIES} ${SQLite3_LIBRARY} $<$:ws2_32>) From 0ac9d0cc2efc0eb2ec26e86435ae98c1cc687997 Mon Sep 17 00:00:00 2001 From: Cekis Date: Sat, 27 Nov 2021 15:19:53 -0500 Subject: [PATCH 5/5] Putting back the changes in light of adjustments to src --- src/stationapi/CMakeLists.txt | 34 +++++++++++++++++----------------- src/stationchat/CMakeLists.txt | 1 - 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/stationapi/CMakeLists.txt b/src/stationapi/CMakeLists.txt index 9503000..b04caea 100644 --- a/src/stationapi/CMakeLists.txt +++ b/src/stationapi/CMakeLists.txt @@ -1,19 +1,19 @@ +add_library( + stationapi + Node.hpp + NodeClient.cpp + NodeClient.hpp + Serialization.hpp + SQLite3.hpp + StreamUtils.cpp + StreamUtils.hpp + StringUtils.cpp + StringUtils.hpp) -add_library(stationapi - Node.hpp - NodeClient.cpp - NodeClient.hpp - Serialization.hpp - SQLite3.hpp - StreamUtils.cpp - StreamUtils.hpp - StringUtils.cpp - StringUtils.hpp) +target_include_directories( + stationapi + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/externals/catch + ${PROJECT_SOURCE_DIR}/externals/easyloggingpp ${Boost_INCLUDE_DIRS} + ${SQLite3_INCLUDE_DIR}) -target_include_directories(stationapi PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/externals/catch - ${PROJECT_SOURCE_DIR}/externals/easyloggingpp - ${PROJECT_SOURCE_DIR}/externals/udplibrary - ${Boost_INCLUDE_DIRS} - ${SQLite3_INCLUDE_DIR}) \ No newline at end of file +target_link_libraries(stationapi udplibrary) diff --git a/src/stationchat/CMakeLists.txt b/src/stationchat/CMakeLists.txt index c2796dc..e594d09 100644 --- a/src/stationchat/CMakeLists.txt +++ b/src/stationchat/CMakeLists.txt @@ -65,7 +65,6 @@ add_executable( # cmake-format: off target_link_libraries(stationchat stationapi - udplibrary ${Boost_LIBRARIES} ${SQLite3_LIBRARY} $<$:ws2_32>)