mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-18 12:15:01 -06:00
Compare commits
150 Commits
scripting-
...
better-bit
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d874d5157 | |||
| 0dc4ad6a17 | |||
| 043d7366d7 | |||
| 6dfd5ca933 | |||
| 50ac686b7f | |||
| f10e45a2dd | |||
| 612d0d6a56 | |||
| 845e499510 | |||
| 7a0b245cb5 | |||
| 5c4a174691 | |||
| 820d7f7093 | |||
| e145d237e4 | |||
| 7e2747a2d2 | |||
| a29253d2f0 | |||
|
|
e5b69745aa | ||
|
|
040a78c386 | ||
|
|
d8a5fd49a4 | ||
|
|
208ed02158 | ||
| 952786c166 | |||
|
|
9a07020a51 | ||
| a22ecf385f | |||
| c2b4aa4026 | |||
|
|
0d48cfe8c0 | ||
| e299bf9b62 | |||
|
|
304af7922a | ||
|
|
0610fe99f8 | ||
|
|
d1316cfc9f | ||
| bd5ead40f6 | |||
|
|
c791d1a237 | ||
|
|
54454973a1 | ||
|
|
b87537c637 | ||
|
|
a625d2eae5 | ||
|
|
887e2a25f0 | ||
|
|
34392932b3 | ||
|
|
cc251d0986 | ||
|
|
0c0f7216a1 | ||
|
|
342da56678 | ||
|
|
11b0097488 | ||
|
|
3e3148e910 | ||
|
|
080a833144 | ||
|
|
455f9470a5 | ||
| 9375c36c7b | |||
|
|
5cc7479f29 | ||
|
|
c4135eac46 | ||
| 41898bef86 | |||
|
|
787dac7cd9 | ||
|
|
e32cec6691 | ||
|
|
85aa82b4b9 | ||
|
|
393733cc67 | ||
|
|
8156e5cc91 | ||
|
|
d0e79d19fc | ||
|
|
45256a0338 | ||
|
|
238fc98ea5 | ||
|
|
d340874284 | ||
|
|
fe23c7c5f7 | ||
|
|
132d31d3ab | ||
|
|
2d31b7e4bb | ||
|
|
f46bc33dd4 | ||
|
|
0d6bd33f9e | ||
| 1a74c028c2 | |||
|
|
2a0f63c0a1 | ||
|
|
12d7ab9034 | ||
|
|
c99e2a372b | ||
|
|
dab075fc39 | ||
|
|
b4aa5db305 | ||
|
|
259f0c8371 | ||
|
|
a5e63529dc | ||
|
|
c572f2a58d | ||
|
|
5bff441c01 | ||
|
|
96fc6e81d8 | ||
|
|
59d7121978 | ||
|
|
b589755655 | ||
|
|
8ae1e1bc6b | ||
|
|
9fabff16e4 | ||
|
|
8267823ca4 | ||
|
|
b8878da61b | ||
|
|
47deca6f4f | ||
|
|
8a1f275176 | ||
|
|
e1a7b4993e | ||
|
|
0ecc5d83c3 | ||
|
|
a43e03255c | ||
|
|
83da45575e | ||
|
|
f5f599764d | ||
|
|
7b1626901a | ||
|
|
a595347211 | ||
|
|
0107d05d55 | ||
|
|
f26e66da4d | ||
|
|
e47169fec5 | ||
|
|
238751f14e | ||
| 59387e5fe3 | |||
|
|
f9b52ad01c | ||
|
|
1f3df08730 | ||
| 9708ea28dc | |||
|
|
8a065ad074 | ||
|
|
2117a18d62 | ||
|
|
4fe335cc66 | ||
| 9d105a287d | |||
| 1af70161eb | |||
| 739eae5244 | |||
|
|
07803a7ca2 | ||
|
|
61ae619886 | ||
|
|
8a8006bee5 | ||
|
|
c5afd7d4a3 | ||
| a809f36548 | |||
| 0e01948414 | |||
| 6e6a05fc1d | |||
| 5af5b0f1c1 | |||
| bf0ae6f181 | |||
| b1cd2776fa | |||
|
|
af1abe9e74 | ||
|
|
4dba8d9225 | ||
|
|
3448426caf | ||
|
|
7a067e7b48 | ||
|
|
411c9eaf1f | ||
|
|
fcf5c5ea8a | ||
| 4ff5afd9f7 | |||
|
|
ce931c2cfe | ||
|
|
6c2312fe87 | ||
|
|
d98ad4b94f | ||
|
|
5c086909ed | ||
|
|
7aad6e4bc2 | ||
|
|
1c7ac93d4b | ||
|
|
64a947e338 | ||
|
|
0f307ac4be | ||
| 8ceabadcde | |||
|
|
bc518be654 | ||
|
|
820b375c50 | ||
|
|
df3265c82e | ||
|
|
3b8f18d2be | ||
|
|
0faef7d791 | ||
|
|
28a0492201 | ||
|
|
2ab995b9c3 | ||
|
|
8de528e77c | ||
|
|
a3626a3b53 | ||
|
|
b5e3bd22e3 | ||
|
|
48264e2cf4 | ||
|
|
10a2c24d5e | ||
|
|
89f427ace0 | ||
|
|
08220d6852 | ||
|
|
42870028e4 | ||
|
|
fcb088d263 | ||
|
|
ed2639ce4e | ||
|
|
41355cea58 | ||
|
|
c91f0d16b3 | ||
|
|
c02963013b | ||
|
|
308d56968a | ||
|
|
47445ada54 | ||
|
|
426bc963fe | ||
|
|
1e4e1b914c | ||
|
|
b432a3f5da |
@@ -14,4 +14,4 @@ EXTERNAL_IP=localhost
|
||||
MARIADB_USER=darkflame
|
||||
MARIADB_PASSWORD=SECRET_VALUE_CHANGE_ME
|
||||
MARIADB_ROOT_PASSWORD=SECRET_VALUE_CHANGE_ME
|
||||
MARIADB_DATABASE=darkflame
|
||||
MARIADB_DATABASE=darkflame
|
||||
|
||||
26
.github/workflows/build-and-test.yml
vendored
26
.github/workflows/build-and-test.yml
vendored
@@ -36,22 +36,16 @@ jobs:
|
||||
testPreset: "ci-${{matrix.os}}"
|
||||
- name: artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ github.ref == 'ref/head/main' }}
|
||||
with:
|
||||
name: build-${{matrix.os}}
|
||||
path: |
|
||||
build
|
||||
!build/tests
|
||||
!build/Testing
|
||||
!build/CMakeFiles
|
||||
!build/DartConfiguration.tcl
|
||||
!build/CTestTestfile.cmake
|
||||
!build/CMakeCache.txt
|
||||
!build/build.ninja
|
||||
!build/_deps
|
||||
!build/cmake_install.cmake
|
||||
!build/*.a
|
||||
!build/*.lib
|
||||
!build/*.dir
|
||||
!build/*.vcxproj
|
||||
!build/*.vcxproj.filters
|
||||
build/*Server*
|
||||
build/*.ini
|
||||
build/*.so
|
||||
build/*.dll
|
||||
build/vanity/
|
||||
build/navmeshes/
|
||||
build/migrations/
|
||||
build/*.dcf
|
||||
!build/*.pdb
|
||||
!build/d*/
|
||||
|
||||
@@ -97,15 +97,56 @@ make_directory(${CMAKE_BINARY_DIR}/logs)
|
||||
|
||||
# Copy resource files on first build
|
||||
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blacklist.dcf")
|
||||
foreach(resource_file ${RESOURCE_FILES})
|
||||
if (NOT EXISTS ${PROJECT_BINARY_DIR}/${resource_file})
|
||||
message(STATUS "Checking resource file integrity")
|
||||
foreach (resource_file ${RESOURCE_FILES})
|
||||
set(file_size 0)
|
||||
if (EXISTS ${PROJECT_BINARY_DIR}/${resource_file})
|
||||
file(SIZE ${PROJECT_BINARY_DIR}/${resource_file} file_size)
|
||||
endif()
|
||||
if (${file_size} EQUAL 0)
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/resources/${resource_file} ${PROJECT_BINARY_DIR}/${resource_file}
|
||||
COPYONLY
|
||||
)
|
||||
message("Moved ${resource_file} to project binary directory")
|
||||
message(STATUS "Moved " ${resource_file} " to project binary directory")
|
||||
elseif (resource_file MATCHES ".ini")
|
||||
message(STATUS "Checking " ${resource_file} " for missing config options")
|
||||
file(READ ${PROJECT_BINARY_DIR}/${resource_file} current_file_contents)
|
||||
string(REPLACE "\\\n" "" current_file_contents ${current_file_contents})
|
||||
string(REPLACE "\n" ";" current_file_contents ${current_file_contents})
|
||||
set(parsed_current_file_contents "")
|
||||
# Remove comment lines so they do not interfere with the variable parsing
|
||||
foreach (line ${current_file_contents})
|
||||
string(FIND ${line} "#" is_comment)
|
||||
if (NOT ${is_comment} EQUAL 0)
|
||||
string(APPEND parsed_current_file_contents ${line})
|
||||
endif()
|
||||
endforeach()
|
||||
file(READ ${CMAKE_SOURCE_DIR}/resources/${resource_file} depot_file_contents)
|
||||
string(REPLACE "\\\n" "" depot_file_contents ${depot_file_contents})
|
||||
string(REPLACE "\n" ";" depot_file_contents ${depot_file_contents})
|
||||
set(line_to_add "")
|
||||
foreach (line ${depot_file_contents})
|
||||
string(FIND ${line} "#" is_comment)
|
||||
if (NOT ${is_comment} EQUAL 0)
|
||||
string(REPLACE "=" ";" line_split ${line})
|
||||
list(GET line_split 0 variable_name)
|
||||
if (NOT ${parsed_current_file_contents} MATCHES ${variable_name})
|
||||
message(STATUS "Adding missing config option " ${variable_name} " to " ${resource_file})
|
||||
set(line_to_add ${line_to_add} ${line})
|
||||
foreach (line_to_append ${line_to_add})
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n" ${line_to_append})
|
||||
endforeach()
|
||||
file(APPEND ${PROJECT_BINARY_DIR}/${resource_file} "\n")
|
||||
endif()
|
||||
set(line_to_add "")
|
||||
else()
|
||||
set(line_to_add ${line_to_add} ${line})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
message(STATUS "Resource file integrity check complete")
|
||||
|
||||
# Copy navmesh data on first build and extract it
|
||||
if (NOT EXISTS ${PROJECT_BINARY_DIR}/navmeshes/)
|
||||
@@ -255,11 +296,6 @@ set(INCLUDED_DIRECTORIES
|
||||
"tests/dGameTests/dComponentsTests"
|
||||
)
|
||||
|
||||
if(__include_lua__)
|
||||
set(INCLUDED_DIRECTORIES ${INCLUDED_DIRECTORIES} "dLua")
|
||||
set(INCLUDED_DIRECTORIES ${INCLUDED_DIRECTORIES} "dLua/sol")
|
||||
endif()
|
||||
|
||||
# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)
|
||||
if (APPLE)
|
||||
include_directories("/usr/local/include/")
|
||||
@@ -322,7 +358,6 @@ add_subdirectory(dDatabase)
|
||||
add_subdirectory(dChatFilter)
|
||||
add_subdirectory(dNet)
|
||||
add_subdirectory(dScripts) # Add for dGame to use
|
||||
add_subdirectory(dLua)
|
||||
add_subdirectory(dGame)
|
||||
add_subdirectory(dZoneManager)
|
||||
add_subdirectory(dNavigation)
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
PROJECT_VERSION_MAJOR=1
|
||||
PROJECT_VERSION_MINOR=0
|
||||
PROJECT_VERSION_PATCH=4
|
||||
PROJECT_VERSION_PATCH=1
|
||||
# LICENSE
|
||||
LICENSE=AGPL-3.0
|
||||
# The network version.
|
||||
# 171023 - Darkflame Universe client
|
||||
# 171022 - Unmodded client
|
||||
NET_VERSION=171022
|
||||
# Debugging
|
||||
# Set __dynamic to 1 to enable the -rdynamic flag for the linker, yielding some symbols in crashlogs.
|
||||
__dynamic=1
|
||||
|
||||
@@ -179,7 +179,7 @@ If you would like to build the server faster, append `-j<number>` where number i
|
||||
### Notes
|
||||
Depending on your operating system, you may need to adjust some pre-processor defines in [CMakeVariables.txt](./CMakeVariables.txt) before building:
|
||||
* If you are on MacOS, ensure OPENSSL_ROOT_DIR is pointing to the openssl root directory.
|
||||
* If you are using a Darkflame Universe client, ensure NET_VERSION is changed to 171023.
|
||||
* If you are using a Darkflame Universe client, ensure `client_net_version` in `build/sharedconfig.ini` is changed to 171023.
|
||||
|
||||
## Configuring your server
|
||||
This server has a few steps that need to be taken to configure the server for your use case.
|
||||
@@ -338,7 +338,7 @@ This is a Work in Progress, but below are some quick links to documentaion for s
|
||||
## Former Contributors
|
||||
* TheMachine
|
||||
* Matthew
|
||||
* [Raine](https://github.com/Rainebannister)
|
||||
* [Raine](https://github.com/uwainium)
|
||||
* Bricknave
|
||||
|
||||
## Special Thanks
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Game {
|
||||
dServer* server = nullptr;
|
||||
dConfig* config = nullptr;
|
||||
bool shouldShutdown = false;
|
||||
std::mt19937 randomEngine;
|
||||
}
|
||||
|
||||
dLogger* SetupLogger();
|
||||
@@ -83,6 +84,8 @@ int main(int argc, char** argv) {
|
||||
delete res;
|
||||
delete stmt;
|
||||
|
||||
Game::randomEngine = std::mt19937(time(0));
|
||||
|
||||
//It's safe to pass 'localhost' here, as the IP is only used as the external IP.
|
||||
uint32_t maxClients = 50;
|
||||
uint32_t ourPort = 1001; //LU client is hardcoded to use this for auth port, so I'm making it the default.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "PlayerContainer.h"
|
||||
#include "Database.h"
|
||||
#include <vector>
|
||||
#include "PacketUtils.h"
|
||||
#include "BitstreamUtils.h"
|
||||
#include "Game.h"
|
||||
#include "dServer.h"
|
||||
#include "GeneralUtils.h"
|
||||
@@ -22,10 +22,9 @@ extern PlayerContainer playerContainer;
|
||||
|
||||
void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
//Get from the packet which player we want to do something with:
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = 0;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
auto player = playerContainer.GetPlayerData(playerID);
|
||||
if (!player) return;
|
||||
@@ -76,11 +75,11 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) {
|
||||
|
||||
//Now, we need to send the friendlist to the server they came from:
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GET_FRIENDS_LIST_RESPONSE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GET_FRIENDS_LIST_RESPONSE);
|
||||
bitStream.Write<uint8_t>(0);
|
||||
bitStream.Write<uint16_t>(1); //Length of packet -- just writing one as it doesn't matter, client skips it.
|
||||
bitStream.Write((uint16_t)friends.size());
|
||||
@@ -99,36 +98,28 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
auto maxNumberOfBestFriendsAsString = Game::config->GetValue("max_number_of_best_friends");
|
||||
// If this config option doesn't exist, default to 5 which is what live used.
|
||||
auto maxNumberOfBestFriends = maxNumberOfBestFriendsAsString != "" ? std::stoi(maxNumberOfBestFriendsAsString) : 5U;
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID requestorPlayerID;
|
||||
inStream.Read(requestorPlayerID);
|
||||
inStream.Read(requestorPlayerID);
|
||||
uint32_t spacing{};
|
||||
inStream.Read(spacing);
|
||||
std::string playerName = "";
|
||||
uint16_t character;
|
||||
bool noMoreLettersInName = false;
|
||||
|
||||
for (uint32_t j = 0; j < 33; j++) {
|
||||
inStream.Read(character);
|
||||
if (character == '\0') noMoreLettersInName = true;
|
||||
if (!noMoreLettersInName) playerName.push_back(static_cast<char>(character));
|
||||
}
|
||||
LUWString playerName(33);
|
||||
inStream.Read(playerName);
|
||||
|
||||
char isBestFriendRequest{};
|
||||
inStream.Read(isBestFriendRequest);
|
||||
|
||||
auto requestor = playerContainer.GetPlayerData(requestorPlayerID);
|
||||
if (requestor->playerName == playerName) {
|
||||
if (requestor->playerName == playerName.GetAsString()) {
|
||||
SendFriendResponse(requestor, requestor, eAddFriendResponseType::MYTHRAN);
|
||||
return;
|
||||
};
|
||||
std::unique_ptr<PlayerData> requestee(playerContainer.GetPlayerData(playerName));
|
||||
std::unique_ptr<PlayerData> requestee(playerContainer.GetPlayerData(playerName.GetAsString()));
|
||||
|
||||
// Check if player is online first
|
||||
if (isBestFriendRequest && !requestee) {
|
||||
for (auto friendDataCandidate : requestor->friends) {
|
||||
if (friendDataCandidate.friendName == playerName) {
|
||||
if (friendDataCandidate.friendName == playerName.GetAsString()) {
|
||||
requestee.reset(new PlayerData());
|
||||
// Setup the needed info since you can add a best friend offline.
|
||||
requestee->playerID = friendDataCandidate.friendID;
|
||||
@@ -152,11 +143,11 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
// Send the response code that corresponds to what the error is.
|
||||
if (!requestee) {
|
||||
std::unique_ptr<sql::PreparedStatement> nameQuery(Database::CreatePreppedStmt("SELECT name from charinfo where name = ?;"));
|
||||
nameQuery->setString(1, playerName);
|
||||
nameQuery->setString(1, playerName.GetAsString());
|
||||
std::unique_ptr<sql::ResultSet> result(nameQuery->executeQuery());
|
||||
|
||||
requestee.reset(new PlayerData());
|
||||
requestee->playerName = playerName;
|
||||
requestee->playerName = playerName.GetAsString();
|
||||
|
||||
SendFriendResponse(requestor, requestee.get(), result->next() ? eAddFriendResponseType::NOTONLINE : eAddFriendResponseType::INVALIDCHARACTER);
|
||||
return;
|
||||
@@ -247,17 +238,18 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleFriendResponse(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
eAddFriendResponseCode clientResponseCode = static_cast<eAddFriendResponseCode>(packet->data[0x14]);
|
||||
std::string friendName = PacketUtils::ReadString(0x15, packet, true);
|
||||
inStream.IgnoreBytes(4);
|
||||
eAddFriendResponseCode clientResponseCode;
|
||||
inStream.Read(clientResponseCode);
|
||||
LUWString friendName(33);
|
||||
inStream.Read(friendName);
|
||||
|
||||
//Now to try and find both of these:
|
||||
auto requestor = playerContainer.GetPlayerData(playerID);
|
||||
auto requestee = playerContainer.GetPlayerData(friendName);
|
||||
auto requestee = playerContainer.GetPlayerData(friendName.GetAsString());
|
||||
if (!requestor || !requestee) return;
|
||||
|
||||
eAddFriendResponseType serverResponseCode{};
|
||||
@@ -323,16 +315,17 @@ void ChatPacketHandler::HandleFriendResponse(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleRemoveFriend(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
std::string friendName = PacketUtils::ReadString(0x14, packet, true);
|
||||
inStream.IgnoreBytes(4);
|
||||
LUWString friendName(33);
|
||||
inStream.Read(friendName);
|
||||
|
||||
//we'll have to query the db here to find the user, since you can delete them while they're offline.
|
||||
//First, we need to find their ID:
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt("SELECT id FROM charinfo WHERE name=? LIMIT 1;"));
|
||||
stmt->setString(1, friendName.c_str());
|
||||
stmt->setString(1, friendName.GetAsString().c_str());
|
||||
|
||||
LWOOBJID friendID = 0;
|
||||
std::unique_ptr<sql::ResultSet> res(stmt->executeQuery());
|
||||
@@ -362,7 +355,8 @@ void ChatPacketHandler::HandleRemoveFriend(Packet* packet) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
SendRemoveFriend(goonA, friendName, true);
|
||||
auto friendString = friendName.GetAsString();
|
||||
SendRemoveFriend(goonA, friendString, true);
|
||||
}
|
||||
|
||||
auto goonB = playerContainer.GetPlayerData(friendID);
|
||||
@@ -381,71 +375,96 @@ void ChatPacketHandler::HandleRemoveFriend(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleChatMessage(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
auto* sender = playerContainer.GetPlayerData(playerID);
|
||||
|
||||
if (sender == nullptr) return;
|
||||
|
||||
if (playerContainer.GetIsMuted(sender)) return;
|
||||
|
||||
const auto senderName = std::string(sender->playerName.c_str());
|
||||
|
||||
inStream.SetReadOffset(0x14 * 8);
|
||||
inStream.IgnoreBytes(20);
|
||||
eChatChannel chatchannel;
|
||||
inStream.Read(chatchannel);
|
||||
LUWString senderNameLU(33);
|
||||
inStream.Read(senderNameLU);
|
||||
LWOOBJID senderID;
|
||||
inStream.Read(senderID);
|
||||
uint16_t sourceID;
|
||||
inStream.Read(sourceID);
|
||||
uint8_t senderGMLevel;
|
||||
inStream.Read(senderGMLevel);
|
||||
LUWString message(512);
|
||||
inStream.Read(message);
|
||||
Game::logger->Log("ChatPacketHandler", "channel %i sender %s, senderID %llu and %llu, sourceID %i, sendergmlevel %i, message %s", chatchannel, senderNameLU.GetAsString().c_str(), playerID, senderID,sourceID, senderGMLevel, message.GetAsString().c_str());
|
||||
|
||||
uint8_t channel = 0;
|
||||
inStream.Read(channel);
|
||||
|
||||
std::string message = PacketUtils::ReadString(0x66, packet, true, 512);
|
||||
Game::logger->Log("ChatPacketHandler", "Got a message from (%s) [%d]: %s", senderName.c_str(), chatchannel, message.GetAsString().c_str());
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Got a message from (%s) [%d]: %s", senderName.c_str(), channel, message.c_str());
|
||||
if (chatchannel != eChatChannel::Team) {
|
||||
auto* team = playerContainer.GetTeam(playerID);
|
||||
if (team == nullptr) return;
|
||||
|
||||
if (channel != 8) return;
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
auto* otherMember = playerContainer.GetPlayerData(memberId);
|
||||
|
||||
auto* team = playerContainer.GetTeam(playerID);
|
||||
if (otherMember == nullptr) return;
|
||||
|
||||
if (team == nullptr) return;
|
||||
const auto otherName = std::string(otherMember->playerName.c_str());
|
||||
|
||||
for (const auto memberId : team->memberIDs) {
|
||||
auto* otherMember = playerContainer.GetPlayerData(memberId);
|
||||
CBITSTREAM;
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
|
||||
if (otherMember == nullptr) return;
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
bitStream.Write(eChatChannel::Team);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
bitStream.Write(LUWString(senderName));
|
||||
bitStream.Write(sender->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
bitStream.Write(LUWString(otherName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write(eChatMessageResponseCode::Sent);
|
||||
bitStream.Write(message);
|
||||
|
||||
const auto otherName = std::string(otherMember->playerName.c_str());
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(otherMember->playerID);
|
||||
bitStream.Write<uint8_t>(8);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(senderName, 33, &bitStream);
|
||||
bitStream.Write(sender->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(otherName, 33, &bitStream);
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(0); //teams?
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
|
||||
SystemAddress sysAddr = otherMember->sysAddr;
|
||||
SEND_PACKET;
|
||||
SystemAddress sysAddr = otherMember->sysAddr;
|
||||
SEND_PACKET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
LWOOBJID senderID = PacketUtils::ReadPacketS64(0x08, packet);
|
||||
std::string receiverName = PacketUtils::ReadString(0x66, packet, true);
|
||||
std::string message = PacketUtils::ReadString(0xAA, packet, true, 512);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID senderID;
|
||||
inStream.Read(senderID);
|
||||
inStream.IgnoreBytes(4);
|
||||
|
||||
eChatChannel chatchannel;
|
||||
inStream.Read(chatchannel);
|
||||
// is there something extra here?
|
||||
LUWString senderName(33);
|
||||
inStream.Read(senderName);
|
||||
LWOOBJID senderID2;
|
||||
inStream.Read(senderID2);
|
||||
uint16_t sourceID;
|
||||
inStream.Read(sourceID);
|
||||
uint8_t senderGMLevel;
|
||||
inStream.Read(senderGMLevel);
|
||||
LUWString receiverName(33);
|
||||
inStream.Read(receiverName);
|
||||
uint8_t receiverGMLevel;
|
||||
inStream.Read(receiverGMLevel);
|
||||
eChatMessageResponseCode responseCode;
|
||||
inStream.Read(responseCode);
|
||||
LUWString message(512);
|
||||
inStream.Read(message);
|
||||
Game::logger->Log("ChatPacketHandler", "channel %i sender %s, senderID %llu and %llu, sourceID %i, sendergmlevel %i", chatchannel, senderName.GetAsString().c_str(), senderID, senderID2,sourceID, senderGMLevel);
|
||||
Game::logger->Log("ChatPacketHandler", "receiver %s, receivergmlevel %i, responsecode %i, message %s", receiverName.GetAsString().c_str(), receiverGMLevel, responseCode, message.GetAsString().c_str());
|
||||
//Get the bois:
|
||||
auto goonA = playerContainer.GetPlayerData(senderID);
|
||||
auto goonB = playerContainer.GetPlayerData(receiverName);
|
||||
auto goonB = playerContainer.GetPlayerData(receiverName.GetAsString());
|
||||
if (!goonA || !goonB) return;
|
||||
|
||||
if (playerContainer.GetIsMuted(goonA)) return;
|
||||
@@ -456,21 +475,21 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
//To the sender:
|
||||
{
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(goonA->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint8_t>(7);
|
||||
bitStream.Write(eChatChannel::Private);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(goonAName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonAName));
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(goonBName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonBName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(0); //success
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
bitStream.Write(eChatMessageResponseCode::Sent);
|
||||
bitStream.Write(message);
|
||||
|
||||
SystemAddress sysAddr = goonA->sysAddr;
|
||||
SEND_PACKET;
|
||||
@@ -479,21 +498,21 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
//To the receiver:
|
||||
{
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(goonB->playerID);
|
||||
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::PRIVATE_CHAT_MESSAGE);
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint8_t>(7);
|
||||
bitStream.Write(eChatChannel::Private);
|
||||
bitStream.Write<unsigned int>(69);
|
||||
PacketUtils::WritePacketWString(goonAName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonAName));
|
||||
bitStream.Write(goonA->playerID);
|
||||
bitStream.Write<uint16_t>(0);
|
||||
bitStream.Write<uint8_t>(0); //not mythran nametag
|
||||
PacketUtils::WritePacketWString(goonBName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(goonBName));
|
||||
bitStream.Write<uint8_t>(0); //not mythran for receiver
|
||||
bitStream.Write<uint8_t>(3); //new whisper
|
||||
PacketUtils::WritePacketWString(message, 512, &bitStream);
|
||||
bitStream.Write(eChatMessageResponseCode::ReceivedNewWhisper);
|
||||
bitStream.Write(LUWString(message.string, 512));
|
||||
|
||||
SystemAddress sysAddr = goonB->sysAddr;
|
||||
SEND_PACKET;
|
||||
@@ -501,11 +520,12 @@ void ChatPacketHandler::HandlePrivateChatMessage(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamInvite(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
std::string invitedPlayer = PacketUtils::ReadString(0x14, packet, true);
|
||||
inStream.IgnoreBytes(4);
|
||||
LUWString invitedPlayer(33);
|
||||
inStream.Read(invitedPlayer);
|
||||
|
||||
auto* player = playerContainer.GetPlayerData(playerID);
|
||||
|
||||
@@ -519,7 +539,7 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) {
|
||||
team = playerContainer.CreateTeam(playerID);
|
||||
}
|
||||
|
||||
auto* other = playerContainer.GetPlayerData(invitedPlayer);
|
||||
auto* other = playerContainer.GetPlayerData(invitedPlayer.GetAsString());
|
||||
|
||||
if (other == nullptr) {
|
||||
return;
|
||||
@@ -538,14 +558,13 @@ void ChatPacketHandler::HandleTeamInvite(Packet* packet) {
|
||||
|
||||
SendTeamInvite(other, player);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "Got team invite: %llu -> %s", playerID, invitedPlayer.c_str());
|
||||
Game::logger->Log("ChatPacketHandler", "Got team invite: %llu -> %s", playerID, invitedPlayer.GetAsString().c_str());
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
uint32_t size = 0;
|
||||
inStream.Read(size);
|
||||
char declined = 0;
|
||||
@@ -576,10 +595,9 @@ void ChatPacketHandler::HandleTeamInviteResponse(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamLeave(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
uint32_t size = 0;
|
||||
inStream.Read(size);
|
||||
|
||||
@@ -593,23 +611,22 @@ void ChatPacketHandler::HandleTeamLeave(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamKick(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
std::string kickedPlayer = PacketUtils::ReadString(0x14, packet, true);
|
||||
LUWString kickedPlayer(33);
|
||||
inStream.Read(kickedPlayer);
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) kicking (%s) from team", playerID, kickedPlayer.GetAsString().c_str());
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) kicking (%s) from team", playerID, kickedPlayer.c_str());
|
||||
|
||||
auto* kicked = playerContainer.GetPlayerData(kickedPlayer);
|
||||
auto* kicked = playerContainer.GetPlayerData(kickedPlayer.GetAsString());
|
||||
|
||||
LWOOBJID kickedId = LWOOBJID_EMPTY;
|
||||
|
||||
if (kicked != nullptr) {
|
||||
kickedId = kicked->playerID;
|
||||
} else {
|
||||
kickedId = playerContainer.GetId(GeneralUtils::UTF8ToUTF16(kickedPlayer));
|
||||
kickedId = playerContainer.GetId(GeneralUtils::UTF8ToUTF16(kickedPlayer.GetAsString()));
|
||||
}
|
||||
|
||||
if (kickedId == LWOOBJID_EMPTY) return;
|
||||
@@ -624,16 +641,16 @@ void ChatPacketHandler::HandleTeamKick(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamPromote(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
std::string promotedPlayer = PacketUtils::ReadString(0x14, packet, true);
|
||||
LUWString promotedPlayer(33);
|
||||
inStream.Read(promotedPlayer);
|
||||
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) promoting (%s) to team leader", playerID, promotedPlayer.c_str());
|
||||
Game::logger->Log("ChatPacketHandler", "(%llu) promoting (%s) to team leader", playerID, promotedPlayer.GetAsString().c_str());
|
||||
|
||||
auto* promoted = playerContainer.GetPlayerData(promotedPlayer);
|
||||
auto* promoted = playerContainer.GetPlayerData(promotedPlayer.GetAsString());
|
||||
|
||||
if (promoted == nullptr) return;
|
||||
|
||||
@@ -647,10 +664,9 @@ void ChatPacketHandler::HandleTeamPromote(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamLootOption(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
uint32_t size = 0;
|
||||
inStream.Read(size);
|
||||
|
||||
@@ -671,10 +687,9 @@ void ChatPacketHandler::HandleTeamLootOption(Packet* packet) {
|
||||
}
|
||||
|
||||
void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY;
|
||||
inStream.Read(playerID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
auto* team = playerContainer.GetTeam(playerID);
|
||||
auto* data = playerContainer.GetPlayerData(playerID);
|
||||
@@ -721,13 +736,13 @@ void ChatPacketHandler::HandleTeamStatusRequest(Packet* packet) {
|
||||
|
||||
void ChatPacketHandler::SendTeamInvite(PlayerData* receiver, PlayerData* sender) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TEAM_INVITE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::TEAM_INVITE);
|
||||
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
bitStream.Write(sender->playerID);
|
||||
|
||||
SystemAddress sysAddr = receiver->sysAddr;
|
||||
@@ -736,7 +751,7 @@ void ChatPacketHandler::SendTeamInvite(PlayerData* receiver, PlayerData* sender)
|
||||
|
||||
void ChatPacketHandler::SendTeamInviteConfirm(PlayerData* receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -763,7 +778,7 @@ void ChatPacketHandler::SendTeamInviteConfirm(PlayerData* receiver, bool bLeader
|
||||
|
||||
void ChatPacketHandler::SendTeamStatus(PlayerData* receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -788,7 +803,7 @@ void ChatPacketHandler::SendTeamStatus(PlayerData* receiver, LWOOBJID i64LeaderI
|
||||
|
||||
void ChatPacketHandler::SendTeamSetLeader(PlayerData* receiver, LWOOBJID i64PlayerID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -805,7 +820,7 @@ void ChatPacketHandler::SendTeamSetLeader(PlayerData* receiver, LWOOBJID i64Play
|
||||
|
||||
void ChatPacketHandler::SendTeamAddPlayer(PlayerData* receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -834,7 +849,7 @@ void ChatPacketHandler::SendTeamAddPlayer(PlayerData* receiver, bool bIsFreeTria
|
||||
|
||||
void ChatPacketHandler::SendTeamRemovePlayer(PlayerData* receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -860,7 +875,7 @@ void ChatPacketHandler::SendTeamRemovePlayer(PlayerData* receiver, bool bDisband
|
||||
|
||||
void ChatPacketHandler::SendTeamSetOffWorldFlag(PlayerData* receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
@@ -894,16 +909,16 @@ void ChatPacketHandler::SendFriendUpdate(PlayerData* friendData, PlayerData* pla
|
||||
[bool] - is FTP*/
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(friendData->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::UPDATE_FRIEND_NOTIFY);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::UPDATE_FRIEND_NOTIFY);
|
||||
bitStream.Write<uint8_t>(notifyType);
|
||||
|
||||
std::string playerName = playerData->playerName.c_str();
|
||||
|
||||
PacketUtils::WritePacketWString(playerName, 33, &bitStream);
|
||||
bitStream.Write(LUWString(playerName));
|
||||
|
||||
bitStream.Write(playerData->zoneID.GetMapID());
|
||||
bitStream.Write(playerData->zoneID.GetInstanceID());
|
||||
@@ -933,12 +948,12 @@ void ChatPacketHandler::SendFriendRequest(PlayerData* receiver, PlayerData* send
|
||||
}
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_REQUEST);
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_REQUEST);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
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;
|
||||
@@ -949,16 +964,16 @@ void ChatPacketHandler::SendFriendResponse(PlayerData* receiver, PlayerData* sen
|
||||
if (!receiver || !sender) return;
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
// Portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::ADD_FRIEND_RESPONSE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::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);
|
||||
// Then write the player name
|
||||
PacketUtils::WritePacketWString(sender->playerName.c_str(), 33, &bitStream);
|
||||
bitStream.Write(LUWString(sender->playerName.c_str()));
|
||||
// Then if this is an acceptance code, write the following extra info.
|
||||
if (responseCode == eAddFriendResponseType::ACCEPTED) {
|
||||
bitStream.Write(sender->playerID);
|
||||
@@ -974,13 +989,13 @@ void ChatPacketHandler::SendRemoveFriend(PlayerData* receiver, std::string& pers
|
||||
if (!receiver) return;
|
||||
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::ROUTE_TO_PLAYER);
|
||||
bitStream.Write(receiver->playerID);
|
||||
|
||||
//portion that will get routed:
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::REMOVE_FRIEND_RESPONSE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::REMOVE_FRIEND_RESPONSE);
|
||||
bitStream.Write<uint8_t>(isSuccessful); //isOnline
|
||||
PacketUtils::WritePacketWString(personToRemove, 33, &bitStream);
|
||||
bitStream.Write(LUWString(personToRemove));
|
||||
|
||||
SystemAddress sysAddr = receiver->sysAddr;
|
||||
SEND_PACKET;
|
||||
|
||||
@@ -6,6 +6,42 @@
|
||||
struct PlayerData;
|
||||
enum class eAddFriendResponseType : uint8_t;
|
||||
|
||||
enum class eChatChannel : uint8_t {
|
||||
SystemNotify,
|
||||
SystemWarning,
|
||||
SystemError,
|
||||
Broadcast,
|
||||
Local,
|
||||
LocalNoanim,
|
||||
Emote,
|
||||
Private,
|
||||
Team,
|
||||
TeamLocal,
|
||||
Guild,
|
||||
GuildNotify,
|
||||
Property,
|
||||
Admin,
|
||||
CombatDamage,
|
||||
CombatHealing,
|
||||
CombatLoot,
|
||||
CombatExp,
|
||||
CombatDeath,
|
||||
General,
|
||||
Trade,
|
||||
Lfg,
|
||||
User
|
||||
};
|
||||
|
||||
enum class eChatMessageResponseCode : uint8_t {
|
||||
Sent,
|
||||
NotOnline,
|
||||
GeneralError,
|
||||
ReceivedNewWhisper,
|
||||
NotFriends,
|
||||
SenderFreeTrial,
|
||||
ReceiverFreeTrial,
|
||||
};
|
||||
|
||||
namespace ChatPacketHandler {
|
||||
void HandleFriendlistRequest(Packet* packet);
|
||||
void HandleFriendRequest(Packet* packet);
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Game {
|
||||
dChatFilter* chatFilter = nullptr;
|
||||
AssetManager* assetManager = nullptr;
|
||||
bool shouldShutdown = false;
|
||||
std::mt19937 randomEngine;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +116,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", bool(std::stoi(Game::config->GetValue("dont_generate_dcf"))));
|
||||
|
||||
Game::randomEngine = std::mt19937(time(0));
|
||||
|
||||
//Run it until server gets a kill message from Master:
|
||||
auto t = std::chrono::high_resolution_clock::now();
|
||||
Packet* packet = nullptr;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "dLogger.h"
|
||||
#include "ChatPacketHandler.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitstreamUtils.h"
|
||||
#include "Database.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eChatInternalMessageType.h"
|
||||
@@ -19,9 +19,8 @@ PlayerContainer::~PlayerContainer() {
|
||||
}
|
||||
|
||||
void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
PlayerData* data = new PlayerData();
|
||||
inStream.SetReadOffset(inStream.GetReadOffset() + 64);
|
||||
inStream.Read(data->playerID);
|
||||
|
||||
uint32_t len;
|
||||
@@ -52,9 +51,8 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
|
||||
}
|
||||
|
||||
void PlayerContainer::RemovePlayer(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID); //skip header
|
||||
inStream.Read(playerID);
|
||||
|
||||
//Before they get kicked, we need to also send a message to their friends saying that they disconnected.
|
||||
@@ -97,9 +95,8 @@ void PlayerContainer::RemovePlayer(Packet* packet) {
|
||||
}
|
||||
|
||||
void PlayerContainer::MuteUpdate(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID); //skip header
|
||||
inStream.Read(playerID);
|
||||
time_t expire = 0;
|
||||
inStream.Read(expire);
|
||||
@@ -118,9 +115,8 @@ void PlayerContainer::MuteUpdate(Packet* packet) {
|
||||
}
|
||||
|
||||
void PlayerContainer::CreateTeamServer(Packet* packet) {
|
||||
CINSTREAM;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID); //skip header
|
||||
inStream.Read(playerID);
|
||||
size_t membersSize = 0;
|
||||
inStream.Read(membersSize);
|
||||
@@ -150,7 +146,7 @@ void PlayerContainer::CreateTeamServer(Packet* packet) {
|
||||
|
||||
void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::MUTE_UPDATE);
|
||||
|
||||
bitStream.Write(player);
|
||||
bitStream.Write(time);
|
||||
@@ -349,7 +345,7 @@ void PlayerContainer::TeamStatusUpdate(TeamData* team) {
|
||||
|
||||
void PlayerContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::TEAM_UPDATE);
|
||||
|
||||
bitStream.Write(team->teamID);
|
||||
bitStream.Write(deleteTeam);
|
||||
|
||||
@@ -1,77 +1,79 @@
|
||||
#include "AMFDeserialize.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Amf3.h"
|
||||
|
||||
/**
|
||||
* AMF3 Reference document https://rtmp.veriskope.com/pdf/amf3-file-format-spec.pdf
|
||||
* AMF3 Deserializer written by EmosewaMC
|
||||
*/
|
||||
|
||||
AMFValue* AMFDeserialize::Read(RakNet::BitStream* inStream) {
|
||||
AMFBaseValue* AMFDeserialize::Read(RakNet::BitStream* inStream) {
|
||||
if (!inStream) return nullptr;
|
||||
AMFValue* returnValue = nullptr;
|
||||
AMFBaseValue* returnValue = nullptr;
|
||||
// Read in the value type from the bitStream
|
||||
int8_t marker;
|
||||
eAmf marker;
|
||||
inStream->Read(marker);
|
||||
// Based on the typing, create the value associated with that and return the base value class
|
||||
switch (marker) {
|
||||
case AMFValueType::AMFUndefined: {
|
||||
returnValue = new AMFUndefinedValue();
|
||||
case eAmf::Undefined: {
|
||||
returnValue = new AMFBaseValue();
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFNull: {
|
||||
case eAmf::Null: {
|
||||
returnValue = new AMFNullValue();
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFFalse: {
|
||||
returnValue = new AMFFalseValue();
|
||||
case eAmf::False: {
|
||||
returnValue = new AMFBoolValue(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFTrue: {
|
||||
returnValue = new AMFTrueValue();
|
||||
case eAmf::True: {
|
||||
returnValue = new AMFBoolValue(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFInteger: {
|
||||
case eAmf::Integer: {
|
||||
returnValue = ReadAmfInteger(inStream);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFDouble: {
|
||||
case eAmf::Double: {
|
||||
returnValue = ReadAmfDouble(inStream);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFString: {
|
||||
case eAmf::String: {
|
||||
returnValue = ReadAmfString(inStream);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFValueType::AMFArray: {
|
||||
case eAmf::Array: {
|
||||
returnValue = ReadAmfArray(inStream);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO We do not need these values, but if someone wants to implement them
|
||||
// then please do so and add the corresponding unit tests.
|
||||
case AMFValueType::AMFXMLDoc:
|
||||
case AMFValueType::AMFDate:
|
||||
case AMFValueType::AMFObject:
|
||||
case AMFValueType::AMFXML:
|
||||
case AMFValueType::AMFByteArray:
|
||||
case AMFValueType::AMFVectorInt:
|
||||
case AMFValueType::AMFVectorUInt:
|
||||
case AMFValueType::AMFVectorDouble:
|
||||
case AMFValueType::AMFVectorObject:
|
||||
case AMFValueType::AMFDictionary: {
|
||||
throw static_cast<AMFValueType>(marker);
|
||||
// These values are unimplemented in the live client and will remain unimplemented
|
||||
// unless someone modifies the client to allow serializing of these values.
|
||||
case eAmf::XMLDoc:
|
||||
case eAmf::Date:
|
||||
case eAmf::Object:
|
||||
case eAmf::XML:
|
||||
case eAmf::ByteArray:
|
||||
case eAmf::VectorInt:
|
||||
case eAmf::VectorUInt:
|
||||
case eAmf::VectorDouble:
|
||||
case eAmf::VectorObject:
|
||||
case eAmf::Dictionary: {
|
||||
throw marker;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw static_cast<AMFValueType>(marker);
|
||||
throw std::invalid_argument("Invalid AMF3 marker" + std::to_string(static_cast<int32_t>(marker)));
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
@@ -99,7 +101,7 @@ uint32_t AMFDeserialize::ReadU29(RakNet::BitStream* inStream) {
|
||||
return actualNumber;
|
||||
}
|
||||
|
||||
std::string AMFDeserialize::ReadString(RakNet::BitStream* inStream) {
|
||||
const std::string AMFDeserialize::ReadString(RakNet::BitStream* inStream) {
|
||||
auto length = ReadU29(inStream);
|
||||
// Check if this is a reference
|
||||
bool isReference = length % 2 == 1;
|
||||
@@ -113,48 +115,39 @@ std::string AMFDeserialize::ReadString(RakNet::BitStream* inStream) {
|
||||
return value;
|
||||
} else {
|
||||
// Length is a reference to a previous index - use that as the read in value
|
||||
return accessedElements[length];
|
||||
return accessedElements.at(length);
|
||||
}
|
||||
}
|
||||
|
||||
AMFValue* AMFDeserialize::ReadAmfDouble(RakNet::BitStream* inStream) {
|
||||
auto doubleValue = new AMFDoubleValue();
|
||||
AMFBaseValue* AMFDeserialize::ReadAmfDouble(RakNet::BitStream* inStream) {
|
||||
double value;
|
||||
inStream->Read<double>(value);
|
||||
doubleValue->SetDoubleValue(value);
|
||||
return doubleValue;
|
||||
return new AMFDoubleValue(value);
|
||||
}
|
||||
|
||||
AMFValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream* inStream) {
|
||||
AMFBaseValue* AMFDeserialize::ReadAmfArray(RakNet::BitStream* inStream) {
|
||||
auto arrayValue = new AMFArrayValue();
|
||||
|
||||
// Read size of dense array
|
||||
auto sizeOfDenseArray = (ReadU29(inStream) >> 1);
|
||||
|
||||
// Then read Key'd portion
|
||||
// Then read associative portion
|
||||
while (true) {
|
||||
auto key = ReadString(inStream);
|
||||
// No more values when we encounter an empty string
|
||||
// No more associative values when we encounter an empty string key
|
||||
if (key.size() == 0) break;
|
||||
arrayValue->InsertValue(key, Read(inStream));
|
||||
arrayValue->Insert(key, Read(inStream));
|
||||
}
|
||||
|
||||
// Finally read dense portion
|
||||
for (uint32_t i = 0; i < sizeOfDenseArray; i++) {
|
||||
arrayValue->PushBackValue(Read(inStream));
|
||||
arrayValue->Insert(i, Read(inStream));
|
||||
}
|
||||
|
||||
return arrayValue;
|
||||
}
|
||||
|
||||
AMFValue* AMFDeserialize::ReadAmfString(RakNet::BitStream* inStream) {
|
||||
auto stringValue = new AMFStringValue();
|
||||
stringValue->SetStringValue(ReadString(inStream));
|
||||
return stringValue;
|
||||
AMFBaseValue* AMFDeserialize::ReadAmfString(RakNet::BitStream* inStream) {
|
||||
return new AMFStringValue(ReadString(inStream));
|
||||
}
|
||||
|
||||
AMFValue* AMFDeserialize::ReadAmfInteger(RakNet::BitStream* inStream) {
|
||||
auto integerValue = new AMFIntegerValue();
|
||||
integerValue->SetIntegerValue(ReadU29(inStream));
|
||||
return integerValue;
|
||||
AMFBaseValue* AMFDeserialize::ReadAmfInteger(RakNet::BitStream* inStream) {
|
||||
return new AMFIntValue(ReadU29(inStream));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class AMFValue;
|
||||
class AMFBaseValue;
|
||||
|
||||
class AMFDeserialize {
|
||||
public:
|
||||
/**
|
||||
@@ -14,7 +15,7 @@ public:
|
||||
* @param inStream inStream to read value from.
|
||||
* @return Returns an AMFValue with all the information from the bitStream in it.
|
||||
*/
|
||||
AMFValue* Read(RakNet::BitStream* inStream);
|
||||
AMFBaseValue* Read(RakNet::BitStream* inStream);
|
||||
private:
|
||||
/**
|
||||
* @brief Private method to read a U29 integer from a bitstream
|
||||
@@ -30,7 +31,7 @@ private:
|
||||
* @param inStream bitStream to read data from
|
||||
* @return The read string
|
||||
*/
|
||||
std::string ReadString(RakNet::BitStream* inStream);
|
||||
const std::string ReadString(RakNet::BitStream* inStream);
|
||||
|
||||
/**
|
||||
* @brief Read an AMFDouble value from a bitStream
|
||||
@@ -38,7 +39,7 @@ private:
|
||||
* @param inStream bitStream to read data from
|
||||
* @return Double value represented as an AMFValue
|
||||
*/
|
||||
AMFValue* ReadAmfDouble(RakNet::BitStream* inStream);
|
||||
AMFBaseValue* ReadAmfDouble(RakNet::BitStream* inStream);
|
||||
|
||||
/**
|
||||
* @brief Read an AMFArray from a bitStream
|
||||
@@ -46,7 +47,7 @@ private:
|
||||
* @param inStream bitStream to read data from
|
||||
* @return Array value represented as an AMFValue
|
||||
*/
|
||||
AMFValue* ReadAmfArray(RakNet::BitStream* inStream);
|
||||
AMFBaseValue* ReadAmfArray(RakNet::BitStream* inStream);
|
||||
|
||||
/**
|
||||
* @brief Read an AMFString from a bitStream
|
||||
@@ -54,7 +55,7 @@ private:
|
||||
* @param inStream bitStream to read data from
|
||||
* @return String value represented as an AMFValue
|
||||
*/
|
||||
AMFValue* ReadAmfString(RakNet::BitStream* inStream);
|
||||
AMFBaseValue* ReadAmfString(RakNet::BitStream* inStream);
|
||||
|
||||
/**
|
||||
* @brief Read an AMFInteger from a bitStream
|
||||
@@ -62,7 +63,7 @@ private:
|
||||
* @param inStream bitStream to read data from
|
||||
* @return Integer value represented as an AMFValue
|
||||
*/
|
||||
AMFValue* ReadAmfInteger(RakNet::BitStream* inStream);
|
||||
AMFBaseValue* ReadAmfInteger(RakNet::BitStream* inStream);
|
||||
|
||||
/**
|
||||
* List of strings read so far saved to be read by reference.
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
#include "AMFFormat.h"
|
||||
|
||||
// AMFInteger
|
||||
void AMFIntegerValue::SetIntegerValue(uint32_t value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
uint32_t AMFIntegerValue::GetIntegerValue() {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
// AMFDouble
|
||||
void AMFDoubleValue::SetDoubleValue(double value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
double AMFDoubleValue::GetDoubleValue() {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
// AMFString
|
||||
void AMFStringValue::SetStringValue(const std::string& value) {
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
std::string AMFStringValue::GetStringValue() {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
// AMFXMLDoc
|
||||
void AMFXMLDocValue::SetXMLDocValue(const std::string& value) {
|
||||
this->xmlData = value;
|
||||
}
|
||||
|
||||
std::string AMFXMLDocValue::GetXMLDocValue() {
|
||||
return this->xmlData;
|
||||
}
|
||||
|
||||
// AMFDate
|
||||
void AMFDateValue::SetDateValue(uint64_t value) {
|
||||
this->millisecondTimestamp = value;
|
||||
}
|
||||
|
||||
uint64_t AMFDateValue::GetDateValue() {
|
||||
return this->millisecondTimestamp;
|
||||
}
|
||||
|
||||
// AMFArray Insert Value
|
||||
void AMFArrayValue::InsertValue(const std::string& key, AMFValue* value) {
|
||||
this->associative.insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
// AMFArray Remove Value
|
||||
void AMFArrayValue::RemoveValue(const std::string& key) {
|
||||
_AMFArrayMap_::iterator it = this->associative.find(key);
|
||||
if (it != this->associative.end()) {
|
||||
this->associative.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
// AMFArray Get Associative Iterator Begin
|
||||
_AMFArrayMap_::iterator AMFArrayValue::GetAssociativeIteratorValueBegin() {
|
||||
return this->associative.begin();
|
||||
}
|
||||
|
||||
// AMFArray Get Associative Iterator End
|
||||
_AMFArrayMap_::iterator AMFArrayValue::GetAssociativeIteratorValueEnd() {
|
||||
return this->associative.end();
|
||||
}
|
||||
|
||||
// AMFArray Push Back Value
|
||||
void AMFArrayValue::PushBackValue(AMFValue* value) {
|
||||
this->dense.push_back(value);
|
||||
}
|
||||
|
||||
// AMFArray Pop Back Value
|
||||
void AMFArrayValue::PopBackValue() {
|
||||
this->dense.pop_back();
|
||||
}
|
||||
|
||||
// AMFArray Get Dense List Size
|
||||
uint32_t AMFArrayValue::GetDenseValueSize() {
|
||||
return (uint32_t)this->dense.size();
|
||||
}
|
||||
|
||||
// AMFArray Get Dense Iterator Begin
|
||||
_AMFArrayList_::iterator AMFArrayValue::GetDenseIteratorBegin() {
|
||||
return this->dense.begin();
|
||||
}
|
||||
|
||||
// AMFArray Get Dense Iterator End
|
||||
_AMFArrayList_::iterator AMFArrayValue::GetDenseIteratorEnd() {
|
||||
return this->dense.end();
|
||||
}
|
||||
|
||||
AMFArrayValue::~AMFArrayValue() {
|
||||
for (auto valueToDelete : GetDenseArray()) {
|
||||
if (valueToDelete) delete valueToDelete;
|
||||
}
|
||||
for (auto valueToDelete : GetAssociativeMap()) {
|
||||
if (valueToDelete.second) delete valueToDelete.second;
|
||||
}
|
||||
}
|
||||
|
||||
// AMFObject Constructor
|
||||
AMFObjectValue::AMFObjectValue(std::vector<std::pair<std::string, AMFValueType>> traits) {
|
||||
this->traits.reserve(traits.size());
|
||||
std::vector<std::pair<std::string, AMFValueType>>::iterator it = traits.begin();
|
||||
while (it != traits.end()) {
|
||||
this->traits.insert(std::make_pair(it->first, std::make_pair(it->second, new AMFNullValue())));
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
// AMFObject Set Value
|
||||
void AMFObjectValue::SetTraitValue(const std::string& trait, AMFValue* value) {
|
||||
if (value) {
|
||||
_AMFObjectTraits_::iterator it = this->traits.find(trait);
|
||||
if (it != this->traits.end()) {
|
||||
if (it->second.first == value->GetValueType()) {
|
||||
it->second.second = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AMFObject Get Value
|
||||
AMFValue* AMFObjectValue::GetTraitValue(const std::string& trait) {
|
||||
_AMFObjectTraits_::iterator it = this->traits.find(trait);
|
||||
if (it != this->traits.end()) {
|
||||
return it->second.second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// AMFObject Get Trait Iterator Begin
|
||||
_AMFObjectTraits_::iterator AMFObjectValue::GetTraitsIteratorBegin() {
|
||||
return this->traits.begin();
|
||||
}
|
||||
|
||||
// AMFObject Get Trait Iterator End
|
||||
_AMFObjectTraits_::iterator AMFObjectValue::GetTraitsIteratorEnd() {
|
||||
return this->traits.end();
|
||||
}
|
||||
|
||||
// AMFObject Get Trait Size
|
||||
uint32_t AMFObjectValue::GetTraitArrayCount() {
|
||||
return (uint32_t)this->traits.size();
|
||||
}
|
||||
|
||||
AMFObjectValue::~AMFObjectValue() {
|
||||
for (auto valueToDelete = GetTraitsIteratorBegin(); valueToDelete != GetTraitsIteratorEnd(); valueToDelete++) {
|
||||
if (valueToDelete->second.second) delete valueToDelete->second.second;
|
||||
}
|
||||
}
|
||||
@@ -1,413 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Custom Classes
|
||||
#include "dCommonVars.h"
|
||||
|
||||
// C++
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/*!
|
||||
\file AMFFormat.hpp
|
||||
\brief A class for managing AMF values
|
||||
*/
|
||||
|
||||
class AMFValue; // Forward declaration
|
||||
|
||||
// Definitions
|
||||
#define _AMFArrayMap_ std::unordered_map<std::string, AMFValue*>
|
||||
#define _AMFArrayList_ std::vector<AMFValue*>
|
||||
|
||||
#define _AMFObjectTraits_ std::unordered_map<std::string, std::pair<AMFValueType, AMFValue*>>
|
||||
#define _AMFObjectDynamicTraits_ std::unordered_map<std::string, AMFValue*>
|
||||
|
||||
//! An enum for each AMF value type
|
||||
enum AMFValueType : unsigned char {
|
||||
AMFUndefined = 0x00, //!< An undefined AMF Value
|
||||
AMFNull = 0x01, //!< A null AMF value
|
||||
AMFFalse = 0x02, //!< A false AMF value
|
||||
AMFTrue = 0x03, //!< A true AMF value
|
||||
AMFInteger = 0x04, //!< An integer AMF value
|
||||
AMFDouble = 0x05, //!< A double AMF value
|
||||
AMFString = 0x06, //!< A string AMF value
|
||||
AMFXMLDoc = 0x07, //!< An XML Doc AMF value
|
||||
AMFDate = 0x08, //!< A date AMF value
|
||||
AMFArray = 0x09, //!< An array AMF value
|
||||
AMFObject = 0x0A, //!< An object AMF value
|
||||
AMFXML = 0x0B, //!< An XML AMF value
|
||||
AMFByteArray = 0x0C, //!< A byte array AMF value
|
||||
AMFVectorInt = 0x0D, //!< An integer vector AMF value
|
||||
AMFVectorUInt = 0x0E, //!< An unsigned integer AMF value
|
||||
AMFVectorDouble = 0x0F, //!< A double vector AMF value
|
||||
AMFVectorObject = 0x10, //!< An object vector AMF value
|
||||
AMFDictionary = 0x11 //!< A dictionary AMF value
|
||||
};
|
||||
|
||||
//! An enum for the object value types
|
||||
enum AMFObjectValueType : unsigned char {
|
||||
AMFObjectAnonymous = 0x01,
|
||||
AMFObjectTyped = 0x02,
|
||||
AMFObjectDynamic = 0x03,
|
||||
AMFObjectExternalizable = 0x04
|
||||
};
|
||||
|
||||
//! The base AMF value class
|
||||
class AMFValue {
|
||||
public:
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
virtual AMFValueType GetValueType() = 0;
|
||||
virtual ~AMFValue() {};
|
||||
};
|
||||
|
||||
//! A typedef for a pointer to an AMF value
|
||||
typedef AMFValue* NDGFxValue;
|
||||
|
||||
|
||||
// The various AMF value types
|
||||
|
||||
//! The undefined value AMF type
|
||||
class AMFUndefinedValue : public AMFValue {
|
||||
private:
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFUndefined;
|
||||
};
|
||||
|
||||
//! The null value AMF type
|
||||
class AMFNullValue : public AMFValue {
|
||||
private:
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFNull;
|
||||
};
|
||||
|
||||
//! The false value AMF type
|
||||
class AMFFalseValue : public AMFValue {
|
||||
private:
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFFalse;
|
||||
};
|
||||
|
||||
//! The true value AMF type
|
||||
class AMFTrueValue : public AMFValue {
|
||||
private:
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFTrue;
|
||||
};
|
||||
|
||||
//! The integer value AMF type
|
||||
class AMFIntegerValue : public AMFValue {
|
||||
private:
|
||||
uint32_t value; //!< The value of the AMF type
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFInteger;
|
||||
//! Sets the integer value
|
||||
/*!
|
||||
\param value The value to set
|
||||
*/
|
||||
void SetIntegerValue(uint32_t value);
|
||||
|
||||
//! Gets the integer value
|
||||
/*!
|
||||
\return The integer value
|
||||
*/
|
||||
uint32_t GetIntegerValue();
|
||||
};
|
||||
|
||||
//! The double value AMF type
|
||||
class AMFDoubleValue : public AMFValue {
|
||||
private:
|
||||
double value; //!< The value of the AMF type
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFDouble;
|
||||
//! Sets the double value
|
||||
/*!
|
||||
\param value The value to set to
|
||||
*/
|
||||
void SetDoubleValue(double value);
|
||||
|
||||
//! Gets the double value
|
||||
/*!
|
||||
\return The double value
|
||||
*/
|
||||
double GetDoubleValue();
|
||||
};
|
||||
|
||||
//! The string value AMF type
|
||||
class AMFStringValue : public AMFValue {
|
||||
private:
|
||||
std::string value; //!< The value of the AMF type
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFString;
|
||||
//! Sets the string value
|
||||
/*!
|
||||
\param value The string value to set to
|
||||
*/
|
||||
void SetStringValue(const std::string& value);
|
||||
|
||||
//! Gets the string value
|
||||
/*!
|
||||
\return The string value
|
||||
*/
|
||||
std::string GetStringValue();
|
||||
};
|
||||
|
||||
//! The XML doc value AMF type
|
||||
class AMFXMLDocValue : public AMFValue {
|
||||
private:
|
||||
std::string xmlData; //!< The value of the AMF type
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFXMLDoc;
|
||||
//! Sets the XML Doc value
|
||||
/*!
|
||||
\param value The value to set to
|
||||
*/
|
||||
void SetXMLDocValue(const std::string& value);
|
||||
|
||||
//! Gets the XML Doc value
|
||||
/*!
|
||||
\return The XML Doc value
|
||||
*/
|
||||
std::string GetXMLDocValue();
|
||||
};
|
||||
|
||||
//! The date value AMF type
|
||||
class AMFDateValue : public AMFValue {
|
||||
private:
|
||||
uint64_t millisecondTimestamp; //!< The time in milliseconds since the ephoch
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFDate;
|
||||
//! Sets the date time
|
||||
/*!
|
||||
\param value The value to set to
|
||||
*/
|
||||
void SetDateValue(uint64_t value);
|
||||
|
||||
//! Gets the date value
|
||||
/*!
|
||||
\return The date value in milliseconds since the epoch
|
||||
*/
|
||||
uint64_t GetDateValue();
|
||||
};
|
||||
|
||||
//! The array value AMF type
|
||||
// This object will manage it's own memory map and list. Do not delete its values.
|
||||
class AMFArrayValue : public AMFValue {
|
||||
private:
|
||||
_AMFArrayMap_ associative; //!< The array map (associative part)
|
||||
_AMFArrayList_ dense; //!< The array list (dense part)
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() override { return ValueType; }
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFArray;
|
||||
|
||||
~AMFArrayValue() override;
|
||||
//! Inserts an item into the array map for a specific key
|
||||
/*!
|
||||
\param key The key to set
|
||||
\param value The value to add
|
||||
*/
|
||||
void InsertValue(const std::string& key, AMFValue* value);
|
||||
|
||||
//! Removes an item for a specific key
|
||||
/*!
|
||||
\param key The key to remove
|
||||
*/
|
||||
void RemoveValue(const std::string& key);
|
||||
|
||||
//! Finds an AMF value
|
||||
/*!
|
||||
\return The AMF value if found, nullptr otherwise
|
||||
*/
|
||||
template <typename T>
|
||||
T* FindValue(const std::string& key) const {
|
||||
_AMFArrayMap_::const_iterator it = this->associative.find(key);
|
||||
if (it != this->associative.end() && T::ValueType == it->second->GetValueType()) {
|
||||
return dynamic_cast<T*>(it->second);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
//! Returns where the associative iterator begins
|
||||
/*!
|
||||
\return Where the array map iterator begins
|
||||
*/
|
||||
_AMFArrayMap_::iterator GetAssociativeIteratorValueBegin();
|
||||
|
||||
//! Returns where the associative iterator ends
|
||||
/*!
|
||||
\return Where the array map iterator ends
|
||||
*/
|
||||
_AMFArrayMap_::iterator GetAssociativeIteratorValueEnd();
|
||||
|
||||
//! Pushes back a value into the array list
|
||||
/*!
|
||||
\param value The value to push back
|
||||
*/
|
||||
void PushBackValue(AMFValue* value);
|
||||
|
||||
//! Pops back the last value in the array list
|
||||
void PopBackValue();
|
||||
|
||||
//! Gets the count of the dense list
|
||||
/*!
|
||||
\return The dense list size
|
||||
*/
|
||||
uint32_t GetDenseValueSize();
|
||||
|
||||
//! Gets a specific value from the list for the specified index
|
||||
/*!
|
||||
\param index The index to get
|
||||
*/
|
||||
template <typename T>
|
||||
T* GetValueAt(uint32_t index) {
|
||||
if (index >= this->dense.size()) return nullptr;
|
||||
AMFValue* foundValue = this->dense.at(index);
|
||||
return T::ValueType == foundValue->GetValueType() ? dynamic_cast<T*>(foundValue) : nullptr;
|
||||
};
|
||||
|
||||
//! Returns where the dense iterator begins
|
||||
/*!
|
||||
\return Where the iterator begins
|
||||
*/
|
||||
_AMFArrayList_::iterator GetDenseIteratorBegin();
|
||||
|
||||
//! Returns where the dense iterator ends
|
||||
/*!
|
||||
\return Where the iterator ends
|
||||
*/
|
||||
_AMFArrayList_::iterator GetDenseIteratorEnd();
|
||||
|
||||
//! Returns the associative map
|
||||
/*!
|
||||
\return The associative map
|
||||
*/
|
||||
_AMFArrayMap_ GetAssociativeMap() { return this->associative; };
|
||||
|
||||
//! Returns the dense array
|
||||
/*!
|
||||
\return The dense array
|
||||
*/
|
||||
_AMFArrayList_ GetDenseArray() { return this->dense; };
|
||||
};
|
||||
|
||||
//! The anonymous object value AMF type
|
||||
class AMFObjectValue : public AMFValue {
|
||||
private:
|
||||
_AMFObjectTraits_ traits; //!< The object traits
|
||||
|
||||
//! Returns the AMF value type
|
||||
/*!
|
||||
\return The AMF value type
|
||||
*/
|
||||
AMFValueType GetValueType() override { return ValueType; }
|
||||
~AMFObjectValue() override;
|
||||
|
||||
public:
|
||||
static const AMFValueType ValueType = AMFObject;
|
||||
//! Constructor
|
||||
/*!
|
||||
\param traits The traits to set
|
||||
*/
|
||||
AMFObjectValue(std::vector<std::pair<std::string, AMFValueType>> traits);
|
||||
|
||||
//! Gets the object value type
|
||||
/*!
|
||||
\return The object value type
|
||||
*/
|
||||
virtual AMFObjectValueType GetObjectValueType() { return AMFObjectAnonymous; }
|
||||
|
||||
//! Sets the value of a trait
|
||||
/*!
|
||||
\param trait The trait to set the value for
|
||||
\param value The AMF value to set
|
||||
*/
|
||||
void SetTraitValue(const std::string& trait, AMFValue* value);
|
||||
|
||||
//! Gets a trait value
|
||||
/*!
|
||||
\param trait The trait to get the value for
|
||||
\return The trait value
|
||||
*/
|
||||
AMFValue* GetTraitValue(const std::string& trait);
|
||||
|
||||
//! Gets the beginning of the object traits iterator
|
||||
/*!
|
||||
\return The AMF trait array iterator begin
|
||||
*/
|
||||
_AMFObjectTraits_::iterator GetTraitsIteratorBegin();
|
||||
|
||||
//! Gets the end of the object traits iterator
|
||||
/*!
|
||||
\return The AMF trait array iterator begin
|
||||
*/
|
||||
_AMFObjectTraits_::iterator GetTraitsIteratorEnd();
|
||||
|
||||
//! Gets the amount of traits
|
||||
/*!
|
||||
\return The amount of traits
|
||||
*/
|
||||
uint32_t GetTraitArrayCount();
|
||||
};
|
||||
@@ -1,259 +0,0 @@
|
||||
#include "AMFFormat_BitStream.h"
|
||||
|
||||
// Writes an AMFValue pointer to a RakNet::BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFValue*>(AMFValue* value) {
|
||||
if (value != nullptr) {
|
||||
AMFValueType type = value->GetValueType();
|
||||
|
||||
switch (type) {
|
||||
case AMFUndefined: {
|
||||
AMFUndefinedValue* v = (AMFUndefinedValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFNull: {
|
||||
AMFNullValue* v = (AMFNullValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFFalse: {
|
||||
AMFFalseValue* v = (AMFFalseValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFTrue: {
|
||||
AMFTrueValue* v = (AMFTrueValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFInteger: {
|
||||
AMFIntegerValue* v = (AMFIntegerValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFDouble: {
|
||||
AMFDoubleValue* v = (AMFDoubleValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFString: {
|
||||
AMFStringValue* v = (AMFStringValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFXMLDoc: {
|
||||
AMFXMLDocValue* v = (AMFXMLDocValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFDate: {
|
||||
AMFDateValue* v = (AMFDateValue*)value;
|
||||
this->Write(*v);
|
||||
break;
|
||||
}
|
||||
|
||||
case AMFArray: {
|
||||
this->Write((AMFArrayValue*)value);
|
||||
break;
|
||||
}
|
||||
case AMFObject:
|
||||
case AMFXML:
|
||||
case AMFByteArray:
|
||||
case AMFVectorInt:
|
||||
case AMFVectorUInt:
|
||||
case AMFVectorDouble:
|
||||
case AMFVectorObject:
|
||||
case AMFDictionary:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A private function to write an value to a RakNet::BitStream
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteUInt29(RakNet::BitStream* bs, uint32_t v) {
|
||||
unsigned char b4 = (unsigned char)v;
|
||||
if (v < 0x00200000) {
|
||||
b4 = b4 & 0x7F;
|
||||
if (v > 0x7F) {
|
||||
unsigned char b3;
|
||||
v = v >> 7;
|
||||
b3 = ((unsigned char)(v)) | 0x80;
|
||||
if (v > 0x7F) {
|
||||
unsigned char b2;
|
||||
v = v >> 7;
|
||||
b2 = ((unsigned char)(v)) | 0x80;
|
||||
bs->Write(b2);
|
||||
}
|
||||
|
||||
bs->Write(b3);
|
||||
}
|
||||
} else {
|
||||
unsigned char b1;
|
||||
unsigned char b2;
|
||||
unsigned char b3;
|
||||
|
||||
v = v >> 8;
|
||||
b3 = ((unsigned char)(v)) | 0x80;
|
||||
v = v >> 7;
|
||||
b2 = ((unsigned char)(v)) | 0x80;
|
||||
v = v >> 7;
|
||||
b1 = ((unsigned char)(v)) | 0x80;
|
||||
|
||||
bs->Write(b1);
|
||||
bs->Write(b2);
|
||||
bs->Write(b3);
|
||||
}
|
||||
|
||||
bs->Write(b4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a flag number to a RakNet::BitStream
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteFlagNumber(RakNet::BitStream* bs, uint32_t v) {
|
||||
v = (v << 1) | 0x01;
|
||||
WriteUInt29(bs, v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an AMFString to a RakNet::BitStream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFString(RakNet::BitStream* bs, const std::string& str) {
|
||||
WriteFlagNumber(bs, (uint32_t)str.size());
|
||||
bs->Write(str.c_str(), (uint32_t)str.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U16 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU16(RakNet::BitStream* bs, uint16_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U32 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU32(RakNet::BitStream* bs, uint32_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U64 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU64(RakNet::BitStream* bs, uint64_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
|
||||
// Writes an AMFUndefinedValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFUndefinedValue>(AMFUndefinedValue value) {
|
||||
this->Write(AMFUndefined);
|
||||
}
|
||||
|
||||
// Writes an AMFNullValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFNullValue>(AMFNullValue value) {
|
||||
this->Write(AMFNull);
|
||||
}
|
||||
|
||||
// Writes an AMFFalseValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFFalseValue>(AMFFalseValue value) {
|
||||
this->Write(AMFFalse);
|
||||
}
|
||||
|
||||
// Writes an AMFTrueValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFTrueValue>(AMFTrueValue value) {
|
||||
this->Write(AMFTrue);
|
||||
}
|
||||
|
||||
// Writes an AMFIntegerValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFIntegerValue>(AMFIntegerValue value) {
|
||||
this->Write(AMFInteger);
|
||||
WriteUInt29(this, value.GetIntegerValue());
|
||||
}
|
||||
|
||||
// Writes an AMFDoubleValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFDoubleValue>(AMFDoubleValue value) {
|
||||
this->Write(AMFDouble);
|
||||
double d = value.GetDoubleValue();
|
||||
WriteAMFU64(this, *((unsigned long long*) & d));
|
||||
}
|
||||
|
||||
// Writes an AMFStringValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFStringValue>(AMFStringValue value) {
|
||||
this->Write(AMFString);
|
||||
std::string v = value.GetStringValue();
|
||||
WriteAMFString(this, v);
|
||||
}
|
||||
|
||||
// Writes an AMFXMLDocValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFXMLDocValue>(AMFXMLDocValue value) {
|
||||
this->Write(AMFXMLDoc);
|
||||
std::string v = value.GetXMLDocValue();
|
||||
WriteAMFString(this, v);
|
||||
}
|
||||
|
||||
// Writes an AMFDateValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFDateValue>(AMFDateValue value) {
|
||||
this->Write(AMFDate);
|
||||
uint64_t date = value.GetDateValue();
|
||||
WriteAMFU64(this, date);
|
||||
}
|
||||
|
||||
// Writes an AMFArrayValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFArrayValue*>(AMFArrayValue* value) {
|
||||
this->Write(AMFArray);
|
||||
uint32_t denseSize = value->GetDenseValueSize();
|
||||
WriteFlagNumber(this, denseSize);
|
||||
|
||||
_AMFArrayMap_::iterator it = value->GetAssociativeIteratorValueBegin();
|
||||
_AMFArrayMap_::iterator end = value->GetAssociativeIteratorValueEnd();
|
||||
|
||||
while (it != end) {
|
||||
WriteAMFString(this, it->first);
|
||||
this->Write(it->second);
|
||||
it++;
|
||||
}
|
||||
|
||||
this->Write(AMFNull);
|
||||
|
||||
if (denseSize > 0) {
|
||||
_AMFArrayList_::iterator it2 = value->GetDenseIteratorBegin();
|
||||
_AMFArrayList_::iterator end2 = value->GetDenseIteratorEnd();
|
||||
|
||||
while (it2 != end2) {
|
||||
this->Write(*it2);
|
||||
it2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Custom Classes
|
||||
#include "AMFFormat.h"
|
||||
|
||||
// RakNet
|
||||
#include <BitStream.h>
|
||||
|
||||
/*!
|
||||
\file AMFFormat_BitStream.h
|
||||
\brief A class that implements native writing of AMF values to RakNet::BitStream
|
||||
*/
|
||||
|
||||
// We are using the RakNet namespace
|
||||
namespace RakNet {
|
||||
//! Writes an AMFValue pointer to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFValue*>(AMFValue* value);
|
||||
|
||||
//! Writes an AMFUndefinedValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFUndefinedValue>(AMFUndefinedValue value);
|
||||
|
||||
//! Writes an AMFNullValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFNullValue>(AMFNullValue value);
|
||||
|
||||
//! Writes an AMFFalseValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFFalseValue>(AMFFalseValue value);
|
||||
|
||||
//! Writes an AMFTrueValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFTrueValue>(AMFTrueValue value);
|
||||
|
||||
//! Writes an AMFIntegerValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFIntegerValue>(AMFIntegerValue value);
|
||||
|
||||
//! Writes an AMFDoubleValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFDoubleValue>(AMFDoubleValue value);
|
||||
|
||||
//! Writes an AMFStringValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFStringValue>(AMFStringValue value);
|
||||
|
||||
//! Writes an AMFXMLDocValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFXMLDocValue>(AMFXMLDocValue value);
|
||||
|
||||
//! Writes an AMFDateValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFDateValue>(AMFDateValue value);
|
||||
|
||||
//! Writes an AMFArrayValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFArrayValue*>(AMFArrayValue* value);
|
||||
} // namespace RakNet
|
||||
367
dCommon/Amf3.h
Normal file
367
dCommon/Amf3.h
Normal file
@@ -0,0 +1,367 @@
|
||||
#ifndef __AMF3__H__
|
||||
#define __AMF3__H__
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "dLogger.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
enum class eAmf : uint8_t {
|
||||
Undefined = 0x00, // An undefined AMF Value
|
||||
Null = 0x01, // A null AMF value
|
||||
False = 0x02, // A false AMF value
|
||||
True = 0x03, // A true AMF value
|
||||
Integer = 0x04, // An integer AMF value
|
||||
Double = 0x05, // A double AMF value
|
||||
String = 0x06, // A string AMF value
|
||||
XMLDoc = 0x07, // Unused in the live client and cannot be serialized without modification. An XML Doc AMF value
|
||||
Date = 0x08, // Unused in the live client and cannot be serialized without modification. A date AMF value
|
||||
Array = 0x09, // An array AMF value
|
||||
Object = 0x0A, // Unused in the live client and cannot be serialized without modification. An object AMF value
|
||||
XML = 0x0B, // Unused in the live client and cannot be serialized without modification. An XML AMF value
|
||||
ByteArray = 0x0C, // Unused in the live client and cannot be serialized without modification. A byte array AMF value
|
||||
VectorInt = 0x0D, // Unused in the live client and cannot be serialized without modification. An integer vector AMF value
|
||||
VectorUInt = 0x0E, // Unused in the live client and cannot be serialized without modification. An unsigned integer AMF value
|
||||
VectorDouble = 0x0F, // Unused in the live client and cannot be serialized without modification. A double vector AMF value
|
||||
VectorObject = 0x10, // Unused in the live client and cannot be serialized without modification. An object vector AMF value
|
||||
Dictionary = 0x11 // Unused in the live client and cannot be serialized without modification. A dictionary AMF value
|
||||
};
|
||||
|
||||
class AMFBaseValue {
|
||||
public:
|
||||
virtual eAmf GetValueType() { return eAmf::Undefined; };
|
||||
AMFBaseValue() {};
|
||||
virtual ~AMFBaseValue() {};
|
||||
};
|
||||
|
||||
template<typename ValueType>
|
||||
class AMFValue : public AMFBaseValue {
|
||||
public:
|
||||
AMFValue() {};
|
||||
AMFValue(ValueType value) { SetValue(value); };
|
||||
virtual ~AMFValue() override {};
|
||||
|
||||
eAmf GetValueType() override { return eAmf::Undefined; };
|
||||
|
||||
const ValueType& GetValue() { return data; };
|
||||
void SetValue(ValueType value) { data = value; };
|
||||
protected:
|
||||
ValueType data;
|
||||
};
|
||||
|
||||
// As a string this is much easier to write and read from a BitStream.
|
||||
template<>
|
||||
class AMFValue<const char*> : public AMFBaseValue {
|
||||
public:
|
||||
AMFValue() {};
|
||||
AMFValue(const char* value) { SetValue(std::string(value)); };
|
||||
virtual ~AMFValue() override {};
|
||||
|
||||
eAmf GetValueType() override { return eAmf::String; };
|
||||
|
||||
const std::string& GetValue() { return data; };
|
||||
void SetValue(std::string value) { data = value; };
|
||||
protected:
|
||||
std::string data;
|
||||
};
|
||||
|
||||
typedef AMFValue<std::nullptr_t> AMFNullValue;
|
||||
typedef AMFValue<bool> AMFBoolValue;
|
||||
typedef AMFValue<int32_t> AMFIntValue;
|
||||
typedef AMFValue<std::string> AMFStringValue;
|
||||
typedef AMFValue<double> AMFDoubleValue;
|
||||
|
||||
template<> inline eAmf AMFValue<std::nullptr_t>::GetValueType() { return eAmf::Null; };
|
||||
template<> inline eAmf AMFValue<bool>::GetValueType() { return this->data ? eAmf::True : eAmf::False; };
|
||||
template<> inline eAmf AMFValue<int32_t>::GetValueType() { return eAmf::Integer; };
|
||||
template<> inline eAmf AMFValue<uint32_t>::GetValueType() { return eAmf::Integer; };
|
||||
template<> inline eAmf AMFValue<std::string>::GetValueType() { return eAmf::String; };
|
||||
template<> inline eAmf AMFValue<double>::GetValueType() { return eAmf::Double; };
|
||||
|
||||
/**
|
||||
* The AMFArrayValue object holds 2 types of lists:
|
||||
* An associative list where a key maps to a value
|
||||
* A Dense list where elements are stored back to back
|
||||
*
|
||||
* Objects that are Registered are owned by this object
|
||||
* and are not to be deleted by a caller.
|
||||
*/
|
||||
class AMFArrayValue : public AMFBaseValue {
|
||||
|
||||
typedef std::unordered_map<std::string, AMFBaseValue*> AMFAssociative;
|
||||
typedef std::vector<AMFBaseValue*> AMFDense;
|
||||
|
||||
public:
|
||||
eAmf GetValueType() override { return eAmf::Array; };
|
||||
|
||||
~AMFArrayValue() override {
|
||||
for (auto valueToDelete : GetDense()) {
|
||||
if (valueToDelete) {
|
||||
delete valueToDelete;
|
||||
valueToDelete = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto valueToDelete : GetAssociative()) {
|
||||
if (valueToDelete.second) {
|
||||
delete valueToDelete.second;
|
||||
valueToDelete.second = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the Associative portion of the object
|
||||
*/
|
||||
inline AMFAssociative& GetAssociative() { return this->associative; };
|
||||
|
||||
/**
|
||||
* Returns the dense portion of the object
|
||||
*/
|
||||
inline AMFDense& GetDense() { return this->dense; };
|
||||
|
||||
/**
|
||||
* Inserts an AMFValue into the associative portion with the given key.
|
||||
* If a duplicate is attempted to be inserted, it is ignored and the
|
||||
* first value with that key is kept in the map.
|
||||
*
|
||||
* These objects are not to be deleted by the caller as they are owned by
|
||||
* the AMFArray object which manages its own memory.
|
||||
*
|
||||
* @param key The key to associate with the value
|
||||
* @param value The value to insert
|
||||
*
|
||||
* @return The inserted element if the type matched,
|
||||
* or nullptr if a key existed and was not the same type
|
||||
*/
|
||||
template<typename ValueType>
|
||||
std::pair<AMFValue<ValueType>*, bool> Insert(const std::string& key, ValueType value) {
|
||||
auto element = associative.find(key);
|
||||
AMFValue<ValueType>* val = nullptr;
|
||||
bool found = true;
|
||||
if (element == associative.end()) {
|
||||
val = new AMFValue<ValueType>(value);
|
||||
associative.insert(std::make_pair(key, val));
|
||||
} else {
|
||||
val = dynamic_cast<AMFValue<ValueType>*>(element->second);
|
||||
found = false;
|
||||
}
|
||||
return std::make_pair(val, found);
|
||||
};
|
||||
|
||||
// Associates an array with a string key
|
||||
std::pair<AMFBaseValue*, bool> Insert(const std::string& key) {
|
||||
auto element = associative.find(key);
|
||||
AMFArrayValue* val = nullptr;
|
||||
bool found = true;
|
||||
if (element == associative.end()) {
|
||||
val = new AMFArrayValue();
|
||||
associative.insert(std::make_pair(key, val));
|
||||
} else {
|
||||
val = dynamic_cast<AMFArrayValue*>(element->second);
|
||||
found = false;
|
||||
}
|
||||
return std::make_pair(val, found);
|
||||
};
|
||||
|
||||
// Associates an array with an integer key
|
||||
std::pair<AMFBaseValue*, bool> Insert(const uint32_t& index) {
|
||||
AMFArrayValue* val = nullptr;
|
||||
bool inserted = false;
|
||||
if (index >= dense.size()) {
|
||||
dense.resize(index + 1);
|
||||
val = new AMFArrayValue();
|
||||
dense.at(index) = val;
|
||||
inserted = true;
|
||||
}
|
||||
return std::make_pair(dynamic_cast<AMFArrayValue*>(dense.at(index)), inserted);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Inserts an AMFValue into the AMFArray key'd by index.
|
||||
* Attempting to insert the same key to the same value twice overwrites
|
||||
* the previous value with the new one.
|
||||
*
|
||||
* @param index The index to associate with the value
|
||||
* @param value The value to insert
|
||||
* @return The inserted element, or nullptr if the type did not match
|
||||
* what was at the index.
|
||||
*/
|
||||
template<typename ValueType>
|
||||
std::pair<AMFValue<ValueType>*, bool> Insert(const uint32_t& index, ValueType value) {
|
||||
AMFValue<ValueType>* val = nullptr;
|
||||
bool inserted = false;
|
||||
if (index >= this->dense.size()) {
|
||||
this->dense.resize(index + 1);
|
||||
val = new AMFValue<ValueType>(value);
|
||||
this->dense.at(index) = val;
|
||||
inserted = true;
|
||||
}
|
||||
return std::make_pair(dynamic_cast<AMFValue<ValueType>*>(this->dense.at(index)), inserted);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inserts an AMFValue into the associative portion with the given key.
|
||||
* If a duplicate is attempted to be inserted, it replaces the original
|
||||
*
|
||||
* The inserted element is now owned by this object and is not to be deleted
|
||||
*
|
||||
* @param key The key to associate with the value
|
||||
* @param value The value to insert
|
||||
*/
|
||||
void Insert(const std::string& key, AMFBaseValue* value) {
|
||||
auto element = associative.find(key);
|
||||
if (element != associative.end() && element->second) {
|
||||
delete element->second;
|
||||
element->second = value;
|
||||
} else {
|
||||
associative.insert(std::make_pair(key, value));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Inserts an AMFValue into the associative portion with the given index.
|
||||
* If a duplicate is attempted to be inserted, it replaces the original
|
||||
*
|
||||
* The inserted element is now owned by this object and is not to be deleted
|
||||
*
|
||||
* @param key The key to associate with the value
|
||||
* @param value The value to insert
|
||||
*/
|
||||
void Insert(const uint32_t index, AMFBaseValue* value) {
|
||||
if (index < dense.size()) {
|
||||
AMFDense::iterator itr = dense.begin() + index;
|
||||
if (*itr) delete dense.at(index);
|
||||
} else {
|
||||
dense.resize(index + 1);
|
||||
}
|
||||
dense.at(index) = value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pushes an AMFValue into the back of the dense portion.
|
||||
*
|
||||
* These objects are not to be deleted by the caller as they are owned by
|
||||
* the AMFArray object which manages its own memory.
|
||||
*
|
||||
* @param value The value to insert
|
||||
*
|
||||
* @return The inserted pointer, or nullptr should the key already be in use.
|
||||
*/
|
||||
template<typename ValueType>
|
||||
inline AMFValue<ValueType>* Push(ValueType value) {
|
||||
return Insert(this->dense.size(), value).first;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the key from the associative portion
|
||||
*
|
||||
* The pointer removed is now no longer managed by this container
|
||||
*
|
||||
* @param key The key to remove from the associative portion
|
||||
*/
|
||||
void Remove(const std::string& key, bool deleteValue = true) {
|
||||
AMFAssociative::iterator it = this->associative.find(key);
|
||||
if (it != this->associative.end()) {
|
||||
if (deleteValue) delete it->second;
|
||||
this->associative.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the last element in the dense portion, deleting it in the process.
|
||||
*/
|
||||
void Remove(const uint32_t index) {
|
||||
if (!this->dense.empty() && index < this->dense.size()) {
|
||||
auto itr = this->dense.begin() + index;
|
||||
if (*itr) delete (*itr);
|
||||
this->dense.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void Pop() {
|
||||
if (!this->dense.empty()) Remove(this->dense.size() - 1);
|
||||
}
|
||||
|
||||
AMFArrayValue* GetArray(const std::string& key) {
|
||||
AMFAssociative::const_iterator it = this->associative.find(key);
|
||||
if (it != this->associative.end()) {
|
||||
return dynamic_cast<AMFArrayValue*>(it->second);
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
AMFArrayValue* GetArray(const uint32_t index) {
|
||||
return index >= this->dense.size() ? nullptr : dynamic_cast<AMFArrayValue*>(this->dense.at(index));
|
||||
};
|
||||
|
||||
inline AMFArrayValue* InsertArray(const std::string& key) {
|
||||
return static_cast<AMFArrayValue*>(Insert(key).first);
|
||||
};
|
||||
|
||||
inline AMFArrayValue* InsertArray(const uint32_t index) {
|
||||
return static_cast<AMFArrayValue*>(Insert(index).first);
|
||||
};
|
||||
|
||||
inline AMFArrayValue* PushArray() {
|
||||
return static_cast<AMFArrayValue*>(Insert(this->dense.size()).first);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an AMFValue by the key from the associative portion and converts it
|
||||
* to the AmfValue template type. If the key did not exist, it is inserted.
|
||||
*
|
||||
* @tparam The target object type
|
||||
* @param key The key to lookup
|
||||
*
|
||||
* @return The AMFValue
|
||||
*/
|
||||
template <typename AmfType>
|
||||
AMFValue<AmfType>* Get(const std::string& key) const {
|
||||
AMFAssociative::const_iterator it = this->associative.find(key);
|
||||
return it != this->associative.end() ?
|
||||
dynamic_cast<AMFValue<AmfType>*>(it->second) :
|
||||
nullptr;
|
||||
};
|
||||
|
||||
// Get from the array but dont cast it
|
||||
AMFBaseValue* Get(const std::string& key) const {
|
||||
AMFAssociative::const_iterator it = this->associative.find(key);
|
||||
return it != this->associative.end() ? it->second : nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get an AMFValue object at a position in the dense portion.
|
||||
* Gets an AMFValue by the index from the dense portion and converts it
|
||||
* to the AmfValue template type. If the index did not exist, it is inserted.
|
||||
*
|
||||
* @tparam The target object type
|
||||
* @param index The index to get
|
||||
* @return The casted object, or nullptr.
|
||||
*/
|
||||
template <typename AmfType>
|
||||
AMFValue<AmfType>* Get(uint32_t index) const {
|
||||
return index < this->dense.size() ?
|
||||
dynamic_cast<AMFValue<AmfType>*>(this->dense.at(index)) :
|
||||
nullptr;
|
||||
};
|
||||
|
||||
// Get from the dense but dont cast it
|
||||
AMFBaseValue* Get(const uint32_t index) const {
|
||||
return index < this->dense.size() ? this->dense.at(index) : nullptr;
|
||||
};
|
||||
private:
|
||||
/**
|
||||
* The associative portion. These values are key'd with strings to an AMFValue.
|
||||
*/
|
||||
AMFAssociative associative;
|
||||
|
||||
/**
|
||||
* The dense portion. These AMFValue's are stored one after
|
||||
* another with the most recent addition being at the back.
|
||||
*/
|
||||
AMFDense dense;
|
||||
};
|
||||
|
||||
#endif //!__AMF3__H__
|
||||
184
dCommon/AmfSerialize.cpp
Normal file
184
dCommon/AmfSerialize.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#include "AmfSerialize.h"
|
||||
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
|
||||
// Writes an AMFValue pointer to a RakNet::BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFBaseValue&>(AMFBaseValue& value) {
|
||||
eAmf type = value.GetValueType();
|
||||
this->Write(type);
|
||||
switch (type) {
|
||||
case eAmf::Integer: {
|
||||
this->Write<AMFIntValue&>(*static_cast<AMFIntValue*>(&value));
|
||||
break;
|
||||
}
|
||||
|
||||
case eAmf::Double: {
|
||||
this->Write<AMFDoubleValue&>(*static_cast<AMFDoubleValue*>(&value));
|
||||
break;
|
||||
}
|
||||
|
||||
case eAmf::String: {
|
||||
this->Write<AMFStringValue&>(*static_cast<AMFStringValue*>(&value));
|
||||
break;
|
||||
}
|
||||
|
||||
case eAmf::Array: {
|
||||
this->Write<AMFArrayValue&>(*static_cast<AMFArrayValue*>(&value));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Game::logger->Log("AmfSerialize", "Encountered unwritable AMFType %i!", type);
|
||||
}
|
||||
case eAmf::Undefined:
|
||||
case eAmf::Null:
|
||||
case eAmf::False:
|
||||
case eAmf::True:
|
||||
case eAmf::Date:
|
||||
case eAmf::Object:
|
||||
case eAmf::XML:
|
||||
case eAmf::XMLDoc:
|
||||
case eAmf::ByteArray:
|
||||
case eAmf::VectorInt:
|
||||
case eAmf::VectorUInt:
|
||||
case eAmf::VectorDouble:
|
||||
case eAmf::VectorObject:
|
||||
case eAmf::Dictionary:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A private function to write an value to a RakNet::BitStream
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteUInt29(RakNet::BitStream* bs, uint32_t v) {
|
||||
unsigned char b4 = (unsigned char)v;
|
||||
if (v < 0x00200000) {
|
||||
b4 = b4 & 0x7F;
|
||||
if (v > 0x7F) {
|
||||
unsigned char b3;
|
||||
v = v >> 7;
|
||||
b3 = ((unsigned char)(v)) | 0x80;
|
||||
if (v > 0x7F) {
|
||||
unsigned char b2;
|
||||
v = v >> 7;
|
||||
b2 = ((unsigned char)(v)) | 0x80;
|
||||
bs->Write(b2);
|
||||
}
|
||||
|
||||
bs->Write(b3);
|
||||
}
|
||||
} else {
|
||||
unsigned char b1;
|
||||
unsigned char b2;
|
||||
unsigned char b3;
|
||||
|
||||
v = v >> 8;
|
||||
b3 = ((unsigned char)(v)) | 0x80;
|
||||
v = v >> 7;
|
||||
b2 = ((unsigned char)(v)) | 0x80;
|
||||
v = v >> 7;
|
||||
b1 = ((unsigned char)(v)) | 0x80;
|
||||
|
||||
bs->Write(b1);
|
||||
bs->Write(b2);
|
||||
bs->Write(b3);
|
||||
}
|
||||
|
||||
bs->Write(b4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a flag number to a RakNet::BitStream
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteFlagNumber(RakNet::BitStream* bs, uint32_t v) {
|
||||
v = (v << 1) | 0x01;
|
||||
WriteUInt29(bs, v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an AMFString to a RakNet::BitStream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFString(RakNet::BitStream* bs, const std::string& str) {
|
||||
WriteFlagNumber(bs, (uint32_t)str.size());
|
||||
bs->Write(str.c_str(), (uint32_t)str.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U16 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU16(RakNet::BitStream* bs, uint16_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U32 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU32(RakNet::BitStream* bs, uint32_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an U64 to a bitstream
|
||||
*
|
||||
* RakNet writes in the correct byte order - do not reverse this.
|
||||
*/
|
||||
void WriteAMFU64(RakNet::BitStream* bs, uint64_t value) {
|
||||
bs->Write(value);
|
||||
}
|
||||
|
||||
// Writes an AMFIntegerValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFIntValue&>(AMFIntValue& value) {
|
||||
WriteUInt29(this, value.GetValue());
|
||||
}
|
||||
|
||||
// Writes an AMFDoubleValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFDoubleValue&>(AMFDoubleValue& value) {
|
||||
double d = value.GetValue();
|
||||
WriteAMFU64(this, *reinterpret_cast<uint64_t*>(&d));
|
||||
}
|
||||
|
||||
// Writes an AMFStringValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFStringValue&>(AMFStringValue& value) {
|
||||
WriteAMFString(this, value.GetValue());
|
||||
}
|
||||
|
||||
// Writes an AMFArrayValue to BitStream
|
||||
template<>
|
||||
void RakNet::BitStream::Write<AMFArrayValue&>(AMFArrayValue& value) {
|
||||
uint32_t denseSize = value.GetDense().size();
|
||||
WriteFlagNumber(this, denseSize);
|
||||
|
||||
auto it = value.GetAssociative().begin();
|
||||
auto end = value.GetAssociative().end();
|
||||
|
||||
while (it != end) {
|
||||
WriteAMFString(this, it->first);
|
||||
this->Write<AMFBaseValue&>(*it->second);
|
||||
it++;
|
||||
}
|
||||
|
||||
this->Write(eAmf::Null);
|
||||
|
||||
if (denseSize > 0) {
|
||||
auto it2 = value.GetDense().begin();
|
||||
auto end2 = value.GetDense().end();
|
||||
|
||||
while (it2 != end2) {
|
||||
this->Write<AMFBaseValue&>(**it2);
|
||||
it2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
dCommon/AmfSerialize.h
Normal file
50
dCommon/AmfSerialize.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
// Custom Classes
|
||||
#include "Amf3.h"
|
||||
|
||||
// RakNet
|
||||
#include <BitStream.h>
|
||||
|
||||
/*!
|
||||
\file AmfSerialize.h
|
||||
\brief A class that implements native writing of AMF values to RakNet::BitStream
|
||||
*/
|
||||
|
||||
// We are using the RakNet namespace
|
||||
namespace RakNet {
|
||||
//! Writes an AMFValue pointer to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFBaseValue&>(AMFBaseValue& value);
|
||||
|
||||
//! Writes an AMFIntegerValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFIntValue&>(AMFIntValue& value);
|
||||
|
||||
//! Writes an AMFDoubleValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFDoubleValue&>(AMFDoubleValue& value);
|
||||
|
||||
//! Writes an AMFStringValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFStringValue&>(AMFStringValue& value);
|
||||
|
||||
//! Writes an AMFArrayValue to a RakNet::BitStream
|
||||
/*!
|
||||
\param value The value to write
|
||||
*/
|
||||
template <>
|
||||
void RakNet::BitStream::Write<AMFArrayValue&>(AMFArrayValue& value);
|
||||
} // namespace RakNet
|
||||
@@ -1,6 +1,6 @@
|
||||
set(DCOMMON_SOURCES "AMFFormat.cpp"
|
||||
set(DCOMMON_SOURCES
|
||||
"AMFDeserialize.cpp"
|
||||
"AMFFormat_BitStream.cpp"
|
||||
"AmfSerialize.cpp"
|
||||
"BinaryIO.cpp"
|
||||
"dConfig.cpp"
|
||||
"Diagnostics.cpp"
|
||||
|
||||
12
dCommon/DluAssert.h
Normal file
12
dCommon/DluAssert.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __DLUASSERT__H__
|
||||
#define __DLUASSERT__H__
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define DluAssert(expression) assert(expression)
|
||||
#else
|
||||
# define DluAssert(expression)
|
||||
#endif
|
||||
|
||||
#endif //!__DLUASSERT__H__
|
||||
@@ -10,6 +10,8 @@ class dConfig;
|
||||
class RakPeerInterface;
|
||||
class AssetManager;
|
||||
struct SystemAddress;
|
||||
class EntityManager;
|
||||
class dZoneManager;
|
||||
|
||||
namespace Game {
|
||||
extern dLogger* logger;
|
||||
@@ -22,4 +24,6 @@ namespace Game {
|
||||
extern AssetManager* assetManager;
|
||||
extern SystemAddress chatSysAddr;
|
||||
extern bool shouldShutdown;
|
||||
extern EntityManager* entityManager;
|
||||
extern dZoneManager* zoneManager;
|
||||
}
|
||||
|
||||
@@ -111,29 +111,6 @@ namespace GeneralUtils {
|
||||
*/
|
||||
bool CheckBit(int64_t value, uint32_t index);
|
||||
|
||||
// MARK: Random Number Generation
|
||||
|
||||
//! Generates a random number
|
||||
/*!
|
||||
\param min The minimum the generate from
|
||||
\param max The maximum to generate to
|
||||
*/
|
||||
template <typename T>
|
||||
inline T GenerateRandomNumber(std::size_t min, std::size_t max) {
|
||||
// Make sure it is a numeric type
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
|
||||
if constexpr (std::is_integral_v<T>) { // constexpr only necessary on first statement
|
||||
std::uniform_int_distribution<T> distribution(min, max);
|
||||
return distribution(Game::randomEngine);
|
||||
} else if (std::is_floating_point_v<T>) {
|
||||
std::uniform_real_distribution<T> distribution(min, max);
|
||||
return distribution(Game::randomEngine);
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
bool ReplaceInString(std::string& str, const std::string& from, const std::string& to);
|
||||
|
||||
std::u16string ReadWString(RakNet::BitStream* inStream);
|
||||
@@ -223,4 +200,42 @@ namespace GeneralUtils {
|
||||
std::hash<T> h;
|
||||
s ^= h(v) + 0x9e3779b9 + (s << 6) + (s >> 2);
|
||||
}
|
||||
|
||||
// MARK: Random Number Generation
|
||||
|
||||
//! Generates a random number
|
||||
/*!
|
||||
\param min The minimum the generate from
|
||||
\param max The maximum to generate to
|
||||
*/
|
||||
template <typename T>
|
||||
inline T GenerateRandomNumber(std::size_t min, std::size_t max) {
|
||||
// Make sure it is a numeric type
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
|
||||
if constexpr (std::is_integral_v<T>) { // constexpr only necessary on first statement
|
||||
std::uniform_int_distribution<T> distribution(min, max);
|
||||
return distribution(Game::randomEngine);
|
||||
} else if (std::is_floating_point_v<T>) {
|
||||
std::uniform_real_distribution<T> distribution(min, max);
|
||||
return distribution(Game::randomEngine);
|
||||
}
|
||||
|
||||
return T();
|
||||
}
|
||||
|
||||
// on Windows we need to undef these or else they conflict with our numeric limits calls
|
||||
// DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS DEVELOPERS
|
||||
#ifdef _WIN32
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline T GenerateRandomNumber() {
|
||||
// Make sure it is a numeric type
|
||||
static_assert(std::is_arithmetic<T>::value, "Not an arithmetic type");
|
||||
|
||||
return GenerateRandomNumber<T>(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +129,13 @@ NiPoint3 NiPoint3::operator+(const NiPoint3& point) const {
|
||||
}
|
||||
|
||||
//! Operator for addition of vectors
|
||||
NiPoint3 NiPoint3::operator+=(const NiPoint3& point) const {
|
||||
return NiPoint3(this->x + point.x, this->y + point.y, this->z + point.z);
|
||||
NiPoint3& NiPoint3::operator+=(const NiPoint3& point) {
|
||||
this->x += point.x;
|
||||
this->y += point.y;
|
||||
this->z += point.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//! Operator for subtraction of vectors
|
||||
NiPoint3 NiPoint3::operator-(const NiPoint3& point) const {
|
||||
return NiPoint3(this->x - point.x, this->y - point.y, this->z - point.z);
|
||||
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
NiPoint3 operator+(const NiPoint3& point) const;
|
||||
|
||||
//! Operator for addition of vectors
|
||||
NiPoint3 operator+=(const NiPoint3& point) const;
|
||||
NiPoint3& operator+=(const NiPoint3& point);
|
||||
|
||||
//! Operator for subtraction of vectors
|
||||
NiPoint3 operator-(const NiPoint3& point) const;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "BitStream.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eClientMessageType.h"
|
||||
#include "BitstreamUtils.h"
|
||||
|
||||
#pragma warning (disable:4251) //Disables SQL warnings
|
||||
|
||||
@@ -28,9 +29,11 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate);
|
||||
|
||||
//========== MACROS ===========
|
||||
|
||||
#define HEADER_SIZE 8
|
||||
#define CBITSTREAM RakNet::BitStream bitStream;
|
||||
#define CINSTREAM RakNet::BitStream inStream(packet->data, packet->length, false);
|
||||
#define CMSGHEADER PacketUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
#define CINSTREAM_SKIP_HEADER CINSTREAM if (inStream.GetNumberOfUnreadBits() >= BYTES_TO_BITS(HEADER_SIZE)) inStream.IgnoreBytes(HEADER_SIZE); else inStream.IgnoreBits(inStream.GetNumberOfUnreadBits());
|
||||
#define CMSGHEADER BitstreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
#define SEND_PACKET Game::server->Send(&bitStream, sysAddr, false);
|
||||
#define SEND_PACKET_BROADCAST Game::server->Send(&bitStream, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -107,7 +107,7 @@ enum class eReplicaComponentType : uint32_t {
|
||||
DONATION_VENDOR,
|
||||
COMBAT_MEDIATOR,
|
||||
COMMENDATION_VENDOR,
|
||||
UNKNOWN_103,
|
||||
GATE_RUSH_CONTROL,
|
||||
RAIL_ACTIVATOR,
|
||||
ROLLER,
|
||||
PLAYER_FORCED_MOVEMENT,
|
||||
@@ -119,7 +119,7 @@ enum class eReplicaComponentType : uint32_t {
|
||||
UNKNOWN_112,
|
||||
PROPERTY_PLAQUE,
|
||||
BUILD_BORDER,
|
||||
UNKOWN_115,
|
||||
UNKNOWN_115,
|
||||
CULLING_PLANE,
|
||||
DESTROYABLE = 1000 // Actually 7
|
||||
};
|
||||
|
||||
48
dCommon/dEnums/eStamps.h
Normal file
48
dCommon/dEnums/eStamps.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef __ESTAMPS__H__
|
||||
#define __ESTAMPS__H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum class eStamps : uint32_t {
|
||||
PASSPORT_AUTH_START,
|
||||
PASSPORT_AUTH_BYPASS,
|
||||
PASSPORT_AUTH_ERROR,
|
||||
PASSPORT_AUTH_DB_SELECT_START,
|
||||
PASSPORT_AUTH_DB_SELECT_FINISH,
|
||||
PASSPORT_AUTH_DB_INSERT_START,
|
||||
PASSPORT_AUTH_DB_INSERT_FINISH,
|
||||
PASSPORT_AUTH_LEGOINT_COMMUNICATION_START,
|
||||
PASSPORT_AUTH_LEGOINT_RECEIVED,
|
||||
PASSPORT_AUTH_LEGOINT_THREAD_SPAWN,
|
||||
PASSPORT_AUTH_LEGOINT_WEBSERVICE_START,
|
||||
PASSPORT_AUTH_LEGOINT_WEBSERVICE_FINISH,
|
||||
PASSPORT_AUTH_LEGOINT_LEGOCLUB_START,
|
||||
PASSPORT_AUTH_LEGOINT_LEGOCLUB_FINISH,
|
||||
PASSPORT_AUTH_LEGOINT_THREAD_FINISH,
|
||||
PASSPORT_AUTH_LEGOINT_REPLY,
|
||||
PASSPORT_AUTH_LEGOINT_ERROR,
|
||||
PASSPORT_AUTH_LEGOINT_COMMUNICATION_END,
|
||||
PASSPORT_AUTH_LEGOINT_DISCONNECT,
|
||||
PASSPORT_AUTH_WORLD_COMMUNICATION_START,
|
||||
PASSPORT_AUTH_CLIENT_OS,
|
||||
PASSPORT_AUTH_WORLD_PACKET_RECEIVED,
|
||||
PASSPORT_AUTH_IM_COMMUNICATION_START,
|
||||
PASSPORT_AUTH_IM_LOGIN_START,
|
||||
PASSPORT_AUTH_IM_LOGIN_ALREADY_LOGGED_IN,
|
||||
PASSPORT_AUTH_IM_OTHER_LOGIN_REMOVED,
|
||||
PASSPORT_AUTH_IM_LOGIN_QUEUED,
|
||||
PASSPORT_AUTH_IM_LOGIN_RESPONSE,
|
||||
PASSPORT_AUTH_IM_COMMUNICATION_END,
|
||||
PASSPORT_AUTH_WORLD_SESSION_CONFIRM_TO_AUTH,
|
||||
PASSPORT_AUTH_WORLD_COMMUNICATION_FINISH,
|
||||
PASSPORT_AUTH_WORLD_DISCONNECT,
|
||||
NO_LEGO_INTERFACE,
|
||||
DB_ERROR,
|
||||
GM_REQUIRED,
|
||||
NO_LEGO_WEBSERVICE_XML,
|
||||
LEGO_WEBSERVICE_TIMEOUT,
|
||||
LEGO_WEBSERVICE_ERROR,
|
||||
NO_WORLD_SERVER
|
||||
};
|
||||
|
||||
#endif //!__ESTAMPS__H__
|
||||
@@ -16,9 +16,6 @@
|
||||
// Enable this to cache all entries in each table for fast access, comes with more memory cost
|
||||
//#define CDCLIENT_CACHE_ALL
|
||||
|
||||
// Enable this to skip some unused columns in some tables
|
||||
#define UNUSED(v)
|
||||
|
||||
/*!
|
||||
\file CDClientDatabase.hpp
|
||||
\brief An interface between the CDClient.sqlite file and the server
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
CDClientManager::CDClientManager() {
|
||||
CDActivityRewardsTable::Instance();
|
||||
UNUSED(CDAnimationsTable::Instance());
|
||||
CDAnimationsTable::Instance();
|
||||
CDBehaviorParameterTable::Instance();
|
||||
CDBehaviorTemplateTable::Instance();
|
||||
CDComponentsRegistryTable::Instance();
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "Singleton.h"
|
||||
|
||||
#define UNUSED_TABLE(v)
|
||||
|
||||
/**
|
||||
* Initialize the CDClient tables so they are all loaded into memory.
|
||||
*/
|
||||
|
||||
@@ -1,56 +1,83 @@
|
||||
#include "CDAnimationsTable.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "Game.h"
|
||||
|
||||
CDAnimationsTable::CDAnimationsTable(void) {
|
||||
bool CDAnimationsTable::CacheData(CppSQLite3Statement& queryToCache) {
|
||||
auto tableData = queryToCache.execQuery();
|
||||
// If we received a bad lookup, cache it anyways so we do not run the query again.
|
||||
if (tableData.eof()) return false;
|
||||
|
||||
// First, get the size of the table
|
||||
unsigned int size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Animations");
|
||||
while (!tableSize.eof()) {
|
||||
size = tableSize.getIntField(0, 0);
|
||||
do {
|
||||
std::string animation_type = tableData.getStringField("animation_type", "");
|
||||
DluAssert(!animation_type.empty());
|
||||
AnimationGroupID animationGroupID = tableData.getIntField("animationGroupID", -1);
|
||||
DluAssert(animationGroupID != -1);
|
||||
|
||||
tableSize.nextRow();
|
||||
}
|
||||
|
||||
tableSize.finalize();
|
||||
|
||||
// Reserve the size
|
||||
this->entries.reserve(size);
|
||||
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Animations");
|
||||
while (!tableData.eof()) {
|
||||
CDAnimations entry;
|
||||
entry.animationGroupID = tableData.getIntField("animationGroupID", -1);
|
||||
entry.animation_type = tableData.getStringField("animation_type", "");
|
||||
CDAnimation entry;
|
||||
entry.animation_name = tableData.getStringField("animation_name", "");
|
||||
entry.chance_to_play = tableData.getFloatField("chance_to_play", -1.0f);
|
||||
entry.min_loops = tableData.getIntField("min_loops", -1);
|
||||
entry.max_loops = tableData.getIntField("max_loops", -1);
|
||||
entry.animation_length = tableData.getFloatField("animation_length", -1.0f);
|
||||
entry.hideEquip = tableData.getIntField("hideEquip", -1) == 1 ? true : false;
|
||||
entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", -1) == 1 ? true : false;
|
||||
entry.restartable = tableData.getIntField("restartable", -1) == 1 ? true : false;
|
||||
entry.face_animation_name = tableData.getStringField("face_animation_name", "");
|
||||
entry.priority = tableData.getFloatField("priority", -1.0f);
|
||||
entry.blendTime = tableData.getFloatField("blendTime", -1.0f);
|
||||
entry.chance_to_play = tableData.getFloatField("chance_to_play", 1.0f);
|
||||
UNUSED_COLUMN(entry.min_loops = tableData.getIntField("min_loops", 0);)
|
||||
UNUSED_COLUMN(entry.max_loops = tableData.getIntField("max_loops", 0);)
|
||||
entry.animation_length = tableData.getFloatField("animation_length", 0.0f);
|
||||
UNUSED_COLUMN(entry.hideEquip = tableData.getIntField("hideEquip", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.restartable = tableData.getIntField("restartable", 0) == 1;)
|
||||
UNUSED_COLUMN(entry.face_animation_name = tableData.getStringField("face_animation_name", "");)
|
||||
UNUSED_COLUMN(entry.priority = tableData.getFloatField("priority", 0.0f);)
|
||||
UNUSED_COLUMN(entry.blendTime = tableData.getFloatField("blendTime", 0.0f);)
|
||||
|
||||
this->entries.push_back(entry);
|
||||
this->animations[CDAnimationKey(animation_type, animationGroupID)].push_back(entry);
|
||||
tableData.nextRow();
|
||||
}
|
||||
} while (!tableData.eof());
|
||||
|
||||
tableData.finalize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<CDAnimations> CDAnimationsTable::Query(std::function<bool(CDAnimations)> predicate) {
|
||||
|
||||
std::vector<CDAnimations> data = cpplinq::from(this->entries)
|
||||
>> cpplinq::where(predicate)
|
||||
>> cpplinq::to_vector();
|
||||
|
||||
return data;
|
||||
void CDAnimationsTable::CacheAnimations(const CDAnimationKey animationKey) {
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Animations WHERE animationGroupID = ? and animation_type = ?");
|
||||
query.bind(1, static_cast<int32_t>(animationKey.second));
|
||||
query.bind(2, animationKey.first.c_str());
|
||||
// If we received a bad lookup, cache it anyways so we do not run the query again.
|
||||
if (!CacheData(query)) {
|
||||
this->animations[animationKey];
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CDAnimations> CDAnimationsTable::GetEntries(void) const {
|
||||
return this->entries;
|
||||
void CDAnimationsTable::CacheAnimationGroup(AnimationGroupID animationGroupID) {
|
||||
auto animationEntryCached = this->animations.find(CDAnimationKey("", animationGroupID));
|
||||
if (animationEntryCached != this->animations.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Animations WHERE animationGroupID = ?");
|
||||
query.bind(1, static_cast<int32_t>(animationGroupID));
|
||||
|
||||
// Cache the query so we don't run the query again.
|
||||
CacheData(query);
|
||||
this->animations[CDAnimationKey("", animationGroupID)];
|
||||
}
|
||||
|
||||
CDAnimationLookupResult CDAnimationsTable::GetAnimation(const AnimationID& animationType, const std::string& previousAnimationName, const AnimationGroupID animationGroupID) {
|
||||
CDAnimationKey animationKey(animationType, animationGroupID);
|
||||
auto animationEntryCached = this->animations.find(animationKey);
|
||||
if (animationEntryCached == this->animations.end()) {
|
||||
this->CacheAnimations(animationKey);
|
||||
}
|
||||
|
||||
auto animationEntry = this->animations.find(animationKey);
|
||||
// If we have only one animation, return it regardless of the chance to play.
|
||||
if (animationEntry->second.size() == 1) {
|
||||
return CDAnimationLookupResult(animationEntry->second.front());
|
||||
}
|
||||
auto randomAnimation = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
|
||||
for (auto& animationEntry : animationEntry->second) {
|
||||
randomAnimation -= animationEntry.chance_to_play;
|
||||
// This is how the client gets the random animation.
|
||||
if (animationEntry.animation_name != previousAnimationName && randomAnimation <= 0.0f) return CDAnimationLookupResult(animationEntry);
|
||||
}
|
||||
|
||||
return CDAnimationLookupResult();
|
||||
}
|
||||
|
||||
@@ -1,33 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
// Custom Classes
|
||||
#include "CDTable.h"
|
||||
#include <list>
|
||||
|
||||
struct CDAnimations {
|
||||
unsigned int animationGroupID; //!< The animation group ID
|
||||
std::string animation_type; //!< The animation type
|
||||
struct CDAnimation {
|
||||
// unsigned int animationGroupID;
|
||||
// std::string animation_type;
|
||||
// The above two are a pair to represent a primary key in the map.
|
||||
std::string animation_name; //!< The animation name
|
||||
float chance_to_play; //!< The chance to play the animation
|
||||
unsigned int min_loops; //!< The minimum number of loops
|
||||
unsigned int max_loops; //!< The maximum number of loops
|
||||
UNUSED_COLUMN(unsigned int min_loops;) //!< The minimum number of loops
|
||||
UNUSED_COLUMN(unsigned int max_loops;) //!< The maximum number of loops
|
||||
float animation_length; //!< The animation length
|
||||
bool hideEquip; //!< Whether or not to hide the equip
|
||||
bool ignoreUpperBody; //!< Whether or not to ignore the upper body
|
||||
bool restartable; //!< Whether or not the animation is restartable
|
||||
std::string face_animation_name; //!< The face animation name
|
||||
float priority; //!< The priority
|
||||
float blendTime; //!< The blend time
|
||||
UNUSED_COLUMN(bool hideEquip;) //!< Whether or not to hide the equip
|
||||
UNUSED_COLUMN(bool ignoreUpperBody;) //!< Whether or not to ignore the upper body
|
||||
UNUSED_COLUMN(bool restartable;) //!< Whether or not the animation is restartable
|
||||
UNUSED_COLUMN(std::string face_animation_name;) //!< The face animation name
|
||||
UNUSED_COLUMN(float priority;) //!< The priority
|
||||
UNUSED_COLUMN(float blendTime;) //!< The blend time
|
||||
};
|
||||
|
||||
typedef LookupResult<CDAnimation> CDAnimationLookupResult;
|
||||
|
||||
class CDAnimationsTable : public CDTable<CDAnimationsTable> {
|
||||
private:
|
||||
std::vector<CDAnimations> entries;
|
||||
|
||||
typedef int32_t AnimationGroupID;
|
||||
typedef std::string AnimationID;
|
||||
typedef std::pair<std::string, AnimationGroupID> CDAnimationKey;
|
||||
public:
|
||||
CDAnimationsTable();
|
||||
// Queries the table with a custom "where" clause
|
||||
std::vector<CDAnimations> Query(std::function<bool(CDAnimations)> predicate);
|
||||
/**
|
||||
* Given an animationType and the previousAnimationName played, return the next animationType to play.
|
||||
* If there are more than 1 animationTypes that can be played, one is selected at random but also does not allow
|
||||
* the previousAnimationName to be played twice.
|
||||
*
|
||||
* @param animationType The animationID to lookup
|
||||
* @param previousAnimationName The previously played animation
|
||||
* @param animationGroupID The animationGroupID to lookup
|
||||
* @return CDAnimationLookupResult
|
||||
*/
|
||||
[[nodiscard]] CDAnimationLookupResult GetAnimation(const AnimationID& animationType, const std::string& previousAnimationName, const AnimationGroupID animationGroupID);
|
||||
|
||||
std::vector<CDAnimations> GetEntries(void) const;
|
||||
/**
|
||||
* Cache a full AnimationGroup by its ID.
|
||||
*/
|
||||
void CacheAnimationGroup(AnimationGroupID animationGroupID);
|
||||
private:
|
||||
|
||||
/**
|
||||
* Cache all animations given a premade key
|
||||
*/
|
||||
void CacheAnimations(const CDAnimationKey animationKey);
|
||||
|
||||
/**
|
||||
* Run the query responsible for caching the data.
|
||||
* @param queryToCache
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool CacheData(CppSQLite3Statement& queryToCache);
|
||||
|
||||
/**
|
||||
* Each animation is key'd by its animationName and its animationGroupID. Each
|
||||
* animation has a possible list of animations. This is because there can be animations have a percent chance to play so one is selected at random.
|
||||
*/
|
||||
std::map<CDAnimationKey, std::list<CDAnimation>> animations;
|
||||
};
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
#include "CDBehaviorParameterTable.h"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
|
||||
uint64_t GetHash(const uint32_t behaviorID, const uint32_t parameterID) {
|
||||
uint64_t hash = behaviorID;
|
||||
hash <<= 31U;
|
||||
hash |= parameterID;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
CDBehaviorParameterTable::CDBehaviorParameterTable() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter");
|
||||
uint32_t uniqueParameterId = 0;
|
||||
uint64_t hash = 0;
|
||||
while (!tableData.eof()) {
|
||||
CDBehaviorParameter entry;
|
||||
entry.behaviorID = tableData.getIntField("behaviorID", -1);
|
||||
uint32_t behaviorID = tableData.getIntField("behaviorID", -1);
|
||||
auto candidateStringToAdd = std::string(tableData.getStringField("parameterID", ""));
|
||||
auto parameter = m_ParametersList.find(candidateStringToAdd);
|
||||
uint32_t parameterId;
|
||||
if (parameter != m_ParametersList.end()) {
|
||||
entry.parameterID = parameter;
|
||||
parameterId = parameter->second;
|
||||
} else {
|
||||
entry.parameterID = m_ParametersList.insert(std::make_pair(candidateStringToAdd, uniqueParameterId)).first;
|
||||
uniqueParameterId++;
|
||||
parameterId = m_ParametersList.insert(std::make_pair(candidateStringToAdd, m_ParametersList.size())).first->second;
|
||||
}
|
||||
hash = entry.behaviorID;
|
||||
hash = (hash << 31U) | entry.parameterID->second;
|
||||
entry.value = tableData.getFloatField("value", -1.0f);
|
||||
uint64_t hash = GetHash(behaviorID, parameterId);
|
||||
float value = tableData.getFloatField("value", -1.0f);
|
||||
|
||||
m_Entries.insert(std::make_pair(hash, entry));
|
||||
m_Entries.insert(std::make_pair(hash, value));
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
@@ -30,27 +34,22 @@ CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
|
||||
float CDBehaviorParameterTable::GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue) {
|
||||
auto parameterID = this->m_ParametersList.find(name);
|
||||
if (parameterID == this->m_ParametersList.end()) return defaultValue;
|
||||
|
||||
uint64_t hash = behaviorID;
|
||||
|
||||
hash = (hash << 31U) | parameterID->second;
|
||||
auto hash = GetHash(behaviorID, parameterID->second);
|
||||
|
||||
// Search for specific parameter
|
||||
const auto& it = m_Entries.find(hash);
|
||||
return it != m_Entries.end() ? it->second.value : defaultValue;
|
||||
auto it = m_Entries.find(hash);
|
||||
return it != m_Entries.end() ? it->second : defaultValue;
|
||||
}
|
||||
|
||||
std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID(uint32_t behaviorID) {
|
||||
uint64_t hashBase = behaviorID;
|
||||
std::map<std::string, float> returnInfo;
|
||||
uint64_t hash;
|
||||
for (auto& parameterCandidate : m_ParametersList) {
|
||||
hash = (hashBase << 31U) | parameterCandidate.second;
|
||||
for (auto& [parameterString, parameterId] : m_ParametersList) {
|
||||
uint64_t hash = GetHash(hashBase, parameterId);
|
||||
auto infoCandidate = m_Entries.find(hash);
|
||||
if (infoCandidate != m_Entries.end()) {
|
||||
returnInfo.insert(std::make_pair(infoCandidate->second.parameterID->first, infoCandidate->second.value));
|
||||
returnInfo.insert(std::make_pair(parameterString, infoCandidate->second));
|
||||
}
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,18 +5,15 @@
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
struct CDBehaviorParameter {
|
||||
unsigned int behaviorID; //!< The Behavior ID
|
||||
std::unordered_map<std::string, uint32_t>::iterator parameterID; //!< The Parameter ID
|
||||
float value; //!< The value of the behavior template
|
||||
};
|
||||
|
||||
class CDBehaviorParameterTable : public CDTable<CDBehaviorParameterTable> {
|
||||
private:
|
||||
std::unordered_map<uint64_t, CDBehaviorParameter> m_Entries;
|
||||
typedef uint64_t BehaviorParameterHash;
|
||||
typedef float BehaviorParameterValue;
|
||||
std::unordered_map<BehaviorParameterHash, BehaviorParameterValue> m_Entries;
|
||||
std::unordered_map<std::string, uint32_t> m_ParametersList;
|
||||
public:
|
||||
CDBehaviorParameterTable();
|
||||
|
||||
float GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0);
|
||||
|
||||
std::map<std::string, float> GetParametersByBehaviorID(uint32_t behaviorID);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "Singleton.h"
|
||||
#include "DluAssert.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@@ -15,6 +16,12 @@
|
||||
#endif
|
||||
#include "cpplinq.hpp"
|
||||
|
||||
// Used for legacy
|
||||
#define UNUSED(x)
|
||||
|
||||
// Enable this to skip some unused columns in some tables
|
||||
#define UNUSED_COLUMN(v)
|
||||
|
||||
#pragma warning (disable : 4244) //Disable double to float conversion warnings
|
||||
#pragma warning (disable : 4715) //Disable "not all control paths return a value"
|
||||
|
||||
@@ -23,3 +30,15 @@ class CDTable : public Singleton<Table> {
|
||||
protected:
|
||||
virtual ~CDTable() = default;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class LookupResult {
|
||||
typedef std::pair<T, bool> DataType;
|
||||
public:
|
||||
LookupResult() { m_data.first = T(); m_data.second = false; };
|
||||
LookupResult(T& data) { m_data.first = data; m_data.second = true; };
|
||||
inline const T& Data() { return m_data.first; };
|
||||
inline const bool& FoundData() { return m_data.second; };
|
||||
private:
|
||||
DataType m_data;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ CDVendorComponentTable::CDVendorComponentTable(void) {
|
||||
while (!tableData.eof()) {
|
||||
CDVendorComponent entry;
|
||||
entry.id = tableData.getIntField("id", -1);
|
||||
entry.buyScalar = tableData.getFloatField("buyScalar", -1.0f);
|
||||
entry.buyScalar = tableData.getFloatField("buyScalar", 0.0f);
|
||||
entry.sellScalar = tableData.getFloatField("sellScalar", -1.0f);
|
||||
entry.refreshTimeSeconds = tableData.getFloatField("refreshTimeSeconds", -1.0f);
|
||||
entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1);
|
||||
|
||||
@@ -60,25 +60,6 @@ foreach(file ${DSCRIPTS_SOURCES})
|
||||
set(DGAME_SOURCES ${DGAME_SOURCES} "${PROJECT_SOURCE_DIR}/dScripts/${file}")
|
||||
endforeach()
|
||||
|
||||
# If we are including LUA, include the dLua files in dGame
|
||||
if(__include_lua__)
|
||||
# Append the dLua files to the dGame files
|
||||
foreach(file ${DGAME_DLUA_SOURCES})
|
||||
set(DGAME_SOURCES ${DGAME_SOURCES} "${PROJECT_SOURCE_DIR}/dLua/${file}")
|
||||
endforeach()
|
||||
|
||||
find_package(Lua REQUIRED)
|
||||
|
||||
add_library(dGame STATIC ${DGAME_SOURCES})
|
||||
|
||||
target_link_libraries(dGame dDatabase Recast Detour ${LUA_LIBRARIES})
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/dLua/")
|
||||
|
||||
message(STATUS "Linking dGame to LUA " ${LUA_LIBRARIES})
|
||||
else()
|
||||
add_library(dGame STATIC ${DGAME_SOURCES})
|
||||
|
||||
target_link_libraries(dGame dDatabase Recast Detour)
|
||||
endif()
|
||||
add_library(dGame STATIC ${DGAME_SOURCES})
|
||||
|
||||
target_link_libraries(dGame dDatabase Recast Detour)
|
||||
|
||||
@@ -241,7 +241,7 @@ void Character::DoQuickXMLDataParse() {
|
||||
//To try and fix the AG landing into:
|
||||
if (m_ZoneID == 1000 && Game::server->GetZoneID() == 1100) {
|
||||
//sneakily insert our position:
|
||||
auto pos = dZoneManager::Instance()->GetZone()->GetSpawnPos();
|
||||
auto pos = Game::zoneManager->GetZone()->GetSpawnPos();
|
||||
character->SetAttribute("lzx", pos.x);
|
||||
character->SetAttribute("lzy", pos.y);
|
||||
character->SetAttribute("lzz", pos.z);
|
||||
@@ -290,13 +290,13 @@ void Character::DoQuickXMLDataParse() {
|
||||
|
||||
void Character::UnlockEmote(int emoteID) {
|
||||
m_UnlockedEmotes.push_back(emoteID);
|
||||
GameMessages::SendSetEmoteLockState(EntityManager::Instance()->GetEntity(m_ObjectID), false, emoteID);
|
||||
GameMessages::SendSetEmoteLockState(Game::entityManager->GetEntity(m_ObjectID), false, emoteID);
|
||||
}
|
||||
|
||||
void Character::SetBuildMode(bool buildMode) {
|
||||
m_BuildMode = buildMode;
|
||||
|
||||
auto* controller = dZoneManager::Instance()->GetZoneControlObject();
|
||||
auto* controller = Game::zoneManager->GetZoneControlObject();
|
||||
|
||||
controller->OnFireEventServerSide(m_OurEntity, buildMode ? "OnBuildModeEnter" : "OnBuildModeLeave");
|
||||
}
|
||||
@@ -312,7 +312,7 @@ void Character::SaveXMLToDatabase() {
|
||||
character->SetAttribute("gm", static_cast<uint32_t>(m_GMLevel));
|
||||
character->SetAttribute("cc", m_Coins);
|
||||
|
||||
auto zoneInfo = dZoneManager::Instance()->GetZone()->GetZoneID();
|
||||
auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID();
|
||||
// lzid garbage, binary concat of zoneID, zoneInstance and zoneClone
|
||||
if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0) {
|
||||
uint64_t lzidConcat = zoneInfo.GetCloneID();
|
||||
@@ -418,13 +418,13 @@ void Character::WriteToDatabase() {
|
||||
delete printer;
|
||||
}
|
||||
|
||||
void Character::SetPlayerFlag(const int32_t flagId, const bool value) {
|
||||
void Character::SetPlayerFlag(const uint32_t flagId, const bool value) {
|
||||
// If the flag is already set, we don't have to recalculate it
|
||||
if (GetPlayerFlag(flagId) == value) return;
|
||||
|
||||
if (value) {
|
||||
// Update the mission component:
|
||||
auto* player = EntityManager::Instance()->GetEntity(m_ObjectID);
|
||||
auto* player = Game::entityManager->GetEntity(m_ObjectID);
|
||||
|
||||
if (player != nullptr) {
|
||||
auto* missionComponent = player->GetComponent<MissionComponent>();
|
||||
@@ -465,7 +465,7 @@ void Character::SetPlayerFlag(const int32_t flagId, const bool value) {
|
||||
GameMessages::SendNotifyClientFlagChange(m_ObjectID, flagId, value, m_ParentUser->GetSystemAddress());
|
||||
}
|
||||
|
||||
bool Character::GetPlayerFlag(const int32_t flagId) const {
|
||||
bool Character::GetPlayerFlag(const uint32_t flagId) const {
|
||||
// Calculate the index first
|
||||
const auto flagIndex = uint32_t(std::floor(flagId / 64));
|
||||
|
||||
@@ -602,7 +602,7 @@ void Character::SetCoins(int64_t newCoins, eLootSourceType lootSource) {
|
||||
|
||||
m_Coins = newCoins;
|
||||
|
||||
GameMessages::SendSetCurrency(EntityManager::Instance()->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource);
|
||||
GameMessages::SendSetCurrency(Game::entityManager->GetEntity(m_ObjectID), m_Coins, 0, 0, 0, 0, true, lootSource);
|
||||
}
|
||||
|
||||
bool Character::HasBeenToWorld(LWOMAPID mapID) const {
|
||||
|
||||
@@ -415,14 +415,14 @@ public:
|
||||
* @param flagId the ID of the flag to set
|
||||
* @param value the value to set for the flag
|
||||
*/
|
||||
void SetPlayerFlag(int32_t flagId, bool value);
|
||||
void SetPlayerFlag(uint32_t flagId, bool value);
|
||||
|
||||
/**
|
||||
* Gets the value for a certain character flag
|
||||
* @param flagId the ID of the flag to get a value for
|
||||
* @return the value of the flag given the ID (the default is false, obviously)
|
||||
*/
|
||||
bool GetPlayerFlag(int32_t flagId) const;
|
||||
bool GetPlayerFlag(uint32_t flagId) const;
|
||||
|
||||
/**
|
||||
* Notifies the character that they're now muted
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include <PacketUtils.h>
|
||||
#include <functional>
|
||||
#include "CDDestructibleComponentTable.h"
|
||||
#include "CDClientDatabase.h"
|
||||
@@ -51,6 +50,7 @@
|
||||
#include "BuildBorderComponent.h"
|
||||
#include "MovementAIComponent.h"
|
||||
#include "VendorComponent.h"
|
||||
#include "DonationVendorComponent.h"
|
||||
#include "RocketLaunchpadControlComponent.h"
|
||||
#include "PropertyComponent.h"
|
||||
#include "BaseCombatAIComponent.h"
|
||||
@@ -263,17 +263,17 @@ void Entity::Initialize() {
|
||||
NiQuaternion rot;
|
||||
|
||||
const auto& targetSceneName = m_Character->GetTargetScene();
|
||||
auto* targetScene = EntityManager::Instance()->GetSpawnPointEntity(targetSceneName);
|
||||
auto* targetScene = Game::entityManager->GetSpawnPointEntity(targetSceneName);
|
||||
|
||||
if (m_Character->HasBeenToWorld(mapID) && targetSceneName.empty()) {
|
||||
pos = m_Character->GetRespawnPoint(mapID);
|
||||
rot = dZoneManager::Instance()->GetZone()->GetSpawnRot();
|
||||
rot = Game::zoneManager->GetZone()->GetSpawnRot();
|
||||
} else if (targetScene != nullptr) {
|
||||
pos = targetScene->GetPosition();
|
||||
rot = targetScene->GetRotation();
|
||||
} else {
|
||||
pos = dZoneManager::Instance()->GetZone()->GetSpawnPos();
|
||||
rot = dZoneManager::Instance()->GetZone()->GetSpawnRot();
|
||||
pos = Game::zoneManager->GetZone()->GetSpawnPos();
|
||||
rot = Game::zoneManager->GetZone()->GetSpawnRot();
|
||||
}
|
||||
|
||||
controllablePhysics->SetPosition(pos);
|
||||
@@ -386,8 +386,8 @@ void Entity::Initialize() {
|
||||
comp->SetMaxCoins(currencyValues[0].maxvalue);
|
||||
}
|
||||
|
||||
// extraInfo overrides
|
||||
comp->SetIsSmashable(GetVarAs<int32_t>(u"is_smashable") != 0);
|
||||
// extraInfo overrides. Client ORs the database smashable and the luz smashable.
|
||||
comp->SetIsSmashable(comp->GetIsSmashable() | (GetVarAs<int32_t>(u"is_smashable") != 0));
|
||||
}
|
||||
} else {
|
||||
comp->SetHealth(1);
|
||||
@@ -505,7 +505,7 @@ void Entity::Initialize() {
|
||||
// ZoneControl script
|
||||
if (m_TemplateID == 2365) {
|
||||
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
|
||||
const auto zoneID = dZoneManager::Instance()->GetZoneID();
|
||||
const auto zoneID = Game::zoneManager->GetZoneID();
|
||||
const CDZoneTable* zoneData = zoneTable->Query(zoneID.GetMapID());
|
||||
|
||||
if (zoneData != nullptr) {
|
||||
@@ -578,6 +578,9 @@ void Entity::Initialize() {
|
||||
if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::VENDOR) > 0)) {
|
||||
VendorComponent* comp = new VendorComponent(this);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::VENDOR, comp));
|
||||
} else if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::DONATION_VENDOR, -1) != -1)) {
|
||||
DonationVendorComponent* comp = new DonationVendorComponent(this);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::DONATION_VENDOR, comp));
|
||||
}
|
||||
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY_VENDOR, -1) != -1) {
|
||||
@@ -595,8 +598,9 @@ void Entity::Initialize() {
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::BOUNCER, comp));
|
||||
}
|
||||
|
||||
if ((compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER) > 0 && m_TemplateID != 2365) || m_Character) {
|
||||
RenderComponent* render = new RenderComponent(this);
|
||||
int32_t renderComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RENDER);
|
||||
if ((renderComponentId > 0 && m_TemplateID != 2365) || m_Character) {
|
||||
RenderComponent* render = new RenderComponent(this, renderComponentId);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::RENDER, render));
|
||||
}
|
||||
|
||||
@@ -690,7 +694,7 @@ void Entity::Initialize() {
|
||||
}
|
||||
|
||||
std::string pathName = GetVarAsString(u"attached_path");
|
||||
const Path* path = dZoneManager::Instance()->GetZone()->GetPath(pathName);
|
||||
const Path* path = Game::zoneManager->GetZone()->GetPath(pathName);
|
||||
|
||||
//Check to see if we have an attached path and add the appropiate component to handle it:
|
||||
if (path){
|
||||
@@ -707,6 +711,13 @@ void Entity::Initialize() {
|
||||
// TODO: create movementAIcomp and set path
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
// else we still need to setup moving platform if it has a moving platform comp but no path
|
||||
int32_t movingPlatformComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MOVING_PLATFORM, -1);
|
||||
if (movingPlatformComponentId >= 0) {
|
||||
MovingPlatformComponent* plat = new MovingPlatformComponent(this, pathName);
|
||||
m_Components.insert(std::make_pair(eReplicaComponentType::MOVING_PLATFORM, plat));
|
||||
}
|
||||
}
|
||||
|
||||
int proximityMonitorID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROXIMITY_MONITOR);
|
||||
@@ -727,7 +738,7 @@ void Entity::Initialize() {
|
||||
}
|
||||
});
|
||||
|
||||
if (!m_Character && EntityManager::Instance()->GetGhostingEnabled()) {
|
||||
if (!m_Character && Game::entityManager->GetGhostingEnabled()) {
|
||||
// Don't ghost what is likely large scene elements
|
||||
if (HasComponent(eReplicaComponentType::SIMPLE_PHYSICS) && HasComponent(eReplicaComponentType::RENDER) && (m_Components.size() == 2 || (HasComponent(eReplicaComponentType::TRIGGER) && m_Components.size() == 3))) {
|
||||
goto no_ghosting;
|
||||
@@ -1152,6 +1163,11 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType
|
||||
vendorComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
|
||||
}
|
||||
|
||||
DonationVendorComponent* donationVendorComponent;
|
||||
if (TryGetComponent(eReplicaComponentType::DONATION_VENDOR, donationVendorComponent)) {
|
||||
donationVendorComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
|
||||
}
|
||||
|
||||
BouncerComponent* bouncerComponent;
|
||||
if (TryGetComponent(eReplicaComponentType::BOUNCER, bouncerComponent)) {
|
||||
bouncerComponent->Serialize(outBitStream, bIsInitialUpdate, flags);
|
||||
@@ -1276,12 +1292,12 @@ void Entity::Update(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (m_ShouldDestroyAfterUpdate) {
|
||||
EntityManager::Instance()->DestroyEntity(this->GetObjectID());
|
||||
Game::entityManager->DestroyEntity(this->GetObjectID());
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxName, const std::string& status) {
|
||||
Entity* other = EntityManager::Instance()->GetEntity(otherEntity);
|
||||
Entity* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
@@ -1295,7 +1311,7 @@ void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxN
|
||||
}
|
||||
|
||||
void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
|
||||
auto* other = EntityManager::Instance()->GetEntity(otherEntity);
|
||||
auto* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
@@ -1342,7 +1358,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
|
||||
}
|
||||
|
||||
void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) {
|
||||
auto* other = EntityManager::Instance()->GetEntity(otherEntity);
|
||||
auto* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
@@ -1485,18 +1501,24 @@ void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16s
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnRequestActivityExit(sender, player, canceled);
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType) {
|
||||
if (!m_PlayerIsReadyForUpdates) return;
|
||||
|
||||
auto* destroyableComponent = GetComponent<DestroyableComponent>();
|
||||
if (destroyableComponent == nullptr) {
|
||||
Kill(EntityManager::Instance()->GetEntity(source));
|
||||
Kill(Game::entityManager->GetEntity(source));
|
||||
return;
|
||||
}
|
||||
auto* possessorComponent = GetComponent<PossessorComponent>();
|
||||
if (possessorComponent) {
|
||||
if (possessorComponent->GetPossessable() != LWOOBJID_EMPTY) {
|
||||
auto* mount = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
|
||||
auto* mount = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
|
||||
if (mount) possessorComponent->Dismount(mount, true);
|
||||
}
|
||||
}
|
||||
@@ -1524,20 +1546,20 @@ void Entity::Kill(Entity* murderer) {
|
||||
}
|
||||
|
||||
if (!IsPlayer()) {
|
||||
EntityManager::Instance()->DestroyEntity(this);
|
||||
Game::entityManager->DestroyEntity(this);
|
||||
}
|
||||
|
||||
const auto& grpNameQBShowBricks = GetVar<std::string>(u"grpNameQBShowBricks");
|
||||
|
||||
if (!grpNameQBShowBricks.empty()) {
|
||||
auto spawners = dZoneManager::Instance()->GetSpawnersByName(grpNameQBShowBricks);
|
||||
auto spawners = Game::zoneManager->GetSpawnersByName(grpNameQBShowBricks);
|
||||
|
||||
Spawner* spawner = nullptr;
|
||||
|
||||
if (!spawners.empty()) {
|
||||
spawner = spawners[0];
|
||||
} else {
|
||||
spawners = dZoneManager::Instance()->GetSpawnersInGroup(grpNameQBShowBricks);
|
||||
spawners = Game::zoneManager->GetSpawnersInGroup(grpNameQBShowBricks);
|
||||
|
||||
if (!spawners.empty()) {
|
||||
spawner = spawners[0];
|
||||
@@ -1705,7 +1727,7 @@ void Entity::CancelCallbackTimers() {
|
||||
|
||||
void Entity::ScheduleKillAfterUpdate(Entity* murderer) {
|
||||
//if (m_Info.spawner) m_Info.spawner->ScheduleKill(this);
|
||||
EntityManager::Instance()->ScheduleForKill(this);
|
||||
Game::entityManager->ScheduleForKill(this);
|
||||
|
||||
if (murderer) m_ScheduleKiller = murderer;
|
||||
}
|
||||
@@ -1749,7 +1771,7 @@ void Entity::TriggerEvent(eTriggerEventType event, Entity* optionalTarget) {
|
||||
|
||||
Entity* Entity::GetOwner() const {
|
||||
if (m_OwnerOverride != LWOOBJID_EMPTY) {
|
||||
auto* other = EntityManager::Instance()->GetEntity(m_OwnerOverride);
|
||||
auto* other = Game::entityManager->GetEntity(m_OwnerOverride);
|
||||
|
||||
if (other != nullptr) {
|
||||
return other->GetOwner();
|
||||
@@ -1813,8 +1835,6 @@ bool Entity::IsSleeping() const {
|
||||
|
||||
|
||||
const NiPoint3& Entity::GetPosition() const {
|
||||
if (!this) return NiPoint3::ZERO;
|
||||
|
||||
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllable != nullptr) {
|
||||
@@ -1895,7 +1915,7 @@ void Entity::SetPosition(NiPoint3 position) {
|
||||
vehicel->SetPosition(position);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(this);
|
||||
Game::entityManager->SerializeEntity(this);
|
||||
}
|
||||
|
||||
void Entity::SetRotation(NiQuaternion rotation) {
|
||||
@@ -1923,7 +1943,7 @@ void Entity::SetRotation(NiQuaternion rotation) {
|
||||
vehicel->SetRotation(rotation);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(this);
|
||||
Game::entityManager->SerializeEntity(this);
|
||||
}
|
||||
|
||||
bool Entity::GetBoolean(const std::u16string& name) const {
|
||||
@@ -1975,7 +1995,7 @@ std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() {
|
||||
for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) {
|
||||
const auto id = m_TargetsInPhantom.at(i);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
||||
auto* entity = Game::entityManager->GetEntity(id);
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
bool GetPlayerReadyForUpdates() const { return m_PlayerIsReadyForUpdates; }
|
||||
|
||||
bool GetIsGhostingCandidate() const;
|
||||
void SetIsGhostingCandidate(bool value) { m_IsGhostingCandidate = value; };
|
||||
|
||||
int8_t GetObservers() const;
|
||||
|
||||
@@ -207,6 +208,7 @@ public:
|
||||
|
||||
void OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData);
|
||||
void OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier);
|
||||
void RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled);
|
||||
|
||||
void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u"");
|
||||
void Kill(Entity* murderer = nullptr);
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "eReplicaPacketType.h"
|
||||
|
||||
EntityManager* EntityManager::m_Address = nullptr;
|
||||
|
||||
// Configure which zones have ghosting disabled, mostly small worlds.
|
||||
std::vector<LWOMAPID> EntityManager::m_GhostingExcludedZones = {
|
||||
// Small zones
|
||||
@@ -62,7 +60,7 @@ void EntityManager::Initialize() {
|
||||
m_GhostingEnabled = std::find(
|
||||
m_GhostingExcludedZones.begin(),
|
||||
m_GhostingExcludedZones.end(),
|
||||
dZoneManager::Instance()->GetZoneID().GetMapID()
|
||||
Game::zoneManager->GetZoneID().GetMapID()
|
||||
) == m_GhostingExcludedZones.end();
|
||||
|
||||
// grab hardcore mode settings and load them with sane defaults
|
||||
@@ -77,10 +75,7 @@ void EntityManager::Initialize() {
|
||||
|
||||
// If cloneID is not zero, then hardcore mode is disabled
|
||||
// aka minigames and props
|
||||
if (dZoneManager::Instance()->GetZoneID().GetCloneID() != 0) m_HardcoreMode = false;
|
||||
}
|
||||
|
||||
EntityManager::~EntityManager() {
|
||||
if (Game::zoneManager->GetZoneID().GetCloneID() != 0) m_HardcoreMode = false;
|
||||
}
|
||||
|
||||
Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentEntity, const bool controller, const LWOOBJID explicitId) {
|
||||
@@ -161,9 +156,7 @@ void EntityManager::DestroyEntity(const LWOOBJID& objectID) {
|
||||
}
|
||||
|
||||
void EntityManager::DestroyEntity(Entity* entity) {
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (!entity) return;
|
||||
|
||||
entity->TriggerEvent(eTriggerEventType::DESTROY, entity);
|
||||
|
||||
@@ -182,15 +175,11 @@ void EntityManager::DestroyEntity(Entity* entity) {
|
||||
ScheduleForDeletion(id);
|
||||
}
|
||||
|
||||
void EntityManager::UpdateEntities(const float deltaTime) {
|
||||
for (const auto& e : m_Entities) {
|
||||
e.second->Update(deltaTime);
|
||||
}
|
||||
|
||||
void EntityManager::SerializeEntities() {
|
||||
for (auto entry = m_EntitiesToSerialize.begin(); entry != m_EntitiesToSerialize.end(); entry++) {
|
||||
auto* entity = GetEntity(*entry);
|
||||
|
||||
if (entity == nullptr) continue;
|
||||
if (!entity) continue;
|
||||
|
||||
m_SerializationCounter++;
|
||||
|
||||
@@ -212,11 +201,16 @@ void EntityManager::UpdateEntities(const float deltaTime) {
|
||||
}
|
||||
}
|
||||
m_EntitiesToSerialize.clear();
|
||||
}
|
||||
|
||||
void EntityManager::KillEntities() {
|
||||
for (auto entry = m_EntitiesToKill.begin(); entry != m_EntitiesToKill.end(); entry++) {
|
||||
auto* entity = GetEntity(*entry);
|
||||
|
||||
if (!entity) continue;
|
||||
if (!entity) {
|
||||
Game::logger->Log("EntityManager", "Attempting to kill null entity %llu", *entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity->GetScheduledKiller()) {
|
||||
entity->Smash(entity->GetScheduledKiller()->GetObjectID(), eKillType::SILENT);
|
||||
@@ -225,32 +219,41 @@ void EntityManager::UpdateEntities(const float deltaTime) {
|
||||
}
|
||||
}
|
||||
m_EntitiesToKill.clear();
|
||||
}
|
||||
|
||||
void EntityManager::DeleteEntities() {
|
||||
for (auto entry = m_EntitiesToDelete.begin(); entry != m_EntitiesToDelete.end(); entry++) {
|
||||
|
||||
// Get all this info first before we delete the player.
|
||||
auto entityToDelete = GetEntity(*entry);
|
||||
auto networkIdToErase = entityToDelete->GetNetworkId();
|
||||
const auto& ghostingToDelete = std::find(m_EntitiesToGhost.begin(), m_EntitiesToGhost.end(), entityToDelete);
|
||||
|
||||
if (entityToDelete) {
|
||||
// If we are a player run through the player destructor.
|
||||
if (entityToDelete->IsPlayer()) {
|
||||
delete dynamic_cast<Player*>(entityToDelete);
|
||||
} else {
|
||||
delete entityToDelete;
|
||||
}
|
||||
// Get all this info first before we delete the player.
|
||||
auto networkIdToErase = entityToDelete->GetNetworkId();
|
||||
const auto& ghostingToDelete = std::find(m_EntitiesToGhost.begin(), m_EntitiesToGhost.end(), entityToDelete);
|
||||
|
||||
delete entityToDelete;
|
||||
|
||||
entityToDelete = nullptr;
|
||||
|
||||
if (networkIdToErase != 0) m_LostNetworkIds.push(networkIdToErase);
|
||||
|
||||
if (ghostingToDelete != m_EntitiesToGhost.end()) m_EntitiesToGhost.erase(ghostingToDelete);
|
||||
} else {
|
||||
Game::logger->Log("EntityManager", "Attempted to delete non-existent entity %llu", *entry);
|
||||
}
|
||||
|
||||
if (ghostingToDelete != m_EntitiesToGhost.end()) m_EntitiesToGhost.erase(ghostingToDelete);
|
||||
|
||||
m_Entities.erase(*entry);
|
||||
}
|
||||
m_EntitiesToDelete.clear();
|
||||
}
|
||||
|
||||
void EntityManager::UpdateEntities(const float deltaTime) {
|
||||
for (const auto& e : m_Entities) {
|
||||
e.second->Update(deltaTime);
|
||||
}
|
||||
|
||||
SerializeEntities();
|
||||
KillEntities();
|
||||
DeleteEntities();
|
||||
}
|
||||
|
||||
Entity* EntityManager::GetEntity(const LWOOBJID& objectId) const {
|
||||
const auto& index = m_Entities.find(objectId);
|
||||
|
||||
@@ -316,6 +319,11 @@ const std::unordered_map<std::string, LWOOBJID>& EntityManager::GetSpawnPointEnt
|
||||
}
|
||||
|
||||
void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr, const bool skipChecks) {
|
||||
if (!entity) {
|
||||
Game::logger->Log("EntityManager", "Attempted to construct null entity");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity->GetNetworkId() == 0) {
|
||||
uint16_t networkId;
|
||||
|
||||
@@ -395,9 +403,7 @@ void EntityManager::ConstructAllEntities(const SystemAddress& sysAddr) {
|
||||
}
|
||||
|
||||
void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr) {
|
||||
if (entity->GetNetworkId() == 0) {
|
||||
return;
|
||||
}
|
||||
if (!entity || entity->GetNetworkId() == 0) return;
|
||||
|
||||
RakNet::BitStream stream;
|
||||
|
||||
@@ -414,9 +420,7 @@ void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr)
|
||||
}
|
||||
|
||||
void EntityManager::SerializeEntity(Entity* entity) {
|
||||
if (entity->GetNetworkId() == 0) {
|
||||
return;
|
||||
}
|
||||
if (!entity || entity->GetNetworkId() == 0) return;
|
||||
|
||||
if (std::find(m_EntitiesToSerialize.begin(), m_EntitiesToSerialize.end(), entity->GetObjectID()) == m_EntitiesToSerialize.end()) {
|
||||
m_EntitiesToSerialize.push_back(entity->GetObjectID());
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#ifndef ENTITYMANAGER_H
|
||||
#define ENTITYMANAGER_H
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
|
||||
class Entity;
|
||||
class EntityInfo;
|
||||
class Player;
|
||||
@@ -17,19 +18,8 @@ struct SystemAddress;
|
||||
|
||||
class EntityManager {
|
||||
public:
|
||||
static EntityManager* Instance() {
|
||||
if (!m_Address) {
|
||||
m_Address = new EntityManager();
|
||||
m_Address->Initialize();
|
||||
}
|
||||
|
||||
return m_Address;
|
||||
}
|
||||
|
||||
void Initialize();
|
||||
|
||||
~EntityManager();
|
||||
|
||||
void UpdateEntities(float deltaTime);
|
||||
Entity* CreateEntity(EntityInfo info, User* user = nullptr, Entity* parentEntity = nullptr, bool controller = false, LWOOBJID explicitId = LWOOBJID_EMPTY);
|
||||
void DestroyEntity(const LWOOBJID& objectID);
|
||||
@@ -85,7 +75,10 @@ public:
|
||||
const uint32_t GetHardcoreUscoreEnemiesMultiplier() { return m_HardcoreUscoreEnemiesMultiplier; };
|
||||
|
||||
private:
|
||||
static EntityManager* m_Address; //For singleton method
|
||||
void SerializeEntities();
|
||||
void KillEntities();
|
||||
void DeleteEntities();
|
||||
|
||||
static std::vector<LWOMAPID> m_GhostingExcludedZones;
|
||||
static std::vector<LOT> m_GhostingExcludedLOTs;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "LeaderboardManager.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "Database.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Character.h"
|
||||
@@ -10,461 +13,400 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "Entity.h"
|
||||
#include "LDFFormat.h"
|
||||
#include "DluAssert.h"
|
||||
|
||||
#include "CDActivitiesTable.h"
|
||||
#include "Metrics.hpp"
|
||||
|
||||
Leaderboard::Leaderboard(uint32_t gameID, uint32_t infoType, bool weekly, std::vector<LeaderboardEntry> entries,
|
||||
LWOOBJID relatedPlayer, LeaderboardType leaderboardType) {
|
||||
this->relatedPlayer = relatedPlayer;
|
||||
namespace LeaderboardManager {
|
||||
std::map<GameID, Leaderboard::Type> leaderboardCache;
|
||||
}
|
||||
|
||||
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, LWOOBJID relatedPlayer, const Leaderboard::Type leaderboardType) {
|
||||
this->gameID = gameID;
|
||||
this->weekly = weekly;
|
||||
this->infoType = infoType;
|
||||
this->entries = std::move(entries);
|
||||
this->leaderboardType = leaderboardType;
|
||||
this->relatedPlayer = relatedPlayer;
|
||||
}
|
||||
|
||||
std::u16string Leaderboard::ToString() const {
|
||||
std::string leaderboard;
|
||||
Leaderboard::~Leaderboard() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
leaderboard += "ADO.Result=7:1\n";
|
||||
leaderboard += "Result.Count=1:1\n";
|
||||
leaderboard += "Result[0].Index=0:RowNumber\n";
|
||||
leaderboard += "Result[0].RowCount=1:" + std::to_string(entries.size()) + "\n";
|
||||
void Leaderboard::Clear() {
|
||||
for (auto& entry : entries) for (auto ldfData : entry) delete ldfData;
|
||||
}
|
||||
|
||||
auto index = 0;
|
||||
for (const auto& entry : entries) {
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].LastPlayed=8:" + std::to_string(entry.lastPlayed) + "\n";
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].CharacterID=8:" + std::to_string(entry.playerID) + "\n";
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].NumPlayed=1:1\n";
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].RowNumber=8:" + std::to_string(entry.placement) + "\n";
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Time=1:" + std::to_string(entry.time) + "\n";
|
||||
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, LDFBaseData* data) {
|
||||
leaderboard << "\nResult[0].Row[" << index << "]." << data->GetString();
|
||||
}
|
||||
|
||||
// Only these minigames have a points system
|
||||
if (leaderboardType == Survival || leaderboardType == ShootingGallery) {
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Points=1:" + std::to_string(entry.score) + "\n";
|
||||
} else if (leaderboardType == SurvivalNS) {
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].Wave=1:" + std::to_string(entry.score) + "\n";
|
||||
void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
|
||||
bitStream->Write(gameID);
|
||||
bitStream->Write(infoType);
|
||||
|
||||
std::ostringstream leaderboard;
|
||||
|
||||
leaderboard << "ADO.Result=7:1"; // Unused in 1.10.64, but is in captures
|
||||
leaderboard << "\nResult.Count=1:1"; // number of results, always 1
|
||||
if (!this->entries.empty()) leaderboard << "\nResult[0].Index=0:RowNumber"; // "Primary key". Live doesn't include this if there are no entries.
|
||||
leaderboard << "\nResult[0].RowCount=1:" << entries.size();
|
||||
|
||||
int32_t rowNumber = 0;
|
||||
for (auto& entry : entries) {
|
||||
for (auto* data : entry) {
|
||||
WriteLeaderboardRow(leaderboard, rowNumber, data);
|
||||
}
|
||||
|
||||
leaderboard += "Result[0].Row[" + std::to_string(index) + "].name=0:" + entry.playerName + "\n";
|
||||
index++;
|
||||
rowNumber++;
|
||||
}
|
||||
|
||||
return GeneralUtils::UTF8ToUTF16(leaderboard);
|
||||
// Serialize the thing to a BitStream
|
||||
uint32_t leaderboardSize = leaderboard.tellp();
|
||||
bitStream->Write<uint32_t>(leaderboardSize);
|
||||
// Doing this all in 1 call so there is no possbility of a dangling pointer.
|
||||
bitStream->WriteAlignedBytes(reinterpret_cast<const unsigned char*>(GeneralUtils::ASCIIToUTF16(leaderboard.str()).c_str()), leaderboardSize * sizeof(char16_t));
|
||||
if (leaderboardSize > 0) bitStream->Write<uint16_t>(0);
|
||||
bitStream->Write0();
|
||||
bitStream->Write0();
|
||||
}
|
||||
|
||||
std::vector<LeaderboardEntry> Leaderboard::GetEntries() {
|
||||
return entries;
|
||||
void Leaderboard::QueryToLdf(std::unique_ptr<sql::ResultSet>& rows) {
|
||||
Clear();
|
||||
if (rows->rowsCount() == 0) return;
|
||||
|
||||
this->entries.reserve(rows->rowsCount());
|
||||
while (rows->next()) {
|
||||
constexpr int32_t MAX_NUM_DATA_PER_ROW = 9;
|
||||
this->entries.push_back(std::vector<LDFBaseData*>());
|
||||
auto& entry = this->entries.back();
|
||||
entry.reserve(MAX_NUM_DATA_PER_ROW);
|
||||
entry.push_back(new LDFData<uint64_t>(u"CharacterID", rows->getInt("character_id")));
|
||||
entry.push_back(new LDFData<uint64_t>(u"LastPlayed", rows->getUInt64("lastPlayed")));
|
||||
entry.push_back(new LDFData<int32_t>(u"NumPlayed", rows->getInt("timesPlayed")));
|
||||
entry.push_back(new LDFData<std::u16string>(u"name", GeneralUtils::ASCIIToUTF16(rows->getString("name").c_str())));
|
||||
entry.push_back(new LDFData<uint64_t>(u"RowNumber", rows->getInt("ranking")));
|
||||
switch (leaderboardType) {
|
||||
case Type::ShootingGallery:
|
||||
entry.push_back(new LDFData<int32_t>(u"Score", rows->getInt("primaryScore")));
|
||||
// Score:1
|
||||
entry.push_back(new LDFData<int32_t>(u"Streak", rows->getInt("secondaryScore")));
|
||||
// Streak:1
|
||||
entry.push_back(new LDFData<float>(u"HitPercentage", (rows->getInt("tertiaryScore") / 100.0f)));
|
||||
// HitPercentage:3 between 0 and 1
|
||||
break;
|
||||
case Type::Racing:
|
||||
entry.push_back(new LDFData<float>(u"BestTime", rows->getDouble("primaryScore")));
|
||||
// BestLapTime:3
|
||||
entry.push_back(new LDFData<float>(u"BestLapTime", rows->getDouble("secondaryScore")));
|
||||
// BestTime:3
|
||||
entry.push_back(new LDFData<int32_t>(u"License", 1));
|
||||
// License:1 - 1 if player has completed mission 637 and 0 otherwise
|
||||
entry.push_back(new LDFData<int32_t>(u"NumWins", rows->getInt("numWins")));
|
||||
// NumWins:1
|
||||
break;
|
||||
case Type::UnusedLeaderboard4:
|
||||
entry.push_back(new LDFData<int32_t>(u"Points", rows->getInt("primaryScore")));
|
||||
// Points:1
|
||||
break;
|
||||
case Type::MonumentRace:
|
||||
entry.push_back(new LDFData<int32_t>(u"Time", rows->getInt("primaryScore")));
|
||||
// Time:1(?)
|
||||
break;
|
||||
case Type::FootRace:
|
||||
entry.push_back(new LDFData<int32_t>(u"Time", rows->getInt("primaryScore")));
|
||||
// Time:1
|
||||
break;
|
||||
case Type::Survival:
|
||||
entry.push_back(new LDFData<int32_t>(u"Points", rows->getInt("primaryScore")));
|
||||
// Points:1
|
||||
entry.push_back(new LDFData<int32_t>(u"Time", rows->getInt("secondaryScore")));
|
||||
// Time:1
|
||||
break;
|
||||
case Type::SurvivalNS:
|
||||
entry.push_back(new LDFData<int32_t>(u"Wave", rows->getInt("primaryScore")));
|
||||
// Wave:1
|
||||
entry.push_back(new LDFData<int32_t>(u"Time", rows->getInt("secondaryScore")));
|
||||
// Time:1
|
||||
break;
|
||||
case Type::Donations:
|
||||
entry.push_back(new LDFData<int32_t>(u"Score", rows->getInt("primaryScore")));
|
||||
// Score:1
|
||||
break;
|
||||
case Type::None:
|
||||
// This type is included here simply to resolve a compiler warning on mac about unused enum types
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Leaderboard::GetGameID() const {
|
||||
return gameID;
|
||||
const std::string_view Leaderboard::GetOrdering(Leaderboard::Type leaderboardType) {
|
||||
// Use a switch case and return desc for all 3 columns if higher is better and asc if lower is better
|
||||
switch (leaderboardType) {
|
||||
case Type::Racing:
|
||||
case Type::MonumentRace:
|
||||
return "primaryScore ASC, secondaryScore ASC, tertiaryScore ASC";
|
||||
case Type::Survival:
|
||||
return Game::config->GetValue("classic_survival_scoring") == "1" ?
|
||||
"secondaryScore DESC, primaryScore DESC, tertiaryScore DESC" :
|
||||
"primaryScore DESC, secondaryScore DESC, tertiaryScore DESC";
|
||||
case Type::SurvivalNS:
|
||||
return "primaryScore DESC, secondaryScore ASC, tertiaryScore DESC";
|
||||
case Type::ShootingGallery:
|
||||
case Type::FootRace:
|
||||
case Type::UnusedLeaderboard4:
|
||||
case Type::Donations:
|
||||
case Type::None:
|
||||
default:
|
||||
return "primaryScore DESC, secondaryScore DESC, tertiaryScore DESC";
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Leaderboard::GetInfoType() const {
|
||||
return infoType;
|
||||
void Leaderboard::SetupLeaderboard(bool weekly, uint32_t resultStart, uint32_t resultEnd) {
|
||||
resultStart++;
|
||||
resultEnd++;
|
||||
// We need everything except 1 column so i'm selecting * from leaderboard
|
||||
const std::string queryBase =
|
||||
R"QUERY(
|
||||
WITH leaderboardsRanked AS (
|
||||
SELECT leaderboard.*, charinfo.name,
|
||||
RANK() OVER
|
||||
(
|
||||
ORDER BY %s, UNIX_TIMESTAMP(last_played) ASC, id DESC
|
||||
) AS ranking
|
||||
FROM leaderboard JOIN charinfo on charinfo.id = leaderboard.character_id
|
||||
WHERE game_id = ? %s
|
||||
),
|
||||
myStanding AS (
|
||||
SELECT
|
||||
ranking as myRank
|
||||
FROM leaderboardsRanked
|
||||
WHERE id = ?
|
||||
),
|
||||
lowestRanking AS (
|
||||
SELECT MAX(ranking) AS lowestRank
|
||||
FROM leaderboardsRanked
|
||||
)
|
||||
SELECT leaderboardsRanked.*, character_id, UNIX_TIMESTAMP(last_played) as lastPlayed, leaderboardsRanked.name, leaderboardsRanked.ranking FROM leaderboardsRanked, myStanding, lowestRanking
|
||||
WHERE leaderboardsRanked.ranking
|
||||
BETWEEN
|
||||
LEAST(GREATEST(CAST(myRank AS SIGNED) - 5, %i), lowestRanking.lowestRank - 9)
|
||||
AND
|
||||
LEAST(GREATEST(myRank + 5, %i), lowestRanking.lowestRank)
|
||||
ORDER BY ranking ASC;
|
||||
)QUERY";
|
||||
|
||||
std::string friendsFilter =
|
||||
R"QUERY(
|
||||
AND (
|
||||
character_id IN (
|
||||
SELECT fr.requested_player FROM (
|
||||
SELECT CASE
|
||||
WHEN player_id = ? THEN friend_id
|
||||
WHEN friend_id = ? THEN player_id
|
||||
END AS requested_player
|
||||
FROM friends
|
||||
) AS fr
|
||||
JOIN charinfo AS ci
|
||||
ON ci.id = fr.requested_player
|
||||
WHERE fr.requested_player IS NOT NULL
|
||||
)
|
||||
OR character_id = ?
|
||||
)
|
||||
)QUERY";
|
||||
|
||||
std::string weeklyFilter = " AND UNIX_TIMESTAMP(last_played) BETWEEN UNIX_TIMESTAMP(date_sub(now(),INTERVAL 1 WEEK)) AND UNIX_TIMESTAMP(now()) ";
|
||||
|
||||
std::string filter;
|
||||
// Setup our filter based on the query type
|
||||
if (this->infoType == InfoType::Friends) filter += friendsFilter;
|
||||
if (this->weekly) filter += weeklyFilter;
|
||||
const auto orderBase = GetOrdering(this->leaderboardType);
|
||||
|
||||
// For top query, we want to just rank all scores, but for all others we need the scores around a specific player
|
||||
std::string baseLookup;
|
||||
if (this->infoType == InfoType::Top) {
|
||||
baseLookup = "SELECT id, last_played FROM leaderboard WHERE game_id = ? " + (this->weekly ? weeklyFilter : std::string("")) + " ORDER BY ";
|
||||
baseLookup += orderBase.data();
|
||||
} else {
|
||||
baseLookup = "SELECT id, last_played FROM leaderboard WHERE game_id = ? " + (this->weekly ? weeklyFilter : std::string("")) + " AND character_id = ";
|
||||
baseLookup += std::to_string(static_cast<uint32_t>(this->relatedPlayer));
|
||||
}
|
||||
baseLookup += " LIMIT 1";
|
||||
Game::logger->LogDebug("LeaderboardManager", "query is %s", baseLookup.c_str());
|
||||
std::unique_ptr<sql::PreparedStatement> baseQuery(Database::CreatePreppedStmt(baseLookup));
|
||||
baseQuery->setInt(1, this->gameID);
|
||||
std::unique_ptr<sql::ResultSet> baseResult(baseQuery->executeQuery());
|
||||
|
||||
if (!baseResult->next()) return; // In this case, there are no entries in the leaderboard for this game.
|
||||
|
||||
uint32_t relatedPlayerLeaderboardId = baseResult->getInt("id");
|
||||
|
||||
// Create and execute the actual save here. Using a heap allocated buffer to avoid stack overflow
|
||||
constexpr uint16_t STRING_LENGTH = 4096;
|
||||
std::unique_ptr<char[]> lookupBuffer = std::make_unique<char[]>(STRING_LENGTH);
|
||||
int32_t res = snprintf(lookupBuffer.get(), STRING_LENGTH, queryBase.c_str(), orderBase.data(), filter.c_str(), resultStart, resultEnd);
|
||||
DluAssert(res != -1);
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt(lookupBuffer.get()));
|
||||
Game::logger->LogDebug("LeaderboardManager", "Query is %s vars are %i %i %i", lookupBuffer.get(), this->gameID, this->relatedPlayer, relatedPlayerLeaderboardId);
|
||||
query->setInt(1, this->gameID);
|
||||
if (this->infoType == InfoType::Friends) {
|
||||
query->setInt(2, this->relatedPlayer);
|
||||
query->setInt(3, this->relatedPlayer);
|
||||
query->setInt(4, this->relatedPlayer);
|
||||
query->setInt(5, relatedPlayerLeaderboardId);
|
||||
} else {
|
||||
query->setInt(2, relatedPlayerLeaderboardId);
|
||||
}
|
||||
std::unique_ptr<sql::ResultSet> result(query->executeQuery());
|
||||
QueryToLdf(result);
|
||||
}
|
||||
|
||||
void Leaderboard::Send(LWOOBJID targetID) const {
|
||||
auto* player = EntityManager::Instance()->GetEntity(relatedPlayer);
|
||||
void Leaderboard::Send(const LWOOBJID targetID) const {
|
||||
auto* player = Game::entityManager->GetEntity(relatedPlayer);
|
||||
if (player != nullptr) {
|
||||
GameMessages::SendActivitySummaryLeaderboardData(targetID, this, player->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
void LeaderboardManager::SaveScore(LWOOBJID playerID, uint32_t gameID, uint32_t score, uint32_t time) {
|
||||
const auto* player = EntityManager::Instance()->GetEntity(playerID);
|
||||
if (player == nullptr)
|
||||
return;
|
||||
std::string FormatInsert(const Leaderboard::Type& type, const Score& score, const bool useUpdate) {
|
||||
std::string insertStatement;
|
||||
if (useUpdate) {
|
||||
insertStatement =
|
||||
R"QUERY(
|
||||
UPDATE leaderboard
|
||||
SET primaryScore = %f, secondaryScore = %f, tertiaryScore = %f,
|
||||
timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;
|
||||
)QUERY";
|
||||
} else {
|
||||
insertStatement =
|
||||
R"QUERY(
|
||||
INSERT leaderboard SET
|
||||
primaryScore = %f, secondaryScore = %f, tertiaryScore = %f,
|
||||
character_id = ?, game_id = ?;
|
||||
)QUERY";
|
||||
}
|
||||
|
||||
auto* character = player->GetCharacter();
|
||||
if (character == nullptr)
|
||||
return;
|
||||
constexpr uint16_t STRING_LENGTH = 400;
|
||||
// Then fill in our score
|
||||
char finishedQuery[STRING_LENGTH];
|
||||
int32_t res = snprintf(finishedQuery, STRING_LENGTH, insertStatement.c_str(), score.GetPrimaryScore(), score.GetSecondaryScore(), score.GetTertiaryScore());
|
||||
DluAssert(res != -1);
|
||||
return finishedQuery;
|
||||
}
|
||||
|
||||
auto* select = Database::CreatePreppedStmt("SELECT time, score FROM leaderboard WHERE character_id = ? AND game_id = ?;");
|
||||
void LeaderboardManager::SaveScore(const LWOOBJID& playerID, const GameID activityId, const float primaryScore, const float secondaryScore, const float tertiaryScore) {
|
||||
const Leaderboard::Type leaderboardType = GetLeaderboardType(activityId);
|
||||
|
||||
select->setUInt64(1, character->GetID());
|
||||
select->setInt(2, gameID);
|
||||
|
||||
auto any = false;
|
||||
auto* result = select->executeQuery();
|
||||
auto leaderboardType = GetLeaderboardType(gameID);
|
||||
|
||||
// Check if the new score is a high score
|
||||
while (result->next()) {
|
||||
any = true;
|
||||
|
||||
const auto storedTime = result->getInt(1);
|
||||
const auto storedScore = result->getInt(2);
|
||||
auto highscore = true;
|
||||
bool classicSurvivalScoring = Game::config->GetValue("classic_survival_scoring") == "1";
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt("SELECT * FROM leaderboard WHERE character_id = ? AND game_id = ?;"));
|
||||
query->setInt(1, playerID);
|
||||
query->setInt(2, activityId);
|
||||
std::unique_ptr<sql::ResultSet> myScoreResult(query->executeQuery());
|
||||
|
||||
std::string saveQuery("UPDATE leaderboard SET timesPlayed = timesPlayed + 1 WHERE character_id = ? AND game_id = ?;");
|
||||
Score newScore(primaryScore, secondaryScore, tertiaryScore);
|
||||
if (myScoreResult->next()) {
|
||||
Score oldScore;
|
||||
bool lowerScoreBetter = false;
|
||||
switch (leaderboardType) {
|
||||
case ShootingGallery:
|
||||
if (score <= storedScore)
|
||||
highscore = false;
|
||||
// Higher score better
|
||||
case Leaderboard::Type::ShootingGallery: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
oldScore.SetSecondaryScore(myScoreResult->getInt("secondaryScore"));
|
||||
oldScore.SetTertiaryScore(myScoreResult->getInt("tertiaryScore"));
|
||||
break;
|
||||
case Racing:
|
||||
if (time >= storedTime)
|
||||
highscore = false;
|
||||
break;
|
||||
case MonumentRace:
|
||||
if (time >= storedTime)
|
||||
highscore = false;
|
||||
break;
|
||||
case FootRace:
|
||||
if (time <= storedTime)
|
||||
highscore = false;
|
||||
break;
|
||||
case Survival:
|
||||
if (classicSurvivalScoring) {
|
||||
if (time <= storedTime) { // Based on time (LU live)
|
||||
highscore = false;
|
||||
}
|
||||
} else {
|
||||
if (score <= storedScore) // Based on score (DLU)
|
||||
highscore = false;
|
||||
}
|
||||
break;
|
||||
case SurvivalNS:
|
||||
if (!(score > storedScore || (time < storedTime && score >= storedScore)))
|
||||
highscore = false;
|
||||
break;
|
||||
default:
|
||||
highscore = false;
|
||||
}
|
||||
case Leaderboard::Type::FootRace: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::Survival: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
oldScore.SetSecondaryScore(myScoreResult->getInt("secondaryScore"));
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::SurvivalNS: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
oldScore.SetSecondaryScore(myScoreResult->getInt("secondaryScore"));
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::UnusedLeaderboard4:
|
||||
case Leaderboard::Type::Donations: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
newScore.SetPrimaryScore(oldScore.GetPrimaryScore() + newScore.GetPrimaryScore());
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::Racing: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
oldScore.SetSecondaryScore(myScoreResult->getInt("secondaryScore"));
|
||||
|
||||
if (!highscore) {
|
||||
delete select;
|
||||
delete result;
|
||||
// For wins we dont care about the score, just the time, so zero out the tertiary.
|
||||
// Wins are updated later.
|
||||
oldScore.SetTertiaryScore(0);
|
||||
newScore.SetTertiaryScore(0);
|
||||
lowerScoreBetter = true;
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::MonumentRace: {
|
||||
oldScore.SetPrimaryScore(myScoreResult->getInt("primaryScore"));
|
||||
lowerScoreBetter = true;
|
||||
// Do score checking here
|
||||
break;
|
||||
}
|
||||
case Leaderboard::Type::None:
|
||||
default:
|
||||
Game::logger->Log("LeaderboardManager", "Unknown leaderboard type %i for game %i. Cannot save score!", leaderboardType, activityId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
delete select;
|
||||
delete result;
|
||||
|
||||
if (any) {
|
||||
auto* statement = Database::CreatePreppedStmt("UPDATE leaderboard SET time = ?, score = ?, last_played=SYSDATE() WHERE character_id = ? AND game_id = ?;");
|
||||
statement->setInt(1, time);
|
||||
statement->setInt(2, score);
|
||||
statement->setUInt64(3, character->GetID());
|
||||
statement->setInt(4, gameID);
|
||||
statement->execute();
|
||||
|
||||
delete statement;
|
||||
bool newHighScore = lowerScoreBetter ? newScore < oldScore : newScore > oldScore;
|
||||
// Nimbus station has a weird leaderboard where we need a custom scoring system
|
||||
if (leaderboardType == Leaderboard::Type::SurvivalNS) {
|
||||
newHighScore = newScore.GetPrimaryScore() > oldScore.GetPrimaryScore() ||
|
||||
(newScore.GetPrimaryScore() == oldScore.GetPrimaryScore() && newScore.GetSecondaryScore() < oldScore.GetSecondaryScore());
|
||||
} else if (leaderboardType == Leaderboard::Type::Survival && Game::config->GetValue("classic_survival_scoring") == "1") {
|
||||
Score oldScoreFlipped(oldScore.GetSecondaryScore(), oldScore.GetPrimaryScore());
|
||||
Score newScoreFlipped(newScore.GetSecondaryScore(), newScore.GetPrimaryScore());
|
||||
newHighScore = newScoreFlipped > oldScoreFlipped;
|
||||
}
|
||||
if (newHighScore) {
|
||||
saveQuery = FormatInsert(leaderboardType, newScore, true);
|
||||
}
|
||||
} else {
|
||||
// Note: last_played will be set to SYSDATE() by default when inserting into leaderboard
|
||||
auto* statement = Database::CreatePreppedStmt("INSERT INTO leaderboard (character_id, game_id, time, score) VALUES (?, ?, ?, ?);");
|
||||
statement->setUInt64(1, character->GetID());
|
||||
statement->setInt(2, gameID);
|
||||
statement->setInt(3, time);
|
||||
statement->setInt(4, score);
|
||||
statement->execute();
|
||||
saveQuery = FormatInsert(leaderboardType, newScore, false);
|
||||
}
|
||||
Game::logger->Log("LeaderboardManager", "save query %s %i %i", saveQuery.c_str(), playerID, activityId);
|
||||
std::unique_ptr<sql::PreparedStatement> saveStatement(Database::CreatePreppedStmt(saveQuery));
|
||||
saveStatement->setInt(1, playerID);
|
||||
saveStatement->setInt(2, activityId);
|
||||
saveStatement->execute();
|
||||
|
||||
delete statement;
|
||||
// track wins separately
|
||||
if (leaderboardType == Leaderboard::Type::Racing && tertiaryScore != 0.0f) {
|
||||
std::unique_ptr<sql::PreparedStatement> winUpdate(Database::CreatePreppedStmt("UPDATE leaderboard SET numWins = numWins + 1 WHERE character_id = ? AND game_id = ?;"));
|
||||
winUpdate->setInt(1, playerID);
|
||||
winUpdate->setInt(2, activityId);
|
||||
winUpdate->execute();
|
||||
}
|
||||
}
|
||||
|
||||
Leaderboard* LeaderboardManager::GetLeaderboard(uint32_t gameID, InfoType infoType, bool weekly, LWOOBJID playerID) {
|
||||
auto leaderboardType = GetLeaderboardType(gameID);
|
||||
|
||||
std::string query;
|
||||
bool classicSurvivalScoring = Game::config->GetValue("classic_survival_scoring") == "1";
|
||||
switch (infoType) {
|
||||
case InfoType::Standings:
|
||||
switch (leaderboardType) {
|
||||
case ShootingGallery:
|
||||
query = standingsScoreQuery; // Shooting gallery is based on the highest score.
|
||||
break;
|
||||
case FootRace:
|
||||
query = standingsTimeQuery; // The higher your time, the better for FootRace.
|
||||
break;
|
||||
case Survival:
|
||||
query = classicSurvivalScoring ? standingsTimeQuery : standingsScoreQuery;
|
||||
break;
|
||||
case SurvivalNS:
|
||||
query = standingsScoreQueryAsc; // BoNS is scored by highest wave (score) first, then time.
|
||||
break;
|
||||
default:
|
||||
query = standingsTimeQueryAsc; // MonumentRace and Racing are based on the shortest time.
|
||||
}
|
||||
break;
|
||||
case InfoType::Friends:
|
||||
switch (leaderboardType) {
|
||||
case ShootingGallery:
|
||||
query = friendsScoreQuery; // Shooting gallery is based on the highest score.
|
||||
break;
|
||||
case FootRace:
|
||||
query = friendsTimeQuery; // The higher your time, the better for FootRace.
|
||||
break;
|
||||
case Survival:
|
||||
query = classicSurvivalScoring ? friendsTimeQuery : friendsScoreQuery;
|
||||
break;
|
||||
case SurvivalNS:
|
||||
query = friendsScoreQueryAsc; // BoNS is scored by highest wave (score) first, then time.
|
||||
break;
|
||||
default:
|
||||
query = friendsTimeQueryAsc; // MonumentRace and Racing are based on the shortest time.
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
switch (leaderboardType) {
|
||||
case ShootingGallery:
|
||||
query = topPlayersScoreQuery; // Shooting gallery is based on the highest score.
|
||||
break;
|
||||
case FootRace:
|
||||
query = topPlayersTimeQuery; // The higher your time, the better for FootRace.
|
||||
break;
|
||||
case Survival:
|
||||
query = classicSurvivalScoring ? topPlayersTimeQuery : topPlayersScoreQuery;
|
||||
break;
|
||||
case SurvivalNS:
|
||||
query = topPlayersScoreQueryAsc; // BoNS is scored by highest wave (score) first, then time.
|
||||
break;
|
||||
default:
|
||||
query = topPlayersTimeQueryAsc; // MonumentRace and Racing are based on the shortest time.
|
||||
}
|
||||
}
|
||||
|
||||
auto* statement = Database::CreatePreppedStmt(query);
|
||||
statement->setUInt(1, gameID);
|
||||
|
||||
// Only the standings and friends leaderboards require the character ID to be set
|
||||
if (infoType == Standings || infoType == Friends) {
|
||||
auto characterID = 0;
|
||||
|
||||
const auto* player = EntityManager::Instance()->GetEntity(playerID);
|
||||
if (player != nullptr) {
|
||||
auto* character = player->GetCharacter();
|
||||
if (character != nullptr)
|
||||
characterID = character->GetID();
|
||||
}
|
||||
|
||||
statement->setUInt64(2, characterID);
|
||||
}
|
||||
|
||||
auto* res = statement->executeQuery();
|
||||
|
||||
std::vector<LeaderboardEntry> entries{};
|
||||
|
||||
uint32_t index = 0;
|
||||
while (res->next()) {
|
||||
LeaderboardEntry entry;
|
||||
entry.playerID = res->getUInt64(4);
|
||||
entry.playerName = res->getString(5);
|
||||
entry.time = res->getUInt(1);
|
||||
entry.score = res->getUInt(2);
|
||||
entry.placement = res->getUInt(3);
|
||||
entry.lastPlayed = res->getUInt(6);
|
||||
|
||||
entries.push_back(entry);
|
||||
index++;
|
||||
}
|
||||
|
||||
delete res;
|
||||
delete statement;
|
||||
|
||||
return new Leaderboard(gameID, infoType, weekly, entries, playerID, leaderboardType);
|
||||
void LeaderboardManager::SendLeaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID, const uint32_t resultStart, const uint32_t resultEnd) {
|
||||
Leaderboard leaderboard(gameID, infoType, weekly, playerID, GetLeaderboardType(gameID));
|
||||
leaderboard.SetupLeaderboard(weekly, resultStart, resultEnd);
|
||||
leaderboard.Send(targetID);
|
||||
}
|
||||
|
||||
void LeaderboardManager::SendLeaderboard(uint32_t gameID, InfoType infoType, bool weekly, LWOOBJID targetID,
|
||||
LWOOBJID playerID) {
|
||||
const auto* leaderboard = LeaderboardManager::GetLeaderboard(gameID, infoType, weekly, playerID);
|
||||
leaderboard->Send(targetID);
|
||||
delete leaderboard;
|
||||
}
|
||||
Leaderboard::Type LeaderboardManager::GetLeaderboardType(const GameID gameID) {
|
||||
auto lookup = leaderboardCache.find(gameID);
|
||||
if (lookup != leaderboardCache.end()) return lookup->second;
|
||||
|
||||
LeaderboardType LeaderboardManager::GetLeaderboardType(uint32_t gameID) {
|
||||
auto* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([=](const CDActivities& entry) {
|
||||
return (entry.ActivityID == gameID);
|
||||
std::vector<CDActivities> activities = activitiesTable->Query([gameID](const CDActivities& entry) {
|
||||
return entry.ActivityID == gameID;
|
||||
});
|
||||
|
||||
for (const auto& activity : activities) {
|
||||
return static_cast<LeaderboardType>(activity.leaderboardType);
|
||||
}
|
||||
|
||||
return LeaderboardType::None;
|
||||
auto type = !activities.empty() ? static_cast<Leaderboard::Type>(activities.at(0).leaderboardType) : Leaderboard::Type::None;
|
||||
leaderboardCache.insert_or_assign(gameID, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
const std::string LeaderboardManager::topPlayersScoreQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
"RANK() OVER ( ORDER BY l.score DESC, l.time DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
"INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
"WHERE l.game_id = ? "
|
||||
"ORDER BY leaderboard_rank) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales LIMIT 11;";
|
||||
|
||||
const std::string LeaderboardManager::friendsScoreQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, f.friend_id, f.player_id, "
|
||||
" RANK() OVER ( ORDER BY l.score DESC, l.time DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" INNER JOIN friends f ON f.player_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
" personal_values AS ( "
|
||||
" SELECT id as related_player_id, "
|
||||
" GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE leaderboard_vales.id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank AND (player_id = related_player_id OR friend_id = related_player_id);";
|
||||
|
||||
const std::string LeaderboardManager::standingsScoreQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
" RANK() OVER ( ORDER BY l.score DESC, l.time DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
"personal_values AS ( "
|
||||
" SELECT GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank;";
|
||||
|
||||
const std::string LeaderboardManager::topPlayersScoreQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
"RANK() OVER ( ORDER BY l.score DESC, l.time ASC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
"INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
"WHERE l.game_id = ? "
|
||||
"ORDER BY leaderboard_rank) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales LIMIT 11;";
|
||||
|
||||
const std::string LeaderboardManager::friendsScoreQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, f.friend_id, f.player_id, "
|
||||
" RANK() OVER ( ORDER BY l.score DESC, l.time ASC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" INNER JOIN friends f ON f.player_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
" personal_values AS ( "
|
||||
" SELECT id as related_player_id, "
|
||||
" GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE leaderboard_vales.id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank AND (player_id = related_player_id OR friend_id = related_player_id);";
|
||||
|
||||
const std::string LeaderboardManager::standingsScoreQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
" RANK() OVER ( ORDER BY l.score DESC, l.time ASC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
"personal_values AS ( "
|
||||
" SELECT GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank;";
|
||||
|
||||
const std::string LeaderboardManager::topPlayersTimeQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
"RANK() OVER ( ORDER BY l.time DESC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
"INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
"WHERE l.game_id = ? "
|
||||
"ORDER BY leaderboard_rank) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales LIMIT 11;";
|
||||
|
||||
const std::string LeaderboardManager::friendsTimeQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, f.friend_id, f.player_id, "
|
||||
" RANK() OVER ( ORDER BY l.time DESC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" INNER JOIN friends f ON f.player_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
" personal_values AS ( "
|
||||
" SELECT id as related_player_id, "
|
||||
" GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE leaderboard_vales.id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank AND (player_id = related_player_id OR friend_id = related_player_id);";
|
||||
|
||||
const std::string LeaderboardManager::standingsTimeQuery =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
" RANK() OVER ( ORDER BY l.time DESC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
"personal_values AS ( "
|
||||
" SELECT GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank;";
|
||||
|
||||
const std::string LeaderboardManager::topPlayersTimeQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
"RANK() OVER ( ORDER BY l.time ASC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
"INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
"WHERE l.game_id = ? "
|
||||
"ORDER BY leaderboard_rank) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales LIMIT 11;";
|
||||
|
||||
const std::string LeaderboardManager::friendsTimeQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, f.friend_id, f.player_id, "
|
||||
" RANK() OVER ( ORDER BY l.time ASC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" INNER JOIN friends f ON f.player_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
" personal_values AS ( "
|
||||
" SELECT id as related_player_id, "
|
||||
" GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE leaderboard_vales.id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank AND (player_id = related_player_id OR friend_id = related_player_id);";
|
||||
|
||||
const std::string LeaderboardManager::standingsTimeQueryAsc =
|
||||
"WITH leaderboard_vales AS ( "
|
||||
" SELECT l.time, l.score, UNIX_TIMESTAMP(l.last_played) last_played, c.name, c.id, "
|
||||
" RANK() OVER ( ORDER BY l.time ASC, l.score DESC, last_played ) leaderboard_rank "
|
||||
" FROM leaderboard l "
|
||||
" INNER JOIN charinfo c ON l.character_id = c.id "
|
||||
" WHERE l.game_id = ? "
|
||||
" ORDER BY leaderboard_rank), "
|
||||
"personal_values AS ( "
|
||||
" SELECT GREATEST(CAST(leaderboard_rank AS SIGNED) - 5, 1) AS min_rank, "
|
||||
" GREATEST(leaderboard_rank + 5, 11) AS max_rank "
|
||||
" FROM leaderboard_vales WHERE id = ? LIMIT 1) "
|
||||
"SELECT time, score, leaderboard_rank, id, name, last_played "
|
||||
"FROM leaderboard_vales, personal_values "
|
||||
"WHERE leaderboard_rank BETWEEN min_rank AND max_rank;";
|
||||
|
||||
@@ -1,80 +1,134 @@
|
||||
#pragma once
|
||||
#ifndef __LEADERBOARDMANAGER__H__
|
||||
#define __LEADERBOARDMANAGER__H__
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
|
||||
#include "Singleton.h"
|
||||
#include "dCommonVars.h"
|
||||
#include "LDFFormat.h"
|
||||
|
||||
struct LeaderboardEntry {
|
||||
uint64_t playerID;
|
||||
std::string playerName;
|
||||
uint32_t time;
|
||||
uint32_t score;
|
||||
uint32_t placement;
|
||||
time_t lastPlayed;
|
||||
namespace sql {
|
||||
class ResultSet;
|
||||
};
|
||||
|
||||
enum InfoType : uint32_t {
|
||||
Top, // Top 11 all time players
|
||||
Standings, // Ranking of the current player
|
||||
Friends // Ranking between friends
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
enum LeaderboardType : uint32_t {
|
||||
ShootingGallery,
|
||||
Racing,
|
||||
MonumentRace,
|
||||
FootRace,
|
||||
Survival = 5,
|
||||
SurvivalNS = 6,
|
||||
None = UINT_MAX
|
||||
class Score {
|
||||
public:
|
||||
Score() {
|
||||
primaryScore = 0;
|
||||
secondaryScore = 0;
|
||||
tertiaryScore = 0;
|
||||
}
|
||||
Score(const float primaryScore, const float secondaryScore = 0, const float tertiaryScore = 0) {
|
||||
this->primaryScore = primaryScore;
|
||||
this->secondaryScore = secondaryScore;
|
||||
this->tertiaryScore = tertiaryScore;
|
||||
}
|
||||
bool operator<(const Score& rhs) const {
|
||||
return primaryScore < rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore < rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore < rhs.tertiaryScore);
|
||||
}
|
||||
bool operator>(const Score& rhs) const {
|
||||
return primaryScore > rhs.primaryScore || (primaryScore == rhs.primaryScore && secondaryScore > rhs.secondaryScore) || (primaryScore == rhs.primaryScore && secondaryScore == rhs.secondaryScore && tertiaryScore > rhs.tertiaryScore);
|
||||
}
|
||||
void SetPrimaryScore(const float score) { primaryScore = score; }
|
||||
float GetPrimaryScore() const { return primaryScore; }
|
||||
|
||||
void SetSecondaryScore(const float score) { secondaryScore = score; }
|
||||
float GetSecondaryScore() const { return secondaryScore; }
|
||||
|
||||
void SetTertiaryScore(const float score) { tertiaryScore = score; }
|
||||
float GetTertiaryScore() const { return tertiaryScore; }
|
||||
private:
|
||||
float primaryScore;
|
||||
float secondaryScore;
|
||||
float tertiaryScore;
|
||||
};
|
||||
|
||||
using GameID = uint32_t;
|
||||
|
||||
class Leaderboard {
|
||||
public:
|
||||
Leaderboard(uint32_t gameID, uint32_t infoType, bool weekly, std::vector<LeaderboardEntry> entries,
|
||||
LWOOBJID relatedPlayer = LWOOBJID_EMPTY, LeaderboardType = None);
|
||||
std::vector<LeaderboardEntry> GetEntries();
|
||||
[[nodiscard]] std::u16string ToString() const;
|
||||
[[nodiscard]] uint32_t GetGameID() const;
|
||||
[[nodiscard]] uint32_t GetInfoType() const;
|
||||
void Send(LWOOBJID targetID) const;
|
||||
|
||||
// Enums for leaderboards
|
||||
enum InfoType : uint32_t {
|
||||
Top, // Top 11 all time players
|
||||
MyStanding, // Ranking of the current player
|
||||
Friends // Ranking between friends
|
||||
};
|
||||
|
||||
enum Type : uint32_t {
|
||||
ShootingGallery,
|
||||
Racing,
|
||||
MonumentRace,
|
||||
FootRace,
|
||||
UnusedLeaderboard4, // There is no 4 defined anywhere in the cdclient, but it takes a Score.
|
||||
Survival,
|
||||
SurvivalNS,
|
||||
Donations,
|
||||
None
|
||||
};
|
||||
Leaderboard() = delete;
|
||||
Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, LWOOBJID relatedPlayer, const Leaderboard::Type = None);
|
||||
|
||||
~Leaderboard();
|
||||
|
||||
/**
|
||||
* @brief Resets the leaderboard state and frees its allocated memory
|
||||
*
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
/**
|
||||
* Serialize the Leaderboard to a BitStream
|
||||
*
|
||||
* Expensive! Leaderboards are very string intensive so be wary of performatnce calling this method.
|
||||
*/
|
||||
void Serialize(RakNet::BitStream* bitStream) const;
|
||||
|
||||
/**
|
||||
* Builds the leaderboard from the database based on the associated gameID
|
||||
*
|
||||
* @param resultStart The index to start the leaderboard at. Zero indexed.
|
||||
* @param resultEnd The index to end the leaderboard at. Zero indexed.
|
||||
*/
|
||||
void SetupLeaderboard(bool weekly, uint32_t resultStart = 0, uint32_t resultEnd = 10);
|
||||
|
||||
/**
|
||||
* Sends the leaderboard to the client specified by targetID.
|
||||
*/
|
||||
void Send(const LWOOBJID targetID) const;
|
||||
|
||||
// Helper function to get the columns, ordering and insert format for a leaderboard
|
||||
static const std::string_view GetOrdering(Type leaderboardType);
|
||||
private:
|
||||
std::vector<LeaderboardEntry> entries{};
|
||||
// Takes the resulting query from a leaderboard lookup and converts it to the LDF we need
|
||||
// to send it to a client.
|
||||
void QueryToLdf(std::unique_ptr<sql::ResultSet>& rows);
|
||||
|
||||
using LeaderboardEntry = std::vector<LDFBaseData*>;
|
||||
using LeaderboardEntries = std::vector<LeaderboardEntry>;
|
||||
|
||||
LeaderboardEntries entries;
|
||||
LWOOBJID relatedPlayer;
|
||||
uint32_t gameID;
|
||||
uint32_t infoType;
|
||||
LeaderboardType leaderboardType;
|
||||
GameID gameID;
|
||||
InfoType infoType;
|
||||
Leaderboard::Type leaderboardType;
|
||||
bool weekly;
|
||||
};
|
||||
|
||||
class LeaderboardManager {
|
||||
public:
|
||||
static LeaderboardManager* Instance() {
|
||||
if (address == nullptr)
|
||||
address = new LeaderboardManager;
|
||||
return address;
|
||||
}
|
||||
static void SendLeaderboard(uint32_t gameID, InfoType infoType, bool weekly, LWOOBJID targetID,
|
||||
LWOOBJID playerID = LWOOBJID_EMPTY);
|
||||
static Leaderboard* GetLeaderboard(uint32_t gameID, InfoType infoType, bool weekly, LWOOBJID playerID = LWOOBJID_EMPTY);
|
||||
static void SaveScore(LWOOBJID playerID, uint32_t gameID, uint32_t score, uint32_t time);
|
||||
static LeaderboardType GetLeaderboardType(uint32_t gameID);
|
||||
private:
|
||||
static LeaderboardManager* address;
|
||||
namespace LeaderboardManager {
|
||||
void SendLeaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const LWOOBJID playerID, const LWOOBJID targetID, const uint32_t resultStart = 0, const uint32_t resultEnd = 10);
|
||||
|
||||
// Modified 12/12/2021: Existing queries were renamed to be more descriptive.
|
||||
static const std::string topPlayersScoreQuery;
|
||||
static const std::string friendsScoreQuery;
|
||||
static const std::string standingsScoreQuery;
|
||||
static const std::string topPlayersScoreQueryAsc;
|
||||
static const std::string friendsScoreQueryAsc;
|
||||
static const std::string standingsScoreQueryAsc;
|
||||
void SaveScore(const LWOOBJID& playerID, const GameID activityId, const float primaryScore, const float secondaryScore = 0, const float tertiaryScore = 0);
|
||||
|
||||
// Added 12/12/2021: Queries dictated by time are needed for certain minigames.
|
||||
static const std::string topPlayersTimeQuery;
|
||||
static const std::string friendsTimeQuery;
|
||||
static const std::string standingsTimeQuery;
|
||||
static const std::string topPlayersTimeQueryAsc;
|
||||
static const std::string friendsTimeQueryAsc;
|
||||
static const std::string standingsTimeQueryAsc;
|
||||
Leaderboard::Type GetLeaderboardType(const GameID gameID);
|
||||
extern std::map<GameID, Leaderboard::Type> leaderboardCache;
|
||||
};
|
||||
|
||||
#endif //!__LEADERBOARDMANAGER__H__
|
||||
|
||||
@@ -32,7 +32,9 @@ Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Enti
|
||||
m_GhostReferencePoint = NiPoint3::ZERO;
|
||||
m_GhostOverridePoint = NiPoint3::ZERO;
|
||||
m_GhostOverride = false;
|
||||
m_ObservedEntities.reserve(256);
|
||||
m_ObservedEntitiesLength = 256;
|
||||
m_ObservedEntitiesUsed = 0;
|
||||
m_ObservedEntities.resize(m_ObservedEntitiesLength);
|
||||
|
||||
m_Character->SetEntity(this);
|
||||
|
||||
@@ -60,7 +62,7 @@ void Player::SetSystemAddress(const SystemAddress& value) {
|
||||
void Player::SetRespawnPos(const NiPoint3 position) {
|
||||
m_respawnPos = position;
|
||||
|
||||
m_Character->SetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID(), position);
|
||||
m_Character->SetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID(), position);
|
||||
}
|
||||
|
||||
void Player::SetRespawnRot(const NiQuaternion rotation) {
|
||||
@@ -83,7 +85,7 @@ void Player::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) {
|
||||
const auto objid = GetObjectID();
|
||||
|
||||
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, zoneId, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(objid);
|
||||
auto* entity = Game::entityManager->GetEntity(objid);
|
||||
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
@@ -106,30 +108,40 @@ void Player::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) {
|
||||
|
||||
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
|
||||
|
||||
EntityManager::Instance()->DestructEntity(entity);
|
||||
Game::entityManager->DestructEntity(entity);
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
void Player::AddLimboConstruction(LWOOBJID objectId)
|
||||
{
|
||||
m_LimboConstructions.insert(objectId);
|
||||
void Player::AddLimboConstruction(LWOOBJID objectId) {
|
||||
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
||||
|
||||
if (iter != m_LimboConstructions.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_LimboConstructions.push_back(objectId);
|
||||
}
|
||||
|
||||
void Player::RemoveLimboConstruction(LWOOBJID objectId)
|
||||
{
|
||||
m_LimboConstructions.erase(objectId);
|
||||
void Player::RemoveLimboConstruction(LWOOBJID objectId) {
|
||||
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
||||
|
||||
if (iter == m_LimboConstructions.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_LimboConstructions.erase(iter);
|
||||
}
|
||||
|
||||
void Player::ConstructLimboEntities() {
|
||||
for (const auto objectId : m_LimboConstructions) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(objectId);
|
||||
auto* entity = Game::entityManager->GetEntity(objectId);
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(entity, m_SystemAddress);
|
||||
Game::entityManager->ConstructEntity(entity, m_SystemAddress);
|
||||
}
|
||||
|
||||
m_LimboConstructions.clear();
|
||||
@@ -167,19 +179,42 @@ bool Player::GetGhostOverride() const {
|
||||
return m_GhostOverride;
|
||||
}
|
||||
|
||||
void Player::ObserveEntity(int32_t id)
|
||||
{
|
||||
m_ObservedEntities.insert(id);
|
||||
void Player::ObserveEntity(int32_t id) {
|
||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
||||
if (m_ObservedEntities[i] == 0 || m_ObservedEntities[i] == id) {
|
||||
m_ObservedEntities[i] = id;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto index = m_ObservedEntitiesUsed++;
|
||||
|
||||
if (m_ObservedEntitiesUsed > m_ObservedEntitiesLength) {
|
||||
m_ObservedEntities.resize(m_ObservedEntitiesLength + m_ObservedEntitiesLength);
|
||||
|
||||
m_ObservedEntitiesLength = m_ObservedEntitiesLength + m_ObservedEntitiesLength;
|
||||
}
|
||||
|
||||
m_ObservedEntities[index] = id;
|
||||
}
|
||||
|
||||
bool Player::IsObserved(int32_t id)
|
||||
{
|
||||
return m_ObservedEntities.find(id) != m_ObservedEntities.end();
|
||||
bool Player::IsObserved(int32_t id) {
|
||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
||||
if (m_ObservedEntities[i] == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Player::GhostEntity(int32_t id)
|
||||
{
|
||||
m_ObservedEntities.erase(id);
|
||||
void Player::GhostEntity(int32_t id) {
|
||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
||||
if (m_ObservedEntities[i] == id) {
|
||||
m_ObservedEntities[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Player* Player::GetPlayer(const SystemAddress& sysAddr) {
|
||||
@@ -189,7 +224,7 @@ Player* Player::GetPlayer(const SystemAddress& sysAddr) {
|
||||
}
|
||||
|
||||
Player* Player::GetPlayer(const std::string& name) {
|
||||
const auto characters = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
|
||||
const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
|
||||
|
||||
for (auto* character : characters) {
|
||||
if (!character->IsPlayer()) continue;
|
||||
@@ -227,16 +262,19 @@ void Player::SetDroppedCoins(uint64_t value) {
|
||||
Player::~Player() {
|
||||
Game::logger->Log("Player", "Deleted player");
|
||||
|
||||
for (const auto id : m_ObservedEntities)
|
||||
{
|
||||
auto* entity = EntityManager::Instance()->GetGhostCandidate(id);
|
||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++) {
|
||||
const auto id = m_ObservedEntities[i];
|
||||
|
||||
if (id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* entity = Game::entityManager->GetGhostCandidate(id);
|
||||
|
||||
if (entity != nullptr) {
|
||||
entity->SetObservers(entity->GetObservers() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
m_ObservedEntities.clear();
|
||||
|
||||
m_LimboConstructions.clear();
|
||||
|
||||
@@ -247,12 +285,12 @@ Player::~Player() {
|
||||
}
|
||||
|
||||
if (IsPlayer()) {
|
||||
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerExit(zoneControl, this);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
/**
|
||||
* Extended Entity for player data and behavior.
|
||||
*
|
||||
@@ -123,9 +120,13 @@ private:
|
||||
|
||||
bool m_GhostOverride;
|
||||
|
||||
std::unordered_set<int32_t> m_ObservedEntities;
|
||||
std::vector<int32_t> m_ObservedEntities;
|
||||
|
||||
std::set<LWOOBJID> m_LimboConstructions;
|
||||
int32_t m_ObservedEntitiesLength;
|
||||
|
||||
int32_t m_ObservedEntitiesUsed;
|
||||
|
||||
std::vector<LWOOBJID> m_LimboConstructions;
|
||||
|
||||
std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
|
||||
|
||||
|
||||
@@ -40,11 +40,11 @@ LWOOBJID Trade::GetParticipantB() const {
|
||||
}
|
||||
|
||||
Entity* Trade::GetParticipantAEntity() const {
|
||||
return EntityManager::Instance()->GetEntity(m_ParticipantA);
|
||||
return Game::entityManager->GetEntity(m_ParticipantA);
|
||||
}
|
||||
|
||||
Entity* Trade::GetParticipantBEntity() const {
|
||||
return EntityManager::Instance()->GetEntity(m_ParticipantB);
|
||||
return Game::entityManager->GetEntity(m_ParticipantB);
|
||||
}
|
||||
|
||||
void Trade::SetCoins(LWOOBJID participant, uint64_t coins) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <WorldPackets.h>
|
||||
#include "Character.h"
|
||||
#include <BitStream.h>
|
||||
#include "PacketUtils.h"
|
||||
#include "BitstreamUtils.h"
|
||||
#include "../dWorldServer/ObjectIDManager.h"
|
||||
#include "dLogger.h"
|
||||
#include "GeneralUtils.h"
|
||||
@@ -220,7 +220,7 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
|
||||
skillComponent->Reset();
|
||||
}
|
||||
|
||||
EntityManager::Instance()->DestroyEntity(chars[i]->GetEntity());
|
||||
Game::entityManager->DestroyEntity(chars[i]->GetEntity());
|
||||
|
||||
chars[i]->SaveXMLToDatabase();
|
||||
|
||||
@@ -248,30 +248,45 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) {
|
||||
void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet) {
|
||||
User* u = GetUser(sysAddr);
|
||||
if (!u) return;
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LUWString name(33);
|
||||
inStream.Read(name);
|
||||
|
||||
std::string name = PacketUtils::ReadString(8, packet, true);
|
||||
|
||||
uint32_t firstNameIndex = PacketUtils::ReadPacketU32(74, packet);
|
||||
uint32_t middleNameIndex = PacketUtils::ReadPacketU32(78, packet);
|
||||
uint32_t lastNameIndex = PacketUtils::ReadPacketU32(82, packet);
|
||||
uint32_t firstNameIndex;
|
||||
inStream.Read(firstNameIndex);
|
||||
uint32_t middleNameIndex;
|
||||
inStream.Read(middleNameIndex);
|
||||
uint32_t lastNameIndex;
|
||||
inStream.Read(lastNameIndex);
|
||||
std::string predefinedName = GetPredefinedName(firstNameIndex, middleNameIndex, lastNameIndex);
|
||||
|
||||
uint32_t shirtColor = PacketUtils::ReadPacketU32(95, packet);
|
||||
uint32_t shirtStyle = PacketUtils::ReadPacketU32(99, packet);
|
||||
uint32_t pantsColor = PacketUtils::ReadPacketU32(103, packet);
|
||||
uint32_t hairStyle = PacketUtils::ReadPacketU32(107, packet);
|
||||
uint32_t hairColor = PacketUtils::ReadPacketU32(111, packet);
|
||||
uint32_t lh = PacketUtils::ReadPacketU32(115, packet);
|
||||
uint32_t rh = PacketUtils::ReadPacketU32(119, packet);
|
||||
uint32_t eyebrows = PacketUtils::ReadPacketU32(123, packet);
|
||||
uint32_t eyes = PacketUtils::ReadPacketU32(127, packet);
|
||||
uint32_t mouth = PacketUtils::ReadPacketU32(131, packet);
|
||||
inStream.IgnoreBytes(9);
|
||||
uint32_t shirtColor;
|
||||
inStream.Read(shirtColor);
|
||||
uint32_t shirtStyle;
|
||||
inStream.Read(shirtStyle);
|
||||
uint32_t pantsColor;
|
||||
inStream.Read(pantsColor);
|
||||
uint32_t hairStyle;
|
||||
inStream.Read(hairStyle);
|
||||
uint32_t hairColor;
|
||||
inStream.Read(hairColor);
|
||||
uint32_t lh;
|
||||
inStream.Read(lh);
|
||||
uint32_t rh;
|
||||
inStream.Read(rh);
|
||||
uint32_t eyebrows;
|
||||
inStream.Read(eyebrows);
|
||||
uint32_t eyes;
|
||||
inStream.Read(eyes);
|
||||
uint32_t mouth;
|
||||
inStream.Read(mouth);
|
||||
|
||||
LOT shirtLOT = FindCharShirtID(shirtColor, shirtStyle);
|
||||
LOT pantsLOT = FindCharPantsID(pantsColor);
|
||||
|
||||
if (name != "" && !UserManager::IsNameAvailable(name)) {
|
||||
Game::logger->Log("UserManager", "AccountID: %i chose unavailable name: %s", u->GetAccountID(), name.c_str());
|
||||
if (name.GetAsString() != "" && !UserManager::IsNameAvailable(name.GetAsString())) {
|
||||
Game::logger->Log("UserManager", "AccountID: %i chose unavailable name: %s", u->GetAccountID(), name.GetAsString().c_str());
|
||||
WorldPackets::SendCharacterCreationResponse(sysAddr, eCharacterCreationResponse::CUSTOM_NAME_IN_USE);
|
||||
return;
|
||||
}
|
||||
@@ -282,10 +297,10 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
return;
|
||||
}
|
||||
|
||||
if (name == "") {
|
||||
if (name.GetAsString() == "") {
|
||||
Game::logger->Log("UserManager", "AccountID: %i is creating a character with predefined name: %s", u->GetAccountID(), predefinedName.c_str());
|
||||
} else {
|
||||
Game::logger->Log("UserManager", "AccountID: %i is creating a character with name: %s (temporary: %s)", u->GetAccountID(), name.c_str(), predefinedName.c_str());
|
||||
Game::logger->Log("UserManager", "AccountID: %i is creating a character with name: %s (temporary: %s)", u->GetAccountID(), name.GetAsString().c_str(), predefinedName.c_str());
|
||||
}
|
||||
|
||||
//Now that the name is ok, we can get an objectID from Master:
|
||||
@@ -334,20 +349,20 @@ void UserManager::CreateCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
xml3 << "</in></items></inv><lvl l=\"1\" cv=\"1\" sb=\"500\"/><flag></flag></obj>";
|
||||
|
||||
//Check to see if our name was pre-approved:
|
||||
bool nameOk = IsNamePreapproved(name);
|
||||
bool nameOk = IsNamePreapproved(name.GetAsString());
|
||||
if (!nameOk && u->GetMaxGMLevel() > eGameMasterLevel::FORUM_MODERATOR) nameOk = true;
|
||||
|
||||
if (name != "") {
|
||||
if (name.GetAsString() != "") {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`) VALUES (?,?,?,?,?,?)");
|
||||
stmt->setUInt(1, objectID);
|
||||
stmt->setUInt(2, u->GetAccountID());
|
||||
stmt->setString(3, predefinedName.c_str());
|
||||
stmt->setString(4, name.c_str());
|
||||
stmt->setString(4, name.GetAsString().c_str());
|
||||
stmt->setBoolean(5, false);
|
||||
stmt->setUInt64(6, time(NULL));
|
||||
|
||||
if (nameOk) {
|
||||
stmt->setString(3, name.c_str());
|
||||
stmt->setString(3, name.GetAsString().c_str());
|
||||
stmt->setString(4, "");
|
||||
}
|
||||
|
||||
@@ -386,8 +401,9 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
Game::logger->Log("UserManager", "Couldn't get user to delete character");
|
||||
return;
|
||||
}
|
||||
|
||||
LWOOBJID objectID = PacketUtils::ReadPacketS64(8, packet);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID objectID;
|
||||
inStream.Read(objectID);
|
||||
uint32_t charID = static_cast<uint32_t>(objectID);
|
||||
|
||||
Game::logger->Log("UserManager", "Received char delete req for ID: %llu (%u)", objectID, charID);
|
||||
@@ -423,7 +439,7 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
||||
BitstreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::PLAYER_REMOVED_NOTIFICATION);
|
||||
bitStream.Write(objectID);
|
||||
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
|
||||
}
|
||||
@@ -482,15 +498,17 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
Game::logger->Log("UserManager", "Couldn't get user to delete character");
|
||||
return;
|
||||
}
|
||||
|
||||
LWOOBJID objectID = PacketUtils::ReadPacketS64(8, packet);
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
LWOOBJID objectID;
|
||||
inStream.Read(objectID);
|
||||
GeneralUtils::ClearBit(objectID, eObjectBits::CHARACTER);
|
||||
GeneralUtils::ClearBit(objectID, eObjectBits::PERSISTENT);
|
||||
|
||||
uint32_t charID = static_cast<uint32_t>(objectID);
|
||||
Game::logger->Log("UserManager", "Received char rename request for ID: %llu (%u)", objectID, charID);
|
||||
|
||||
std::string newName = PacketUtils::ReadString(16, packet, true);
|
||||
LUWString newName(33);
|
||||
inStream.Read(newName);
|
||||
|
||||
Character* character = nullptr;
|
||||
|
||||
@@ -505,32 +523,32 @@ void UserManager::RenameCharacter(const SystemAddress& sysAddr, Packet* packet)
|
||||
Game::logger->Log("UserManager", "User %i tried to rename a character that it does not own!", u->GetAccountID());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::UNKNOWN_ERROR);
|
||||
} else if (hasCharacter && character) {
|
||||
if (newName == character->GetName()) {
|
||||
if (newName.GetAsString() == character->GetName()) {
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::NAME_UNAVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsNameAvailable(newName)) {
|
||||
if (IsNamePreapproved(newName)) {
|
||||
if (IsNameAvailable(newName.GetAsString())) {
|
||||
if (IsNamePreapproved(newName.GetAsString())) {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charinfo SET name=?, pending_name='', needs_rename=0, last_login=? WHERE id=? LIMIT 1");
|
||||
stmt->setString(1, newName);
|
||||
stmt->setString(1, newName.GetAsString());
|
||||
stmt->setUInt64(2, time(NULL));
|
||||
stmt->setUInt(3, character->GetID());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
Game::logger->Log("UserManager", "Character %s now known as %s", character->GetName().c_str(), newName.c_str());
|
||||
Game::logger->Log("UserManager", "Character %s now known as %s", character->GetName().c_str(), newName.GetAsString().c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
} else {
|
||||
sql::PreparedStatement* stmt = Database::CreatePreppedStmt("UPDATE charinfo SET pending_name=?, needs_rename=0, last_login=? WHERE id=? LIMIT 1");
|
||||
stmt->setString(1, newName);
|
||||
stmt->setString(1, newName.GetAsString());
|
||||
stmt->setUInt64(2, time(NULL));
|
||||
stmt->setUInt(3, character->GetID());
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
|
||||
Game::logger->Log("UserManager", "Character %s has been renamed to %s and is pending approval by a moderator.", character->GetName().c_str(), newName.c_str());
|
||||
Game::logger->Log("UserManager", "Character %s has been renamed to %s and is pending approval by a moderator.", character->GetName().c_str(), newName.GetAsString().c_str());
|
||||
WorldPackets::SendCharacterRenameResponse(sysAddr, eRenameResponse::SUCCESS);
|
||||
UserManager::RequestCharacterList(sysAddr);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ void AirMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
auto* behavior = CreateBehavior(behaviorId);
|
||||
|
||||
if (EntityManager::Instance()->GetEntity(target) != nullptr) {
|
||||
if (Game::entityManager->GetEntity(target) != nullptr) {
|
||||
branch.target = target;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target == LWOOBJID_EMPTY ? context->originator : branch.target);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
|
||||
@@ -19,7 +19,7 @@ void ApplyBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
}
|
||||
|
||||
void ApplyBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void AreaOfEffectBehavior::Handle(BehaviorContext* context, RakNet::BitStream* b
|
||||
}
|
||||
|
||||
void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto* self = Game::entityManager->GetEntity(context->caster);
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("AreaOfEffectBehavior", "Invalid self for (%llu)!", context->originator);
|
||||
|
||||
@@ -58,7 +58,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
|
||||
|
||||
std::vector<Entity*> targets;
|
||||
|
||||
auto* presetTarget = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* presetTarget = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (presetTarget != nullptr) {
|
||||
if (this->m_radius * this->m_radius >= Vector3::DistanceSquared(reference, presetTarget->GetPosition())) {
|
||||
@@ -75,7 +75,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
|
||||
|
||||
// Gets all of the valid targets, passing in if should target enemies and friends
|
||||
for (auto validTarget : context->GetValidTargets(m_ignoreFaction, includeFaction, m_TargetSelf == 1, m_targetEnemy == 1, m_targetFriend == 1)) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(validTarget);
|
||||
auto* entity = Game::entityManager->GetEntity(validTarget);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("AreaOfEffectBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
void BasicAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (context->unmanaged) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
if (destroyableComponent != nullptr) {
|
||||
@@ -38,7 +38,7 @@ void BasicAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bi
|
||||
}
|
||||
|
||||
void BasicAttackBehavior::DoHandleBehavior(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(branch.target);
|
||||
if (!targetEntity) {
|
||||
Game::logger->Log("BasicAttackBehavior", "Target targetEntity %llu not found.", branch.target);
|
||||
return;
|
||||
@@ -61,7 +61,7 @@ void BasicAttackBehavior::DoHandleBehavior(BehaviorContext* context, RakNet::Bit
|
||||
|
||||
if (isBlocked) {
|
||||
destroyableComponent->SetAttacksToBlock(std::min(destroyableComponent->GetAttacksToBlock() - 1, 0U));
|
||||
EntityManager::Instance()->SerializeEntity(targetEntity);
|
||||
Game::entityManager->SerializeEntity(targetEntity);
|
||||
this->m_OnFailBlocked->Handle(context, bitStream, branch);
|
||||
return;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ void BasicAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream*
|
||||
}
|
||||
|
||||
void BasicAttackBehavior::DoBehaviorCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(branch.target);
|
||||
if (!targetEntity) {
|
||||
Game::logger->Log("BasicAttackBehavior", "Target entity %llu is null!", branch.target);
|
||||
return;
|
||||
@@ -173,7 +173,7 @@ void BasicAttackBehavior::DoBehaviorCalculation(BehaviorContext* context, RakNet
|
||||
|
||||
if (isBlocking) {
|
||||
destroyableComponent->SetAttacksToBlock(destroyableComponent->GetAttacksToBlock() - 1);
|
||||
EntityManager::Instance()->SerializeEntity(targetEntity);
|
||||
Game::entityManager->SerializeEntity(targetEntity);
|
||||
this->m_OnFailBlocked->Calculate(context, bitStream, branch);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include "SpeedBehavior.h"
|
||||
#include "DamageReductionBehavior.h"
|
||||
#include "JetPackBehavior.h"
|
||||
#include "FallSpeedBehavior.h"
|
||||
#include "ChangeIdleFlagsBehavior.h"
|
||||
#include "DarkInspirationBehavior.h"
|
||||
|
||||
@@ -164,7 +165,9 @@ Behavior* Behavior::CreateBehavior(const uint32_t behaviorId) {
|
||||
case BehaviorTemplates::BEHAVIOR_CAR_BOOST:
|
||||
behavior = new CarBoostBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_FALL_SPEED: break;
|
||||
case BehaviorTemplates::BEHAVIOR_FALL_SPEED:
|
||||
behavior = new FallSpeedBehavior(behaviorId);
|
||||
break;
|
||||
case BehaviorTemplates::BEHAVIOR_SHIELD: break;
|
||||
case BehaviorTemplates::BEHAVIOR_REPAIR_ARMOR:
|
||||
behavior = new RepairBehavior(behaviorId);
|
||||
@@ -311,7 +314,7 @@ BehaviorTemplates Behavior::GetBehaviorTemplate(const uint32_t behaviorId) {
|
||||
|
||||
// For use with enemies, to display the correct damage animations on the players
|
||||
void Behavior::PlayFx(std::u16string type, const LWOOBJID target, const LWOOBJID secondary) {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (targetEntity == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Game.h"
|
||||
#include "dLogger.h"
|
||||
#include "dServer.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitstreamUtils.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -27,7 +27,7 @@ BehaviorEndEntry::BehaviorEndEntry() {
|
||||
}
|
||||
|
||||
uint32_t BehaviorContext::GetUniqueSkillId() const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(this->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(this->originator);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BehaviorContext", "Invalid entity for (%llu)!", this->originator);
|
||||
@@ -94,11 +94,11 @@ void BehaviorContext::ScheduleUpdate(const LWOOBJID id) {
|
||||
|
||||
void BehaviorContext::ExecuteUpdates() {
|
||||
for (const auto& id : this->scheduledUpdates) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
||||
auto* entity = Game::entityManager->GetEntity(id);
|
||||
|
||||
if (entity == nullptr) continue;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
this->scheduledUpdates.clear();
|
||||
@@ -253,7 +253,7 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime) {
|
||||
// Write message
|
||||
RakNet::BitStream message;
|
||||
|
||||
PacketUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
BitstreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
message.Write(this->originator);
|
||||
echo.Serialize(&message);
|
||||
|
||||
@@ -308,7 +308,7 @@ void BehaviorContext::Reset() {
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf, bool targetEnemy, bool targetFriend) const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(this->caster);
|
||||
auto* entity = Game::entityManager->GetEntity(this->caster);
|
||||
|
||||
std::vector<LWOOBJID> targets;
|
||||
|
||||
@@ -320,7 +320,7 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
|
||||
|
||||
if (!ignoreFaction && !includeFaction) {
|
||||
for (auto entry : entity->GetTargetsInPhantom()) {
|
||||
auto* instance = EntityManager::Instance()->GetEntity(entry);
|
||||
auto* instance = Game::entityManager->GetEntity(entry);
|
||||
|
||||
if (instance == nullptr) {
|
||||
continue;
|
||||
@@ -336,7 +336,7 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
|
||||
return targets;
|
||||
}
|
||||
|
||||
auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS);
|
||||
auto entities = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS);
|
||||
for (auto* candidate : entities) {
|
||||
const auto id = candidate->GetObjectID();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
void BlockBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -40,7 +40,7 @@ void BlockBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
void BlockBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
const auto target = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
||||
@@ -30,7 +30,7 @@ void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
component->SetMaxArmor(component->GetMaxArmor() + this->m_armor);
|
||||
component->SetMaxImagination(component->GetMaxImagination() + this->m_imagination);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
|
||||
if (!context->unmanaged) {
|
||||
if (branch.duration > 0) {
|
||||
@@ -44,7 +44,7 @@ void BuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
const auto target = branch.target != LWOOBJID_EMPTY ? branch.target : context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BuffBehavior", "Invalid target (%llu)!", target);
|
||||
@@ -64,7 +64,7 @@ void BuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch
|
||||
component->SetMaxArmor(component->GetMaxArmor() - this->m_armor);
|
||||
component->SetMaxImagination(component->GetMaxImagination() - this->m_imagination);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
void BuffBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, LWOOBJID second) {
|
||||
|
||||
@@ -22,6 +22,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
||||
"DurationBehavior.cpp"
|
||||
"EmptyBehavior.cpp"
|
||||
"EndBehavior.cpp"
|
||||
"FallSpeedBehavior.cpp"
|
||||
"ForceMovementBehavior.cpp"
|
||||
"HealBehavior.cpp"
|
||||
"ImaginationBehavior.cpp"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
GameMessages::SendVehicleAddPassiveBoostAction(branch.target, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
@@ -22,7 +22,7 @@ void CarBoostBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
auto* possessableComponent = entity->GetComponent<PossessableComponent>();
|
||||
if (possessableComponent != nullptr) {
|
||||
|
||||
auto* possessor = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
|
||||
auto* possessor = Game::entityManager->GetEntity(possessableComponent->GetPossessor());
|
||||
if (possessor != nullptr) {
|
||||
|
||||
auto* characterComponent = possessor->GetComponent<CharacterComponent>();
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
|
||||
void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Entity* sourceEntity;
|
||||
if (this->m_orientCaster) sourceEntity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
else sourceEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
if (this->m_orientCaster) sourceEntity = Game::entityManager->GetEntity(context->originator);
|
||||
else sourceEntity = Game::entityManager->GetEntity(branch.target);
|
||||
if (!sourceEntity) return;
|
||||
|
||||
if (this->m_toTarget) {
|
||||
Entity* destinationEntity;
|
||||
if (this->m_orientCaster) destinationEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
else destinationEntity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
if (this->m_orientCaster) destinationEntity = Game::entityManager->GetEntity(branch.target);
|
||||
else destinationEntity = Game::entityManager->GetEntity(context->originator);
|
||||
if (!destinationEntity) return;
|
||||
|
||||
sourceEntity->SetRotation(
|
||||
@@ -23,7 +23,7 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS
|
||||
if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector();
|
||||
sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle));
|
||||
} else return;
|
||||
EntityManager::Instance()->SerializeEntity(sourceEntity);
|
||||
Game::entityManager->SerializeEntity(sourceEntity);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void DamageAbsorptionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -34,7 +34,7 @@ void DamageAbsorptionBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
}
|
||||
|
||||
void DamageAbsorptionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
auto* target = Game::entityManager->GetEntity(second);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
void DamageReductionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageReductionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -32,7 +32,7 @@ void DamageReductionBehavior::Calculate(BehaviorContext* context, RakNet::BitStr
|
||||
}
|
||||
|
||||
void DamageReductionBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
auto* target = Game::entityManager->GetEntity(second);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("DamageReductionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "BehaviorContext.h"
|
||||
|
||||
void DarkInspirationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->LogDebug("DarkInspirationBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -26,7 +26,7 @@ void DarkInspirationBehavior::Handle(BehaviorContext* context, RakNet::BitStream
|
||||
}
|
||||
|
||||
void DarkInspirationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->LogDebug("DarkInspirationBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
50
dGame/dBehaviors/FallSpeedBehavior.cpp
Normal file
50
dGame/dBehaviors/FallSpeedBehavior.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "FallSpeedBehavior.h"
|
||||
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "BehaviorContext.h"
|
||||
#include "BehaviorBranchContext.h"
|
||||
|
||||
|
||||
void FallSpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
// make sure required parameter has non-default value
|
||||
if (m_PercentSlowed == 0.0f) return;
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
controllablePhysicsComponent->SetGravityScale(m_PercentSlowed);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0.0f) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
} else if (branch.start > 0) {
|
||||
context->RegisterEndBehavior(this, branch);
|
||||
}
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
Handle(context, bitStream, branch);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
End(context, branch, second);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
End(context, branch, LWOOBJID_EMPTY);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
controllablePhysicsComponent->SetGravityScale(1);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void FallSpeedBehavior::Load(){
|
||||
m_PercentSlowed = GetFloat("percent_slowed");
|
||||
}
|
||||
18
dGame/dBehaviors/FallSpeedBehavior.h
Normal file
18
dGame/dBehaviors/FallSpeedBehavior.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "Behavior.h"
|
||||
|
||||
class FallSpeedBehavior final : public Behavior
|
||||
{
|
||||
public:
|
||||
explicit FallSpeedBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
|
||||
|
||||
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
|
||||
void Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
void End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) override;
|
||||
void UnCast(BehaviorContext* context, BehaviorBranchContext branch) override;
|
||||
void Load() override;
|
||||
|
||||
private:
|
||||
float m_PercentSlowed;
|
||||
};
|
||||
@@ -42,7 +42,7 @@ void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStrea
|
||||
return;
|
||||
}
|
||||
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto* casterEntity = Game::entityManager->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
@@ -51,7 +51,7 @@ void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStrea
|
||||
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
Game::entityManager->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void ForceMovementBehavior::Load() {
|
||||
}
|
||||
|
||||
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto* casterEntity = Game::entityManager->GetEntity(context->caster);
|
||||
if (casterEntity != nullptr) {
|
||||
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
@@ -80,7 +80,7 @@ void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::Bi
|
||||
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
|
||||
controllablePhysicsComponent->SetVelocity({});
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(casterEntity);
|
||||
Game::entityManager->SerializeEntity(casterEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
void HealBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("HealBehavior", "Failed to find entity for (%llu)!", branch.target);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
void ImaginationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
void ImmunityBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (!target) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -56,7 +56,7 @@ void ImmunityBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bi
|
||||
}
|
||||
|
||||
void ImmunityBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(second);
|
||||
auto* target = Game::entityManager->GetEntity(second);
|
||||
|
||||
if (!target) {
|
||||
Game::logger->Log("DamageAbsorptionBehavior", "Failed to find target (%llu)!", second);
|
||||
|
||||
@@ -42,7 +42,7 @@ void InterruptBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
|
||||
if (branch.target == context->originator) return;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) return;
|
||||
|
||||
@@ -67,7 +67,7 @@ void InterruptBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* b
|
||||
|
||||
if (branch.target == context->originator) return;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) return;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "Character.h"
|
||||
|
||||
void JetPackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
GameMessages::SendSetJetPackMode(entity, true, this->m_BypassChecks, this->m_EnableHover, this->m_effectId, this->m_Airspeed, this->m_MaxAirspeed, this->m_VerticalVelocity, this->m_WarningEffectID);
|
||||
|
||||
@@ -20,7 +20,7 @@ void JetPackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_st
|
||||
}
|
||||
|
||||
void JetPackBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
GameMessages::SendSetJetPackMode(entity, false);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void KnockbackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
void KnockbackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
bool blocked = false;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr) {
|
||||
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "LootBuffBehavior.h"
|
||||
|
||||
void LootBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto target = Game::entityManager->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->AddPickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0) context->RegisterTimerBehavior(this, branch);
|
||||
|
||||
@@ -19,14 +19,14 @@ void LootBuffBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bi
|
||||
}
|
||||
|
||||
void LootBuffBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
auto target = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto target = Game::entityManager->GetEntity(context->caster);
|
||||
if (!target) return;
|
||||
|
||||
auto controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->RemovePickupRadiusScale(m_Scale);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void LootBuffBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
void OverTimeBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
const auto originator = context->originator;
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
auto* entity = Game::entityManager->GetEntity(originator);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
|
||||
for (size_t i = 0; i < m_NumIntervals; i++) {
|
||||
entity->AddCallbackTimer((i + 1) * m_Delay, [originator, branch, this]() {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(originator);
|
||||
auto* entity = Game::entityManager->GetEntity(originator);
|
||||
|
||||
if (entity == nullptr) return;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
return;
|
||||
};
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find originator (%llu)!", context->originator);
|
||||
@@ -40,7 +40,7 @@ void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
};
|
||||
}
|
||||
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(target);
|
||||
|
||||
for (auto i = 0u; i < this->m_projectileCount; ++i) {
|
||||
LWOOBJID projectileId{};
|
||||
@@ -61,7 +61,7 @@ void ProjectileAttackBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
bitStream->Write(branch.target);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Failed to find originator (%llu)!", context->originator);
|
||||
@@ -78,7 +78,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt
|
||||
|
||||
}
|
||||
|
||||
auto* other = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* other = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (other == nullptr) {
|
||||
Game::logger->Log("ProjectileAttackBehavior", "Invalid projectile target (%llu)!", branch.target);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "dZoneManager.h"
|
||||
|
||||
void PropertyTeleportBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto* caster = Game::entityManager->GetEntity(context->caster);
|
||||
if (!caster) return;
|
||||
|
||||
auto* character = caster->GetCharacter();
|
||||
@@ -23,16 +23,16 @@ void PropertyTeleportBehavior::Handle(BehaviorContext* context, RakNet::BitStrea
|
||||
LWOMAPID targetMapId = m_MapId;
|
||||
LWOCLONEID targetCloneId = character->GetPropertyCloneID();
|
||||
|
||||
if (dZoneManager::Instance()->GetZoneID().GetCloneID() == character->GetPropertyCloneID()) {
|
||||
if (Game::zoneManager->GetZoneID().GetCloneID() == character->GetPropertyCloneID()) {
|
||||
targetMapId = character->GetLastNonInstanceZoneID();
|
||||
targetCloneId = 0;
|
||||
} else {
|
||||
character->SetLastNonInstanceZoneID(dZoneManager::Instance()->GetZoneID().GetMapID());
|
||||
character->SetLastNonInstanceZoneID(Game::zoneManager->GetZoneID().GetMapID());
|
||||
}
|
||||
|
||||
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, targetMapId, targetCloneId, false, [objId](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(objId);
|
||||
auto* entity = Game::entityManager->GetEntity(objId);
|
||||
if (!entity) return;
|
||||
|
||||
const auto sysAddr = entity->GetSystemAddress();
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "MovementAIComponent.h"
|
||||
|
||||
void PullToPointBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr || target == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "BuffComponent.h"
|
||||
|
||||
void RemoveBuffBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->caster);
|
||||
auto* entity = Game::entityManager->GetEntity(context->caster);
|
||||
if (!entity) return;
|
||||
|
||||
auto* buffComponent = entity->GetComponent<BuffComponent>();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
void RepairBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("RepairBehavior", "Failed to find entity for (%llu)!", branch.target);
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "CppScripts.h"
|
||||
|
||||
void SkillEventBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
auto* caster = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
@@ -17,8 +17,8 @@ void SkillEventBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit
|
||||
|
||||
void
|
||||
SkillEventBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* caster = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
auto* caster = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* origin = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* origin = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (origin == nullptr) {
|
||||
Game::logger->Log("SpawnBehavior", "Failed to find self entity (%llu)!", context->originator);
|
||||
@@ -21,7 +21,7 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
}
|
||||
|
||||
if (branch.isProjectile) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr) {
|
||||
origin = target;
|
||||
@@ -38,10 +38,10 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
info.spawnerNodeID = 0;
|
||||
info.pos = info.pos + (info.rot.GetForwardVector() * m_Distance);
|
||||
|
||||
auto* entity = EntityManager::Instance()->CreateEntity(
|
||||
auto* entity = Game::entityManager->CreateEntity(
|
||||
info,
|
||||
nullptr,
|
||||
EntityManager::Instance()->GetEntity(context->originator)
|
||||
Game::entityManager->GetEntity(context->originator)
|
||||
);
|
||||
|
||||
if (entity == nullptr) {
|
||||
@@ -59,7 +59,7 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
rebuildComponent->SetRepositionPlayer(false);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(entity);
|
||||
Game::entityManager->ConstructEntity(entity);
|
||||
|
||||
if (branch.duration > 0) {
|
||||
context->RegisterTimerBehavior(this, branch, entity->GetObjectID());
|
||||
@@ -79,7 +79,7 @@ void SpawnBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitSt
|
||||
}
|
||||
|
||||
void SpawnBehavior::Timer(BehaviorContext* context, const BehaviorBranchContext branch, const LWOOBJID second) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(second);
|
||||
auto* entity = Game::entityManager->GetEntity(second);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("SpawnBehavior", "Failed to find spawned entity (%llu)!", second);
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
void SpeedBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
if (m_AffectsCaster) branch.target = context->caster;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->AddSpeedboost(m_RunSpeed);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
|
||||
if (branch.duration > 0.0f) {
|
||||
context->RegisterTimerBehavior(this, branch);
|
||||
@@ -38,14 +38,14 @@ void SpeedBehavior::Timer(BehaviorContext* context, BehaviorBranchContext branch
|
||||
}
|
||||
|
||||
void SpeedBehavior::End(BehaviorContext* context, BehaviorBranchContext branch, LWOOBJID second) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
if (!target) return;
|
||||
|
||||
auto* controllablePhysicsComponent = target->GetComponent<ControllablePhysicsComponent>();
|
||||
if (!controllablePhysicsComponent) return;
|
||||
|
||||
controllablePhysicsComponent->RemoveSpeedboost(m_RunSpeed);
|
||||
EntityManager::Instance()->SerializeEntity(target);
|
||||
Game::entityManager->SerializeEntity(target);
|
||||
}
|
||||
|
||||
void SpeedBehavior::Load() {
|
||||
|
||||
@@ -21,7 +21,7 @@ void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
return;
|
||||
};
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("StunBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -44,7 +44,7 @@ void StunBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream
|
||||
|
||||
void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
|
||||
if (this->m_stunCaster || branch.target == context->originator) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* self = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("StunBehavior", "Invalid self entity (%llu)!", context->originator);
|
||||
@@ -69,7 +69,7 @@ void StunBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStr
|
||||
|
||||
bool blocked = false;
|
||||
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target != nullptr) {
|
||||
auto* destroyableComponent = target->GetComponent<DestroyableComponent>();
|
||||
|
||||
@@ -16,7 +16,7 @@ void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
};
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* entity = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (entity == nullptr) {
|
||||
return;
|
||||
@@ -30,7 +30,7 @@ void SwitchBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
|
||||
Game::logger->LogDebug("SwitchBehavior", "[%i] State: (%d), imagination: (%i) / (%f)", entity->GetLOT(), state, destroyableComponent->GetImagination(), destroyableComponent->GetMaxImagination());
|
||||
|
||||
if (state || (entity->GetLOT() == 8092 && destroyableComponent->GetImagination() >= m_imagination)) {
|
||||
if (state) {
|
||||
this->m_actionTrue->Handle(context, bitStream, branch);
|
||||
} else {
|
||||
this->m_actionFalse->Handle(context, bitStream, branch);
|
||||
@@ -41,7 +41,7 @@ void SwitchBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
auto state = true;
|
||||
|
||||
if (this->m_imagination > 0 || !this->m_isEnemyFaction) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
state = entity != nullptr;
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ void TacArcBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStre
|
||||
}
|
||||
|
||||
void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* self = Game::entityManager->GetEntity(context->originator);
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid self for (%llu)!", context->originator);
|
||||
return;
|
||||
@@ -85,7 +85,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
const auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
||||
|
||||
if ((this->m_usePickedTarget || context->clientInitalized) && branch.target > 0) {
|
||||
const auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
const auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
return;
|
||||
@@ -120,7 +120,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
// Find all valid targets, based on whether we target enemies or friends
|
||||
for (const auto& contextTarget : context->GetValidTargets()) {
|
||||
if (destroyableComponent != nullptr) {
|
||||
const auto* targetEntity = EntityManager::Instance()->GetEntity(contextTarget);
|
||||
const auto* targetEntity = Game::entityManager->GetEntity(contextTarget);
|
||||
|
||||
if (m_targetEnemy && destroyableComponent->IsEnemy(targetEntity)
|
||||
|| m_targetFriend && destroyableComponent->IsFriend(targetEntity)) {
|
||||
@@ -136,7 +136,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitS
|
||||
break;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(validTarget);
|
||||
auto* entity = Game::entityManager->GetEntity(validTarget);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("TacArcBehavior", "Invalid target (%llu) for (%llu)!", validTarget, context->originator);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
void TauntBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("TauntBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
@@ -23,7 +23,7 @@ void TauntBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStrea
|
||||
}
|
||||
|
||||
void TauntBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (target == nullptr) {
|
||||
Game::logger->Log("TauntBehavior", "Failed to find target (%llu)!", branch.target);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
void VentureVisionBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
|
||||
const auto targetEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
const auto targetEntity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (targetEntity) {
|
||||
auto characterComponent = targetEntity->GetComponent<CharacterComponent>();
|
||||
@@ -21,7 +21,7 @@ void VentureVisionBehavior::Handle(BehaviorContext* context, RakNet::BitStream*
|
||||
}
|
||||
|
||||
void VentureVisionBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) {
|
||||
const auto targetEntity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
const auto targetEntity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
if (targetEntity) {
|
||||
auto characterComponent = targetEntity->GetComponent<CharacterComponent>();
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
|
||||
|
||||
void VerifyBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(branch.target);
|
||||
auto* entity = Game::entityManager->GetEntity(branch.target);
|
||||
|
||||
auto success = true;
|
||||
|
||||
if (entity == nullptr) {
|
||||
success = false;
|
||||
} else if (this->m_rangeCheck) {
|
||||
auto* self = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* self = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (self == nullptr) {
|
||||
Game::logger->Log("VerifyBehavior", "Invalid self for (%llu)", context->originator);
|
||||
|
||||
@@ -173,7 +173,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (m_SoftTimer <= 0.0f) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
m_SoftTimer = 5.0f;
|
||||
} else {
|
||||
@@ -305,7 +305,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (serilizationRequired) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 6270, u"tether", "tether");
|
||||
@@ -318,7 +318,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
// Speed towards start position
|
||||
if (m_MovementAI != nullptr) {
|
||||
m_MovementAI->SetHaltDistance(0);
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
}
|
||||
|
||||
@@ -382,8 +382,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
}
|
||||
|
||||
LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
//const auto reference = m_MovementAI == nullptr ? m_StartPosition : m_MovementAI->ApproximateLocation();
|
||||
|
||||
NiPoint3 reference = m_StartPosition;
|
||||
|
||||
if (m_MovementAI) reference = m_MovementAI->ApproximateLocation();
|
||||
@@ -412,7 +410,7 @@ LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
float biggestThreat = 0;
|
||||
|
||||
for (const auto& entry : possibleTargets) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(entry);
|
||||
auto* entity = Game::entityManager->GetEntity(entry);
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
@@ -458,7 +456,7 @@ LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
std::vector<LWOOBJID> deadThreats{};
|
||||
|
||||
for (const auto& threatTarget : m_ThreatEntries) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(threatTarget.first);
|
||||
auto* entity = Game::entityManager->GetEntity(threatTarget.first);
|
||||
|
||||
if (entity == nullptr) {
|
||||
deadThreats.push_back(threatTarget.first);
|
||||
@@ -497,7 +495,7 @@ std::vector<LWOOBJID> BaseCombatAIComponent::GetTargetWithinAggroRange() const {
|
||||
std::vector<LWOOBJID> targets;
|
||||
|
||||
for (auto id : m_Parent->GetTargetsInPhantom()) {
|
||||
auto* other = EntityManager::Instance()->GetEntity(id);
|
||||
auto* other = Game::entityManager->GetEntity(id);
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(m_Parent->GetPosition(), other->GetPosition());
|
||||
|
||||
@@ -535,11 +533,11 @@ void BaseCombatAIComponent::SetAiState(AiState newState) {
|
||||
if (newState == this->m_State) return;
|
||||
this->m_State = newState;
|
||||
m_DirtyStateOrTarget = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
bool BaseCombatAIComponent::IsEnemy(LWOOBJID target) const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BaseCombatAIComponent", "Invalid entity for checking validity (%llu)!", target);
|
||||
@@ -588,11 +586,11 @@ void BaseCombatAIComponent::SetTarget(const LWOOBJID target) {
|
||||
if (this->m_Target == target) return;
|
||||
m_Target = target;
|
||||
m_DirtyStateOrTarget = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
Entity* BaseCombatAIComponent::GetTargetEntity() const {
|
||||
return EntityManager::Instance()->GetEntity(m_Target);
|
||||
return Game::entityManager->GetEntity(m_Target);
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::Taunt(LWOOBJID offender, float threat) {
|
||||
@@ -660,17 +658,17 @@ void BaseCombatAIComponent::Wander() {
|
||||
destination.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(destination);
|
||||
}
|
||||
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetCurrentPosition()) < 2 * 2) {
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetParent()->GetPosition()) < 2 * 2) {
|
||||
m_MovementAI->Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_MovementAI->SetSpeed(m_TetherSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_TetherSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(destination);
|
||||
|
||||
m_Timer += (m_MovementAI->GetCurrentPosition().x - destination.x) / m_TetherSpeed;
|
||||
m_Timer += (m_MovementAI->GetParent()->GetPosition().x - destination.x) / m_TetherSpeed;
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::OnAggro() {
|
||||
@@ -685,21 +683,21 @@ void BaseCombatAIComponent::OnAggro() {
|
||||
m_MovementAI->SetHaltDistance(m_AttackRadius);
|
||||
|
||||
NiPoint3 targetPos = target->GetPosition();
|
||||
NiPoint3 currentPos = m_MovementAI->GetCurrentPosition();
|
||||
NiPoint3 currentPos = m_MovementAI->GetParent()->GetPosition();
|
||||
|
||||
// If the player's position is within range, attack
|
||||
if (Vector3::DistanceSquared(currentPos, targetPos) <= m_AttackRadius * m_AttackRadius) {
|
||||
m_MovementAI->Stop();
|
||||
} else if (Vector3::DistanceSquared(m_StartPosition, targetPos) > m_HardTetherRadius * m_HardTetherRadius) //Return to spawn if we're too far
|
||||
{
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
} else //Chase the player's new position
|
||||
{
|
||||
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
||||
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(targetPos);
|
||||
|
||||
@@ -725,7 +723,7 @@ void BaseCombatAIComponent::OnTether() {
|
||||
m_MovementAI->Stop();
|
||||
} else if (Vector3::DistanceSquared(m_StartPosition, targetPos) > m_HardTetherRadius * m_HardTetherRadius) //Return to spawn if we're too far
|
||||
{
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
|
||||
@@ -733,7 +731,7 @@ void BaseCombatAIComponent::OnTether() {
|
||||
} else {
|
||||
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
||||
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(targetPos);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ Entity* BouncerComponent::GetParentEntity() const {
|
||||
void BouncerComponent::SetPetEnabled(bool value) {
|
||||
m_PetEnabled = value;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
@@ -44,7 +44,7 @@ void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
|
||||
GameMessages::SendBouncerActiveStatus(m_Parent->GetObjectID(), value, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
if (value) {
|
||||
m_Parent->TriggerEvent(eTriggerEventType::PET_ON_SWITCH, m_Parent);
|
||||
@@ -68,7 +68,7 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
const auto& groups = m_Parent->GetGroups();
|
||||
|
||||
for (const auto& group : groups) {
|
||||
const auto& entities = EntityManager::Instance()->GetEntitiesInGroup(group);
|
||||
const auto& entities = Game::entityManager->GetEntitiesInGroup(group);
|
||||
|
||||
for (auto* entity : entities) {
|
||||
auto* switchComponent = entity->GetComponent<SwitchComponent>();
|
||||
@@ -79,7 +79,7 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
m_PetSwitchLoaded = true;
|
||||
m_PetEnabled = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
Game::logger->Log("BouncerComponent", "Loaded pet bouncer");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ BuildBorderComponent::~BuildBorderComponent() {
|
||||
|
||||
void BuildBorderComponent::OnUse(Entity* originator) {
|
||||
if (originator->GetCharacter()) {
|
||||
const auto& entities = EntityManager::Instance()->GetEntitiesInGroup("PropertyPlaque");
|
||||
const auto& entities = Game::entityManager->GetEntitiesInGroup("PropertyPlaque");
|
||||
|
||||
auto buildArea = m_Parent->GetObjectID();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
|
||||
"Component.cpp"
|
||||
"ControllablePhysicsComponent.cpp"
|
||||
"DestroyableComponent.cpp"
|
||||
"DonationVendorComponent.cpp"
|
||||
"InventoryComponent.cpp"
|
||||
"LevelProgressionComponent.cpp"
|
||||
"LUPExhibitComponent.cpp"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "VehiclePhysicsComponent.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Item.h"
|
||||
#include "AMFFormat.h"
|
||||
#include "Amf3.h"
|
||||
#include "eGameMasterLevel.h"
|
||||
#include "eGameActivity.h"
|
||||
|
||||
@@ -419,7 +419,7 @@ void CharacterComponent::TrackMissionCompletion(bool isAchievement) {
|
||||
|
||||
// Achievements are tracked separately for the zone
|
||||
if (isAchievement) {
|
||||
const auto mapID = dZoneManager::Instance()->GetZoneID().GetMapID();
|
||||
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
|
||||
GetZoneStatisticsForMap(mapID).m_AchievementsCollected++;
|
||||
}
|
||||
}
|
||||
@@ -480,7 +480,7 @@ void CharacterComponent::TrackArmorDelta(int32_t armor) {
|
||||
void CharacterComponent::TrackRebuildComplete() {
|
||||
UpdatePlayerStatistic(QuickBuildsCompleted);
|
||||
|
||||
const auto mapID = dZoneManager::Instance()->GetZoneID().GetMapID();
|
||||
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
|
||||
GetZoneStatisticsForMap(mapID).m_QuickBuildsCompleted++;
|
||||
}
|
||||
|
||||
@@ -734,6 +734,6 @@ void CharacterComponent::RemoveVentureVisionEffect(std::string ventureVisionType
|
||||
void CharacterComponent::UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const {
|
||||
if (!m_Parent) return;
|
||||
AMFArrayValue arrayToSend;
|
||||
arrayToSend.InsertValue(ventureVisionType, showFaction ? static_cast<AMFValue*>(new AMFTrueValue()) : static_cast<AMFValue*>(new AMFFalseValue()));
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", &arrayToSend);
|
||||
arrayToSend.Insert(ventureVisionType, showFaction);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", arrayToSend);
|
||||
}
|
||||
|
||||
@@ -276,6 +276,10 @@ public:
|
||||
*/
|
||||
void UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const;
|
||||
|
||||
void SetCurrentInteracting(LWOOBJID objectID) {m_CurrentInteracting = objectID;};
|
||||
|
||||
LWOOBJID GetCurrentInteracting() {return m_CurrentInteracting;};
|
||||
|
||||
/**
|
||||
* Character info regarding this character, including clothing styles, etc.
|
||||
*/
|
||||
@@ -560,6 +564,8 @@ private:
|
||||
* ID of the last rocket used
|
||||
*/
|
||||
LWOOBJID m_LastRocketItemID = LWOOBJID_EMPTY;
|
||||
|
||||
LWOOBJID m_CurrentInteracting = LWOOBJID_EMPTY;
|
||||
};
|
||||
|
||||
#endif // CHARACTERCOMPONENT_H
|
||||
|
||||
@@ -194,7 +194,7 @@ void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto zoneInfo = dZoneManager::Instance()->GetZone()->GetZoneID();
|
||||
auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0) {
|
||||
character->SetAttribute("lzx", m_Position.x);
|
||||
@@ -300,7 +300,7 @@ void ControllablePhysicsComponent::RemovePickupRadiusScale(float value) {
|
||||
auto candidateRadius = m_ActivePickupRadiusScales[i];
|
||||
if (m_PickupRadius < candidateRadius) m_PickupRadius = candidateRadius;
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::AddSpeedboost(float value) {
|
||||
@@ -320,14 +320,14 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
|
||||
|
||||
// Recalculate speedboost since we removed one
|
||||
m_SpeedBoost = 0.0f;
|
||||
if (m_ActiveSpeedBoosts.size() == 0) { // no active speed boosts left, so return to base speed
|
||||
if (m_ActiveSpeedBoosts.empty()) { // no active speed boosts left, so return to base speed
|
||||
auto* levelProgressionComponent = m_Parent->GetComponent<LevelProgressionComponent>();
|
||||
if (levelProgressionComponent) m_SpeedBoost = levelProgressionComponent->GetSpeedBase();
|
||||
} else { // Used the last applied speedboost
|
||||
m_SpeedBoost = m_ActiveSpeedBoosts.back();
|
||||
}
|
||||
SetSpeedMultiplier(m_SpeedBoost / 500.0f); // 500 being the base speed
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bool specialAnims){
|
||||
@@ -339,13 +339,13 @@ void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bo
|
||||
m_IsInBubble = true;
|
||||
m_DirtyBubble = true;
|
||||
m_SpecialAnims = specialAnims;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::DeactivateBubbleBuff(){
|
||||
m_DirtyBubble = true;
|
||||
m_IsInBubble = false;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
};
|
||||
|
||||
void ControllablePhysicsComponent::SetStunImmunity(
|
||||
|
||||
@@ -276,7 +276,7 @@ public:
|
||||
* The speed boosts of this component.
|
||||
* @return All active Speed boosts for this component.
|
||||
*/
|
||||
std::vector<float> GetActiveSpeedboosts() { return m_ActivePickupRadiusScales; };
|
||||
std::vector<float> GetActiveSpeedboosts() { return m_ActiveSpeedBoosts; };
|
||||
|
||||
/**
|
||||
* Activates the Bubble Buff
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "Game.h"
|
||||
#include "dConfig.h"
|
||||
|
||||
#include "AMFFormat.h"
|
||||
#include "AMFFormat_BitStream.h"
|
||||
#include "Amf3.h"
|
||||
#include "AmfSerialize.h"
|
||||
#include "GameMessages.h"
|
||||
#include "User.h"
|
||||
#include "CDClientManager.h"
|
||||
@@ -51,7 +51,7 @@ DestroyableComponent::DestroyableComponent(Entity* parent) : Component(parent) {
|
||||
m_IsGMImmune = false;
|
||||
m_IsShielded = false;
|
||||
m_DamageToAbsorb = 0;
|
||||
m_HasBricks = false;
|
||||
m_IsModuleAssembly = m_Parent->HasComponent(eReplicaComponentType::MODULE_ASSEMBLY);
|
||||
m_DirtyThreatList = false;
|
||||
m_HasThreats = false;
|
||||
m_ExplodeFactor = 1.0f;
|
||||
@@ -163,7 +163,7 @@ void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIn
|
||||
outBitStream->Write(m_IsSmashed);
|
||||
|
||||
if (m_IsSmashable) {
|
||||
outBitStream->Write(m_HasBricks);
|
||||
outBitStream->Write(m_IsModuleAssembly);
|
||||
outBitStream->Write(m_ExplodeFactor != 1.0f);
|
||||
if (m_ExplodeFactor != 1.0f) outBitStream->Write(m_ExplodeFactor);
|
||||
}
|
||||
@@ -245,19 +245,15 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(difference));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("health");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(difference));
|
||||
args.Insert("type", "health");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetArmor(int32_t value) {
|
||||
@@ -290,19 +286,15 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(value));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("armor");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(value));
|
||||
args.Insert("type", "armor");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetImagination(int32_t value) {
|
||||
@@ -334,18 +326,14 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
||||
if (playAnim) {
|
||||
// Now update the player bar
|
||||
if (!m_Parent->GetParentUser()) return;
|
||||
AMFStringValue* amount = new AMFStringValue();
|
||||
amount->SetStringValue(std::to_string(difference));
|
||||
AMFStringValue* type = new AMFStringValue();
|
||||
type->SetStringValue("imagination");
|
||||
|
||||
AMFArrayValue args;
|
||||
args.InsertValue("amount", amount);
|
||||
args.InsertValue("type", type);
|
||||
args.Insert("amount", std::to_string(difference));
|
||||
args.Insert("type", "imagination");
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", &args);
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetDamageToAbsorb(int32_t value) {
|
||||
@@ -494,11 +482,11 @@ LWOOBJID DestroyableComponent::GetKillerID() const {
|
||||
}
|
||||
|
||||
Entity* DestroyableComponent::GetKiller() const {
|
||||
return EntityManager::Instance()->GetEntity(m_KillerID);
|
||||
return Game::entityManager->GetEntity(m_KillerID);
|
||||
}
|
||||
|
||||
bool DestroyableComponent::CheckValidity(const LWOOBJID target, const bool ignoreFactions, const bool targetEnemy, const bool targetFriend) const {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (targetEntity == nullptr) {
|
||||
Game::logger->Log("DestroyableComponent", "Invalid entity for checking validity (%llu)!", target);
|
||||
@@ -544,7 +532,7 @@ void DestroyableComponent::Heal(const uint32_t health) {
|
||||
|
||||
SetHealth(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -562,7 +550,7 @@ void DestroyableComponent::Imagine(const int32_t deltaImagination) {
|
||||
|
||||
SetImagination(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -576,7 +564,7 @@ void DestroyableComponent::Repair(const uint32_t armor) {
|
||||
|
||||
SetArmor(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -638,7 +626,7 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
if (possessor) {
|
||||
auto possessableId = possessor->GetPossessable();
|
||||
if (possessableId != LWOOBJID_EMPTY) {
|
||||
auto possessable = EntityManager::Instance()->GetEntity(possessableId);
|
||||
auto possessable = Game::entityManager->GetEntity(possessableId);
|
||||
if (possessable) {
|
||||
possessor->Dismount(possessable);
|
||||
}
|
||||
@@ -650,10 +638,10 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
}
|
||||
|
||||
if (echo) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
auto* attacker = EntityManager::Instance()->GetEntity(source);
|
||||
auto* attacker = Game::entityManager->GetEntity(source);
|
||||
m_Parent->OnHit(attacker);
|
||||
m_Parent->OnHitOrHealResult(attacker, sourceDamage);
|
||||
NotifySubscribers(attacker, sourceDamage);
|
||||
@@ -673,7 +661,7 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
}
|
||||
|
||||
//check if hardcore mode is enabled
|
||||
if (EntityManager::Instance()->GetHardcoreMode()) {
|
||||
if (Game::entityManager->GetHardcoreMode()) {
|
||||
DoHardcoreModeDrops(source);
|
||||
}
|
||||
|
||||
@@ -708,12 +696,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
SetArmor(0);
|
||||
SetHealth(0);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
m_KillerID = source;
|
||||
|
||||
auto* owner = EntityManager::Instance()->GetEntity(source);
|
||||
auto* owner = Game::entityManager->GetEntity(source);
|
||||
|
||||
if (owner != nullptr) {
|
||||
owner = owner->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
@@ -733,7 +721,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
if (missions != nullptr) {
|
||||
if (team != nullptr) {
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
@@ -773,12 +761,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
if (team->lootOption == 0) { // Round robin
|
||||
specificOwner = TeamManager::Instance()->GetNextLootOwner(team);
|
||||
|
||||
auto* member = EntityManager::Instance()->GetEntity(specificOwner);
|
||||
auto* member = Game::entityManager->GetEntity(specificOwner);
|
||||
|
||||
if (member) LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
} else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
@@ -791,13 +779,13 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
} else {
|
||||
//Check if this zone allows coin drops
|
||||
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath()) {
|
||||
if (Game::zoneManager->GetPlayerLoseCoinOnDeath()) {
|
||||
auto* character = m_Parent->GetCharacter();
|
||||
uint64_t coinsTotal = character->GetCoins();
|
||||
const uint64_t minCoinsToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathMin;
|
||||
const uint64_t minCoinsToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathMin;
|
||||
if (coinsTotal >= minCoinsToLose) {
|
||||
const uint64_t maxCoinsToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathMax;
|
||||
const float coinPercentageToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathPercent;
|
||||
const uint64_t maxCoinsToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathMax;
|
||||
const float coinPercentageToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathPercent;
|
||||
|
||||
uint64_t coinsToLose = std::max(static_cast<uint64_t>(coinsTotal * coinPercentageToLose), minCoinsToLose);
|
||||
coinsToLose = std::min(maxCoinsToLose, coinsToLose);
|
||||
@@ -809,12 +797,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
}
|
||||
|
||||
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerDied(zoneControl, m_Parent);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
@@ -977,7 +965,7 @@ void DestroyableComponent::FixStats() {
|
||||
destroyableComponent->SetImagination(currentImagination);
|
||||
|
||||
// Serialize the entity
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
void DestroyableComponent::AddOnHitCallback(const std::function<void(Entity*)>& callback) {
|
||||
@@ -991,12 +979,12 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
auto* character = m_Parent->GetComponent<CharacterComponent>();
|
||||
auto uscore = character->GetUScore();
|
||||
|
||||
auto uscoreToLose = uscore * (EntityManager::Instance()->GetHardcoreLoseUscoreOnDeathPercent() / 100);
|
||||
auto uscoreToLose = uscore * (Game::entityManager->GetHardcoreLoseUscoreOnDeathPercent() / 100);
|
||||
character->SetUScore(uscore - uscoreToLose);
|
||||
|
||||
GameMessages::SendModifyLEGOScore(m_Parent, m_Parent->GetSystemAddress(), -uscoreToLose, eLootSourceType::MISSION);
|
||||
|
||||
if (EntityManager::Instance()->GetHardcoreDropinventoryOnDeath()) {
|
||||
if (Game::entityManager->GetHardcoreDropinventoryOnDeath()) {
|
||||
//drop all items from inventory:
|
||||
auto* inventory = m_Parent->GetComponent<InventoryComponent>();
|
||||
if (inventory) {
|
||||
@@ -1013,7 +1001,7 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
GameMessages::SendDropClientLoot(m_Parent, source, item.second->GetLot(), 0, m_Parent->GetPosition(), item.second->GetCount());
|
||||
item.second->SetCount(0, false, false);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1033,25 +1021,25 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
|
||||
// Reload the player since we can't normally reduce uscore from the server and we want the UI to update
|
||||
// do this last so we don't get killed.... again
|
||||
EntityManager::Instance()->DestructEntity(m_Parent);
|
||||
EntityManager::Instance()->ConstructEntity(m_Parent);
|
||||
Game::entityManager->DestructEntity(m_Parent);
|
||||
Game::entityManager->ConstructEntity(m_Parent);
|
||||
return;
|
||||
}
|
||||
|
||||
//award the player some u-score:
|
||||
auto* player = EntityManager::Instance()->GetEntity(source);
|
||||
auto* player = Game::entityManager->GetEntity(source);
|
||||
if (player && player->IsPlayer()) {
|
||||
auto* playerStats = player->GetComponent<CharacterComponent>();
|
||||
if (playerStats) {
|
||||
//get the maximum health from this enemy:
|
||||
auto maxHealth = GetMaxHealth();
|
||||
|
||||
int uscore = maxHealth * EntityManager::Instance()->GetHardcoreUscoreEnemiesMultiplier();
|
||||
int uscore = maxHealth * Game::entityManager->GetHardcoreUscoreEnemiesMultiplier();
|
||||
|
||||
playerStats->SetUScore(playerStats->GetUScore() + uscore);
|
||||
GameMessages::SendModifyLEGOScore(player, player->GetSystemAddress(), uscore, eLootSourceType::MISSION);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public:
|
||||
* Returns whether or not this entity has bricks flying out when smashed
|
||||
* @return whether or not this entity has bricks flying out when smashed
|
||||
*/
|
||||
bool GetHasBricks() const { return m_HasBricks; }
|
||||
bool GetHasBricks() const { return m_IsModuleAssembly; }
|
||||
|
||||
/**
|
||||
* Sets the multiplier for the explosion that's visible when the bricks fly out when this entity is smashed
|
||||
@@ -546,7 +546,7 @@ private:
|
||||
/**
|
||||
* Whether this entity has bricks flying out when smashed (causes the client to look up the files)
|
||||
*/
|
||||
bool m_HasBricks;
|
||||
bool m_IsModuleAssembly;
|
||||
|
||||
/**
|
||||
* The rate at which bricks fly out when smashed
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user