mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-21 11:59:37 -06:00
Compare commits
13 Commits
websockets
...
worldServe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c8ca1c1cb | ||
|
|
b31f9670d1 | ||
|
|
1cc1782b35 | ||
|
|
55d409eb82 | ||
|
|
65f3c33ca5 | ||
|
|
93fa4e268f | ||
|
|
1fb1da101c | ||
|
|
6f94043b33 | ||
|
|
5785764a95 | ||
|
|
fa53fa7935 | ||
|
|
6b0f3a66e9 | ||
|
|
f5c212fb86 | ||
|
|
99f6cf2d92 |
@@ -235,8 +235,6 @@ include_directories(
|
||||
|
||||
"dNet"
|
||||
|
||||
"dWeb"
|
||||
|
||||
"tests"
|
||||
"tests/dCommonTests"
|
||||
"tests/dGameTests"
|
||||
@@ -303,7 +301,6 @@ add_subdirectory(dZoneManager)
|
||||
add_subdirectory(dNavigation)
|
||||
add_subdirectory(dPhysics)
|
||||
add_subdirectory(dServer)
|
||||
add_subdirectory(dWeb)
|
||||
|
||||
# Create a list of common libraries shared between all binaries
|
||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "magic_enum")
|
||||
|
||||
25
Dockerfile
25
Dockerfile
@@ -11,7 +11,12 @@ COPY --chmod=0500 ./build.sh /app/
|
||||
|
||||
RUN sed -i 's/MARIADB_CONNECTOR_COMPILE_JOBS__=.*/MARIADB_CONNECTOR_COMPILE_JOBS__=2/' /app/CMakeVariables.txt
|
||||
|
||||
RUN ./build.sh
|
||||
RUN --mount=type=cache,target=/app/build,id=build-cache \
|
||||
mkdir -p /app/build /tmp/persisted-build && \
|
||||
cd /app/build && \
|
||||
cmake .. && \
|
||||
make -j$(nproc --ignore 1) && \
|
||||
cp -r /app/build/* /tmp/persisted-build/
|
||||
|
||||
FROM debian:12 as runtime
|
||||
|
||||
@@ -23,23 +28,23 @@ RUN --mount=type=cache,id=build-apt-cache,target=/var/cache/apt \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Grab libraries and load them
|
||||
COPY --from=build /app/build/mariadbcpp/libmariadbcpp.so /usr/local/lib/
|
||||
COPY --from=build /tmp/persisted-build/mariadbcpp/libmariadbcpp.so /usr/local/lib/
|
||||
RUN ldconfig
|
||||
|
||||
# Server bins
|
||||
COPY --from=build /app/build/*Server /app/
|
||||
COPY --from=build /tmp/persisted-build/*Server /app/
|
||||
|
||||
# Necessary suplimentary files
|
||||
COPY --from=build /app/build/*.ini /app/configs/
|
||||
COPY --from=build /app/build/vanity/*.* /app/vanity/
|
||||
COPY --from=build /app/build/navmeshes /app/navmeshes
|
||||
COPY --from=build /app/build/migrations /app/migrations
|
||||
COPY --from=build /app/build/*.dcf /app/
|
||||
COPY --from=build /tmp/persisted-build/*.ini /app/configs/
|
||||
COPY --from=build /tmp/persisted-build/vanity/*.* /app/vanity/
|
||||
COPY --from=build /tmp/persisted-build/navmeshes /app/navmeshes
|
||||
COPY --from=build /tmp/persisted-build/migrations /app/migrations
|
||||
COPY --from=build /tmp/persisted-build/*.dcf /app/
|
||||
|
||||
# backup of config and vanity files to copy to the host incase
|
||||
# of a mount clobbering the copy from above
|
||||
COPY --from=build /app/build/*.ini /app/default-configs/
|
||||
COPY --from=build /app/build/vanity/*.* /app/default-vanity/
|
||||
COPY --from=build /tmp/persisted-build/*.ini /app/default-configs/
|
||||
COPY --from=build /tmp/persisted-build/vanity/*.* /app/default-vanity/
|
||||
|
||||
# needed as the container runs with the root user
|
||||
# and therefore sudo doesn't exist
|
||||
|
||||
@@ -105,7 +105,7 @@ void dChatFilter::ExportWordlistToDCF(const std::string& filepath, bool allowLis
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList) {
|
||||
std::vector<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList) {
|
||||
if (gmLevel > eGameMasterLevel::FORUM_MODERATOR) return { }; //If anything but a forum mod, return true.
|
||||
if (message.empty()) return { };
|
||||
if (!allowList && m_DeniedWords.empty()) return { { 0, message.length() } };
|
||||
@@ -114,7 +114,7 @@ std::set<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::str
|
||||
std::string segment;
|
||||
std::regex reg("(!*|\\?*|\\;*|\\.*|\\,*)");
|
||||
|
||||
std::set<std::pair<uint8_t, uint8_t>> listOfBadSegments;
|
||||
std::vector<std::pair<uint8_t, uint8_t>> listOfBadSegments = std::vector<std::pair<uint8_t, uint8_t>>();
|
||||
|
||||
uint32_t position = 0;
|
||||
|
||||
@@ -127,17 +127,17 @@ std::set<std::pair<uint8_t, uint8_t>> dChatFilter::IsSentenceOkay(const std::str
|
||||
size_t hash = CalculateHash(segment);
|
||||
|
||||
if (std::find(m_UserUnapprovedWordCache.begin(), m_UserUnapprovedWordCache.end(), hash) != m_UserUnapprovedWordCache.end() && allowList) {
|
||||
listOfBadSegments.emplace(position, originalSegment.length());
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
||||
if (std::find(m_ApprovedWords.begin(), m_ApprovedWords.end(), hash) == m_ApprovedWords.end() && allowList) {
|
||||
m_UserUnapprovedWordCache.push_back(hash);
|
||||
listOfBadSegments.emplace(position, originalSegment.length());
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
||||
if (std::find(m_DeniedWords.begin(), m_DeniedWords.end(), hash) != m_DeniedWords.end() && !allowList) {
|
||||
m_UserUnapprovedWordCache.push_back(hash);
|
||||
listOfBadSegments.emplace(position, originalSegment.length());
|
||||
listOfBadSegments.emplace_back(position, originalSegment.length());
|
||||
}
|
||||
|
||||
position += originalSegment.length() + 1;
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
void ReadWordlistPlaintext(const std::string& filepath, bool allowList);
|
||||
bool ReadWordlistDCF(const std::string& filepath, bool allowList);
|
||||
void ExportWordlistToDCF(const std::string& filepath, bool allowList);
|
||||
std::set<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList = true);
|
||||
std::vector<std::pair<uint8_t, uint8_t>> IsSentenceOkay(const std::string& message, eGameMasterLevel gmLevel, bool allowList = true);
|
||||
|
||||
private:
|
||||
bool m_DontGenerateDCF;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
set(DCHATSERVER_SOURCES
|
||||
"ChatIgnoreList.cpp"
|
||||
"ChatJSONUtils.cpp"
|
||||
"ChatPacketHandler.cpp"
|
||||
"PlayerContainer.cpp"
|
||||
"ChatWeb.cpp"
|
||||
"ChatWebAPI.cpp"
|
||||
"JSONUtils.cpp"
|
||||
)
|
||||
|
||||
add_executable(ChatServer "ChatServer.cpp")
|
||||
target_include_directories(ChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dChatFilter" "${PROJECT_SOURCE_DIR}/dWeb")
|
||||
target_include_directories(ChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dChatFilter")
|
||||
add_compile_definitions(ChatServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"")
|
||||
|
||||
add_library(dChatServer ${DCHATSERVER_SOURCES})
|
||||
target_include_directories(dChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dServer" "${PROJECT_SOURCE_DIR}/dChatFilter")
|
||||
target_include_directories(dChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dServer")
|
||||
|
||||
target_link_libraries(dChatServer ${COMMON_LIBRARIES} dChatFilter)
|
||||
target_link_libraries(ChatServer ${COMMON_LIBRARIES} dChatFilter dChatServer dServer dWeb)
|
||||
target_link_libraries(ChatServer ${COMMON_LIBRARIES} dChatFilter dChatServer dServer mongoose)
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// not allowing teams, rejecting DMs, friends requets etc.
|
||||
// The only thing not auto-handled is instance activities force joining the team on the server.
|
||||
|
||||
void WriteOutgoingReplyHeader(RakNet::BitStream& bitStream, const LWOOBJID& receivingPlayer, const ChatIgnoreList::Response type) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET);
|
||||
void WriteOutgoingReplyHeader(RakNet::BitStream& bitStream, const LWOOBJID& receivingPlayer, const MessageType::Client type) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET);
|
||||
bitStream.Write(receivingPlayer);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -48,9 +48,9 @@ void ChatIgnoreList::GetIgnoreList(Packet* packet) {
|
||||
}
|
||||
|
||||
CBITSTREAM;
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, ChatIgnoreList::Response::GET_IGNORE);
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, MessageType::Client::GET_IGNORE_LIST_RESPONSE);
|
||||
|
||||
bitStream.Write<uint8_t>(false); // Probably is Is Free Trial, but we don't care about that
|
||||
bitStream.Write<uint8_t>(false); // Is Free Trial, but we don't care about that
|
||||
bitStream.Write<uint16_t>(0); // literally spacing due to struct alignment
|
||||
|
||||
bitStream.Write<uint16_t>(receiver.ignoredPlayers.size());
|
||||
@@ -86,7 +86,7 @@ void ChatIgnoreList::AddIgnore(Packet* packet) {
|
||||
std::string toIgnoreStr = toIgnoreName.GetAsString();
|
||||
|
||||
CBITSTREAM;
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, ChatIgnoreList::Response::ADD_IGNORE);
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, MessageType::Client::ADD_IGNORE_RESPONSE);
|
||||
|
||||
// Check if the player exists
|
||||
LWOOBJID ignoredPlayerId = LWOOBJID_EMPTY;
|
||||
@@ -161,7 +161,7 @@ void ChatIgnoreList::RemoveIgnore(Packet* packet) {
|
||||
receiver.ignoredPlayers.erase(toRemove, receiver.ignoredPlayers.end());
|
||||
|
||||
CBITSTREAM;
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, ChatIgnoreList::Response::REMOVE_IGNORE);
|
||||
WriteOutgoingReplyHeader(bitStream, receiver.playerID, MessageType::Client::REMOVE_IGNORE_RESPONSE);
|
||||
|
||||
bitStream.Write<int8_t>(0);
|
||||
LUWString playerNameSend(removedIgnoreStr, 33);
|
||||
|
||||
@@ -5,17 +5,16 @@ struct Packet;
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief The ignore list allows players to ignore someone silently. Requests will generally be blocked by the client, but they should also be checked
|
||||
* on the server as well so the sender can get a generic error code in response.
|
||||
*
|
||||
*/
|
||||
namespace ChatIgnoreList {
|
||||
void GetIgnoreList(Packet* packet);
|
||||
void AddIgnore(Packet* packet);
|
||||
void RemoveIgnore(Packet* packet);
|
||||
|
||||
enum class Response : uint8_t {
|
||||
ADD_IGNORE = 32,
|
||||
REMOVE_IGNORE = 33,
|
||||
GET_IGNORE = 34,
|
||||
};
|
||||
|
||||
enum class AddResponse : uint8_t {
|
||||
SUCCESS,
|
||||
ALREADY_IGNORED,
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "StringifiedEnum.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "json.hpp"
|
||||
#include "ChatWeb.h"
|
||||
|
||||
void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
//Get from the packet which player we want to do something with:
|
||||
@@ -75,7 +73,7 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
data.Serialize(bitStream);
|
||||
}
|
||||
|
||||
SystemAddress sysAddr = player.sysAddr;
|
||||
SystemAddress sysAddr = player.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -124,7 +122,7 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
requesteeFriendData.isOnline = false;
|
||||
requesteeFriendData.zoneID = requestor.zoneID;
|
||||
requestee.friends.push_back(requesteeFriendData);
|
||||
requestee.sysAddr = UNASSIGNED_SYSTEM_ADDRESS;
|
||||
requestee.worldServerSysAddr = UNASSIGNED_SYSTEM_ADDRESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -191,8 +189,8 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
Database::Get()->SetBestFriendStatus(requestorPlayerID, requestee.playerID, bestFriendStatus);
|
||||
// Sent the best friend update here if the value is 3
|
||||
if (bestFriendStatus == 3U) {
|
||||
if (requestee.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestee, requestor, eAddFriendResponseType::ACCEPTED, false, true);
|
||||
if (requestor.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::ACCEPTED, false, true);
|
||||
if (requestee.worldServerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestee, requestor, eAddFriendResponseType::ACCEPTED, false, true);
|
||||
if (requestor.worldServerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::ACCEPTED, false, true);
|
||||
|
||||
for (auto& friendData : requestor.friends) {
|
||||
if (friendData.friendID == requestee.playerID) {
|
||||
@@ -213,7 +211,7 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (requestor.sysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::WAITINGAPPROVAL, true, true);
|
||||
if (requestor.worldServerSysAddr != UNASSIGNED_SYSTEM_ADDRESS) SendFriendResponse(requestor, requestee, eAddFriendResponseType::WAITINGAPPROVAL, true, true);
|
||||
}
|
||||
} else {
|
||||
auto maxFriends = Game::playerContainer.GetMaxNumberOfFriends();
|
||||
@@ -366,7 +364,7 @@ void ChatPacketHandler::HandleGMLevelUpdate(Packet* packet) {
|
||||
|
||||
void ChatPacketHandler::HandleWho(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ChatPackets::FindPlayerRequest request;
|
||||
FindPlayerRequest request;
|
||||
request.Deserialize(inStream);
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(request.requestor);
|
||||
@@ -386,13 +384,13 @@ void ChatPacketHandler::HandleWho(Packet* packet) {
|
||||
bitStream.Write(player.zoneID.GetCloneID());
|
||||
bitStream.Write(request.playerName);
|
||||
|
||||
SystemAddress sysAddr = sender.sysAddr;
|
||||
SystemAddress sysAddr = sender.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleShowAll(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ChatPackets::ShowAllRequest request;
|
||||
ShowAllRequest request;
|
||||
request.Deserialize(inStream);
|
||||
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(request.requestor);
|
||||
@@ -420,7 +418,7 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) {
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemAddress sysAddr = sender.sysAddr;
|
||||
SystemAddress sysAddr = sender.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -428,106 +426,119 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) {
|
||||
// that are sent to the server. Because of this, there are large gaps of unused data in chat messages
|
||||
void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
ChatMessage data;
|
||||
LWOOBJID sender;
|
||||
inStream.Read(sender);
|
||||
LOG("Got a message from player %llu", sender);
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
|
||||
data.sender = Game::playerContainer.GetPlayerData(sender);
|
||||
if (!data.sender || data.sender.GetIsMuted()) return;
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(playerID);
|
||||
if (!sender || sender.GetIsMuted()) return;
|
||||
|
||||
eChatChannel channel;
|
||||
uint32_t size;
|
||||
|
||||
inStream.IgnoreBytes(4);
|
||||
inStream.Read(data.channel);
|
||||
inStream.Read(channel);
|
||||
inStream.Read(size);
|
||||
inStream.IgnoreBytes(77);
|
||||
|
||||
data.message = LUWString(size);
|
||||
inStream.Read(data.message);
|
||||
LUWString message(size);
|
||||
inStream.Read(message);
|
||||
|
||||
LOG("Got message from (%s) via [%s]: %s", data.sender.playerName.c_str(), StringifiedEnum::ToString(data.channel).data(), data.message.GetAsString().c_str());
|
||||
|
||||
|
||||
switch (data.channel) {
|
||||
case eChatChannel::TEAM: {
|
||||
auto* team = Game::playerContainer.GetTeam(data.sender.playerID);
|
||||
if (team == nullptr) return;
|
||||
data.teamID = team->teamID;
|
||||
LOG("Got a message from (%s) via [%s]: %s", sender.playerName.c_str(), StringifiedEnum::ToString(channel).data(), message.GetAsString().c_str());
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
const auto& otherMember = Game::playerContainer.GetPlayerData(memberId);
|
||||
if (!otherMember) return;
|
||||
SendPrivateChatMessage(data.sender, otherMember, otherMember, data.message, eChatChannel::TEAM, eChatMessageResponseCode::SENT);
|
||||
}
|
||||
break;
|
||||
switch (channel) {
|
||||
case eChatChannel::TEAM: {
|
||||
auto* team = Game::playerContainer.GetTeam(playerID);
|
||||
if (team == nullptr) return;
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
const auto& otherMember = Game::playerContainer.GetPlayerData(memberId);
|
||||
if (!otherMember) return;
|
||||
SendPrivateChatMessage(sender, otherMember, otherMember, message, eChatChannel::TEAM, eChatMessageResponseCode::SENT);
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("Unhandled Chat channel [%s]", StringifiedEnum::ToString(data.channel).data());
|
||||
break;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG("Unhandled Chat channel [%s]", StringifiedEnum::ToString(channel).data());
|
||||
break;
|
||||
}
|
||||
ChatWeb::SendWSChatMessage(data);
|
||||
}
|
||||
|
||||
// the structure the client uses to send this packet is shared in many chat messages
|
||||
// that are sent to the server. Because of this, there are large gaps of unused data in chat messages
|
||||
void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
ChatMessage data;
|
||||
data.channel = eChatChannel::GENERAL;
|
||||
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
|
||||
data.sender = Game::playerContainer.GetPlayerData(playerID);
|
||||
if (!data.sender || data.sender.GetIsMuted()) return;
|
||||
const auto& sender = Game::playerContainer.GetPlayerData(playerID);
|
||||
if (!sender || sender.GetIsMuted()) return;
|
||||
|
||||
eChatChannel channel;
|
||||
uint32_t size;
|
||||
LUWString LUReceiverName;
|
||||
|
||||
inStream.IgnoreBytes(4);
|
||||
inStream.Read(data.channel);
|
||||
if (data.channel != eChatChannel::PRIVATE_CHAT) LOG("WARNING: Received Private chat with the wrong channel!");
|
||||
inStream.Read(channel);
|
||||
if (channel != eChatChannel::PRIVATE_CHAT) LOG("WARNING: Received Private chat with the wrong channel!");
|
||||
|
||||
inStream.Read(size);
|
||||
inStream.IgnoreBytes(77);
|
||||
|
||||
LUWString LUReceiverName;
|
||||
inStream.Read(LUReceiverName);
|
||||
auto receiverName = LUReceiverName.GetAsString();
|
||||
inStream.IgnoreBytes(2);
|
||||
|
||||
data.message = LUWString(size);
|
||||
inStream.Read(data.message);
|
||||
LUWString message(size);
|
||||
inStream.Read(message);
|
||||
|
||||
LOG("Got a message from (%s) via [%s]: %s to %s", data.sender.playerName.c_str(), StringifiedEnum::ToString(data.channel).data(), data.message.GetAsString().c_str(), receiverName.c_str());
|
||||
LOG("Got a message from (%s) via [%s]: %s to %s", sender.playerName.c_str(), StringifiedEnum::ToString(channel).data(), message.GetAsString().c_str(), receiverName.c_str());
|
||||
|
||||
data.receiver = Game::playerContainer.GetPlayerData(receiverName);
|
||||
if (!data.receiver) {
|
||||
const auto& receiver = Game::playerContainer.GetPlayerData(receiverName);
|
||||
if (!receiver) {
|
||||
PlayerData otherPlayer;
|
||||
otherPlayer.playerName = receiverName;
|
||||
auto responseType = Database::Get()->GetCharacterInfo(receiverName)
|
||||
? eChatMessageResponseCode::NOTONLINE
|
||||
: eChatMessageResponseCode::GENERALERROR;
|
||||
|
||||
SendPrivateChatMessage(data.sender, otherPlayer, data.sender, data.message, data.channel, responseType);
|
||||
SendPrivateChatMessage(sender, otherPlayer, sender, message, eChatChannel::GENERAL, responseType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if they are friends
|
||||
// only freinds can whispr each other
|
||||
for (const auto& fr : data.receiver.friends) {
|
||||
if (fr.friendID == data.sender.playerID) {
|
||||
data.channel = eChatChannel::PRIVATE_CHAT;
|
||||
// To the sender:
|
||||
SendPrivateChatMessage(data.sender, data.receiver, data.sender, data.message, data.channel, eChatMessageResponseCode::SENT);
|
||||
// To the receiver:
|
||||
SendPrivateChatMessage(data.sender, data.receiver, data.receiver, data.message, data.channel, eChatMessageResponseCode::RECEIVEDNEWWHISPER);
|
||||
// To the websocket:
|
||||
ChatWeb::SendWSChatMessage(data);
|
||||
for (const auto& fr : receiver.friends) {
|
||||
if (fr.friendID == sender.playerID) {
|
||||
//To the sender:
|
||||
SendPrivateChatMessage(sender, receiver, sender, message, eChatChannel::PRIVATE_CHAT, eChatMessageResponseCode::SENT);
|
||||
//To the receiver:
|
||||
SendPrivateChatMessage(sender, receiver, receiver, message, eChatChannel::PRIVATE_CHAT, eChatMessageResponseCode::RECEIVEDNEWWHISPER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SendPrivateChatMessage(data.sender, data.receiver, data.sender, data.message, data.channel, eChatMessageResponseCode::NOTFRIENDS);
|
||||
SendPrivateChatMessage(sender, receiver, sender, message, eChatChannel::GENERAL, eChatMessageResponseCode::NOTFRIENDS);
|
||||
}
|
||||
|
||||
void ChatPacketHandler::OnAchievementNotify(RakNet::BitStream& bitstream, const SystemAddress& sysAddr) {
|
||||
ChatPackets::AchievementNotify notify{};
|
||||
notify.Deserialize(bitstream);
|
||||
const auto& playerData = Game::playerContainer.GetPlayerData(notify.earnerName.GetAsString());
|
||||
if (!playerData) return;
|
||||
|
||||
for (const auto& myFriend : playerData.friends) {
|
||||
auto& friendData = Game::playerContainer.GetPlayerData(myFriend.friendID);
|
||||
if (friendData) {
|
||||
notify.targetPlayerName.string = GeneralUtils::ASCIIToUTF16(friendData.playerName);
|
||||
LOG_DEBUG("Sending achievement notify to %s", notify.targetPlayerName.GetAsString().c_str());
|
||||
|
||||
RakNet::BitStream worldStream;
|
||||
BitStreamUtils::WriteHeader(worldStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET);
|
||||
worldStream.Write(friendData.playerID);
|
||||
notify.WriteHeader(worldStream);
|
||||
notify.Serialize(worldStream);
|
||||
Game::server->Send(worldStream, friendData.worldServerSysAddr, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatPacketHandler::SendPrivateChatMessage(const PlayerData& sender, const PlayerData& receiver, const PlayerData& routeTo, const LUWString& message, const eChatChannel channel, const eChatMessageResponseCode responseCode) {
|
||||
@@ -548,7 +559,7 @@ void ChatPacketHandler::SendPrivateChatMessage(const PlayerData& sender, const P
|
||||
bitStream.Write(responseCode);
|
||||
bitStream.Write(message);
|
||||
|
||||
SystemAddress sysAddr = routeTo.sysAddr;
|
||||
SystemAddress sysAddr = routeTo.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -591,6 +602,19 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) {
|
||||
SendTeamInvite(other, player);
|
||||
|
||||
LOG("Got team invite: %llu -> %s", playerID, invitedPlayer.GetAsString().c_str());
|
||||
|
||||
bool failed = false;
|
||||
for (const auto& ignore : other.ignoredPlayers) {
|
||||
if (ignore.playerId == player.playerID) {
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ChatPackets::TeamInviteInitialResponse response{};
|
||||
response.inviteFailedToSend = failed;
|
||||
response.playerName = invitedPlayer.string;
|
||||
ChatPackets::SendRoutedMsg(response, playerID, player.worldServerSysAddr);
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
@@ -604,7 +628,7 @@ void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
LWOOBJID leaderID = LWOOBJID_EMPTY;
|
||||
inStream.Read(leaderID);
|
||||
|
||||
LOG("Accepted invite: %llu -> %llu (%d)", playerID, leaderID, declined);
|
||||
LOG("Invite reponse received: %llu -> %llu (%d)", playerID, leaderID, declined);
|
||||
|
||||
if (declined) {
|
||||
return;
|
||||
@@ -733,14 +757,15 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) {
|
||||
const auto& data = Game::playerContainer.GetPlayerData(playerID);
|
||||
|
||||
if (team != nullptr && data) {
|
||||
LOG_DEBUG("Player %llu is requesting team status", playerID);
|
||||
if (team->local && data.zoneID.GetMapID() != team->zoneId.GetMapID() && data.zoneID.GetCloneID() != team->zoneId.GetCloneID()) {
|
||||
Game::playerContainer.RemoveMember(team, playerID, false, false, true, true);
|
||||
Game::playerContainer.RemoveMember(team, playerID, false, false, false, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (team->memberIDs.size() <= 1 && !team->local) {
|
||||
Game::playerContainer.DisbandTeam(team);
|
||||
Game::playerContainer.DisbandTeam(team, LWOOBJID_EMPTY, u"");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -783,7 +808,7 @@ void ChatPacketHandler::SendTeamInvite(const PlayerData& receiver, const PlayerD
|
||||
bitStream.Write(LUWString(sender.playerName.c_str()));
|
||||
bitStream.Write(sender.playerID);
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -810,7 +835,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(const PlayerData& receiver, bool b
|
||||
bitStream.Write(character);
|
||||
}
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -835,7 +860,7 @@ void ChatPacketHandler::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64L
|
||||
bitStream.Write(character);
|
||||
}
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -852,7 +877,7 @@ void ChatPacketHandler::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i
|
||||
|
||||
bitStream.Write(i64PlayerID);
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -881,7 +906,7 @@ void ChatPacketHandler::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFr
|
||||
}
|
||||
bitStream.Write(zoneID);
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -907,7 +932,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(const PlayerData& receiver, bool bD
|
||||
bitStream.Write(character);
|
||||
}
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -928,7 +953,7 @@ void ChatPacketHandler::SendTeamSetOffWorldFlag(const PlayerData& receiver, LWOO
|
||||
}
|
||||
bitStream.Write(zoneID);
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -970,7 +995,7 @@ void ChatPacketHandler::SendFriendUpdate(const PlayerData& friendData, const Pla
|
||||
bitStream.Write<uint8_t>(isBestFriend); //isBFF
|
||||
bitStream.Write<uint8_t>(0); //isFTP
|
||||
|
||||
SystemAddress sysAddr = friendData.sysAddr;
|
||||
SystemAddress sysAddr = friendData.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -992,7 +1017,7 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play
|
||||
bitStream.Write(LUWString(sender.playerName));
|
||||
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.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -1005,7 +1030,7 @@ void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const Pla
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::ADD_FRIEND_RESPONSE);
|
||||
bitStream.Write(responseCode);
|
||||
// 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 != eAddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender.sysAddr != UNASSIGNED_SYSTEM_ADDRESS);
|
||||
bitStream.Write<uint8_t>(responseCode != eAddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender.worldServerSysAddr != UNASSIGNED_SYSTEM_ADDRESS);
|
||||
// Then write the player name
|
||||
bitStream.Write(LUWString(sender.playerName));
|
||||
// Then if this is an acceptance code, write the following extra info.
|
||||
@@ -1015,7 +1040,7 @@ void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const Pla
|
||||
bitStream.Write(isBestFriendRequest); //isBFF
|
||||
bitStream.Write<uint8_t>(0); //isFTP
|
||||
}
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -1029,6 +1054,6 @@ void ChatPacketHandler::SendRemoveFriend(const PlayerData& receiver, std::string
|
||||
bitStream.Write<uint8_t>(isSuccessful); //isOnline
|
||||
bitStream.Write(LUWString(personToRemove));
|
||||
|
||||
SystemAddress sysAddr = receiver.sysAddr;
|
||||
SystemAddress sysAddr = receiver.worldServerSysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "dCommonVars.h"
|
||||
#include "dNetCommon.h"
|
||||
#include "BitStream.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "eChatMessageResponseCode.h"
|
||||
|
||||
struct PlayerData;
|
||||
|
||||
enum class eAddFriendResponseType : uint8_t;
|
||||
|
||||
@@ -34,13 +34,14 @@ enum class eChatChannel : uint8_t {
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct ChatMessage {
|
||||
LUWString message;
|
||||
PlayerData sender;
|
||||
PlayerData receiver;
|
||||
eChatChannel channel;
|
||||
LWOOBJID teamID;
|
||||
enum class eChatMessageResponseCode : uint8_t {
|
||||
SENT = 0,
|
||||
NOTONLINE,
|
||||
GENERALERROR,
|
||||
RECEIVEDNEWWHISPER,
|
||||
NOTFRIENDS,
|
||||
SENDERFREETRIAL,
|
||||
RECEIVERFREETRIAL,
|
||||
};
|
||||
|
||||
namespace ChatPacketHandler {
|
||||
@@ -63,12 +64,15 @@ namespace ChatPacketHandler {
|
||||
void HandleTeamPromote(Packet* packet);
|
||||
void HandleTeamLootOption(Packet* packet);
|
||||
void HandleTeamStatusRequest(Packet* packet);
|
||||
void OnAchievementNotify(RakNet::BitStream& bitstream, const SystemAddress& sysAddr);
|
||||
|
||||
void SendTeamInvite(const PlayerData& receiver, const PlayerData& sender);
|
||||
void SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName);
|
||||
void SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName);
|
||||
void SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64PlayerID);
|
||||
void SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID);
|
||||
|
||||
/* Sends a message to the provided `receiver` with information about the updated team. If `i64LeaderID` is not LWOOBJID_EMPTY, the client will update the leader to that new playerID. */
|
||||
void SendTeamRemovePlayer(const PlayerData& receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName);
|
||||
void SendTeamSetOffWorldFlag(const PlayerData& receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "RakNetDefines.h"
|
||||
#include "MessageIdentifiers.h"
|
||||
|
||||
#include "ChatWeb.h"
|
||||
#include "ChatWebAPI.h"
|
||||
|
||||
namespace Game {
|
||||
Logger* logger = nullptr;
|
||||
@@ -92,18 +92,17 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// setup the chat api web server
|
||||
const uint32_t web_server_port = GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("web_server_port")).value_or(2005);
|
||||
if (Game::config->GetValue("web_server_enabled") == "1" && !Game::web.Startup("localhost", web_server_port)) {
|
||||
// if we want the web server and it fails to start, exit
|
||||
// seyup the chat api web server
|
||||
bool web_server_enabled = Game::config->GetValue("web_server_enabled") == "1";
|
||||
ChatWebAPI chatwebapi;
|
||||
if (web_server_enabled && !chatwebapi.Startup()){
|
||||
// if we want the web api and it fails to start, exit
|
||||
LOG("Failed to start web server, shutting down.");
|
||||
Database::Destroy("ChatServer");
|
||||
delete Game::logger;
|
||||
delete Game::config;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (Game::web.IsEnabled()) ChatWeb::RegisterRoutes();
|
||||
};
|
||||
|
||||
//Find out the master's IP:
|
||||
std::string masterIP;
|
||||
@@ -167,8 +166,10 @@ int main(int argc, char** argv) {
|
||||
packet = nullptr;
|
||||
}
|
||||
|
||||
// Check and handle web requests:
|
||||
if (Game::web.IsEnabled()) Game::web.ReceiveRequests();
|
||||
//Check and handle web requests:
|
||||
if (web_server_enabled) {
|
||||
chatwebapi.ReceiveRequests();
|
||||
}
|
||||
|
||||
//Push our log every 30s:
|
||||
if (framesSinceLastFlush >= logFlushTime) {
|
||||
@@ -206,7 +207,6 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
void HandlePacket(Packet* packet) {
|
||||
LOG("Received packet with ID: %i", packet->data[0]);
|
||||
if (packet->length < 1) return;
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
LOG("A server has disconnected, erasing their connected players from the list.");
|
||||
@@ -224,6 +224,10 @@ void HandlePacket(Packet* packet) {
|
||||
if (connection != eConnectionType::CHAT) return;
|
||||
inStream.Read(chatMessageID);
|
||||
|
||||
// Our packing byte wasnt there? Probably a false packet
|
||||
if (inStream.GetNumberOfUnreadBits() < 8) return;
|
||||
inStream.IgnoreBytes(1);
|
||||
|
||||
switch (chatMessageID) {
|
||||
case MessageType::Chat::GM_MUTE:
|
||||
Game::playerContainer.MuteUpdate(packet);
|
||||
@@ -322,6 +326,9 @@ void HandlePacket(Packet* packet) {
|
||||
case MessageType::Chat::SHOW_ALL:
|
||||
ChatPacketHandler::HandleShowAll(packet);
|
||||
break;
|
||||
case MessageType::Chat::ACHIEVEMENT_NOTIFY:
|
||||
ChatPacketHandler::OnAchievementNotify(inStream, packet->systemAddress);
|
||||
break;
|
||||
case MessageType::Chat::USER_CHANNEL_CHAT_MESSAGE:
|
||||
case MessageType::Chat::WORLD_DISCONNECT_REQUEST:
|
||||
case MessageType::Chat::WORLD_PROXIMITY_RESPONSE:
|
||||
@@ -357,7 +364,6 @@ void HandlePacket(Packet* packet) {
|
||||
case MessageType::Chat::UGCMANIFEST_REPORT_DONE_BLUEPRINT:
|
||||
case MessageType::Chat::UGCC_REQUEST:
|
||||
case MessageType::Chat::WORLD_PLAYERS_PET_MODERATED_ACKNOWLEDGE:
|
||||
case MessageType::Chat::ACHIEVEMENT_NOTIFY:
|
||||
case MessageType::Chat::GM_CLOSE_PRIVATE_CHAT_WINDOW:
|
||||
case MessageType::Chat::PLAYER_READY:
|
||||
case MessageType::Chat::GET_DONATION_TOTAL:
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
#include "ChatWeb.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
#include "json.hpp"
|
||||
#include "dCommonVars.h"
|
||||
#include "MessageType/Chat.h"
|
||||
#include "dServer.h"
|
||||
#include "dConfig.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "eHTTPMethod.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include "ChatPackets.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "Database.h"
|
||||
#include "ChatJSONUtils.h"
|
||||
#include "JSONUtils.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "dChatFilter.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
void HandleHTTPPlayersRequest(HTTPReply& reply, std::string body) {
|
||||
const json data = Game::playerContainer;
|
||||
reply.status = data.empty() ? eHTTPStatusCode::NO_CONTENT : eHTTPStatusCode::OK;
|
||||
reply.message = data.empty() ? "{\"error\":\"No Players Online\"}" : data.dump();
|
||||
}
|
||||
|
||||
void HandleHTTPTeamsRequest(HTTPReply& reply, std::string body) {
|
||||
const json data = Game::playerContainer.GetTeamContainer();
|
||||
reply.status = data.empty() ? eHTTPStatusCode::NO_CONTENT : eHTTPStatusCode::OK;
|
||||
reply.message = data.empty() ? "{\"error\":\"No Teams Online\"}" : data.dump();
|
||||
}
|
||||
|
||||
void HandleHTTPAnnounceRequest(HTTPReply& reply, std::string body) {
|
||||
auto data = GeneralUtils::TryParse<json>(body);
|
||||
if (!data) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = "{\"error\":\"Invalid JSON\"}";
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& good_data = data.value();
|
||||
auto check = JSONUtils::CheckRequiredData(good_data, { "title", "message" });
|
||||
if (!check.empty()) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = check;
|
||||
} else {
|
||||
|
||||
ChatPackets::Announcement announcement;
|
||||
announcement.title = good_data["title"];
|
||||
announcement.message = good_data["message"];
|
||||
announcement.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
reply.status = eHTTPStatusCode::OK;
|
||||
reply.message = "{\"status\":\"Announcement Sent\"}";
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSChat(mg_connection* connection, json data) {
|
||||
auto check = JSONUtils::CheckRequiredData(data, { "user", "message", "gmlevel", "zone" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto user = data["user"].get<std::string>();
|
||||
const auto message = data["message"].get<std::string>();
|
||||
const auto gmlevel = GeneralUtils::TryParse<eGameMasterLevel>(data["gmlevel"].get<std::string>()).value_or(eGameMasterLevel::CIVILIAN);
|
||||
const auto zone = data["zone"].get<uint32_t>();
|
||||
|
||||
const auto filter_check = Game::chatFilter->IsSentenceOkay(message, gmlevel);
|
||||
if (!filter_check.empty()) {
|
||||
LOG_DEBUG("Chat message \"%s\" from %s was not allowed", message.c_str(), user.c_str());
|
||||
data["error"] = "Chat message blocked by filter";
|
||||
data["filtered"] = json::array();
|
||||
for (const auto& [start, len] : filter_check) {
|
||||
data["filtered"].push_back(message.substr(start, len));
|
||||
}
|
||||
mg_ws_send(connection, data.dump().c_str(), data.dump().size(), WEBSOCKET_OP_TEXT);
|
||||
return;
|
||||
}
|
||||
LOG("%s: %s", user.c_str(), message.c_str());
|
||||
|
||||
// bodge to test
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
bitStream.Write(zone);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write(eChatChannel::LOCAL);
|
||||
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(LUWString(user));
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<char>(0);
|
||||
|
||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
||||
bitStream.Write<uint16_t>(message[i]);
|
||||
}
|
||||
bitStream.Write<uint16_t>(0);
|
||||
Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ChatWeb {
|
||||
void RegisterRoutes() {
|
||||
// REST API v1 routes
|
||||
std::string v1_route = "/api/v1/";
|
||||
Game::web.RegisterHTTPRoute({
|
||||
.path = v1_route + "players",
|
||||
.method = eHTTPMethod::GET,
|
||||
.handle = HandleHTTPPlayersRequest
|
||||
});
|
||||
|
||||
Game::web.RegisterHTTPRoute({
|
||||
.path = v1_route + "teams",
|
||||
.method = eHTTPMethod::GET,
|
||||
.handle = HandleHTTPTeamsRequest
|
||||
});
|
||||
|
||||
Game::web.RegisterHTTPRoute({
|
||||
.path = v1_route + "announce",
|
||||
.method = eHTTPMethod::POST,
|
||||
.handle = HandleHTTPAnnounceRequest
|
||||
});
|
||||
|
||||
// WebSocket Events
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "chat",
|
||||
.handle = HandleWSChat
|
||||
});
|
||||
|
||||
// WebSocket subscriptions
|
||||
Game::web.RegisterWSSubscription("chat");
|
||||
Game::web.RegisterWSSubscription("player");
|
||||
Game::web.RegisterWSSubscription("team");
|
||||
}
|
||||
|
||||
void SendWSPlayerUpdate(const PlayerData& player, eActivityType activityType) {
|
||||
json data;
|
||||
data["player_data"] = player;
|
||||
data["update_type"] = magic_enum::enum_name(activityType);
|
||||
Game::web.SendWSMessage("player", data);
|
||||
}
|
||||
|
||||
void SendWSChatMessage(const ChatMessage& chatMessage) {
|
||||
json data;
|
||||
data["message"] = chatMessage.message.GetAsString();
|
||||
data["sender"] = chatMessage.sender;
|
||||
data["channel"] = magic_enum::enum_name(chatMessage.channel);
|
||||
|
||||
switch (chatMessage.channel) {
|
||||
case eChatChannel::TEAM:
|
||||
data["teamID"] = chatMessage.teamID;
|
||||
break;
|
||||
case eChatChannel::PRIVATE_CHAT:
|
||||
data["receiver"] = chatMessage.receiver;
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
Game::web.SendWSMessage("chat", data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef __CHATWEB_H__
|
||||
#define __CHATWEB_H__
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Web.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "IActivityLog.h"
|
||||
#include "ChatPacketHandler.h"
|
||||
|
||||
namespace ChatWeb {
|
||||
void RegisterRoutes();
|
||||
void SendWSPlayerUpdate(const PlayerData& player, eActivityType activityType);
|
||||
void SendWSChatMessage(const ChatMessage& chatMessage);
|
||||
};
|
||||
|
||||
|
||||
#endif // __CHATWEB_H__
|
||||
|
||||
197
dChatServer/ChatWebAPI.cpp
Normal file
197
dChatServer/ChatWebAPI.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
#include "ChatWebAPI.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Game.h"
|
||||
#include "json.hpp"
|
||||
#include "dCommonVars.h"
|
||||
#include "MessageType/Chat.h"
|
||||
#include "dServer.h"
|
||||
#include "dConfig.h"
|
||||
#include "PlayerContainer.h"
|
||||
#include "JSONUtils.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "eHTTPMethod.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include "ChatPackets.h"
|
||||
#include "StringifiedEnum.h"
|
||||
#include "Database.h"
|
||||
|
||||
#ifdef DARKFLAME_PLATFORM_WIN32
|
||||
#pragma push_macro("DELETE")
|
||||
#undef DELETE
|
||||
#endif
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
typedef struct mg_connection mg_connection;
|
||||
typedef struct mg_http_message mg_http_message;
|
||||
|
||||
namespace {
|
||||
const char* json_content_type = "Content-Type: application/json\r\n";
|
||||
std::map<std::pair<eHTTPMethod, std::string>, WebAPIHTTPRoute> Routes {};
|
||||
}
|
||||
|
||||
bool ValidateAuthentication(const mg_http_message* http_msg) {
|
||||
// TO DO: This is just a placeholder for now
|
||||
// use tokens or something at a later point if we want to implement authentication
|
||||
// bit using the listen bind address to limit external access is good enough to start with
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ValidateJSON(std::optional<json> data, HTTPReply& reply) {
|
||||
if (!data) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = "{\"error\":\"Invalid JSON\"}";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandlePlayersRequest(HTTPReply& reply, std::string body) {
|
||||
const json data = Game::playerContainer;
|
||||
reply.status = data.empty() ? eHTTPStatusCode::NO_CONTENT : eHTTPStatusCode::OK;
|
||||
reply.message = data.empty() ? "{\"error\":\"No Players Online\"}" : data.dump();
|
||||
}
|
||||
|
||||
void HandleTeamsRequest(HTTPReply& reply, std::string body) {
|
||||
const json data = Game::playerContainer.GetTeamContainer();
|
||||
reply.status = data.empty() ? eHTTPStatusCode::NO_CONTENT : eHTTPStatusCode::OK;
|
||||
reply.message = data.empty() ? "{\"error\":\"No Teams Online\"}" : data.dump();
|
||||
}
|
||||
|
||||
void HandleAnnounceRequest(HTTPReply& reply, std::string body) {
|
||||
auto data = GeneralUtils::TryParse<json>(body);
|
||||
if (!ValidateJSON(data, reply)) return;
|
||||
|
||||
const auto& good_data = data.value();
|
||||
auto check = JSONUtils::CheckRequiredData(good_data, { "title", "message" });
|
||||
if (!check.empty()) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = check;
|
||||
} else {
|
||||
|
||||
ChatPackets::Announcement announcement;
|
||||
announcement.title = good_data["title"];
|
||||
announcement.message = good_data["message"];
|
||||
announcement.Send();
|
||||
|
||||
reply.status = eHTTPStatusCode::OK;
|
||||
reply.message = "{\"status\":\"Announcement Sent\"}";
|
||||
}
|
||||
}
|
||||
|
||||
void HandleInvalidRoute(HTTPReply& reply) {
|
||||
reply.status = eHTTPStatusCode::NOT_FOUND;
|
||||
reply.message = "{\"error\":\"Invalid Route\"}";
|
||||
}
|
||||
|
||||
void HandleHTTPMessage(mg_connection* connection, const mg_http_message* http_msg) {
|
||||
HTTPReply reply;
|
||||
|
||||
if (!http_msg) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = "{\"error\":\"Invalid Request\"}";
|
||||
} else if (ValidateAuthentication(http_msg)) {
|
||||
|
||||
// convert method from cstring to std string
|
||||
std::string method_string(http_msg->method.buf, http_msg->method.len);
|
||||
// get mehtod from mg to enum
|
||||
const eHTTPMethod method = magic_enum::enum_cast<eHTTPMethod>(method_string).value_or(eHTTPMethod::INVALID);
|
||||
|
||||
// convert uri from cstring to std string
|
||||
std::string uri(http_msg->uri.buf, http_msg->uri.len);
|
||||
std::transform(uri.begin(), uri.end(), uri.begin(), ::tolower);
|
||||
|
||||
// convert body from cstring to std string
|
||||
std::string body(http_msg->body.buf, http_msg->body.len);
|
||||
|
||||
|
||||
const auto routeItr = Routes.find({method, uri});
|
||||
|
||||
if (routeItr != Routes.end()) {
|
||||
const auto& [_, route] = *routeItr;
|
||||
route.handle(reply, body);
|
||||
} else HandleInvalidRoute(reply);
|
||||
} else {
|
||||
reply.status = eHTTPStatusCode::UNAUTHORIZED;
|
||||
reply.message = "{\"error\":\"Unauthorized\"}";
|
||||
}
|
||||
mg_http_reply(connection, static_cast<int>(reply.status), json_content_type, reply.message.c_str());
|
||||
}
|
||||
|
||||
|
||||
void HandleRequests(mg_connection* connection, int request, void* request_data) {
|
||||
switch (request) {
|
||||
case MG_EV_HTTP_MSG:
|
||||
HandleHTTPMessage(connection, static_cast<mg_http_message*>(request_data));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ChatWebAPI::RegisterHTTPRoutes(WebAPIHTTPRoute route) {
|
||||
auto [_, success] = Routes.try_emplace({ route.method, route.path }, route);
|
||||
if (!success) {
|
||||
LOG_DEBUG("Failed to register route %s", route.path.c_str());
|
||||
} else {
|
||||
LOG_DEBUG("Registered route %s", route.path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ChatWebAPI::ChatWebAPI() {
|
||||
mg_log_set(MG_LL_NONE);
|
||||
mg_mgr_init(&mgr); // Initialize event manager
|
||||
}
|
||||
|
||||
ChatWebAPI::~ChatWebAPI() {
|
||||
mg_mgr_free(&mgr);
|
||||
}
|
||||
|
||||
bool ChatWebAPI::Startup() {
|
||||
// Make listen address
|
||||
// std::string listen_ip = Game::config->GetValue("web_server_listen_ip");
|
||||
// if (listen_ip == "localhost") listen_ip = "127.0.0.1";
|
||||
|
||||
const std::string& listen_port = Game::config->GetValue("web_server_listen_port");
|
||||
// const std::string& listen_address = "http://" + listen_ip + ":" + listen_port;
|
||||
const std::string& listen_address = "http://localhost:" + listen_port;
|
||||
LOG("Starting web server on %s", listen_address.c_str());
|
||||
|
||||
// Create HTTP listener
|
||||
if (!mg_http_listen(&mgr, listen_address.c_str(), HandleRequests, NULL)) {
|
||||
LOG("Failed to create web server listener on %s", listen_port.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Register routes
|
||||
|
||||
// API v1 routes
|
||||
std::string v1_route = "/api/v1/";
|
||||
RegisterHTTPRoutes({
|
||||
.path = v1_route + "players",
|
||||
.method = eHTTPMethod::GET,
|
||||
.handle = HandlePlayersRequest
|
||||
});
|
||||
|
||||
RegisterHTTPRoutes({
|
||||
.path = v1_route + "teams",
|
||||
.method = eHTTPMethod::GET,
|
||||
.handle = HandleTeamsRequest
|
||||
});
|
||||
|
||||
RegisterHTTPRoutes({
|
||||
.path = v1_route + "announce",
|
||||
.method = eHTTPMethod::POST,
|
||||
.handle = HandleAnnounceRequest
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatWebAPI::ReceiveRequests() {
|
||||
mg_mgr_poll(&mgr, 15);
|
||||
}
|
||||
|
||||
#ifdef DARKFLAME_PLATFORM_WIN32
|
||||
#pragma pop_macro("DELETE")
|
||||
#endif
|
||||
36
dChatServer/ChatWebAPI.h
Normal file
36
dChatServer/ChatWebAPI.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef __CHATWEBAPI_H__
|
||||
#define __CHATWEBAPI_H__
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "eHTTPStatusCode.h"
|
||||
|
||||
enum class eHTTPMethod;
|
||||
|
||||
typedef struct mg_mgr mg_mgr;
|
||||
|
||||
struct HTTPReply {
|
||||
eHTTPStatusCode status = eHTTPStatusCode::NOT_FOUND;
|
||||
std::string message = "{\"error\":\"Not Found\"}";
|
||||
};
|
||||
|
||||
struct WebAPIHTTPRoute {
|
||||
std::string path;
|
||||
eHTTPMethod method;
|
||||
std::function<void(HTTPReply&, const std::string&)> handle;
|
||||
};
|
||||
|
||||
class ChatWebAPI {
|
||||
public:
|
||||
ChatWebAPI();
|
||||
~ChatWebAPI();
|
||||
void ReceiveRequests();
|
||||
void RegisterHTTPRoutes(WebAPIHTTPRoute route);
|
||||
bool Startup();
|
||||
private:
|
||||
mg_mgr mgr;
|
||||
|
||||
};
|
||||
|
||||
#endif // __CHATWEBAPI_H__
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "ChatJSONUtils.h"
|
||||
#include "JSONUtils.h"
|
||||
|
||||
#include "json.hpp"
|
||||
|
||||
@@ -47,3 +47,16 @@ void to_json(json& data, const TeamData& teamData) {
|
||||
members.push_back(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
std::string JSONUtils::CheckRequiredData(const json& data, const std::vector<std::string>& requiredData) {
|
||||
json check;
|
||||
check["error"] = json::array();
|
||||
for (const auto& required : requiredData) {
|
||||
if (!data.contains(required)) {
|
||||
check["error"].push_back("Missing Parameter: " + required);
|
||||
} else if (data[required] == "") {
|
||||
check["error"].push_back("Empty Parameter: " + required);
|
||||
}
|
||||
}
|
||||
return check["error"].empty() ? "" : check.dump();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __CHATJSONUTILS_H__
|
||||
#define __CHATJSONUTILS_H__
|
||||
#ifndef __JSONUTILS_H__
|
||||
#define __JSONUTILS_H__
|
||||
|
||||
#include "json_fwd.hpp"
|
||||
#include "PlayerContainer.h"
|
||||
@@ -9,4 +9,9 @@ void to_json(nlohmann::json& data, const PlayerContainer& playerContainer);
|
||||
void to_json(nlohmann::json& data, const TeamContainer& teamData);
|
||||
void to_json(nlohmann::json& data, const TeamData& teamData);
|
||||
|
||||
#endif // __CHATJSONUTILS_H__
|
||||
namespace JSONUtils {
|
||||
// check required data for reqeust
|
||||
std::string CheckRequiredData(const nlohmann::json& data, const std::vector<std::string>& requiredData);
|
||||
}
|
||||
|
||||
#endif // __JSONUTILS_H__
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "ChatPackets.h"
|
||||
#include "dConfig.h"
|
||||
#include "MessageType/Chat.h"
|
||||
#include "ChatWeb.h"
|
||||
|
||||
void PlayerContainer::Initialize() {
|
||||
m_MaxNumberOfBestFriends =
|
||||
@@ -53,14 +52,14 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
if (!inStream.Read(data.zoneID)) return;
|
||||
if (!inStream.Read(data.muteExpire)) return;
|
||||
if (!inStream.Read(data.gmLevel)) return;
|
||||
data.sysAddr = packet->systemAddress;
|
||||
data.worldServerSysAddr = packet->systemAddress;
|
||||
|
||||
m_Names[data.playerID] = GeneralUtils::UTF8ToUTF16(data.playerName);
|
||||
m_PlayerCount++;
|
||||
|
||||
LOG("Added user: %s (%llu), zone: %i", data.playerName.c_str(), data.playerID, data.zoneID.GetMapID());
|
||||
ChatWeb::SendWSPlayerUpdate(data, isLogin ? eActivityType::PlayerLoggedIn : eActivityType::PlayerChangedZone);
|
||||
Database::Get()->UpdateActivityLog(data.playerID, isLogin ? eActivityType::PlayerLoggedIn : eActivityType::PlayerChangedZone, data.zoneID.GetMapID());
|
||||
|
||||
Database::Get()->UpdateActivityLog(data.playerID, eActivityType::PlayerLoggedIn, data.zoneID.GetMapID());
|
||||
m_PlayersToRemove.erase(playerId);
|
||||
}
|
||||
|
||||
@@ -114,8 +113,6 @@ void PlayerContainer::RemovePlayer(const LWOOBJID playerID) {
|
||||
}
|
||||
}
|
||||
|
||||
ChatWeb::SendWSPlayerUpdate(player, eActivityType::PlayerLoggedOut);
|
||||
|
||||
m_PlayerCount--;
|
||||
LOG("Removed user: %llu", playerID);
|
||||
m_Players.erase(playerID);
|
||||
@@ -244,7 +241,7 @@ void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) {
|
||||
LOG("Tried to add player to team that already had 4 players");
|
||||
const auto& player = GetPlayerData(playerID);
|
||||
if (!player) return;
|
||||
ChatPackets::SendSystemMessage(player.sysAddr, u"The teams is full! You have not been added to a team!");
|
||||
ChatPackets::SendSystemMessage(player.worldServerSysAddr, u"The teams is full! You have not been added to a team!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -287,41 +284,39 @@ void PlayerContainer::AddMember(TeamData* team, LWOOBJID playerID) {
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerContainer::RemoveMember(TeamData* team, LWOOBJID playerID, bool disband, bool kicked, bool leaving, bool silent) {
|
||||
const auto index = std::find(team->memberIDs.begin(), team->memberIDs.end(), playerID);
|
||||
void PlayerContainer::RemoveMember(TeamData* team, LWOOBJID causingPlayerID, bool disband, bool kicked, bool leaving, bool silent) {
|
||||
LOG_DEBUG("Player %llu is leaving team %i", causingPlayerID, team->teamID);
|
||||
const auto index = std::ranges::find(team->memberIDs, causingPlayerID);
|
||||
|
||||
if (index == team->memberIDs.end()) return;
|
||||
|
||||
const auto& member = GetPlayerData(playerID);
|
||||
|
||||
if (member && !silent) {
|
||||
ChatPacketHandler::SendTeamSetLeader(member, LWOOBJID_EMPTY);
|
||||
}
|
||||
|
||||
const auto memberName = GetName(playerID);
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
if (silent && memberId == playerID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& otherMember = GetPlayerData(memberId);
|
||||
|
||||
if (!otherMember) continue;
|
||||
|
||||
ChatPacketHandler::SendTeamRemovePlayer(otherMember, disband, kicked, leaving, false, team->leaderID, playerID, memberName);
|
||||
}
|
||||
|
||||
team->memberIDs.erase(index);
|
||||
|
||||
UpdateTeamsOnWorld(team, false);
|
||||
const auto& member = GetPlayerData(causingPlayerID);
|
||||
|
||||
const auto causingMemberName = GetName(causingPlayerID);
|
||||
|
||||
if (member && !silent) {
|
||||
ChatPacketHandler::SendTeamRemovePlayer(member, disband, kicked, leaving, team->local, LWOOBJID_EMPTY, causingPlayerID, causingMemberName);
|
||||
}
|
||||
|
||||
if (team->memberIDs.size() <= 1) {
|
||||
DisbandTeam(team);
|
||||
} else {
|
||||
if (playerID == team->leaderID) {
|
||||
PromoteMember(team, team->memberIDs[0]);
|
||||
DisbandTeam(team, causingPlayerID, causingMemberName);
|
||||
} else /* team has enough members to be a team still */ {
|
||||
team->leaderID = (causingPlayerID == team->leaderID) ? team->memberIDs[0] : team->leaderID;
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
if (silent && memberId == causingPlayerID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& otherMember = GetPlayerData(memberId);
|
||||
|
||||
if (!otherMember) continue;
|
||||
|
||||
ChatPacketHandler::SendTeamRemovePlayer(otherMember, disband, kicked, leaving, team->local, team->leaderID, causingPlayerID, causingMemberName);
|
||||
}
|
||||
|
||||
UpdateTeamsOnWorld(team, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,20 +332,19 @@ void PlayerContainer::PromoteMember(TeamData* team, LWOOBJID newLeader) {
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerContainer::DisbandTeam(TeamData* team) {
|
||||
const auto index = std::find(GetTeams().begin(), GetTeams().end(), team);
|
||||
void PlayerContainer::DisbandTeam(TeamData* team, const LWOOBJID causingPlayerID, const std::u16string& causingPlayerName) {
|
||||
const auto index = std::ranges::find(GetTeams(), team);
|
||||
|
||||
if (index == GetTeams().end()) return;
|
||||
LOG_DEBUG("Disbanding team %i", (*index)->teamID);
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
const auto& otherMember = GetPlayerData(memberId);
|
||||
|
||||
if (!otherMember) continue;
|
||||
|
||||
const auto memberName = GeneralUtils::UTF8ToUTF16(otherMember.playerName);
|
||||
|
||||
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, causingPlayerID, causingPlayerName);
|
||||
}
|
||||
|
||||
UpdateTeamsOnWorld(team, true);
|
||||
|
||||
@@ -42,7 +42,7 @@ struct PlayerData {
|
||||
return muteExpire == 1 || muteExpire > time(NULL);
|
||||
}
|
||||
|
||||
SystemAddress sysAddr{};
|
||||
SystemAddress worldServerSysAddr{};
|
||||
LWOZONEID zoneID{};
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
time_t muteExpire = 0;
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
void AddMember(TeamData* team, LWOOBJID playerID);
|
||||
void RemoveMember(TeamData* team, LWOOBJID playerID, bool disband, bool kicked, bool leaving, bool silent = false);
|
||||
void PromoteMember(TeamData* team, LWOOBJID newLeader);
|
||||
void DisbandTeam(TeamData* team);
|
||||
void DisbandTeam(TeamData* team, const LWOOBJID causingPlayerID, const std::u16string& causingPlayerName);
|
||||
void TeamStatusUpdate(TeamData* team);
|
||||
void UpdateTeamsOnWorld(TeamData* team, bool deleteTeam);
|
||||
std::u16string GetName(LWOOBJID playerID);
|
||||
|
||||
@@ -7,7 +7,6 @@ set(DCOMMON_SOURCES
|
||||
"Logger.cpp"
|
||||
"Game.cpp"
|
||||
"GeneralUtils.cpp"
|
||||
"JSONUtils.cpp"
|
||||
"LDFFormat.cpp"
|
||||
"Metrics.cpp"
|
||||
"NiPoint3.cpp"
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "JSONUtils.h"
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::string JSONUtils::CheckRequiredData(const json& data, const std::vector<std::string>& requiredData) {
|
||||
json check;
|
||||
check["error"] = json::array();
|
||||
for (const auto& required : requiredData) {
|
||||
if (!data.contains(required)) {
|
||||
check["error"].push_back("Missing Parameter: " + required);
|
||||
} else if (data[required] == "") {
|
||||
check["error"].push_back("Empty Parameter: " + required);
|
||||
}
|
||||
}
|
||||
return check["error"].empty() ? "" : check.dump();
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef _JSONUTILS_H_
|
||||
#define _JSONUTILS_H_
|
||||
|
||||
#include "json_fwd.hpp"
|
||||
|
||||
namespace JSONUtils {
|
||||
// check required data for reqeust
|
||||
std::string CheckRequiredData(const nlohmann::json& data, const std::vector<std::string>& requiredData);
|
||||
}
|
||||
|
||||
#endif // _JSONUTILS_H_
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
constexpr LWOZONEID() noexcept = default;
|
||||
constexpr LWOZONEID(const LWOMAPID& mapID, const LWOINSTANCEID& instanceID, const LWOCLONEID& cloneID) noexcept { m_MapID = mapID; m_InstanceID = instanceID; m_CloneID = cloneID; }
|
||||
constexpr LWOZONEID(const LWOZONEID& replacement) noexcept { *this = replacement; }
|
||||
constexpr bool operator==(const LWOZONEID&) const = default;
|
||||
|
||||
private:
|
||||
LWOMAPID m_MapID = LWOMAPID_INVALID; //1000 for VE, 1100 for AG, etc...
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef __ECHATMESSAGERESPONSECODES__H__
|
||||
#define __ECHATMESSAGERESPONSECODES__H__
|
||||
|
||||
#include <cstdint>
|
||||
enum class eChatMessageResponseCode : uint8_t {
|
||||
SENT = 0,
|
||||
NOTONLINE,
|
||||
GENERALERROR,
|
||||
RECEIVEDNEWWHISPER,
|
||||
NOTFRIENDS,
|
||||
SENDERFREETRIAL,
|
||||
RECEIVERFREETRIAL,
|
||||
};
|
||||
|
||||
#endif //!__ECHATMESSAGERESPONSECODES__H__
|
||||
@@ -8,7 +8,6 @@
|
||||
enum class eActivityType : uint32_t {
|
||||
PlayerLoggedIn,
|
||||
PlayerLoggedOut,
|
||||
PlayerChangedZone,
|
||||
};
|
||||
|
||||
class IActivityLog {
|
||||
|
||||
@@ -204,6 +204,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
while (currentChild) {
|
||||
const auto* temp = currentChild->Attribute("v");
|
||||
const auto* id = currentChild->Attribute("id");
|
||||
const auto* si = currentChild->Attribute("si");
|
||||
if (temp && id) {
|
||||
uint32_t index = 0;
|
||||
uint64_t value = 0;
|
||||
@@ -212,6 +213,9 @@ void Character::DoQuickXMLDataParse() {
|
||||
value = std::stoull(temp);
|
||||
|
||||
m_PlayerFlags.insert(std::make_pair(index, value));
|
||||
} else if (si) {
|
||||
auto value = GeneralUtils::TryParse<uint32_t>(si);
|
||||
if (value) m_SessionFlags.insert(value.value());
|
||||
}
|
||||
currentChild = currentChild->NextSiblingElement();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "Character.h"
|
||||
|
||||
#include "CDMissionEmailTable.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
|
||||
m_MissionComponent = missionComponent;
|
||||
@@ -355,12 +357,25 @@ void Mission::Complete(const bool yieldRewards) {
|
||||
for (const auto& email : missionEmails) {
|
||||
const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_";
|
||||
|
||||
if (email.messageType == 1) {
|
||||
if (email.messageType == 1 /* Send an email to the player */) {
|
||||
const auto subject = "%[" + missionEmailBase + "subjectText]";
|
||||
const auto body = "%[" + missionEmailBase + "bodyText]";
|
||||
const auto sender = "%[" + missionEmailBase + "senderName]";
|
||||
|
||||
Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1);
|
||||
} else if (email.messageType == 2 /* Send an announcement in chat */) {
|
||||
auto* character = entity->GetCharacter();
|
||||
|
||||
ChatPackets::AchievementNotify notify{};
|
||||
notify.missionEmailID = email.ID;
|
||||
notify.earningPlayerID = entity->GetObjectID();
|
||||
notify.earnerName.string = character ? GeneralUtils::ASCIIToUTF16(character->GetName()) : u"";
|
||||
|
||||
// Manual write since it's sent to chat server and not a game client
|
||||
RakNet::BitStream bitstream;
|
||||
notify.WriteHeader(bitstream);
|
||||
notify.Serialize(bitstream);
|
||||
Game::chatServer->Send(&bitstream, HIGH_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,7 +777,7 @@ void SlashCommandHandler::Startup() {
|
||||
.info = "Crashes the server",
|
||||
.aliases = { "crash", "pumpkin" },
|
||||
.handle = DEVGMCommands::Crash,
|
||||
.requiredLevel = eGameMasterLevel::DEVELOPER
|
||||
.requiredLevel = eGameMasterLevel::OPERATOR
|
||||
};
|
||||
RegisterCommand(CrashCommand);
|
||||
|
||||
@@ -1444,4 +1444,13 @@ void SlashCommandHandler::Startup() {
|
||||
.requiredLevel = eGameMasterLevel::CIVILIAN
|
||||
};
|
||||
RegisterCommand(removeIgnoreCommand);
|
||||
|
||||
Command shutdownCommand{
|
||||
.help = "Shuts this world down",
|
||||
.info = "Shuts this world down",
|
||||
.aliases = {"shutdown"},
|
||||
.handle = DEVGMCommands::Shutdown,
|
||||
.requiredLevel = eGameMasterLevel::DEVELOPER
|
||||
};
|
||||
RegisterCommand(shutdownCommand);
|
||||
}
|
||||
|
||||
@@ -1622,4 +1622,10 @@ namespace DEVGMCommands {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Shutdown(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
auto* character = entity->GetCharacter();
|
||||
if (character) LOG("Mythran (%s) has shutdown the world", character->GetName().c_str());
|
||||
Game::OnSignal(-1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace DEVGMCommands {
|
||||
void RollLoot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void CastSkill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
void Shutdown(Entity* entity, const SystemAddress& sysAddr, const std::string args);
|
||||
}
|
||||
|
||||
#endif //!DEVGMCOMMANDS_H
|
||||
|
||||
@@ -296,12 +296,15 @@ namespace GMGreaterThanZeroCommands {
|
||||
if (!splitArgs.empty() && !splitArgs.at(0).empty()) displayZoneData = splitArgs.at(0) == "1";
|
||||
if (splitArgs.size() > 1) displayIndividualPlayers = splitArgs.at(1) == "1";
|
||||
|
||||
ChatPackets::ShowAllRequest request;
|
||||
request.requestor = entity->GetObjectID();
|
||||
request.displayZoneData = displayZoneData;
|
||||
request.displayIndividualPlayers = displayIndividualPlayers;
|
||||
ShowAllRequest request {
|
||||
.requestor = entity->GetObjectID(),
|
||||
.displayZoneData = displayZoneData,
|
||||
.displayIndividualPlayers = displayIndividualPlayers
|
||||
};
|
||||
|
||||
request.Send(Game::chatSysAddr);
|
||||
CBITSTREAM;
|
||||
request.Serialize(bitStream);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
|
||||
void FindPlayer(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
@@ -310,11 +313,14 @@ namespace GMGreaterThanZeroCommands {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatPackets::FindPlayerRequest request;
|
||||
request.requestor = entity->GetObjectID();
|
||||
request.playerName = LUWString(args);
|
||||
FindPlayerRequest request {
|
||||
.requestor = entity->GetObjectID(),
|
||||
.playerName = LUWString(args)
|
||||
};
|
||||
|
||||
request.Send(Game::chatSysAddr);
|
||||
CBITSTREAM;
|
||||
request.Serialize(bitStream);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
|
||||
void Spectate(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
|
||||
@@ -273,6 +273,16 @@ Instance* InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
||||
for (Instance* i : m_Instances) {
|
||||
if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password) {
|
||||
auto* instance = FindPrivateInstance(password);
|
||||
|
||||
|
||||
@@ -76,25 +76,25 @@ public:
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
std::string m_IP;
|
||||
uint32_t m_Port;
|
||||
LWOZONEID m_ZoneID;
|
||||
int m_MaxClientsSoftCap;
|
||||
int m_MaxClientsHardCap;
|
||||
int m_CurrentClientCount;
|
||||
std::vector<Player> m_Players;
|
||||
SystemAddress m_SysAddr;
|
||||
bool m_Ready;
|
||||
bool m_IsShuttingDown;
|
||||
std::vector<PendingInstanceRequest> m_PendingRequests;
|
||||
std::vector<PendingInstanceRequest> m_PendingAffirmations;
|
||||
std::string m_IP{};
|
||||
uint32_t m_Port{};
|
||||
LWOZONEID m_ZoneID{};
|
||||
int m_MaxClientsSoftCap{};
|
||||
int m_MaxClientsHardCap{};
|
||||
int m_CurrentClientCount{};
|
||||
std::vector<Player> m_Players{};
|
||||
SystemAddress m_SysAddr{};
|
||||
bool m_Ready{};
|
||||
bool m_IsShuttingDown{};
|
||||
std::vector<PendingInstanceRequest> m_PendingRequests{};
|
||||
std::vector<PendingInstanceRequest> m_PendingAffirmations{};
|
||||
|
||||
uint32_t m_AffirmationTimeout;
|
||||
uint32_t m_AffirmationTimeout{};
|
||||
|
||||
bool m_IsPrivate;
|
||||
std::string m_Password;
|
||||
bool m_IsPrivate{};
|
||||
std::string m_Password{};
|
||||
|
||||
bool m_Shutdown;
|
||||
bool m_Shutdown{};
|
||||
|
||||
//Private functions:
|
||||
};
|
||||
@@ -125,6 +125,7 @@ public:
|
||||
|
||||
Instance* FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId = 0);
|
||||
Instance* FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
Instance* FindInstanceWithPrivate(LWOMAPID mapID, LWOINSTANCEID instanceID);
|
||||
|
||||
Instance* CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password);
|
||||
Instance* FindPrivateInstance(const std::string& password);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "Server.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "StringifiedEnum.h"
|
||||
|
||||
#ifdef DARKFLAME_PLATFORM_UNIX
|
||||
|
||||
@@ -212,6 +213,13 @@ int main(int argc, char** argv) {
|
||||
// Run migrations should any need to be run.
|
||||
MigrationRunner::RunSQLiteMigrations();
|
||||
|
||||
// Check for the --migrations-only flag
|
||||
if ((argc > 1 &&
|
||||
(strcmp(argv[1], "--migrations-only") == 0 || strcmp(argv[1], "-m") == 0))) {
|
||||
LOG("Migrations only flag detected. Exiting.");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
//If the first command line argument is -a or --account then make the user
|
||||
//input a username and password, with the password being hidden.
|
||||
bool createAccount = Database::Get()->GetAccountCount() == 0 && Game::config->GetValue("skip_account_creation") != "1";
|
||||
@@ -556,7 +564,7 @@ void HandlePacket(Packet* packet) {
|
||||
Instance* in = Game::im->GetInstance(zoneID, false, zoneClone);
|
||||
|
||||
for (auto* instance : Game::im->GetInstances()) {
|
||||
LOG("Instance: %i/%i/%i -> %i", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance == in);
|
||||
LOG("Instance: %i/%i/%i -> %i %s", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance == in, instance->GetSysAddr().ToString());
|
||||
}
|
||||
|
||||
if (in && !in->GetIsReady()) //Instance not ready, make a pending request
|
||||
@@ -597,15 +605,10 @@ void HandlePacket(Packet* packet) {
|
||||
if (!Game::im->IsPortInUse(theirPort)) {
|
||||
Instance* in = new Instance(theirIP.string, theirPort, theirZoneID, theirInstanceID, 0, 12, 12);
|
||||
|
||||
SystemAddress copy;
|
||||
copy.binaryAddress = packet->systemAddress.binaryAddress;
|
||||
copy.port = packet->systemAddress.port;
|
||||
|
||||
in->SetSysAddr(copy);
|
||||
in->SetSysAddr(packet->systemAddress);
|
||||
Game::im->AddInstance(in);
|
||||
} else {
|
||||
auto instance = Game::im->FindInstance(
|
||||
theirZoneID, static_cast<uint16_t>(theirInstanceID));
|
||||
auto* instance = Game::im->FindInstanceWithPrivate(theirZoneID, static_cast<LWOINSTANCEID>(theirInstanceID));
|
||||
if (instance) {
|
||||
instance->SetSysAddr(packet->systemAddress);
|
||||
}
|
||||
@@ -613,22 +616,14 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
if (theirServerType == ServerType::Chat) {
|
||||
SystemAddress copy;
|
||||
copy.binaryAddress = packet->systemAddress.binaryAddress;
|
||||
copy.port = packet->systemAddress.port;
|
||||
|
||||
chatServerMasterPeerSysAddr = copy;
|
||||
chatServerMasterPeerSysAddr = packet->systemAddress;
|
||||
}
|
||||
|
||||
if (theirServerType == ServerType::Auth) {
|
||||
SystemAddress copy;
|
||||
copy.binaryAddress = packet->systemAddress.binaryAddress;
|
||||
copy.port = packet->systemAddress.port;
|
||||
|
||||
authServerMasterPeerSysAddr = copy;
|
||||
authServerMasterPeerSysAddr = packet->systemAddress;
|
||||
}
|
||||
|
||||
LOG("Received server info, instance: %i port: %i", theirInstanceID, theirPort);
|
||||
LOG("Received %s server info, instance: %i port: %i", StringifiedEnum::ToString(theirServerType).data(), theirInstanceID, theirPort);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -692,7 +687,7 @@ void HandlePacket(Packet* packet) {
|
||||
if (instance) {
|
||||
instance->AddPlayer(Player());
|
||||
} else {
|
||||
printf("Instance missing? What?");
|
||||
LOG("Instance missing? What?");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -733,8 +728,8 @@ void HandlePacket(Packet* packet) {
|
||||
inStream.Read<char>(character);
|
||||
password += character;
|
||||
}
|
||||
|
||||
Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
|
||||
auto* newInst = Game::im->CreatePrivateInstance(mapId, cloneId, password.c_str());
|
||||
LOG("Creating private zone %i/%i/%i with password %s", newInst->GetMapID(), newInst->GetCloneID(), newInst->GetInstanceID(), password.c_str());
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -835,11 +830,10 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case MessageType::Master::SHUTDOWN_RESPONSE: {
|
||||
RakNet::BitStream inStream(packet->data, packet->length, false);
|
||||
uint64_t header = inStream.Read(header);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
|
||||
auto* instance = Game::im->GetInstanceBySysAddr(packet->systemAddress);
|
||||
|
||||
LOG("Got shutdown response from %s", packet->systemAddress.ToString());
|
||||
if (instance == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,9 +61,6 @@ struct LUBitStream {
|
||||
void WriteHeader(RakNet::BitStream& bitStream) const;
|
||||
bool ReadHeader(RakNet::BitStream& bitStream);
|
||||
void Send(const SystemAddress& sysAddr) const;
|
||||
void Broadcast() const {
|
||||
Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
};
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const {}
|
||||
virtual bool Deserialize(RakNet::BitStream& bitStream) { return true; }
|
||||
|
||||
@@ -11,136 +11,140 @@
|
||||
#include "dServer.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "MessageType/Chat.h"
|
||||
namespace ChatPackets {
|
||||
void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->displayZoneData);
|
||||
bitStream.Write(this->displayIndividualPlayers);
|
||||
}
|
||||
|
||||
bool ShowAllRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
VALIDATE_READ(inStream.Read(this->requestor));
|
||||
VALIDATE_READ(inStream.Read(this->displayZoneData));
|
||||
VALIDATE_READ(inStream.Read(this->displayIndividualPlayers));
|
||||
return true;
|
||||
}
|
||||
|
||||
void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->playerName);
|
||||
}
|
||||
|
||||
bool FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
VALIDATE_READ(inStream.Read(this->requestor));
|
||||
VALIDATE_READ(inStream.Read(this->playerName));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatMessage::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write<uint64_t>(0);// senderID
|
||||
bitStream.Write(chatChannel);
|
||||
|
||||
bitStream.Write<uint32_t>(message.GetAsString().size());
|
||||
bitStream.Write(LUWString(senderName));
|
||||
|
||||
bitStream.Write(playerObjectID); // senderID
|
||||
bitStream.Write<uint16_t>(0); // sourceID
|
||||
bitStream.Write(responseCode);
|
||||
bitStream.Write(message);
|
||||
|
||||
}
|
||||
|
||||
bool ChatMessage::Deserialize(RakNet::BitStream& inStream) {
|
||||
//TODO: Implement this
|
||||
return false;
|
||||
}
|
||||
void ChatMessage::Handle(){
|
||||
|
||||
}
|
||||
|
||||
void WorldChatMessage::Serialize(RakNet::BitStream& bitStream) const {
|
||||
|
||||
}
|
||||
bool WorldChatMessage::Deserialize(RakNet::BitStream& inStream) {
|
||||
VALIDATE_READ(inStream.Read(chatChannel));
|
||||
uint16_t padding;
|
||||
VALIDATE_READ(inStream.Read(padding));
|
||||
uint32_t messageLength;
|
||||
VALIDATE_READ(inStream.Read(messageLength));
|
||||
string message_tmp;
|
||||
for (uint32_t i = 0; i < messageLength; ++i) {
|
||||
uint16_t character;
|
||||
VALIDATE_READ(inStream.Read(character));
|
||||
message_tmp.push_back(character);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void WorldChatMessage::Handle() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PrivateChatMessage::Serialize(RakNet::BitStream& bitStream) const {
|
||||
|
||||
}
|
||||
bool PrivateChatMessage::Deserialize(RakNet::BitStream& inStream) {
|
||||
|
||||
}
|
||||
void PrivateChatMessage::Handle() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void UserChatMessage::Serialize(RakNet::BitStream& bitStream) const {
|
||||
|
||||
}
|
||||
bool UserChatMessage::Deserialize(RakNet::BitStream& inStream) {
|
||||
|
||||
}
|
||||
void UserChatMessage::Handle() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write<char>(4);
|
||||
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(LUWString("", 33));
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<char>(0);
|
||||
|
||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
||||
bitStream.Write<uint16_t>(message[i]);
|
||||
}
|
||||
|
||||
bitStream.Write<uint16_t>(0);
|
||||
|
||||
//This is so Wincent's announcement works:
|
||||
if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
|
||||
SEND_PACKET;
|
||||
return;
|
||||
}
|
||||
|
||||
SEND_PACKET_BROADCAST;
|
||||
}
|
||||
|
||||
void MessageFailure::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write(this->cannedText);
|
||||
}
|
||||
|
||||
void Announcement::Serialize(RakNet::BitStream& bitStream) const {
|
||||
bitStream.Write<uint32_t>(title.size());
|
||||
bitStream.Write(title);
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(message);
|
||||
}
|
||||
void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::SHOW_ALL);
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->displayZoneData);
|
||||
bitStream.Write(this->displayIndividualPlayers);
|
||||
}
|
||||
|
||||
void ShowAllRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
inStream.Read(this->requestor);
|
||||
inStream.Read(this->displayZoneData);
|
||||
inStream.Read(this->displayIndividualPlayers);
|
||||
}
|
||||
|
||||
void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) {
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WHO);
|
||||
bitStream.Write(this->requestor);
|
||||
bitStream.Write(this->playerName);
|
||||
}
|
||||
|
||||
void FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) {
|
||||
inStream.Read(this->requestor);
|
||||
inStream.Read(this->playerName);
|
||||
}
|
||||
|
||||
void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write(chatChannel);
|
||||
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(LUWString(senderName));
|
||||
|
||||
bitStream.Write(playerObjectID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<char>(0);
|
||||
|
||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
||||
bitStream.Write<uint16_t>(message[i]);
|
||||
}
|
||||
bitStream.Write<uint16_t>(0);
|
||||
|
||||
SEND_PACKET_BROADCAST;
|
||||
}
|
||||
|
||||
void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write<char>(4);
|
||||
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(LUWString("", 33));
|
||||
|
||||
bitStream.Write<uint64_t>(0);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<char>(0);
|
||||
|
||||
for (uint32_t i = 0; i < message.size(); ++i) {
|
||||
bitStream.Write<uint16_t>(message[i]);
|
||||
}
|
||||
|
||||
bitStream.Write<uint16_t>(0);
|
||||
|
||||
//This is so Wincent's announcement works:
|
||||
if (sysAddr != UNASSIGNED_SYSTEM_ADDRESS) {
|
||||
SEND_PACKET;
|
||||
return;
|
||||
}
|
||||
|
||||
SEND_PACKET_BROADCAST;
|
||||
}
|
||||
|
||||
void ChatPackets::SendMessageFail(const SystemAddress& sysAddr) {
|
||||
//0x00 - "Chat is currently disabled."
|
||||
//0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players."
|
||||
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SEND_CANNED_TEXT);
|
||||
bitStream.Write<uint8_t>(0); //response type, options above ^
|
||||
//docs say there's a wstring here-- no idea what it's for, or if it's even needed so leaving it as is for now.
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void ChatPackets::Announcement::Send() {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE);
|
||||
bitStream.Write<uint32_t>(title.size());
|
||||
bitStream.Write(title);
|
||||
bitStream.Write<uint32_t>(message.size());
|
||||
bitStream.Write(message);
|
||||
SEND_PACKET_BROADCAST;
|
||||
}
|
||||
|
||||
void ChatPackets::AchievementNotify::Serialize(RakNet::BitStream& bitstream) const {
|
||||
bitstream.Write<uint64_t>(0); // Packing
|
||||
bitstream.Write<uint32_t>(0); // Packing
|
||||
bitstream.Write<uint8_t>(0); // Packing
|
||||
bitstream.Write(targetPlayerName);
|
||||
bitstream.Write<uint64_t>(0); // Packing / No way to know meaning because of not enough data.
|
||||
bitstream.Write<uint32_t>(0); // Packing / No way to know meaning because of not enough data.
|
||||
bitstream.Write<uint16_t>(0); // Packing / No way to know meaning because of not enough data.
|
||||
bitstream.Write<uint8_t>(0); // Packing / No way to know meaning because of not enough data.
|
||||
bitstream.Write(missionEmailID);
|
||||
bitstream.Write(earningPlayerID);
|
||||
bitstream.Write(earnerName);
|
||||
}
|
||||
|
||||
bool ChatPackets::AchievementNotify::Deserialize(RakNet::BitStream& bitstream) {
|
||||
bitstream.IgnoreBytes(13);
|
||||
VALIDATE_READ(bitstream.Read(targetPlayerName));
|
||||
bitstream.IgnoreBytes(15);
|
||||
VALIDATE_READ(bitstream.Read(missionEmailID));
|
||||
VALIDATE_READ(bitstream.Read(earningPlayerID));
|
||||
VALIDATE_READ(bitstream.Read(earnerName));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatPackets::TeamInviteInitialResponse::Serialize(RakNet::BitStream& bitstream) const {
|
||||
bitstream.Write<uint8_t>(inviteFailedToSend);
|
||||
bitstream.Write(playerName);
|
||||
}
|
||||
|
||||
void ChatPackets::SendRoutedMsg(const LUBitStream& msg, const LWOOBJID targetID, const SystemAddress& sysAddr) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET);
|
||||
bitStream.Write(targetID);
|
||||
|
||||
// Now write the actual packet
|
||||
msg.WriteHeader(bitStream);
|
||||
msg.Serialize(bitStream);
|
||||
Game::server->Send(bitStream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
@@ -10,85 +10,55 @@ struct SystemAddress;
|
||||
|
||||
#include <string>
|
||||
#include "dCommonVars.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "MessageType/Chat.h"
|
||||
#include "eChatMessageResponseCode.h"
|
||||
#include "BitStreamUtils.h"
|
||||
|
||||
enum class eCannedText : uint8_t {
|
||||
CHAT_DISABLED = 0,
|
||||
F2P_CHAT_DISABLED = 1
|
||||
struct ShowAllRequest{
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
bool displayZoneData = true;
|
||||
bool displayIndividualPlayers = true;
|
||||
void Serialize(RakNet::BitStream& bitStream);
|
||||
void Deserialize(RakNet::BitStream& inStream);
|
||||
};
|
||||
|
||||
struct FindPlayerRequest{
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
LUWString playerName;
|
||||
void Serialize(RakNet::BitStream& bitStream);
|
||||
void Deserialize(RakNet::BitStream& inStream);
|
||||
};
|
||||
|
||||
namespace ChatPackets {
|
||||
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast = false);
|
||||
|
||||
struct ShowAllRequest : public LUBitStream {
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
bool displayZoneData = true;
|
||||
bool displayIndividualPlayers = true;
|
||||
|
||||
ShowAllRequest() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::WHO) {};
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||
};
|
||||
|
||||
struct FindPlayerRequest : public LUBitStream {
|
||||
LWOOBJID requestor = LWOOBJID_EMPTY;
|
||||
LUWString playerName;
|
||||
FindPlayerRequest() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::WHO) {};
|
||||
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||
};
|
||||
|
||||
struct Announcement : public LUBitStream {
|
||||
struct Announcement {
|
||||
std::string title;
|
||||
std::string message;
|
||||
|
||||
Announcement() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE) {};
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
void Send();
|
||||
};
|
||||
|
||||
struct ChatMessage : public LUBitStream {
|
||||
char chatChannel;
|
||||
std::string senderName;
|
||||
LWOOBJID playerObjectID;
|
||||
bool senderMythran;
|
||||
eChatMessageResponseCode responseCode = eChatMessageResponseCode::SENT;
|
||||
LUWString message;
|
||||
|
||||
ChatMessage() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE) {};
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||
virtual void Handle() override {};
|
||||
struct AchievementNotify : public LUBitStream {
|
||||
LUWString targetPlayerName{};
|
||||
uint32_t missionEmailID{};
|
||||
LWOOBJID earningPlayerID{};
|
||||
LUWString earnerName{};
|
||||
AchievementNotify() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::ACHIEVEMENT_NOTIFY) {}
|
||||
void Serialize(RakNet::BitStream& bitstream) const override;
|
||||
bool Deserialize(RakNet::BitStream& bitstream) override;
|
||||
};
|
||||
|
||||
struct WorldChatMessage : public ChatMessage {
|
||||
virtual bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual void Handle() override;
|
||||
struct TeamInviteInitialResponse : public LUBitStream {
|
||||
bool inviteFailedToSend{};
|
||||
LUWString playerName{};
|
||||
TeamInviteInitialResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::TEAM_INVITE_INITIAL_RESPONSE) {}
|
||||
|
||||
void Serialize(RakNet::BitStream& bitstream) const override;
|
||||
// No Deserialize needed on our end
|
||||
};
|
||||
|
||||
struct PrivateChatMessage : public ChatMessage {
|
||||
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual void Handle() override;
|
||||
};
|
||||
|
||||
struct UserChatMessage : public ChatMessage {
|
||||
virtual bool Deserialize(RakNet::BitStream& inStream) override;
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
virtual void Handle() override;
|
||||
};
|
||||
|
||||
// Should be in client packets since it is a client connection type, but whatever
|
||||
struct MessageFailure : public LUBitStream {
|
||||
eCannedText cannedText = eCannedText::CHAT_DISABLED;
|
||||
|
||||
MessageFailure() : LUBitStream(eConnectionType::CLIENT, MessageType::Chat::SEND_CANNED_TEXT) {};
|
||||
virtual void Serialize(RakNet::BitStream& bitStream) const override;
|
||||
};
|
||||
void SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message);
|
||||
void SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, bool broadcast = false);
|
||||
void SendMessageFail(const SystemAddress& sysAddr);
|
||||
void SendRoutedMsg(const LUBitStream& msg, const LWOOBJID targetID, const SystemAddress& sysAddr);
|
||||
};
|
||||
|
||||
#endif // CHATPACKETS_H
|
||||
|
||||
@@ -13,6 +13,12 @@ class PositionUpdate;
|
||||
|
||||
struct Packet;
|
||||
|
||||
struct ChatMessage {
|
||||
uint8_t chatChannel = 0;
|
||||
uint16_t unknown = 0;
|
||||
std::u16string message;
|
||||
};
|
||||
|
||||
struct ChatModerationRequest {
|
||||
uint8_t chatLevel = 0;
|
||||
uint8_t requestID = 0;
|
||||
@@ -21,6 +27,7 @@ struct ChatModerationRequest {
|
||||
};
|
||||
|
||||
namespace ClientPackets {
|
||||
ChatMessage HandleChatMessage(Packet* packet);
|
||||
PositionUpdate HandleClientPositionUpdate(Packet* packet);
|
||||
ChatModerationRequest HandleChatModerationRequest(Packet* packet);
|
||||
int32_t SendTop5HelpIssues(Packet* packet);
|
||||
|
||||
@@ -134,7 +134,7 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t rep
|
||||
LOG("Sent CreateCharacter for ID: %llu", player);
|
||||
}
|
||||
|
||||
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set<std::pair<uint8_t, uint8_t>> unacceptedItems) {
|
||||
void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING);
|
||||
|
||||
@@ -183,4 +183,4 @@ void WorldPackets::SendDebugOuput(const SystemAddress& sysAddr, const std::strin
|
||||
bitStream.Write<uint32_t>(data.size());
|
||||
bitStream.Write(data);
|
||||
SEND_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ struct SystemAddress;
|
||||
enum class eGameMasterLevel : uint8_t;
|
||||
enum class eCharacterCreationResponse : uint8_t;
|
||||
enum class eRenameResponse : uint8_t;
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
struct HTTPMonitorInfo {
|
||||
uint16_t port = 80;
|
||||
@@ -29,7 +32,7 @@ namespace WorldPackets {
|
||||
void SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift);
|
||||
void SendServerState(const SystemAddress& sysAddr);
|
||||
void SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set<std::pair<uint8_t, uint8_t>> unacceptedItems);
|
||||
void SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::vector<std::pair<uint8_t, uint8_t>> unacceptedItems);
|
||||
void SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel);
|
||||
void SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info);
|
||||
void SendDebugOuput(const SystemAddress& sysAddr, const std::string& data);
|
||||
|
||||
@@ -503,7 +503,7 @@ void BaseSurvivalServer::ActivateSpawnerNetwork(SpawnerNetworkCollection& spawne
|
||||
if (!possibleSpawners.empty()) {
|
||||
auto* spawnerObject = possibleSpawners.at(0);
|
||||
spawnerObject->Activate();
|
||||
spawnerObject->Reset();
|
||||
spawnerObject->SoftReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ void ActSharkPlayerDeathTrigger::OnFireEventServerSide(Entity* self, Entity* sen
|
||||
auto missionComponent = sender->GetComponent<MissionComponent>();
|
||||
if (!missionComponent) return;
|
||||
|
||||
missionComponent->Progress(eMissionTaskType::SCRIPT, 8419);
|
||||
|
||||
// This check is only needed because dlu doesnt have proper collision checks on rotated phantom physics
|
||||
if (sender->GetIsDead() || !sender->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
|
||||
|
||||
missionComponent->Progress(eMissionTaskType::SCRIPT, 8419);
|
||||
|
||||
if (sender->GetCharacter()) {
|
||||
sender->Smash(self->GetObjectID(), eKillType::VIOLENT, u"big-shark-death");
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
set(DWEB_SOURCES
|
||||
"Web.cpp")
|
||||
|
||||
add_library(dWeb STATIC ${DWEB_SOURCES})
|
||||
|
||||
target_include_directories(dWeb PUBLIC ".")
|
||||
target_link_libraries(dWeb dCommon mongoose)
|
||||
289
dWeb/Web.cpp
289
dWeb/Web.cpp
@@ -1,289 +0,0 @@
|
||||
#include "Web.h"
|
||||
#include "Game.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include "json.hpp"
|
||||
#include "Logger.h"
|
||||
#include "eHTTPMethod.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "JSONUtils.h"
|
||||
|
||||
namespace Game {
|
||||
Web web;
|
||||
}
|
||||
|
||||
namespace {
|
||||
const char* json_content_type = "Content-Type: application/json\r\n";
|
||||
std::map<std::pair<eHTTPMethod, std::string>, HTTPRoute> g_HTTPRoutes;
|
||||
std::map<std::string, WSEvent> g_WSEvents;
|
||||
std::vector<std::string> g_WSSubscriptions;
|
||||
}
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
bool ValidateAuthentication(const mg_http_message* http_msg) {
|
||||
// TO DO: This is just a placeholder for now
|
||||
// use tokens or something at a later point if we want to implement authentication
|
||||
// bit using the listen bind address to limit external access is good enough to start with
|
||||
return true;
|
||||
}
|
||||
|
||||
void HandleHTTPMessage(mg_connection* connection, const mg_http_message* http_msg) {
|
||||
if (g_HTTPRoutes.empty()) return;
|
||||
|
||||
HTTPReply reply;
|
||||
|
||||
if (!http_msg) {
|
||||
reply.status = eHTTPStatusCode::BAD_REQUEST;
|
||||
reply.message = "{\"error\":\"Invalid Request\"}";
|
||||
} else if (ValidateAuthentication(http_msg)) {
|
||||
|
||||
// convert method from cstring to std string
|
||||
std::string method_string(http_msg->method.buf, http_msg->method.len);
|
||||
// get mehtod from mg to enum
|
||||
const eHTTPMethod method = magic_enum::enum_cast<eHTTPMethod>(method_string).value_or(eHTTPMethod::INVALID);
|
||||
|
||||
// convert uri from cstring to std string
|
||||
std::string uri(http_msg->uri.buf, http_msg->uri.len);
|
||||
std::transform(uri.begin(), uri.end(), uri.begin(), ::tolower);
|
||||
|
||||
// convert body from cstring to std string
|
||||
std::string body(http_msg->body.buf, http_msg->body.len);
|
||||
|
||||
// Special case for websocket
|
||||
if (uri == "/ws" && method == eHTTPMethod::GET) {
|
||||
mg_ws_upgrade(connection, const_cast<mg_http_message*>(http_msg), NULL);
|
||||
LOG("Upgraded connection to websocket: %d.%d.%d.%d:%i", MG_IPADDR_PARTS(&connection->rem.ip), connection->rem.port);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto routeItr = g_HTTPRoutes.find({method, uri});
|
||||
if (routeItr != g_HTTPRoutes.end()) {
|
||||
const auto& [_, route] = *routeItr;
|
||||
route.handle(reply, body);
|
||||
} else {
|
||||
reply.status = eHTTPStatusCode::NOT_FOUND;
|
||||
reply.message = "{\"error\":\"Not Found\"}";
|
||||
}
|
||||
} else {
|
||||
reply.status = eHTTPStatusCode::UNAUTHORIZED;
|
||||
reply.message = "{\"error\":\"Unauthorized\"}";
|
||||
}
|
||||
mg_http_reply(connection, static_cast<int>(reply.status), json_content_type, reply.message.c_str());
|
||||
}
|
||||
|
||||
|
||||
void HandleWSMessage(mg_connection* connection, const mg_ws_message* ws_msg) {
|
||||
if (!ws_msg) {
|
||||
LOG_DEBUG("Received invalid websocket message");
|
||||
return;
|
||||
} else {
|
||||
LOG_DEBUG("Received websocket message: %.*s", static_cast<uint32_t>(ws_msg->data.len), ws_msg->data.buf);
|
||||
auto data = GeneralUtils::TryParse<json>(std::string(ws_msg->data.buf, ws_msg->data.len));
|
||||
if (data) {
|
||||
const auto& good_data = data.value();
|
||||
auto check = JSONUtils::CheckRequiredData(good_data, { "event" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto event = good_data["event"].get<std::string>();
|
||||
const auto eventItr = g_WSEvents.find(event);
|
||||
if (eventItr != g_WSEvents.end()) {
|
||||
const auto& [_, event] = *eventItr;
|
||||
event.handle(connection, good_data);
|
||||
} else {
|
||||
LOG_DEBUG("Received invalid websocket event: %s", event.c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOG_DEBUG("Received invalid websocket message: %.*s", static_cast<uint32_t>(ws_msg->data.len), ws_msg->data.buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSSubscribe(mg_connection* connection, json data) {
|
||||
auto check = JSONUtils::CheckRequiredData(data, { "subscription" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto subscription = data["subscription"].get<std::string>();
|
||||
LOG_DEBUG("subscription %s subscribed", subscription.c_str());
|
||||
// check subscription vector
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
if (subItr != g_WSSubscriptions.end()) {
|
||||
// get index of subscription
|
||||
auto index = std::distance(g_WSSubscriptions.begin(), subItr);
|
||||
connection->data[index] = 1;
|
||||
mg_ws_send(connection, "{\"status\":\"subscribed\"}", 23, WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSUnsubscribe(mg_connection* connection, json data) {
|
||||
auto check = JSONUtils::CheckRequiredData(data, { "subscription" });
|
||||
if (!check.empty()) {
|
||||
LOG_DEBUG("Received invalid websocket message: %s", check.c_str());
|
||||
} else {
|
||||
const auto subscription = data["subscription"].get<std::string>();
|
||||
LOG_DEBUG("subscription %s unsubscribed", subscription.c_str());
|
||||
// check subscription vector
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
if (subItr != g_WSSubscriptions.end()) {
|
||||
// get index of subscription
|
||||
auto index = std::distance(g_WSSubscriptions.begin(), subItr);
|
||||
connection->data[index] = 0;
|
||||
mg_ws_send(connection, "{\"status\":\"unsubscribed\"}", 25, WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleWSGetSubscriptions(mg_connection* connection, json data) {
|
||||
// list subscribed and non subscribed subscriptions
|
||||
json response;
|
||||
// check subscription vector
|
||||
for (const auto& sub : g_WSSubscriptions) {
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), sub);
|
||||
if (subItr != g_WSSubscriptions.end()) {
|
||||
// get index of subscription
|
||||
auto index = std::distance(g_WSSubscriptions.begin(), subItr);
|
||||
if (connection->data[index] == 1) {
|
||||
response["subscribed"].push_back(sub);
|
||||
} else {
|
||||
response["unsubscribed"].push_back(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
mg_ws_send(connection, response.dump().c_str(), response.dump().size(), WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
|
||||
void HandleMessages(mg_connection* connection, int message, void* message_data) {
|
||||
if (!Game::web.IsEnabled()) return;
|
||||
switch (message) {
|
||||
case MG_EV_HTTP_MSG:
|
||||
HandleHTTPMessage(connection, static_cast<mg_http_message*>(message_data));
|
||||
break;
|
||||
case MG_EV_WS_MSG:
|
||||
HandleWSMessage(connection, static_cast<mg_ws_message*>(message_data));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect logs to our logger
|
||||
static void DLOG(char ch, void *param) {
|
||||
static char buf[256];
|
||||
static size_t len;
|
||||
if (ch != '\n') buf[len++] = ch; // we provide the newline in our logger
|
||||
if (ch == '\n' || len >= sizeof(buf)) {
|
||||
LOG_DEBUG("%.*s", static_cast<int>(len), buf);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Web::RegisterHTTPRoute(HTTPRoute route) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register HTTP route %s: web server not enabled", route.path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto [_, success] = g_HTTPRoutes.try_emplace({ route.method, route.path }, route);
|
||||
if (!success) {
|
||||
LOG_DEBUG("Failed to register HTTP route %s", route.path.c_str());
|
||||
} else {
|
||||
LOG_DEBUG("Registered HTTP route %s", route.path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Web::RegisterWSEvent(WSEvent event) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register WS event %s: web server not enabled", event.name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto [_, success] = g_WSEvents.try_emplace(event.name, event);
|
||||
if (!success) {
|
||||
LOG_DEBUG("Failed to register WS event %s", event.name.c_str());
|
||||
} else {
|
||||
LOG_DEBUG("Registered WS event %s", event.name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Web::RegisterWSSubscription(const std::string& subscription) {
|
||||
if (!Game::web.enabled) {
|
||||
LOG_DEBUG("Failed to register WS subscription %s: web server not enabled", subscription.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// check that subsction is not already in the vector
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
if (subItr != g_WSSubscriptions.end()) {
|
||||
LOG_DEBUG("Failed to register WS subscription %s: duplicate", subscription.c_str());
|
||||
} else {
|
||||
LOG_DEBUG("Registered WS subscription %s", subscription.c_str());
|
||||
g_WSSubscriptions.push_back(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
Web::Web() {
|
||||
mg_log_set_fn(DLOG, NULL); // Redirect logs to our logger
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_mgr_init(&mgr); // Initialize event manager
|
||||
}
|
||||
|
||||
Web::~Web() {
|
||||
mg_mgr_free(&mgr);
|
||||
}
|
||||
|
||||
bool Web::Startup(const std::string& listen_ip, const uint32_t listen_port) {
|
||||
|
||||
// Make listen address
|
||||
const std::string& listen_address = "http://" + listen_ip + ":" + std::to_string(listen_port);
|
||||
LOG("Starting web server on %s", listen_address.c_str());
|
||||
|
||||
// Create HTTP listener
|
||||
if (!mg_http_listen(&mgr, listen_address.c_str(), HandleMessages, NULL)) {
|
||||
LOG("Failed to create web server listener on %s", listen_address.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// WebSocket Events
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "subscribe",
|
||||
.handle = HandleWSSubscribe
|
||||
});
|
||||
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "unsubscribe",
|
||||
.handle = HandleWSUnsubscribe
|
||||
});
|
||||
|
||||
Game::web.RegisterWSEvent({
|
||||
.name = "getSubscriptions",
|
||||
.handle = HandleWSGetSubscriptions
|
||||
});
|
||||
enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Web::ReceiveRequests() {
|
||||
mg_mgr_poll(&mgr, 15);
|
||||
}
|
||||
|
||||
void Web::SendWSMessage(const std::string subscription, json& data) {
|
||||
if (!Game::web.enabled) return; // don't attempt to send if web is not enabled
|
||||
|
||||
// find subscription
|
||||
auto subItr = std::find(g_WSSubscriptions.begin(), g_WSSubscriptions.end(), subscription);
|
||||
if (subItr == g_WSSubscriptions.end()) {
|
||||
LOG_DEBUG("Failed to send WS message: subscription %s not found", subscription.c_str());
|
||||
return;
|
||||
}
|
||||
// tell it the event type
|
||||
data["event"] = subscription;
|
||||
auto index = std::distance(g_WSSubscriptions.begin(), subItr);
|
||||
for (struct mg_connection *wc = Game::web.mgr.conns; wc != NULL; wc = wc->next) {
|
||||
if (wc->is_websocket && wc->data[index] == 1) {
|
||||
mg_ws_send(wc, data.dump().c_str(), data.dump().size(), WEBSOCKET_OP_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
dWeb/Web.h
52
dWeb/Web.h
@@ -1,52 +0,0 @@
|
||||
#ifndef __WEB_H__
|
||||
#define __WEB_H__
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include "mongoose.h"
|
||||
#include "json_fwd.hpp"
|
||||
#include "eHTTPStatusCode.h"
|
||||
|
||||
class Web;
|
||||
namespace Game {
|
||||
extern Web web;
|
||||
}
|
||||
|
||||
enum class eHTTPMethod;
|
||||
|
||||
typedef struct mg_mgr mg_mgr;
|
||||
|
||||
struct HTTPReply {
|
||||
eHTTPStatusCode status = eHTTPStatusCode::NOT_FOUND;
|
||||
std::string message = "{\"error\":\"Not Found\"}";
|
||||
};
|
||||
|
||||
struct HTTPRoute {
|
||||
std::string path;
|
||||
eHTTPMethod method;
|
||||
std::function<void(HTTPReply&, const std::string&)> handle;
|
||||
};
|
||||
|
||||
struct WSEvent {
|
||||
std::string name;
|
||||
std::function<void(mg_connection*, nlohmann::json)> handle;
|
||||
};
|
||||
|
||||
class Web {
|
||||
public:
|
||||
Web();
|
||||
~Web();
|
||||
void ReceiveRequests();
|
||||
void static SendWSMessage(std::string sub, nlohmann::json& message);
|
||||
bool Startup(const std::string& listen_ip, const uint32_t listen_port);
|
||||
void RegisterHTTPRoute(HTTPRoute route);
|
||||
void RegisterWSEvent(WSEvent event);
|
||||
void RegisterWSSubscription(const std::string& subscription);
|
||||
bool IsEnabled() const { return enabled; };
|
||||
private:
|
||||
mg_mgr mgr;
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
#endif // !__WEB_H__
|
||||
@@ -3,69 +3,68 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "UserManager.h"
|
||||
|
||||
#define SOCIAL { lowFrameDelta }
|
||||
#define SOCIAL_HUB { mediumFrameDelta } //Added to compensate for the large playercounts in NS and NT
|
||||
#define BATTLE { highFrameDelta }
|
||||
#define BATTLE_INSTANCE { mediumFrameDelta }
|
||||
#define RACE { highFrameDelta }
|
||||
#define PROPERTY { lowFrameDelta }
|
||||
#define SOCIAL lowFrameDelta
|
||||
#define SOCIAL_HUB mediumFrameDelta //Added to compensate for the large playercounts in NS and NT
|
||||
#define BATTLE highFrameDelta
|
||||
#define BATTLE_INSTANCE mediumFrameDelta
|
||||
#define RACE highFrameDelta
|
||||
#define PROPERTY lowFrameDelta
|
||||
|
||||
PerformanceProfile PerformanceManager::m_CurrentProfile = SOCIAL;
|
||||
namespace {
|
||||
PerformanceProfile m_CurrentProfile = SOCIAL;
|
||||
PerformanceProfile m_DefaultProfile = SOCIAL;
|
||||
PerformanceProfile m_InactiveProfile = lowFrameDelta;
|
||||
std::map<LWOMAPID, PerformanceProfile> m_Profiles = {
|
||||
// VE
|
||||
{ 1000, SOCIAL },
|
||||
|
||||
PerformanceProfile PerformanceManager::m_DefaultProfile = SOCIAL;
|
||||
// AG
|
||||
{ 1100, BATTLE },
|
||||
{ 1101, BATTLE_INSTANCE },
|
||||
{ 1102, BATTLE_INSTANCE },
|
||||
{ 1150, PROPERTY },
|
||||
{ 1151, PROPERTY },
|
||||
|
||||
PerformanceProfile PerformanceManager::m_InactiveProfile = { lowFrameDelta };
|
||||
// NS
|
||||
{ 1200, SOCIAL_HUB },
|
||||
{ 1201, SOCIAL },
|
||||
{ 1203, RACE },
|
||||
{ 1204, BATTLE_INSTANCE },
|
||||
{ 1250, PROPERTY },
|
||||
{ 1251, PROPERTY },
|
||||
|
||||
std::map<LWOMAPID, PerformanceProfile> PerformanceManager::m_Profiles = {
|
||||
// VE
|
||||
{ 1000, SOCIAL },
|
||||
// GF
|
||||
{ 1300, BATTLE },
|
||||
{ 1302, BATTLE_INSTANCE },
|
||||
{ 1303, BATTLE_INSTANCE },
|
||||
{ 1350, PROPERTY },
|
||||
|
||||
// AG
|
||||
{ 1100, BATTLE },
|
||||
{ 1101, BATTLE_INSTANCE },
|
||||
{ 1102, BATTLE_INSTANCE },
|
||||
{ 1150, PROPERTY },
|
||||
{ 1151, PROPERTY },
|
||||
// FV
|
||||
{ 1400, BATTLE },
|
||||
{ 1402, BATTLE_INSTANCE },
|
||||
{ 1403, RACE },
|
||||
{ 1450, PROPERTY },
|
||||
|
||||
// NS
|
||||
{ 1200, SOCIAL_HUB },
|
||||
{ 1201, SOCIAL },
|
||||
{ 1203, RACE },
|
||||
{ 1204, BATTLE_INSTANCE },
|
||||
{ 1250, PROPERTY },
|
||||
{ 1251, PROPERTY },
|
||||
// LUP
|
||||
{ 1600, SOCIAL },
|
||||
{ 1601, SOCIAL },
|
||||
{ 1602, SOCIAL },
|
||||
{ 1603, SOCIAL },
|
||||
{ 1604, SOCIAL },
|
||||
|
||||
// GF
|
||||
{ 1300, BATTLE },
|
||||
{ 1302, BATTLE_INSTANCE },
|
||||
{ 1303, BATTLE_INSTANCE },
|
||||
{ 1350, PROPERTY },
|
||||
// LEGO Club
|
||||
{ 1700, SOCIAL },
|
||||
|
||||
// FV
|
||||
{ 1400, BATTLE },
|
||||
{ 1402, BATTLE_INSTANCE },
|
||||
{ 1403, RACE },
|
||||
{ 1450, PROPERTY },
|
||||
// AM
|
||||
{ 1800, BATTLE },
|
||||
|
||||
// LUP
|
||||
{ 1600, SOCIAL },
|
||||
{ 1601, SOCIAL },
|
||||
{ 1602, SOCIAL },
|
||||
{ 1603, SOCIAL },
|
||||
{ 1604, SOCIAL },
|
||||
// NT
|
||||
{ 1900, SOCIAL_HUB },
|
||||
|
||||
// LEGO Club
|
||||
{ 1700, SOCIAL },
|
||||
|
||||
// AM
|
||||
{ 1800, BATTLE },
|
||||
|
||||
// NT
|
||||
{ 1900, SOCIAL_HUB },
|
||||
|
||||
// NJ
|
||||
{ 2000, BATTLE },
|
||||
{ 2001, BATTLE_INSTANCE },
|
||||
// NJ
|
||||
{ 2000, BATTLE },
|
||||
{ 2001, BATTLE_INSTANCE },
|
||||
};
|
||||
};
|
||||
|
||||
void PerformanceManager::SelectProfile(LWOMAPID mapID) {
|
||||
@@ -74,16 +73,16 @@ void PerformanceManager::SelectProfile(LWOMAPID mapID) {
|
||||
if (zoneTable) {
|
||||
const CDZoneTable* zone = zoneTable->Query(mapID);
|
||||
if (zone) {
|
||||
if (zone->serverPhysicsFramerate == "high"){
|
||||
m_CurrentProfile = { highFrameDelta };
|
||||
if (zone->serverPhysicsFramerate == "high") {
|
||||
m_CurrentProfile = highFrameDelta;
|
||||
return;
|
||||
}
|
||||
if (zone->serverPhysicsFramerate == "medium"){
|
||||
m_CurrentProfile = { mediumFrameDelta };
|
||||
if (zone->serverPhysicsFramerate == "medium") {
|
||||
m_CurrentProfile = mediumFrameDelta;
|
||||
return;
|
||||
}
|
||||
if (zone->serverPhysicsFramerate == "low"){
|
||||
m_CurrentProfile = { lowFrameDelta };
|
||||
if (zone->serverPhysicsFramerate == "low") {
|
||||
m_CurrentProfile = lowFrameDelta;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -91,18 +90,9 @@ void PerformanceManager::SelectProfile(LWOMAPID mapID) {
|
||||
|
||||
// Fall back to hardcoded list and defaults
|
||||
const auto pair = m_Profiles.find(mapID);
|
||||
if (pair == m_Profiles.end()) {
|
||||
m_CurrentProfile = m_DefaultProfile;
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentProfile = pair->second;
|
||||
m_CurrentProfile = pair == m_Profiles.end() ? m_DefaultProfile : pair->second;
|
||||
}
|
||||
|
||||
uint32_t PerformanceManager::GetServerFrameDelta() {
|
||||
if (UserManager::Instance()->GetUserCount() == 0) {
|
||||
return m_InactiveProfile.serverFrameDelta;
|
||||
}
|
||||
|
||||
return m_CurrentProfile.serverFrameDelta;
|
||||
return UserManager::Instance()->GetUserCount() == 0 ? m_CurrentProfile : m_InactiveProfile;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
|
||||
struct PerformanceProfile {
|
||||
uint32_t serverFrameDelta;
|
||||
};
|
||||
|
||||
class PerformanceManager {
|
||||
public:
|
||||
static void SelectProfile(LWOMAPID mapID);
|
||||
|
||||
static uint32_t GetServerFrameDelta();
|
||||
|
||||
private:
|
||||
static PerformanceProfile m_CurrentProfile;
|
||||
static PerformanceProfile m_DefaultProfile;
|
||||
static PerformanceProfile m_InactiveProfile;
|
||||
static std::map<LWOMAPID, PerformanceProfile> m_Profiles;
|
||||
using PerformanceProfile = uint32_t;
|
||||
|
||||
namespace PerformanceManager {
|
||||
/* Sets a performance profile for a given world. */
|
||||
void SelectProfile(LWOMAPID mapID);
|
||||
|
||||
/* Gets the frame millisecond delta. Will return a higher value if the zone is empty. */
|
||||
uint32_t GetServerFrameDelta();
|
||||
};
|
||||
|
||||
@@ -98,9 +98,22 @@ namespace Game {
|
||||
std::string projectVersion = PROJECT_VERSION;
|
||||
} // namespace Game
|
||||
|
||||
bool chatDisabled = false;
|
||||
bool chatConnected = false;
|
||||
bool worldShutdownSequenceComplete = false;
|
||||
namespace {
|
||||
struct TempSessionInfo {
|
||||
SystemAddress sysAddr;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
std::map<std::string, TempSessionInfo> g_PendingUsers;
|
||||
uint32_t g_InstanceID = 0;
|
||||
uint32_t g_CloneID = 0;
|
||||
std::string g_DatabaseChecksum = "";
|
||||
|
||||
bool g_ChatDisabled = false;
|
||||
bool g_ChatConnected = false;
|
||||
bool g_WorldShutdownSequenceComplete = false;
|
||||
}; // namespace anonymous
|
||||
|
||||
void WorldShutdownSequence();
|
||||
void WorldShutdownProcess(uint32_t zoneId);
|
||||
void FinalizeShutdown();
|
||||
@@ -110,16 +123,6 @@ void HandlePacketChat(Packet* packet);
|
||||
void HandleMasterPacket(Packet* packet);
|
||||
void HandlePacket(Packet* packet);
|
||||
|
||||
struct tempSessionInfo {
|
||||
SystemAddress sysAddr;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
std::map<std::string, tempSessionInfo> m_PendingUsers;
|
||||
uint32_t instanceID = 0;
|
||||
uint32_t g_CloneID = 0;
|
||||
std::string databaseChecksum = "";
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Diagnostics::SetProcessName("World");
|
||||
Diagnostics::SetProcessFileName(argv[0]);
|
||||
@@ -137,27 +140,31 @@ int main(int argc, char** argv) {
|
||||
uint32_t ourPort = 2007;
|
||||
|
||||
//Check our arguments:
|
||||
for (int32_t i = 0; i < argc; ++i) {
|
||||
for (int32_t i = 0; (i + 1) < argc; i++) {
|
||||
std::string argument(argv[i]);
|
||||
const auto valOptional = GeneralUtils::TryParse<uint32_t>(argv[i + 1]);
|
||||
if (!valOptional) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument == "-zone") zoneID = atoi(argv[i + 1]);
|
||||
if (argument == "-instance") instanceID = atoi(argv[i + 1]);
|
||||
if (argument == "-clone") cloneID = atoi(argv[i + 1]);
|
||||
if (argument == "-maxclients") maxClients = atoi(argv[i + 1]);
|
||||
if (argument == "-port") ourPort = atoi(argv[i + 1]);
|
||||
if (argument == "-zone") zoneID = valOptional.value_or(1000);
|
||||
else if (argument == "-instance") g_InstanceID = valOptional.value_or(0);
|
||||
else if (argument == "-clone") cloneID = valOptional.value_or(0);
|
||||
else if (argument == "-maxclients") maxClients = valOptional.value_or(8);
|
||||
else if (argument == "-port") ourPort = valOptional.value_or(2007);
|
||||
}
|
||||
|
||||
Game::config = new dConfig("worldconfig.ini");
|
||||
|
||||
//Create all the objects we need to run our service:
|
||||
Server::SetupLogger("WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID));
|
||||
Server::SetupLogger("WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(g_InstanceID));
|
||||
if (!Game::logger) return EXIT_FAILURE;
|
||||
|
||||
LOG("Starting World server...");
|
||||
LOG("Version: %s", Game::projectVersion.c_str());
|
||||
LOG("Compiled on: %s", __TIMESTAMP__);
|
||||
|
||||
if (Game::config->GetValue("disable_chat") == "1") chatDisabled = true;
|
||||
g_ChatDisabled = Game::config->GetValue("disable_chat") == "1";
|
||||
|
||||
try {
|
||||
std::string clientPathStr = Game::config->GetValue("client_location");
|
||||
@@ -167,7 +174,7 @@ int main(int argc, char** argv) {
|
||||
clientPath = BinaryPathFinder::GetBinaryDir() / clientPath;
|
||||
}
|
||||
Game::assetManager = new AssetManager(clientPath);
|
||||
} catch (std::runtime_error& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
LOG("Got an error while setting up assets: %s", ex.what());
|
||||
|
||||
return EXIT_FAILURE;
|
||||
@@ -176,11 +183,14 @@ int main(int argc, char** argv) {
|
||||
// Connect to CDClient
|
||||
try {
|
||||
CDClientDatabase::Connect((BinaryPathFinder::GetBinaryDir() / "resServer" / "CDServer.sqlite").string());
|
||||
} catch (CppSQLite3Exception& e) {
|
||||
} catch (const CppSQLite3Exception& e) {
|
||||
LOG("Unable to connect to CDServer SQLite Database");
|
||||
LOG("Error: %s", e.errorMessage());
|
||||
LOG("Error Code: %i", e.errorCode());
|
||||
return EXIT_FAILURE;
|
||||
} catch (const std::exception& e) {
|
||||
LOG("Caught generic exception %s when connecting to CDClient", e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
CDClientManager::LoadValuesFromDatabase();
|
||||
@@ -194,7 +204,7 @@ int main(int argc, char** argv) {
|
||||
//Connect to the MySQL Database:
|
||||
try {
|
||||
Database::Connect();
|
||||
} catch (std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
LOG("Got an error while connecting to the database: %s", ex.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -203,7 +213,7 @@ int main(int argc, char** argv) {
|
||||
std::string masterIP = "localhost";
|
||||
uint32_t masterPort = 1000;
|
||||
std::string masterPassword;
|
||||
auto masterInfo = Database::Get()->GetMasterInfo();
|
||||
const auto masterInfo = Database::Get()->GetMasterInfo();
|
||||
|
||||
if (masterInfo) {
|
||||
masterIP = masterInfo->ip;
|
||||
@@ -216,13 +226,25 @@ int main(int argc, char** argv) {
|
||||
const bool dontGenerateDCF = GeneralUtils::TryParse<bool>(Game::config->GetValue("dont_generate_dcf")).value_or(false);
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF);
|
||||
|
||||
Game::server = new dServer(masterIP, ourPort, instanceID, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::World, Game::config, &Game::lastSignal, masterPassword, zoneID);
|
||||
Game::server = new dServer(masterIP,
|
||||
ourPort,
|
||||
g_InstanceID,
|
||||
maxClients,
|
||||
false /* Is internal */,
|
||||
true /* Use encryption */,
|
||||
Game::logger,
|
||||
masterIP,
|
||||
masterPort,
|
||||
ServerType::World,
|
||||
Game::config,
|
||||
&Game::lastSignal,
|
||||
masterPassword,
|
||||
zoneID);
|
||||
|
||||
//Connect to the chat server:
|
||||
uint32_t chatPort = 1501;
|
||||
if (Game::config->GetValue("chat_server_port") != "") chatPort = std::atoi(Game::config->GetValue("chat_server_port").c_str());
|
||||
uint32_t chatPort = GeneralUtils::TryParse<uint32_t>(Game::config->GetValue("chat_server_port")).value_or(1501);
|
||||
|
||||
auto chatSock = SocketDescriptor(static_cast<uint16_t>(ourPort + 2), 0);
|
||||
auto chatSock = SocketDescriptor(static_cast<uint16_t>(ourPort + 2), NULL);
|
||||
Game::chatServer = RakNetworkFactory::GetRakPeerInterface();
|
||||
Game::chatServer->Startup(1, 30, &chatSock, 1);
|
||||
Game::chatServer->Connect(masterIP.c_str(), chatPort, NET_PASSWORD_EXTERNAL, strnlen(NET_PASSWORD_EXTERNAL, sizeof(NET_PASSWORD_EXTERNAL)));
|
||||
@@ -260,9 +282,8 @@ int main(int argc, char** argv) {
|
||||
//Load our level:
|
||||
if (zoneID != 0) {
|
||||
dpWorld::Initialize(zoneID);
|
||||
Game::zoneManager->Initialize(LWOZONEID(zoneID, instanceID, cloneID));
|
||||
Game::zoneManager->Initialize(LWOZONEID(zoneID, g_InstanceID, cloneID));
|
||||
g_CloneID = cloneID;
|
||||
|
||||
} else {
|
||||
Game::entityManager->Initialize();
|
||||
}
|
||||
@@ -286,11 +307,11 @@ int main(int argc, char** argv) {
|
||||
const char* nullTerminateBuffer = "\0";
|
||||
md5.update(nullTerminateBuffer, 1); // null terminate the data
|
||||
md5.finalize();
|
||||
databaseChecksum = md5.hexdigest();
|
||||
g_DatabaseChecksum = md5.hexdigest();
|
||||
|
||||
LOG("FDB Checksum calculated as: %s", databaseChecksum.c_str());
|
||||
LOG("FDB Checksum calculated as: %s", g_DatabaseChecksum.c_str());
|
||||
}
|
||||
if (databaseChecksum.empty()) {
|
||||
if (g_DatabaseChecksum.empty()) {
|
||||
LOG("check_fdb is on but no fdb file found.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -334,7 +355,7 @@ int main(int argc, char** argv) {
|
||||
float_t ratioBeforeToAfter = static_cast<float>(currentFrameDelta) / static_cast<float>(newFrameDelta);
|
||||
currentFrameDelta = newFrameDelta;
|
||||
currentFramerate = MS_TO_FRAMES(newFrameDelta);
|
||||
LOG_DEBUG("Framerate for zone/instance/clone %i/%i/%i is now %i", zoneID, instanceID, cloneID, currentFramerate);
|
||||
LOG_DEBUG("Framerate for zone/instance/clone %i/%i/%i is now %i", zoneID, g_InstanceID, cloneID, currentFramerate);
|
||||
logFlushTime = 15 * currentFramerate; // 15 seconds in frames
|
||||
framesSinceLastFlush *= ratioBeforeToAfter;
|
||||
shutdownTimeout = 10 * 60 * currentFramerate; // 10 minutes in frames
|
||||
@@ -367,7 +388,7 @@ int main(int argc, char** argv) {
|
||||
} else framesSinceMasterDisconnect = 0;
|
||||
|
||||
// Check if we're still connected to chat:
|
||||
if (!chatConnected) {
|
||||
if (!g_ChatConnected) {
|
||||
framesSinceChatDisconnect++;
|
||||
|
||||
if (framesSinceChatDisconnect >= chatReconnectionTime) {
|
||||
@@ -404,16 +425,18 @@ int main(int argc, char** argv) {
|
||||
|
||||
//Check for packets here:
|
||||
packet = Game::server->ReceiveFromMaster();
|
||||
if (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
|
||||
while (packet) { //We can get messages not handle-able by the dServer class, so handle them if we returned anything.
|
||||
HandleMasterPacket(packet);
|
||||
Game::server->DeallocateMasterPacket(packet);
|
||||
packet = Game::server->ReceiveFromMaster();
|
||||
}
|
||||
|
||||
//Handle our chat packets:
|
||||
packet = Game::chatServer->Receive();
|
||||
if (packet) {
|
||||
while (packet) {
|
||||
HandlePacketChat(packet);
|
||||
Game::chatServer->DeallocatePacket(packet);
|
||||
packet = Game::chatServer->Receive();
|
||||
}
|
||||
|
||||
//Handle world-specific packets:
|
||||
@@ -421,7 +444,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
UserManager::Instance()->DeletePendingRemovals();
|
||||
|
||||
auto t1 = std::chrono::high_resolution_clock::now();
|
||||
for (uint32_t curPacket = 0; curPacket < maxPacketsToProcess && timeSpent < maxPacketProcessingTime; curPacket++) {
|
||||
packet = Game::server->Receive();
|
||||
if (packet) {
|
||||
@@ -497,20 +519,14 @@ int main(int argc, char** argv) {
|
||||
Metrics::EndMeasurement(MetricVariable::Sleep);
|
||||
|
||||
if (!ready && Game::server->GetIsConnectedToMaster()) {
|
||||
// Some delay is required here or else we crash the client?
|
||||
LOG("Finished loading world with zone (%i), ready up!", Game::server->GetZoneID());
|
||||
|
||||
framesSinceMasterStatus++;
|
||||
MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
|
||||
if (framesSinceMasterStatus >= 200) {
|
||||
LOG("Finished loading world with zone (%i), ready up!", Game::server->GetZoneID());
|
||||
|
||||
MasterPackets::SendWorldReady(Game::server, Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
|
||||
ready = true;
|
||||
}
|
||||
ready = true;
|
||||
}
|
||||
|
||||
if (Game::ShouldShutdown() && !worldShutdownSequenceComplete) {
|
||||
if (Game::ShouldShutdown() && !g_WorldShutdownSequenceComplete) {
|
||||
WorldShutdownProcess(zoneID);
|
||||
break;
|
||||
}
|
||||
@@ -527,14 +543,14 @@ void HandlePacketChat(Packet* packet) {
|
||||
if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || packet->data[0] == ID_CONNECTION_LOST) {
|
||||
LOG("Lost our connection to chat, zone(%i), instance(%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
|
||||
chatConnected = false;
|
||||
g_ChatConnected = false;
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED) {
|
||||
LOG("Established connection to chat, zone(%i), instance (%i)", Game::server->GetZoneID(), Game::server->GetInstanceID());
|
||||
Game::chatSysAddr = packet->systemAddress;
|
||||
|
||||
chatConnected = true;
|
||||
g_ChatConnected = true;
|
||||
}
|
||||
|
||||
if (packet->data[0] == ID_USER_PACKET_ENUM && packet->length >= 4) {
|
||||
@@ -634,36 +650,21 @@ void HandlePacketChat(Packet* packet) {
|
||||
|
||||
inStream.Read(lootOption);
|
||||
inStream.Read(memberCount);
|
||||
LOG("Updating team (%llu), (%i), (%i)", teamID, lootOption, memberCount);
|
||||
LOG("Updating team ID:(%llu), Loot:(%i), #Members:(%i)", teamID, lootOption, memberCount);
|
||||
for (char i = 0; i < memberCount; i++) {
|
||||
LWOOBJID member = LWOOBJID_EMPTY;
|
||||
inStream.Read(member);
|
||||
members.push_back(member);
|
||||
|
||||
LOG("Updating team member (%llu)", member);
|
||||
LOG("Added member (%llu) to the team", member);
|
||||
}
|
||||
|
||||
TeamManager::Instance()->UpdateTeam(teamID, lootOption, members);
|
||||
|
||||
break;
|
||||
}
|
||||
case MessageType::Chat::GENERAL_CHAT_MESSAGE: {
|
||||
// First get the zone and check if we should forward it
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
uint32_t zoneID;
|
||||
inStream.Read(zoneID);
|
||||
if (zoneID != Game::server->GetZoneID()) return;
|
||||
//Write our stream outwards:
|
||||
CBITSTREAM;
|
||||
unsigned char data;
|
||||
while (inStream.Read(data)) {
|
||||
bitStream.Write(data);
|
||||
}
|
||||
SEND_PACKET_BROADCAST;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG("Received an unknown chat: %i", int(packet->data[3]));
|
||||
LOG("Received an unknown chat: %s", StringifiedEnum::ToString(static_cast<MessageType::Chat>(packet->data[3])).data());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -692,8 +693,8 @@ void HandleMasterPacket(Packet* packet) {
|
||||
inStream.Read(username);
|
||||
|
||||
//Find them:
|
||||
auto it = m_PendingUsers.find(username.GetAsString());
|
||||
if (it == m_PendingUsers.end()) return;
|
||||
auto it = g_PendingUsers.find(username.GetAsString());
|
||||
if (it == g_PendingUsers.end()) return;
|
||||
|
||||
//Convert our key:
|
||||
std::string userHash = std::to_string(sessionKey);
|
||||
@@ -733,14 +734,14 @@ void HandleMasterPacket(Packet* packet) {
|
||||
UserManager::Instance()->RequestCharacterList(it->second.sysAddr);
|
||||
}
|
||||
|
||||
m_PendingUsers.erase(username.GetAsString());
|
||||
g_PendingUsers.erase(username.GetAsString());
|
||||
|
||||
//Notify master:
|
||||
{
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_ADDED);
|
||||
bitStream.Write<LWOMAPID>(Game::server->GetZoneID());
|
||||
bitStream.Write<LWOINSTANCEID>(instanceID);
|
||||
bitStream.Write<LWOINSTANCEID>(g_InstanceID);
|
||||
Game::server->SendToMaster(bitStream);
|
||||
}
|
||||
}
|
||||
@@ -843,7 +844,7 @@ void HandlePacket(Packet* packet) {
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_REMOVED);
|
||||
bitStream.Write<LWOMAPID>(Game::server->GetZoneID());
|
||||
bitStream.Write<LWOINSTANCEID>(instanceID);
|
||||
bitStream.Write<LWOINSTANCEID>(g_InstanceID);
|
||||
Game::server->SendToMaster(bitStream);
|
||||
}
|
||||
|
||||
@@ -874,7 +875,7 @@ void HandlePacket(Packet* packet) {
|
||||
inStream.Read(clientDatabaseChecksum);
|
||||
|
||||
// If the check is turned on, validate the client's database checksum.
|
||||
if (Game::config->GetValue("check_fdb") == "1" && !databaseChecksum.empty()) {
|
||||
if (Game::config->GetValue("check_fdb") == "1" && !g_DatabaseChecksum.empty()) {
|
||||
auto accountInfo = Database::Get()->GetAccountInfo(username.GetAsString());
|
||||
if (!accountInfo) {
|
||||
LOG("Client's account does not exist in the database, aborting connection.");
|
||||
@@ -883,7 +884,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
// Developers may skip this check
|
||||
if (clientDatabaseChecksum.string != databaseChecksum) {
|
||||
if (clientDatabaseChecksum.string != g_DatabaseChecksum) {
|
||||
|
||||
if (accountInfo->maxGmLevel < eGameMasterLevel::DEVELOPER) {
|
||||
LOG("Client's database checksum does not match the server's, aborting connection.");
|
||||
@@ -915,10 +916,10 @@ void HandlePacket(Packet* packet) {
|
||||
Game::server->SendToMaster(bitStream);
|
||||
|
||||
//Insert info into our pending list
|
||||
tempSessionInfo info;
|
||||
info.sysAddr = SystemAddress(packet->systemAddress);
|
||||
TempSessionInfo info;
|
||||
info.sysAddr = packet->systemAddress;
|
||||
info.hash = sessionKey.GetAsString();
|
||||
m_PendingUsers.insert(std::make_pair(username.GetAsString(), info));
|
||||
g_PendingUsers[username.GetAsString()] = info;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -933,8 +934,8 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
//This loops prevents users who aren't authenticated to double-request the char list, which
|
||||
//would make the login screen freeze sometimes.
|
||||
if (m_PendingUsers.size() > 0) {
|
||||
for (auto it : m_PendingUsers) {
|
||||
if (g_PendingUsers.size() > 0) {
|
||||
for (const auto& it : g_PendingUsers) {
|
||||
if (it.second.sysAddr == packet->systemAddress) {
|
||||
return;
|
||||
}
|
||||
@@ -1304,7 +1305,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
auto segments = Game::chatFilter->IsSentenceOkay(request.message, entity->GetGMLevel(), !(isBestFriend && request.chatLevel == 1));
|
||||
std::vector<std::pair<uint8_t, uint8_t>> segments = Game::chatFilter->IsSentenceOkay(request.message, entity->GetGMLevel(), !(isBestFriend && request.chatLevel == 1));
|
||||
|
||||
bool bAllClean = segments.empty();
|
||||
|
||||
@@ -1318,10 +1319,11 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
case MessageType::World::GENERAL_CHAT_MESSAGE: {
|
||||
if (chatDisabled) {
|
||||
ChatPackets::MessageFailure().Send(packet->systemAddress);
|
||||
if (g_ChatDisabled) {
|
||||
ChatPackets::SendMessageFail(packet->systemAddress);
|
||||
} else {
|
||||
ChatPackets::WorldChatMessage inChatMessage;
|
||||
auto chatMessage = ClientPackets::HandleChatMessage(packet);
|
||||
|
||||
// TODO: Find a good home for the logic in this case.
|
||||
User* user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) {
|
||||
@@ -1342,36 +1344,7 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
std::string sMessage = GeneralUtils::UTF16ToWTF8(chatMessage.message);
|
||||
LOG("%s: %s", playerName.c_str(), sMessage.c_str());
|
||||
|
||||
ChatPackets::ChatMessage outChatMessage;
|
||||
outChatMessage.chatChannel = chatMessage.chatChannel;
|
||||
outChatMessage.message = chatMessage.message;
|
||||
|
||||
outChatMessage.Broadcast();
|
||||
|
||||
{
|
||||
// TODO: make it so we don't write this manually, but instead use a proper read and writes
|
||||
// aka: this is awful and should be fixed, but I can't be bothered to do it right now
|
||||
// Forward to the chat server
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE);
|
||||
|
||||
bitStream.Write(user->GetLoggedInChar());
|
||||
bitStream.Write<uint32_t>(chatMessage.message.size());
|
||||
bitStream.Write(chatMessage.chatChannel);
|
||||
bitStream.Write<uint32_t>(chatMessage.message.size());
|
||||
|
||||
for (uint32_t i = 0; i < 77; ++i) {
|
||||
bitStream.Write<uint8_t>(0);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < chatMessage.message.size(); ++i) {
|
||||
bitStream.Write<uint16_t>(chatMessage.message[i]);
|
||||
}
|
||||
bitStream.Write<uint16_t>(0);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
|
||||
ChatPackets::SendChatMessage(packet->systemAddress, chatMessage.chatChannel, playerName, user->GetLoggedInChar(), isMythran, chatMessage.message);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1439,7 +1412,7 @@ void HandlePacket(Packet* packet) {
|
||||
}
|
||||
|
||||
void WorldShutdownProcess(uint32_t zoneId) {
|
||||
LOG("Saving map %i instance %i", zoneId, instanceID);
|
||||
LOG("Saving map %i instance %i", zoneId, g_InstanceID);
|
||||
for (auto i = 0; i < Game::server->GetReplicaManager()->GetParticipantCount(); ++i) {
|
||||
const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(i);
|
||||
|
||||
@@ -1464,7 +1437,7 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
LOG("ALL property data saved for zone %i clone %i!", zoneId, PropertyManagementComponent::Instance()->GetCloneId());
|
||||
}
|
||||
|
||||
LOG("ALL DATA HAS BEEN SAVED FOR ZONE %i INSTANCE %i!", zoneId, instanceID);
|
||||
LOG("ALL DATA HAS BEEN SAVED FOR ZONE %i INSTANCE %i!", zoneId, g_InstanceID);
|
||||
|
||||
while (Game::server->GetReplicaManager()->GetParticipantCount() > 0) {
|
||||
const auto& player = Game::server->GetReplicaManager()->GetParticipantAtIndex(0);
|
||||
@@ -1475,7 +1448,7 @@ void WorldShutdownProcess(uint32_t zoneId) {
|
||||
}
|
||||
|
||||
void WorldShutdownSequence() {
|
||||
bool shouldShutdown = Game::ShouldShutdown() || worldShutdownSequenceComplete;
|
||||
bool shouldShutdown = Game::ShouldShutdown() || g_WorldShutdownSequenceComplete;
|
||||
Game::lastSignal = -1;
|
||||
#ifndef DARKFLAME_PLATFORM_WIN32
|
||||
if (shouldShutdown)
|
||||
@@ -1486,13 +1459,13 @@ void WorldShutdownSequence() {
|
||||
|
||||
if (!Game::logger) return;
|
||||
|
||||
LOG("Zone (%i) instance (%i) shutting down outside of main loop!", Game::server->GetZoneID(), instanceID);
|
||||
LOG("Zone (%i) instance (%i) shutting down outside of main loop!", Game::server->GetZoneID(), g_InstanceID);
|
||||
WorldShutdownProcess(Game::server->GetZoneID());
|
||||
FinalizeShutdown();
|
||||
}
|
||||
|
||||
void FinalizeShutdown() {
|
||||
LOG("Shutdown complete, zone (%i), instance (%i)", Game::server->GetZoneID(), instanceID);
|
||||
LOG("Shutdown complete, zone (%i), instance (%i)", Game::server->GetZoneID(), g_InstanceID);
|
||||
|
||||
//Delete our objects here:
|
||||
Metrics::Clear();
|
||||
@@ -1511,7 +1484,7 @@ void FinalizeShutdown() {
|
||||
if (Game::logger) delete Game::logger;
|
||||
Game::logger = nullptr;
|
||||
|
||||
worldShutdownSequenceComplete = true;
|
||||
g_WorldShutdownSequenceComplete = true;
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
asyncapi: 2.0.0
|
||||
info:
|
||||
title: DarkflameServer WebSocket API
|
||||
version: 1.0.0
|
||||
description: API documentation for DarkflameServer WebSocket endpoints
|
||||
|
||||
servers:
|
||||
production:
|
||||
url: http://localhost:2005/ws
|
||||
protocol: http
|
||||
description: Production server
|
||||
|
||||
channels:
|
||||
chat:
|
||||
subscribe:
|
||||
summary: Subscribe to chat messages
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/ChatMessage'
|
||||
publish:
|
||||
summary: Send a chat message
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/ChatMessage'
|
||||
|
||||
player:
|
||||
subscribe:
|
||||
summary: Subscribe to player updates
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/PlayerUpdate'
|
||||
|
||||
team:
|
||||
subscribe:
|
||||
summary: Subscribe to team updates
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/TeamUpdate'
|
||||
|
||||
subscribe:
|
||||
publish:
|
||||
summary: Subscribe to an event
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/Subscription'
|
||||
|
||||
unsubscribe:
|
||||
publish:
|
||||
summary: Unsubscribe from an event
|
||||
message:
|
||||
contentType: application/json
|
||||
payload:
|
||||
$ref: '#/components/schemas/Subscription'
|
||||
|
||||
components:
|
||||
schemas:
|
||||
ChatMessage:
|
||||
type: object
|
||||
properties:
|
||||
user:
|
||||
type: string
|
||||
example: "Player1"
|
||||
message:
|
||||
type: string
|
||||
example: "Hello, world!"
|
||||
gmlevel:
|
||||
type: integer
|
||||
minimum: 0
|
||||
maximum: 9
|
||||
example: 0
|
||||
zone:
|
||||
type: integer
|
||||
example: 1000
|
||||
|
||||
PlayerUpdate:
|
||||
type: object
|
||||
properties:
|
||||
player_data:
|
||||
$ref: '#/components/schemas/Player'
|
||||
update_type:
|
||||
type: string
|
||||
example: "JOIN"
|
||||
|
||||
TeamUpdate:
|
||||
type: object
|
||||
properties:
|
||||
team_data:
|
||||
$ref: '#/components/schemas/Team'
|
||||
update_type:
|
||||
type: string
|
||||
example: "CREATE"
|
||||
|
||||
Subscription:
|
||||
type: object
|
||||
required:
|
||||
- subscription
|
||||
properties:
|
||||
subscription:
|
||||
type: string
|
||||
example: "chat_local"
|
||||
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 1152921508901824000
|
||||
gm_level:
|
||||
type: integer
|
||||
format: uint8
|
||||
example: 0
|
||||
name:
|
||||
type: string
|
||||
example: thisisatestname
|
||||
muted:
|
||||
type: boolean
|
||||
example: false
|
||||
zone_id:
|
||||
$ref: '#/components/schemas/ZoneID'
|
||||
|
||||
ZoneID:
|
||||
type: object
|
||||
properties:
|
||||
map_id:
|
||||
type: integer
|
||||
format: uint16
|
||||
example: 1200
|
||||
instance_id:
|
||||
type: integer
|
||||
format: uint16
|
||||
example: 2
|
||||
clone_id:
|
||||
type: integer
|
||||
format: uint32
|
||||
example: 0
|
||||
|
||||
Team:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 1152921508901824000
|
||||
loot_flag:
|
||||
type: integer
|
||||
format: uint8
|
||||
example: 1
|
||||
local:
|
||||
type: boolean
|
||||
example: false
|
||||
leader:
|
||||
type: string
|
||||
example: thisisatestname
|
||||
members:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Player'
|
||||
@@ -1,121 +0,0 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: DarkflameServer API
|
||||
version: 1.0.0
|
||||
description: API documentation for DarkflameServer HTTP endpoints
|
||||
|
||||
servers:
|
||||
- url: http://localhost:2005/api/v1
|
||||
|
||||
paths:
|
||||
/players:
|
||||
get:
|
||||
summary: Get list of online players
|
||||
responses:
|
||||
'200':
|
||||
description: A list of online players
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Player'
|
||||
'204':
|
||||
description: No players online
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
example: "No Players Online"
|
||||
|
||||
/teams:
|
||||
get:
|
||||
summary: Get list of online teams
|
||||
responses:
|
||||
'200':
|
||||
description: A list of online teams
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Team'
|
||||
'204':
|
||||
description: No teams online
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
example: "No Teams Online"
|
||||
|
||||
/announce:
|
||||
post:
|
||||
summary: Send an announcement
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Announcement'
|
||||
responses:
|
||||
'200':
|
||||
description: Announcement sent successfully
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
example: "Announcement Sent"
|
||||
'400':
|
||||
description: Invalid JSON or missing required fields
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
example: "Invalid JSON"
|
||||
|
||||
components:
|
||||
schemas:
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
playerID:
|
||||
type: integer
|
||||
example: 12345
|
||||
playerName:
|
||||
type: string
|
||||
example: "Player1"
|
||||
|
||||
Team:
|
||||
type: object
|
||||
properties:
|
||||
teamID:
|
||||
type: integer
|
||||
example: 67890
|
||||
teamName:
|
||||
type: string
|
||||
example: "Team1"
|
||||
|
||||
Announcement:
|
||||
type: object
|
||||
required:
|
||||
- title
|
||||
- message
|
||||
properties:
|
||||
title:
|
||||
type: string
|
||||
example: "Server Maintenance"
|
||||
message:
|
||||
type: string
|
||||
example: "The server will be down for maintenance at 10 PM."
|
||||
@@ -12,4 +12,5 @@ namespace Game {
|
||||
SystemAddress chatSysAddr;
|
||||
EntityManager* entityManager = nullptr;
|
||||
std::string projectVersion;
|
||||
Game::signal_t lastSignal = 0;
|
||||
}
|
||||
|
||||
4
thirdparty/SQLite/CppSQLite3.h
vendored
4
thirdparty/SQLite/CppSQLite3.h
vendored
@@ -52,9 +52,9 @@ public:
|
||||
|
||||
virtual ~CppSQLite3Exception();
|
||||
|
||||
const int errorCode() { return mnErrCode; }
|
||||
const int errorCode() const { return mnErrCode; }
|
||||
|
||||
const char* errorMessage() { return mpszErrMess; }
|
||||
const char* errorMessage() const { return mpszErrMess; }
|
||||
|
||||
const char* what() const noexcept override { return mpszErrMess; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user