Merge remote-tracking branch 'origin/main' into ub-fixes

This commit is contained in:
jadebenn 2024-12-26 17:16:48 -06:00
commit 701fc8061b
21 changed files with 239 additions and 36 deletions

View File

@ -1,5 +1,5 @@
PROJECT_VERSION_MAJOR=2
PROJECT_VERSION_MINOR=3
PROJECT_VERSION_MAJOR=3
PROJECT_VERSION_MINOR=0
PROJECT_VERSION_PATCH=0
# Debugging

View File

@ -2,16 +2,25 @@
#include <string>
//For reading null-terminated strings
std::string BinaryIO::ReadString(std::istream& instream) {
std::string toReturn;
char buffer;
template<typename StringType>
StringType ReadString(std::istream& instream) {
StringType toReturn{};
typename StringType::value_type buffer{};
BinaryIO::BinaryRead(instream, buffer);
while (buffer != 0x00) {
toReturn += buffer;
BinaryRead(instream, buffer);
BinaryIO::BinaryRead(instream, buffer);
}
return toReturn;
}
std::string BinaryIO::ReadString(std::istream& instream) {
return ::ReadString<std::string>(instream);
}
std::u8string BinaryIO::ReadU8String(std::istream& instream) {
return ::ReadString<std::u8string>(instream);
}

View File

@ -65,6 +65,8 @@ namespace BinaryIO {
std::string ReadString(std::istream& instream);
std::u8string ReadU8String(std::istream& instream);
inline bool DoesFileExist(const std::string& name) {
std::ifstream f(name.c_str());
return f.good();

View File

@ -65,13 +65,14 @@ int64_t FdbToSqlite::Convert::ReadInt64(std::istream& cdClientBuffer) {
return value;
}
// cdclient is encoded in latin1
std::string FdbToSqlite::Convert::ReadString(std::istream& cdClientBuffer) {
int32_t prevPosition = SeekPointer(cdClientBuffer);
auto readString = BinaryIO::ReadString(cdClientBuffer);
const auto readString = BinaryIO::ReadU8String(cdClientBuffer);
cdClientBuffer.seekg(prevPosition);
return readString;
return GeneralUtils::Latin1ToUTF8(readString);
}
int32_t FdbToSqlite::Convert::SeekPointer(std::istream& cdClientBuffer) {

View File

@ -167,6 +167,15 @@ std::u16string GeneralUtils::ASCIIToUTF16(const std::string_view string, const s
return ret;
}
std::string GeneralUtils::Latin1ToUTF8(const std::u8string_view string, const size_t size) {
std::string toReturn{};
for (const auto u : string) {
PushUTF8CodePoint(toReturn, u);
}
return toReturn;
}
//! Converts a (potentially-ill-formed) UTF-16 string to UTF-8
//! See: <http://simonsapin.github.io/wtf-8/#decoding-ill-formed-utf-16>
std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const size_t size) {
@ -175,9 +184,9 @@ std::string GeneralUtils::UTF16ToWTF8(const std::u16string_view string, const si
ret.reserve(newSize);
for (size_t i = 0; i < newSize; ++i) {
const char16_t u = string[i];
const auto u = string[i];
if (IsLeadSurrogate(u) && (i + 1) < newSize) {
const char16_t next = string[i + 1];
const auto next = string[i + 1];
if (IsTrailSurrogate(next)) {
i += 1;
const char32_t cp = 0x10000

View File

@ -52,6 +52,14 @@ namespace GeneralUtils {
bool _NextUTF8Char(std::string_view& slice, uint32_t& out);
}
//! Converts a Latin1 string to a UTF-8 string
/*!
\param string The string to convert
\param size A size to trim the string to. Default is SIZE_MAX (No trimming)
\return An UTF-8 representation of the string
*/
std::string Latin1ToUTF8(const std::u8string_view string, const size_t size = SIZE_MAX);
//! Converts a UTF-16 string to a UTF-8 string
/*!
\param string The string to convert

View File

@ -1253,6 +1253,7 @@ namespace MessageType {
VEHICLE_NOTIFY_HIT_EXPLODER = 1385,
CHECK_NEAREST_ROCKET_LAUNCH_PRE_CONDITIONS = 1386,
REQUEST_NEAREST_ROCKET_LAUNCH_PRE_CONDITIONS = 1387,
CONFIGURE_RACING_CONTROL = 1388,
CONFIGURE_RACING_CONTROL_CLIENT = 1389,
NOTIFY_RACING_CLIENT = 1390,
RACING_PLAYER_HACK_CAR = 1391,

View File

@ -5,6 +5,7 @@
#include "dConfig.h"
#include "Logger.h"
#include "dPlatforms.h"
#include "BinaryPathFinder.h"
// Static Variables
@ -17,7 +18,14 @@ namespace {
void SQLiteDatabase::Connect() {
LOG("Using SQLite database");
con = new CppSQLite3DB();
con->open(Game::config->GetValue("sqlite_database_path").c_str());
const auto path = BinaryPathFinder::GetBinaryDir() / Game::config->GetValue("sqlite_database_path");
if (!std::filesystem::exists(path)) {
LOG("Creating sqlite path %s", path.string().c_str());
std::filesystem::create_directories(path.parent_path());
}
con->open(path.string().c_str());
isConnected = true;
// Make sure wal is enabled for the database.

View File

@ -35,7 +35,8 @@
RacingControlComponent::RacingControlComponent(Entity* parent)
: Component(parent) {
m_PathName = u"MainPath";
m_RemainingLaps = 3;
m_NumberOfLaps = 3;
m_RemainingLaps = m_NumberOfLaps;
m_LeadingPlayer = LWOOBJID_EMPTY;
m_RaceBestTime = 0;
m_RaceBestLap = 0;
@ -658,23 +659,9 @@ void RacingControlComponent::Update(float deltaTime) {
}
}
// Spawn imagination pickups
auto* minSpawner = Game::zoneManager->GetSpawnersByName(
"ImaginationSpawn_Min")[0];
auto* medSpawner = Game::zoneManager->GetSpawnersByName(
"ImaginationSpawn_Med")[0];
auto* maxSpawner = Game::zoneManager->GetSpawnersByName(
"ImaginationSpawn_Max")[0];
minSpawner->Activate();
if (m_LoadedPlayers > 2) {
medSpawner->Activate();
}
if (m_LoadedPlayers > 4) {
maxSpawner->Activate();
}
GameMessages::ZoneLoadedInfo zoneLoadInfo{};
zoneLoadInfo.maxPlayers = m_LoadedPlayers;
m_Parent->GetScript()->OnZoneLoadedInfo(m_Parent, zoneLoadInfo);
// Reset players to their start location, without smashing them
for (auto& player : m_RacingPlayers) {
@ -764,7 +751,7 @@ void RacingControlComponent::Update(float deltaTime) {
// new checkpoint
uint32_t respawnIndex = 0;
for (const auto& waypoint : path->pathWaypoints) {
if (player.lap == 3) {
if (player.lap == m_NumberOfLaps) {
break;
}
@ -835,7 +822,7 @@ void RacingControlComponent::Update(float deltaTime) {
// Progress lap time tasks
missionComponent->Progress(eMissionTaskType::RACING, lapTime.count(), static_cast<LWOOBJID>(eRacingTaskParam::LAP_TIME));
if (player.lap == 3) {
if (player.lap == m_NumberOfLaps) {
m_Finished++;
player.finished = m_Finished;
@ -882,3 +869,20 @@ void RacingControlComponent::Update(float deltaTime) {
}
}
}
void RacingControlComponent::MsgConfigureRacingControl(const GameMessages::ConfigureRacingControl& msg) {
for (const auto& dataUnique : msg.racingSettings) {
if (!dataUnique) continue;
const auto* const data = dataUnique.get();
if (data->GetKey() == u"Race_PathName" && data->GetValueType() == LDF_TYPE_UTF_16) {
m_PathName = static_cast<const LDFData<std::u16string>*>(data)->GetValue();
} else if (data->GetKey() == u"activityID" && data->GetValueType() == LDF_TYPE_S32) {
m_ActivityID = static_cast<const LDFData<int32_t>*>(data)->GetValue();
} else if (data->GetKey() == u"Number_of_Laps" && data->GetValueType() == LDF_TYPE_S32) {
m_NumberOfLaps = static_cast<const LDFData<int32_t>*>(data)->GetValue();
m_RemainingLaps = m_NumberOfLaps;
} else if (data->GetKey() == u"Minimum_Players_for_Group_Achievements" && data->GetValueType() == LDF_TYPE_S32) {
m_MinimumPlayersForGroupAchievements = static_cast<const LDFData<int32_t>*>(data)->GetValue();
}
}
}

View File

@ -152,6 +152,8 @@ public:
*/
RacingPlayerInfo* GetPlayerData(LWOOBJID playerID);
void MsgConfigureRacingControl(const GameMessages::ConfigureRacingControl& msg);
private:
/**
@ -161,11 +163,13 @@ private:
/**
* The paths that are followed for the camera scenes
* Configurable in the ConfigureRacingControl msg with the key `Race_PathName`.
*/
std::u16string m_PathName;
/**
* The ID of the activity for participating in this race
* Configurable in the ConfigureRacingControl msg with the key `activityID`.
*/
uint32_t m_ActivityID;
@ -245,5 +249,20 @@ private:
* Value for message box response to know if we are exiting the race via the activity dialogue
*/
const int32_t m_ActivityExitConfirm = 1;
bool m_AllPlayersReady = false;
/**
* @brief The number of laps in this race. Configurable in the ConfigureRacingControl msg
* with the key `Number_of_Laps`.
*
*/
int32_t m_NumberOfLaps{ 3 };
/**
* @brief The minimum number of players required to progress group achievements.
* Configurable with the ConfigureRacingControl msg with the key `Minimum_Players_for_Group_Achievements`.
*
*/
int32_t m_MinimumPlayersForGroupAchievements{ 2 };
};

View File

@ -717,6 +717,16 @@ namespace GameMessages {
NiPoint3 targetPosition{};
void Serialize(RakNet::BitStream& bitStream) const override;
};
struct ZoneLoadedInfo : public GameMsg {
ZoneLoadedInfo() : GameMsg(MessageType::Game::ZONE_LOADED_INFO) {}
int32_t maxPlayers{};
};
struct ConfigureRacingControl : public GameMsg {
ConfigureRacingControl() : GameMsg(MessageType::Game::CONFIGURE_RACING_CONTROL) {}
std::vector<std::unique_ptr<LDFBaseData>> racingSettings{};
};
};
#endif // GAMEMESSAGES_H

View File

@ -84,6 +84,24 @@ int main(int argc, char** argv) {
Server::SetupLogger("MasterServer");
if (!Game::logger) return EXIT_FAILURE;
auto folders = { "navmeshes", "migrations", "vanity" };
for (const auto folder : folders) {
if (!std::filesystem::exists(BinaryPathFinder::GetBinaryDir() / folder)) {
std::string msg = "The (" +
std::string(folder) +
") folder was not copied to the binary directory. Please copy the (" +
std::string(folder) +
") folder from your download to the binary directory or re-run cmake.";
LOG("%s", msg.c_str());
// toss an error box up for windows users running the download
#ifdef DARKFLAME_PLATFORM_WIN32
MessageBoxA(nullptr, msg.c_str(), "Missing Folder", MB_OK | MB_ICONERROR);
#endif
return EXIT_FAILURE;
}
}
if (!dConfig::Exists("authconfig.ini")) LOG("Could not find authconfig.ini, using default settings");
if (!dConfig::Exists("chatconfig.ini")) LOG("Could not find chatconfig.ini, using default settings");
if (!dConfig::Exists("masterconfig.ini")) LOG("Could not find masterconfig.ini, using default settings");
@ -177,7 +195,7 @@ int main(int argc, char** argv) {
}
// Run migrations should any need to be run.
MigrationRunner::RunSQLiteMigrations();
MigrationRunner::RunSQLiteMigrations();
//If the first command line argument is -a or --account then make the user
//input a username and password, with the password being hidden.

View File

@ -330,6 +330,7 @@
#include "EnemyClearThreat.h"
#include "AgSpiderBossMessage.h"
#include "GfRaceInstancer.h"
#include "NsRaceServer.h"
#include <map>
#include <string>
@ -692,6 +693,7 @@ namespace {
{"scripts\\02_server\\Map\\General\\L_ENEMY_CLEAR_THREAT.lua", []() {return new EnemyClearThreat();}},
{"scripts\\ai\\AG\\L_AG_SPIDER_BOSS_MESSAGE.lua", []() {return new AgSpiderBossMessage();}},
{"scripts\\ai\\GF\\L_GF_RACE_INSTANCER.lua", []() {return new GfRaceInstancer();}},
{"scripts\\ai\\RACING\\TRACK_NS\\NS_RACE_SERVER.lua", []() {return new NsRaceServer();}},
};
@ -704,9 +706,12 @@ namespace {
"scripts\\empty.lua",
"scripts\\zone\\AG\\L_ZONE_AG.lua",
"scripts\\zone\\NS\\L_ZONE_NS.lua",
"scripts\\zone\\GF\\L_ZONE_GF.lua",
"scripts\\ai\\GF\\L_ZONE_GF.lua",
"scripts\\ai\\AG\\CONCERT_STAGE.lua",
"scripts\\ai\\NS\\L_NS_CAR_MODULAR_BUILD.lua", // In our implementation, this is done in GameMessages.cpp
"scripts\\ai\\PETS\\PET_BLOCKER.lua",
"scripts\\ai\\PETS\\PET_FLEA_MISSION.lua",
"scripts\\ai\\ACT\\L_ACT_PET_INSTANCE_EXIT.lua",
};
};

View File

@ -355,6 +355,8 @@ namespace CppScripts {
* @param canceled if it was done via the cancel button
*/
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {};
virtual void OnZoneLoadedInfo(Entity* self, const GameMessages::ZoneLoadedInfo& info) {};
};
Script* const GetScript(Entity* parent, const std::string& scriptName);

View File

@ -1,4 +1,5 @@
set(DSCRIPTS_SOURCES_AI_RACING)
set(DSCRIPTS_SOURCES_AI_RACING
"RaceImaginationServer.cpp")
add_subdirectory(OBJECTS)
@ -6,6 +7,12 @@ foreach(file ${DSCRIPTS_SOURCES_AI_RACING_OBJECTS})
set(DSCRIPTS_SOURCES_AI_RACING ${DSCRIPTS_SOURCES_AI_RACING} "OBJECTS/${file}")
endforeach()
add_subdirectory(TRACK_NS)
foreach(file ${DSCRIPTS_SOURCES_AI_RACING_TRACK_NS})
set(DSCRIPTS_SOURCES_AI_RACING ${DSCRIPTS_SOURCES_AI_RACING} "TRACK_NS/${file}")
endforeach()
add_library(dScriptsAiRacing OBJECT ${DSCRIPTS_SOURCES_AI_RACING})
target_include_directories(dScriptsAiRacing PUBLIC "." "OBJECTS")
target_include_directories(dScriptsAiRacing PUBLIC "." "OBJECTS" "TRACK_NS")
target_precompile_headers(dScriptsAiRacing REUSE_FROM dScriptsBase)

View File

@ -0,0 +1,19 @@
#include "RaceImaginationServer.h"
#include "dZoneManager.h"
void StartSpawner(const std::vector<Spawner*>& spawner) {
for (auto* const entity : spawner) {
entity->Activate();
}
}
void RaceImaginationServer::OnZoneLoadedInfo(Entity* self, const GameMessages::ZoneLoadedInfo& info) {
// Spawn imagination pickups
StartSpawner(Game::zoneManager->GetSpawnersByName("ImaginationSpawn_Min"));
if (info.maxPlayers > 2) {
StartSpawner(Game::zoneManager->GetSpawnersByName("ImaginationSpawn_Med"));
}
if (info.maxPlayers > 4) {
StartSpawner(Game::zoneManager->GetSpawnersByName("ImaginationSpawn_Max"));
}
}

View File

@ -0,0 +1,11 @@
#ifndef RACEIMAGINATIONSERVER_H
#define RACEIMAGINATIONSERVER_H
#include "CppScripts.h"
class RaceImaginationServer : public virtual CppScripts::Script {
public:
void OnZoneLoadedInfo(Entity* self, const GameMessages::ZoneLoadedInfo& info) override;
};
#endif //!RACEIMAGINATIONSERVER_H

View File

@ -0,0 +1,3 @@
set(DSCRIPTS_SOURCES_AI_RACING_TRACK_NS
"NsRaceServer.cpp"
PARENT_SCOPE)

View File

@ -0,0 +1,54 @@
#include "NsRaceServer.h"
#include "RacingControlComponent.h"
#include "Entity.h"
using std::unique_ptr;
using std::make_unique;
void NsRaceServer::OnStartup(Entity* self) {
GameMessages::ConfigureRacingControl config;
auto& raceSet = config.racingSettings;
raceSet.push_back(make_unique<LDFData<std::u16string>>(u"GameType", u"Racing"));
raceSet.push_back(make_unique<LDFData<std::u16string>>(u"GameState", u"Starting"));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Number_Of_PlayersPerTeam", 6));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Minimum_Players_to_Start", 2));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Minimum_Players_for_Group_Achievements", 2));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Car_Object", 7703));
raceSet.push_back(make_unique<LDFData<std::u16string>>(u"Race_PathName", u"MainPath"));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Current_Lap", 1));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Number_of_Laps", 3));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"activityID", 42));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_1", 100));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_2", 90));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_3", 80));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_4", 70));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_5", 60));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Place_6", 50));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_1", 15));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_2", 25));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_3", 50));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_4", 85));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_5", 90));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Num_of_Players_6", 100));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Number_of_Spawn_Groups", 1));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Red_Spawners", 4847));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Blue_Spawners", 4848));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Blue_Flag", 4850));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Red_Flag", 4851));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Red_Point", 4846));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Blue_Point", 4845));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Red_Mark", 4844));
raceSet.push_back(make_unique<LDFData<int32_t>>(u"Blue_Mark", 4843));
std::vector<Entity*> racingControllers = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::RACING_CONTROL);
for (auto* const racingController : racingControllers) {
auto* racingComponent = racingController->GetComponent<RacingControlComponent>();
if (racingComponent) racingComponent->MsgConfigureRacingControl(config);
}
}

View File

@ -0,0 +1,12 @@
#ifndef NSRACESERVER_H
#define NSRACESERVER_H
#include "CppScripts.h"
#include "RaceImaginationServer.h"
class NsRaceServer : public RaceImaginationServer {
public:
void OnStartup(Entity* self) override;
};
#endif //!NSRACESERVER_H

View File

@ -28,7 +28,8 @@ client_location=
# The maximum outgoing bandwidth in bits. If your clients are having
# issues with enemies taking a while to catch up to them, increse this value.
maximum_outgoing_bandwidth=80000
# Empty or 0 means no limit
maximum_outgoing_bandwidth=0
# The Maximum Translation Unit (MTU) size for packets. If players are
# getting stuck at 55% on the loading screen, lower this number to