From 219afd10cf1dc8f7e75273706c2de3a06305e637 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 10 Feb 2018 01:25:51 +0300 Subject: Add basic support for clans. --- src/net/eathena/clanrecv.cpp | 50 ++++++++++++++++++++++++++++++++------ src/net/eathena/clanrecv.h | 1 + src/net/eathena/generalhandler.cpp | 2 ++ 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'src/net') diff --git a/src/net/eathena/clanrecv.cpp b/src/net/eathena/clanrecv.cpp index bf16627b2..d70d7d876 100644 --- a/src/net/eathena/clanrecv.cpp +++ b/src/net/eathena/clanrecv.cpp @@ -20,11 +20,19 @@ #include "net/eathena/clanrecv.h" +#include "configuration.h" +#include "logger.h" + #include "being/claninfo.h" +#include "gui/widgets/tabs/chat/clantab.h" + +#include "gui/windows/chatwindow.h" + #include "net/messagein.h" -#include "logger.h" +#include "utils/checkutils.h" +#include "utils/delete2.h" #include "debug.h" @@ -50,6 +58,7 @@ void ClanRecv::processClanInfo(Net::MessageIn &msg) clanInfo.antagonistClans.push_back( msg.readString(24, "antagonist clan name")); } + createTab(); } void ClanRecv::processClanOnlineCount(Net::MessageIn &msg) @@ -58,20 +67,47 @@ void ClanRecv::processClanOnlineCount(Net::MessageIn &msg) clanInfo.totalMembers = msg.readInt16("total members count"); } -void ClanRecv::processClanLeave(Net::MessageIn &msg) +void ClanRecv::processClanLeave(Net::MessageIn &msg A_UNUSED) { - UNIMPLEMENTEDPACKET; + delete2(clanTab); } void ClanRecv::processClanChat(Net::MessageIn &msg) { - UNIMPLEMENTEDPACKET; const int chatMsgLength = msg.readInt16("len") - 4 - 24; if (chatMsgLength <= 0) return; - msg.readInt16("len"); - msg.readString(24, "player name"); - msg.readString(chatMsgLength, "message"); + msg.readString(24, "player name (unused)"); + std::string chatMsg = msg.readString(chatMsgLength, "message"); + if (clanTab == nullptr) + { + reportAlways("received clan chat messages without clan."); + return; + } + const size_t pos = chatMsg.find(" : ", 0); + if (pos != std::string::npos) + { + const std::string sender_name = chatMsg.substr(0, pos); + chatMsg.erase(0, pos + 3); + trim(chatMsg); + clanTab->chatLog(sender_name, chatMsg); + } + else + { + clanTab->chatLog(chatMsg, + ChatMsgType::BY_SERVER, + IgnoreRecord_false, + TryRemoveColors_true); + } +} + +void ClanRecv::createTab() +{ + if (clanTab != nullptr) + return; + clanTab = new ClanTab(chatWindow); + if (config.getBoolValue("showChatHistory")) + clanTab->loadFromLogFile("#Clan"); } } // namespace EAthena diff --git a/src/net/eathena/clanrecv.h b/src/net/eathena/clanrecv.h index 6f864bfcc..02e3b7d48 100644 --- a/src/net/eathena/clanrecv.h +++ b/src/net/eathena/clanrecv.h @@ -34,6 +34,7 @@ namespace EAthena void processClanOnlineCount(Net::MessageIn &msg); void processClanLeave(Net::MessageIn &msg); void processClanChat(Net::MessageIn &msg); + void createTab(); } // namespace ClanRecv } // namespace EAthena diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp index aaf762d3f..4f1d0c086 100644 --- a/src/net/eathena/generalhandler.cpp +++ b/src/net/eathena/generalhandler.cpp @@ -28,6 +28,7 @@ #include "gui/windows/skilldialog.h" #include "gui/windows/socialwindow.h" +#include "gui/widgets/tabs/chat/clantab.h" #include "gui/widgets/tabs/chat/guildtab.h" #include "gui/widgets/tabs/chat/partytab.h" @@ -243,6 +244,7 @@ void GeneralHandler::gameEnded() const delete2(guildTab); delete2(partyTab); + delete2(clanTab); } } // namespace EAthena -- cgit v1.2.3-60-g2f50