diff --git a/Code/client/Events/SetTimeCommandEvent.h b/Code/client/Events/SetTimeCommandEvent.h index 00ac1cdf1..c6385d90a 100644 --- a/Code/client/Events/SetTimeCommandEvent.h +++ b/Code/client/Events/SetTimeCommandEvent.h @@ -3,7 +3,10 @@ struct SetTimeCommandEvent { SetTimeCommandEvent() = delete; - SetTimeCommandEvent(uint8_t aHours, uint8_t aMinutes, uint32_t aPlayerId) : Hours(aHours), Minutes(aMinutes), PlayerId(aPlayerId) + SetTimeCommandEvent(uint8_t aHours, uint8_t aMinutes, uint32_t aPlayerId) + : Hours(aHours) + , Minutes(aMinutes) + , PlayerId(aPlayerId) { } diff --git a/Code/encoding/Messages/ClientMessageFactory.h b/Code/encoding/Messages/ClientMessageFactory.h index 501726619..9c90ad351 100644 --- a/Code/encoding/Messages/ClientMessageFactory.h +++ b/Code/encoding/Messages/ClientMessageFactory.h @@ -66,10 +66,10 @@ struct ClientMessageFactory { auto s_visitor = CreateMessageVisitor< AuthenticationRequest, AssignCharacterRequest, CancelAssignmentRequest, ClientReferencesMoveRequest, EnterInteriorCellRequest, RequestInventoryChanges, RequestFactionsChanges, RequestQuestUpdate, PartyInviteRequest, PartyAcceptInviteRequest, PartyLeaveRequest, PartyCreateRequest, - PartyChangeLeaderRequest, PartyKickRequest, RequestActorValueChanges, RequestActorMaxValueChanges, EnterExteriorCellRequest, RequestHealthChangeBroadcast, ActivateRequest, LockChangeRequest, AssignObjectsRequest, RequestDeathStateChange, ShiftGridCellRequest, - RequestOwnershipTransfer, RequestOwnershipClaim, RequestObjectInventoryChanges, SpellCastRequest, ProjectileLaunchRequest, InterruptCastRequest, AddTargetRequest, ScriptAnimationRequest, DrawWeaponRequest, MountRequest, NewPackageRequest, RequestRespawn, SyncExperienceRequest, - RequestEquipmentChanges, SendChatMessageRequest, TeleportCommandRequest, PlayerRespawnRequest, DialogueRequest, SubtitleRequest, PlayerDialogueRequest, PlayerLevelRequest, TeleportRequest, RequestPlayerHealthUpdate, RequestWeatherChange, RequestCurrentWeather, RequestSetWaypoint, - RequestRemoveWaypoint, SetTimeCommandRequest>; + PartyChangeLeaderRequest, PartyKickRequest, RequestActorValueChanges, RequestActorMaxValueChanges, EnterExteriorCellRequest, RequestHealthChangeBroadcast, ActivateRequest, LockChangeRequest, AssignObjectsRequest, RequestDeathStateChange, ShiftGridCellRequest, RequestOwnershipTransfer, + RequestOwnershipClaim, RequestObjectInventoryChanges, SpellCastRequest, ProjectileLaunchRequest, InterruptCastRequest, AddTargetRequest, ScriptAnimationRequest, DrawWeaponRequest, MountRequest, NewPackageRequest, RequestRespawn, SyncExperienceRequest, RequestEquipmentChanges, + SendChatMessageRequest, TeleportCommandRequest, PlayerRespawnRequest, DialogueRequest, SubtitleRequest, PlayerDialogueRequest, PlayerLevelRequest, TeleportRequest, RequestPlayerHealthUpdate, RequestWeatherChange, RequestCurrentWeather, RequestSetWaypoint, RequestRemoveWaypoint, + SetTimeCommandRequest>; return s_visitor(std::forward(func)); } diff --git a/Code/encoding/Messages/NotifySetTimeResult.h b/Code/encoding/Messages/NotifySetTimeResult.h index ef3b0be1b..5c27e059a 100644 --- a/Code/encoding/Messages/NotifySetTimeResult.h +++ b/Code/encoding/Messages/NotifySetTimeResult.h @@ -6,17 +6,15 @@ struct NotifySetTimeResult final : ServerMessage { static constexpr ServerOpcode Opcode = kNotifySetTimeResult; - NotifySetTimeResult() : ServerMessage(Opcode) + NotifySetTimeResult() + : ServerMessage(Opcode) { } void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override; void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override; - bool operator==(const NotifySetTimeResult& achRhs) const noexcept - { - return GetOpcode() == achRhs.GetOpcode() && Result == achRhs.Result; - } + bool operator==(const NotifySetTimeResult& achRhs) const noexcept { return GetOpcode() == achRhs.GetOpcode() && Result == achRhs.Result; } enum class SetTimeResult : uint8_t { diff --git a/Code/encoding/Messages/ServerMessageFactory.h b/Code/encoding/Messages/ServerMessageFactory.h index 9ed9b0a1b..a1db0d4eb 100644 --- a/Code/encoding/Messages/ServerMessageFactory.h +++ b/Code/encoding/Messages/ServerMessageFactory.h @@ -72,8 +72,8 @@ struct ServerMessageFactory AuthenticationResponse, AssignCharacterResponse, ServerReferencesMoveRequest, ServerTimeSettings, CharacterSpawnRequest, NotifyInventoryChanges, StringCacheUpdate, NotifyFactionsChanges, NotifyRemoveCharacter, NotifyQuestUpdate, NotifyPlayerList, NotifyPartyInfo, NotifyPartyInvite, NotifyActorValueChanges, NotifyPartyJoined, NotifyPartyLeft, NotifyActorMaxValueChanges, NotifyHealthChangeBroadcast, NotifySpawnData, NotifyActivate, NotifyLockChange, AssignObjectsResponse, NotifyDeathStateChange, NotifyOwnershipTransfer, NotifyObjectInventoryChanges, NotifySpellCast, NotifyProjectileLaunch, NotifyInterruptCast, NotifyAddTarget, NotifyScriptAnimation, NotifyDrawWeapon, NotifyMount, NotifyNewPackage, NotifyRespawn, NotifySyncExperience, NotifyEquipmentChanges, NotifyChatMessageBroadcast, TeleportCommandResponse, NotifyPlayerRespawn, NotifyDialogue, - NotifySubtitle, NotifyPlayerDialogue, NotifyActorTeleport, NotifyRelinquishControl, NotifyPlayerLeft, NotifyPlayerJoined, NotifyDialogue, NotifySubtitle, NotifyPlayerDialogue, NotifyPlayerLevel, NotifyPlayerCellChanged, NotifyTeleport, NotifyPlayerHealthUpdate, NotifySettingsChange, NotifyWeatherChange, NotifySetWaypoint, - NotifyRemoveWaypoint, NotifySetTimeResult>; + NotifySubtitle, NotifyPlayerDialogue, NotifyActorTeleport, NotifyRelinquishControl, NotifyPlayerLeft, NotifyPlayerJoined, NotifyDialogue, NotifySubtitle, NotifyPlayerDialogue, NotifyPlayerLevel, NotifyPlayerCellChanged, NotifyTeleport, NotifyPlayerHealthUpdate, NotifySettingsChange, + NotifyWeatherChange, NotifySetWaypoint, NotifyRemoveWaypoint, NotifySetTimeResult>; return s_visitor(std::forward(func)); } diff --git a/Code/encoding/Messages/SetTimeCommandRequest.h b/Code/encoding/Messages/SetTimeCommandRequest.h index 3d115e627..071dfad8e 100644 --- a/Code/encoding/Messages/SetTimeCommandRequest.h +++ b/Code/encoding/Messages/SetTimeCommandRequest.h @@ -6,17 +6,15 @@ struct SetTimeCommandRequest final : ClientMessage { static constexpr ClientOpcode Opcode = kSetTimeCommandRequest; - SetTimeCommandRequest() : ClientMessage(Opcode) + SetTimeCommandRequest() + : ClientMessage(Opcode) { } void SerializeRaw(TiltedPhoques::Buffer::Writer& aWriter) const noexcept override; void DeserializeRaw(TiltedPhoques::Buffer::Reader& aReader) noexcept override; - bool operator==(const SetTimeCommandRequest& acRhs) const noexcept - { - return GetOpcode() == acRhs.GetOpcode() && Hours == acRhs.Hours && Minutes == acRhs.Minutes && PlayerId == acRhs.PlayerId; - } + bool operator==(const SetTimeCommandRequest& acRhs) const noexcept { return GetOpcode() == acRhs.GetOpcode() && Hours == acRhs.Hours && Minutes == acRhs.Minutes && PlayerId == acRhs.PlayerId; } uint8_t Hours{}; uint8_t Minutes{}; diff --git a/Code/server/Game/PlayerManager.cpp b/Code/server/Game/PlayerManager.cpp index 3c3380942..a2db42bb2 100644 --- a/Code/server/Game/PlayerManager.cpp +++ b/Code/server/Game/PlayerManager.cpp @@ -102,7 +102,6 @@ Player* PlayerManager::GetByUsername(const String& acUsername) const noexcept return nullptr; } - Player const* PlayerManager::GetByUsername(const String& acUsername) noexcept { auto itor = std::begin(m_players); diff --git a/Code/server/GameServer.cpp b/Code/server/GameServer.cpp index 7127d6b93..572bb7c64 100644 --- a/Code/server/GameServer.cpp +++ b/Code/server/GameServer.cpp @@ -26,105 +26,102 @@ constexpr size_t kMaxServerNameLength = 128u; // -- Cvars -- Console::Setting uServerPort{"GameServer:uPort", "Which port to host the server on", 10578u}; -Console::Setting uMaxPlayerCount{ - "GameServer:uMaxPlayerCount", - "Maximum number of players allowed on the server (going over the default of 8 is not recommended)", 8u}; +Console::Setting uMaxPlayerCount{"GameServer:uMaxPlayerCount", "Maximum number of players allowed on the server (going over the default of 8 is not recommended)", 8u}; Console::Setting bPremiumTickrate{"GameServer:bPremiumMode", "Use premium tick rate", true}; -Console::StringSetting sServerName{"GameServer:sServerName", "Name that shows up in the server list", - "Dedicated Together Server"}; +Console::StringSetting sServerName{"GameServer:sServerName", "Name that shows up in the server list", "Dedicated Together Server"}; Console::StringSetting sAdminPassword{"GameServer:sAdminPassword", "Admin authentication password", ""}; Console::StringSetting sPassword{"GameServer:sPassword", "Server password", ""}; // Gameplay // TODO: to make this easier for users, use game names for difficulty instead of int Console::Setting uDifficulty{"Gameplay:uDifficulty", "In game difficulty (0 to 5)", 4u}; -Console::Setting bEnableGreetings{ - "Gameplay:bEnableGreetings", - "Enables NPC greetings (disabled by default since they can be spammy with dialogue sync)", false}; +Console::Setting bEnableGreetings{"Gameplay:bEnableGreetings", "Enables NPC greetings (disabled by default since they can be spammy with dialogue sync)", false}; Console::Setting bEnablePvp{"Gameplay:bEnablePvp", "Enables pvp", false}; -Console::Setting bSyncPlayerHomes{"Gameplay:bSyncPlayerHomes", - "Sync chests and displays in player homes and other NoResetZones", false}; +Console::Setting bSyncPlayerHomes{"Gameplay:bSyncPlayerHomes", "Sync chests and displays in player homes and other NoResetZones", false}; Console::Setting bEnableDeathSystem{"Gameplay:bEnableDeathSystem", "Enables the custom multiplayer death system", true}; -Console::Setting uTimeScale{ - "Gameplay:uTimeScale", - "How many seconds pass ingame for every real second (0 to 1000). Changing this can make the game unstable", 20u}; -Console::Setting bSyncPlayerCalendar{ - "Gameplay:bSyncPlayerCalendar", - "Syncs up all player calendars to be the same day, month, and year. This uses the date of the player with the furthest ahead date at connection.", false}; -Console::Setting bAutoPartyJoin{ - "Gameplay:bAutoPartyJoin", - "Join parties automatically, as long as there is only one party in the server", true}; +Console::Setting uTimeScale{"Gameplay:uTimeScale", "How many seconds pass ingame for every real second (0 to 1000). Changing this can make the game unstable", 20u}; +Console::Setting bSyncPlayerCalendar{"Gameplay:bSyncPlayerCalendar", "Syncs up all player calendars to be the same day, month, and year. This uses the date of the player with the furthest ahead date at connection.", false}; +Console::Setting bAutoPartyJoin{"Gameplay:bAutoPartyJoin", "Join parties automatically, as long as there is only one party in the server", true}; // ModPolicy Stuff -Console::Setting bEnableModCheck{"ModPolicy:bEnableModCheck", "Bypass the checking of mods on the server", false, - Console::SettingsFlags::kLocked}; -Console::Setting bAllowSKSE{"ModPolicy:bAllowSKSE", "Allow clients with SKSE active to join", true, - Console::SettingsFlags::kLocked}; -Console::Setting bAllowMO2{"ModPolicy:bAllowMO2", "Allow clients running Mod Organizer 2 to join", true, - Console::SettingsFlags::kLocked}; +Console::Setting bEnableModCheck{"ModPolicy:bEnableModCheck", "Bypass the checking of mods on the server", false, Console::SettingsFlags::kLocked}; +Console::Setting bAllowSKSE{"ModPolicy:bAllowSKSE", "Allow clients with SKSE active to join", true, Console::SettingsFlags::kLocked}; +Console::Setting bAllowMO2{"ModPolicy:bAllowMO2", "Allow clients running Mod Organizer 2 to join", true, Console::SettingsFlags::kLocked}; // -- Commands -- -Console::Command<> TogglePremium("TogglePremium", "Toggle Premium Tickrate on/off", [](Console::ArgStack&) { - bPremiumTickrate = !bPremiumTickrate; - spdlog::get("ConOut")->info("Premium Tickrate has been {}.", bPremiumTickrate == true ? "enabled" : "disabled"); -}); +Console::Command<> TogglePremium( + "TogglePremium", "Toggle Premium Tickrate on/off", + [](Console::ArgStack&) + { + bPremiumTickrate = !bPremiumTickrate; + spdlog::get("ConOut")->info("Premium Tickrate has been {}.", bPremiumTickrate == true ? "enabled" : "disabled"); + }); -Console::Command<> TogglePvp("TogglePvp", "Toggle PvP on/off", [](Console::ArgStack&) { - bEnablePvp = !bEnablePvp; - spdlog::get("ConOut")->info("PvP has been {}.", bEnablePvp == true ? "enabled" : "disabled"); - GameServer::Get()->UpdateSettings(); -}); +Console::Command<> TogglePvp( + "TogglePvp", "Toggle PvP on/off", + [](Console::ArgStack&) + { + bEnablePvp = !bEnablePvp; + spdlog::get("ConOut")->info("PvP has been {}.", bEnablePvp == true ? "enabled" : "disabled"); + GameServer::Get()->UpdateSettings(); + }); -Console::Command SetDifficulty("SetDifficulty", - "Set server difficulty (0 being Novice and 5 being Legendary; default is 4)", - [](Console::ArgStack& aStack) { - auto aDiff = aStack.Pop(); +Console::Command SetDifficulty( + "SetDifficulty", "Set server difficulty (0 being Novice and 5 being Legendary; default is 4)", + [](Console::ArgStack& aStack) + { + auto aDiff = aStack.Pop(); - if (aDiff < 0 || aDiff > 5) - { - spdlog::warn("Game difficulty is invalid (should be from 0 to 5, " - "current value is {}), setting difficulty to 4 (master).", - aDiff); + if (aDiff < 0 || aDiff > 5) + { + spdlog::warn( + "Game difficulty is invalid (should be from 0 to 5, " + "current value is {}), setting difficulty to 4 (master).", + aDiff); - aDiff = 4; - } + aDiff = 4; + } - uDifficulty = (uint32_t)aDiff; + uDifficulty = (uint32_t)aDiff; - GameServer::Get()->UpdateSettings(); - spdlog::get("ConOut")->info("Difficulty has been set to {}.", aDiff); - }); + GameServer::Get()->UpdateSettings(); + spdlog::get("ConOut")->info("Difficulty has been set to {}.", aDiff); + }); -Console::Command<> ShowVersion("version", "Show the version the server was compiled with", - [](Console::ArgStack&) { spdlog::get("ConOut")->info("Server " BUILD_COMMIT); }); +Console::Command<> ShowVersion("version", "Show the version the server was compiled with", [](Console::ArgStack&) { spdlog::get("ConOut")->info("Server " BUILD_COMMIT); }); -Console::Command<> CrashServer("crash", "Crashes the server, don't use!", [](Console::ArgStack&) { - int* i = 0; - *i = 42; -}); +Console::Command<> CrashServer( + "crash", "Crashes the server, don't use!", + [](Console::ArgStack&) + { + int* i = 0; + *i = 42; + }); -Console::Command<> ShowMoPoStatus("ShowMOPOStats", "Shows the status of ModPolicy", [](Console::ArgStack&) { - auto formatStatus = [](bool aToggle) { return aToggle ? "yes" : "no"; }; +Console::Command<> ShowMoPoStatus( + "ShowMOPOStats", "Shows the status of ModPolicy", + [](Console::ArgStack&) + { + auto formatStatus = [](bool aToggle) + { + return aToggle ? "yes" : "no"; + }; - spdlog::get("ConOut")->info("Modcheck enabled: {}\nSKSE allowed: {}\nMO2 allowed: {}", - formatStatus(bEnableModCheck), formatStatus(bAllowSKSE), formatStatus(bAllowMO2)); -}); + spdlog::get("ConOut")->info("Modcheck enabled: {}\nSKSE allowed: {}\nMO2 allowed: {}", formatStatus(bEnableModCheck), formatStatus(bAllowSKSE), formatStatus(bAllowMO2)); + }); // -- Constants -- -constexpr char kBypassMoPoWarning[]{ - "ModCheck is disabled. This can lead to desync and other oddities. Make sure you know what you are doing. We " - "may not be able to assist you if ModCheck was disabled."}; +constexpr char kBypassMoPoWarning[]{"ModCheck is disabled. This can lead to desync and other oddities. Make sure you know what you are doing. We " + "may not be able to assist you if ModCheck was disabled."}; -constexpr char kMopoRecordsMissing[]{ - "Failed to start: ModPolicy's ModCheck is enabled, but no mods are installed. Players won't be able " - "to join! Please create a Data/ directory, and put a \"loadorder.txt\" file in there." - "Check the wiki, which can be found on skyrim-together.com, for more details."}; +constexpr char kMopoRecordsMissing[]{"Failed to start: ModPolicy's ModCheck is enabled, but no mods are installed. Players won't be able " + "to join! Please create a Data/ directory, and put a \"loadorder.txt\" file in there." + "Check the wiki, which can be found on skyrim-together.com, for more details."}; -constexpr char kCalendarSyncWarning[]{ - "Calendar sync is enabled. We generally do not recommend that you use this feature." - "Calendar sync can cause the calendar to jump ahead or behind, which might mess up the timing of quests." - "If you disable this feature again (which is the default setting), the days will still progress, but the" - "exact date will differ slightly between clients (which has no impact on gameplay)."}; +constexpr char kCalendarSyncWarning[]{"Calendar sync is enabled. We generally do not recommend that you use this feature." + "Calendar sync can cause the calendar to jump ahead or behind, which might mess up the timing of quests." + "If you disable this feature again (which is the default setting), the days will still progress, but the" + "exact date will differ slightly between clients (which has no impact on gameplay)."}; static uint16_t GetUserTickRate() { @@ -150,8 +147,10 @@ ServerSettings GetSettings() } GameServer::GameServer(Console::ConsoleRegistry& aConsole) noexcept - : m_lastFrameTime(std::chrono::high_resolution_clock::now()), - m_startTime(std::chrono::high_resolution_clock::now()), m_commands(aConsole), m_requestStop(false) + : m_lastFrameTime(std::chrono::high_resolution_clock::now()) + , m_startTime(std::chrono::high_resolution_clock::now()) + , m_commands(aConsole) + , m_requestStop(false) { BASE_ASSERT(s_pInstance == nullptr, "Server instance already exists?"); s_pInstance = this; @@ -165,19 +164,19 @@ GameServer::GameServer(Console::ConsoleRegistry& aConsole) noexcept if (uDifficulty.value_as() > 5) { - spdlog::warn("Game difficulty is invalid (should be from 0 to 5, current value is {}), setting difficulty to 4 " - "(master).", - uDifficulty.value_as()); + spdlog::warn( + "Game difficulty is invalid (should be from 0 to 5, current value is {}), setting difficulty to 4 " + "(master).", + uDifficulty.value_as()); uDifficulty = 4; } if (!bEnableDeathSystem) { - spdlog::warn( - "The multiplayer death system is disabled on this server. We recommend that you ONLY do this if you have" - " a mod that replaces the vanilla death system. You should only disable our death system if you" - " absolutely know what you are doing!"); + spdlog::warn("The multiplayer death system is disabled on this server. We recommend that you ONLY do this if you have" + " a mod that replaces the vanilla death system. You should only disable our death system if you" + " absolutely know what you are doing!"); } m_isPasswordProtected = strcmp(sPassword.value(), "") != 0; @@ -243,10 +242,12 @@ bool GameServer::CheckMoPo() void GameServer::BindMessageHandlers() { - auto handlerGenerator = [this](auto& x) { + auto handlerGenerator = [this](auto& x) + { using T = typename std::remove_reference_t::Type; - m_messageHandlers[T::Opcode] = [this](UniquePtr& apMessage, ConnectionId_t aConnectionId) { + m_messageHandlers[T::Opcode] = [this](UniquePtr& apMessage, ConnectionId_t aConnectionId) + { auto* pPlayer = m_pWorld->GetPlayerManager().GetByConnectionId(aConnectionId); if (!pPlayer) @@ -267,17 +268,18 @@ void GameServer::BindMessageHandlers() ClientMessageFactory::Visit(handlerGenerator); // Override authentication request - m_messageHandlers[AuthenticationRequest::Opcode] = [this](UniquePtr& apMessage, - ConnectionId_t aConnectionId) { + m_messageHandlers[AuthenticationRequest::Opcode] = [this](UniquePtr& apMessage, ConnectionId_t aConnectionId) + { const auto pRealMessage = CastUnique(std::move(apMessage)); HandleAuthenticationRequest(aConnectionId, pRealMessage); }; - auto adminHandlerGenerator = [this](auto& x) { + auto adminHandlerGenerator = [this](auto& x) + { using T = typename std::remove_reference_t::Type; - m_adminMessageHandlers[T::Opcode] = [this](UniquePtr& apMessage, - ConnectionId_t aConnectionId) { + m_adminMessageHandlers[T::Opcode] = [this](UniquePtr& apMessage, ConnectionId_t aConnectionId) + { const auto pRealMessage = CastUnique(std::move(apMessage)); m_pWorld->GetDispatcher().trigger(AdminPacketEvent(pRealMessage.get(), aConnectionId)); }; @@ -290,62 +292,73 @@ void GameServer::BindMessageHandlers() void GameServer::BindServerCommands() { - m_commands.RegisterCommand<>("uptime", "Show how long the server has been running for", [this](Console::ArgStack&) { - Uptime uptime = GetUptime(); - spdlog::get("ConOut")->info("Server uptime: {}w {}d {}h {}m", uptime.weeks, uptime.days, uptime.hours, - uptime.minutes); - }); - - m_commands.RegisterCommand<>("players", "List all players on this server", [&](Console::ArgStack&) { - auto out = spdlog::get("ConOut"); - uint32_t count = m_pWorld->GetPlayerManager().Count(); - if (count == 0) + m_commands.RegisterCommand<>( + "uptime", "Show how long the server has been running for", + [this](Console::ArgStack&) { - out->warn("No players on here. Invite some friends!"); - return; - } + Uptime uptime = GetUptime(); + spdlog::get("ConOut")->info("Server uptime: {}w {}d {}h {}m", uptime.weeks, uptime.days, uptime.hours, uptime.minutes); + }); - out->info("<------Players-({})--->", count); - for (Player* pPlayer : m_pWorld->GetPlayerManager()) + m_commands.RegisterCommand<>( + "players", "List all players on this server", + [&](Console::ArgStack&) { - out->info("{}: {}", pPlayer->GetId(), pPlayer->GetUsername().c_str()); - } - }); + auto out = spdlog::get("ConOut"); + uint32_t count = m_pWorld->GetPlayerManager().Count(); + if (count == 0) + { + out->warn("No players on here. Invite some friends!"); + return; + } - m_commands.RegisterCommand<>("mods", "List all installed mods on this server", [&](Console::ArgStack&) { - auto out = spdlog::get("ConOut"); - auto& mods = m_pWorld->ctx().at().GetServerMods(); - if (mods.size() == 0) - { - out->warn("No mods installed"); - return; - } + out->info("<------Players-({})--->", count); + for (Player* pPlayer : m_pWorld->GetPlayerManager()) + { + out->info("{}: {}", pPlayer->GetId(), pPlayer->GetUsername().c_str()); + } + }); - out->info("<------Mods-({})--->", mods.size()); - for (auto& it : mods) + m_commands.RegisterCommand<>( + "mods", "List all installed mods on this server", + [&](Console::ArgStack&) { - out->info(it.first); - } - }); + auto out = spdlog::get("ConOut"); + auto& mods = m_pWorld->ctx().at().GetServerMods(); + if (mods.size() == 0) + { + out->warn("No mods installed"); + return; + } - m_commands.RegisterCommand<>("resources", "List all loaded resources on the server", [&](Console::ArgStack&) { - auto out = spdlog::get("ConOut"); - if (!m_pResources || m_pResources->GetManifests().size() == 0) + out->info("<------Mods-({})--->", mods.size()); + for (auto& it : mods) + { + out->info(it.first); + } + }); + + m_commands.RegisterCommand<>( + "resources", "List all loaded resources on the server", + [&](Console::ArgStack&) { - out->warn("No resources loaded"); - return; - } + auto out = spdlog::get("ConOut"); + if (!m_pResources || m_pResources->GetManifests().size() == 0) + { + out->warn("No resources loaded"); + return; + } - out->info("<------Resources-({})--->", m_pResources->GetManifests().size()); - m_pResources->ForEachManifest([&](const auto& aManifest) { - out->info("{} -> {}", aManifest.Name.c_str(), aManifest.Description.c_str()); + out->info("<------Resources-({})--->", m_pResources->GetManifests().size()); + m_pResources->ForEachManifest([&](const auto& aManifest) { out->info("{} -> {}", aManifest.Name.c_str(), aManifest.Description.c_str()); }); }); - }); m_commands.RegisterCommand<>("quit", "Stop the server", [&](Console::ArgStack&) { Kill(); }); m_commands.RegisterCommand( - "SetTime", "Set ingame hour and minute", [&](Console::ArgStack& aStack) { + "SetTime", "Set ingame hour and minute", + [&](Console::ArgStack& aStack) + { auto out = spdlog::get("ConOut"); auto hour = aStack.Pop(); @@ -365,7 +378,9 @@ void GameServer::BindServerCommands() }); m_commands.RegisterCommand( - "SetDate", "Set ingame day, month, and year", [&](Console::ArgStack& aStack) { + "SetDate", "Set ingame day, month, and year", + [&](Console::ArgStack& aStack) + { auto out = spdlog::get("ConOut"); auto day = aStack.Pop(); @@ -385,7 +400,9 @@ void GameServer::BindServerCommands() }); m_commands.RegisterCommand( - "AddAdmin", "Add admin privileges to player", [&](Console::ArgStack& aStack) { + "AddAdmin", "Add admin privileges to player", + [&](Console::ArgStack& aStack) + { auto out = spdlog::get("ConOut"); const auto& cUsername = aStack.Pop(); @@ -419,7 +436,9 @@ void GameServer::BindServerCommands() } }); m_commands.RegisterCommand( - "RemoveAdmin", "Remove admin privileges from player", [&](Console::ArgStack& aStack) { + "RemoveAdmin", "Remove admin privileges from player", + [&](Console::ArgStack& aStack) + { auto out = spdlog::get("ConOut"); const auto& cUsername = aStack.Pop(); @@ -448,7 +467,9 @@ void GameServer::BindServerCommands() } }); m_commands.RegisterCommand<>( - "admins", "List all admins", [&](Console::ArgStack&) { + "admins", "List all admins", + [&](Console::ArgStack&) + { auto out = spdlog::get("ConOut"); if (m_adminSessions.size() == 0) { @@ -493,8 +514,7 @@ void GameServer::UpdateInfo() if (cServerName.length() > kMaxServerNameLength) { - spdlog::error("sServerName is longer than the limit of {} characters/bytes, and has been cut short", - kMaxServerNameLength); + spdlog::error("sServerName is longer than the limit of {} characters/bytes, and has been cut short", kMaxServerNameLength); m_info.name = cServerName.substr(0U, kMaxServerNameLength); } else @@ -516,9 +536,7 @@ void GameServer::UpdateTimeScale() if (!timescale_set_successfully) { - spdlog::warn( - "TimeScale is invalid (should be from 0 to 1000, current value is {}), setting TimeScale to 20 (default)", - timescale); + spdlog::warn("TimeScale is invalid (should be from 0 to 1000, current value is {}), setting TimeScale to 20 (default)", timescale); uTimeScale = 20u; } @@ -560,15 +578,15 @@ void GameServer::OnConsume(const void* apData, const uint32_t aSize, const Conne } else {*/ - const ClientMessageFactory factory; - auto pMessage = factory.Extract(reader); - if (!pMessage) - { - spdlog::error("Couldn't parse packet from {:x}", aConnectionId); - return; - } + const ClientMessageFactory factory; + auto pMessage = factory.Extract(reader); + if (!pMessage) + { + spdlog::error("Couldn't parse packet from {:x}", aConnectionId); + return; + } - m_messageHandlers[pMessage->GetOpcode()](pMessage, aConnectionId); + m_messageHandlers[pMessage->GetOpcode()](pMessage, aConnectionId); //} } @@ -584,8 +602,7 @@ void GameServer::OnDisconnection(const ConnectionId_t aConnectionId, EDisconnect auto* pPlayer = m_pWorld->GetPlayerManager().GetByConnectionId(aConnectionId); - spdlog::info("Connection ended {:x} - '{}' disconnected", aConnectionId, - (pPlayer != NULL ? pPlayer->GetUsername().c_str() : "NULL")); + spdlog::info("Connection ended {:x} - '{}' disconnected", aConnectionId, (pPlayer != NULL ? pPlayer->GetUsername().c_str() : "NULL")); m_pWorld->GetScriptService().HandlePlayerQuit(aConnectionId, aReason); @@ -642,8 +659,7 @@ void GameServer::Send(const ConnectionId_t aConnectionId, const ServerMessage& a acServerMessage.Serialize(writer); - TiltedPhoques::PacketView packet(reinterpret_cast(buffer.GetWriteData()), - static_cast(writer.Size())); + TiltedPhoques::PacketView packet(reinterpret_cast(buffer.GetWriteData()), static_cast(writer.Size())); Server::Send(aConnectionId, &packet); s_allocator.Reset(); @@ -659,8 +675,7 @@ void GameServer::Send(ConnectionId_t aConnectionId, const ServerAdminMessage& ac acServerMessage.Serialize(writer); - TiltedPhoques::PacketView packet(reinterpret_cast(buffer.GetWriteData()), - static_cast(writer.Size())); + TiltedPhoques::PacketView packet(reinterpret_cast(buffer.GetWriteData()), static_cast(writer.Size())); Server::Send(aConnectionId, &packet); s_allocator.Reset(); @@ -685,8 +700,7 @@ void GameServer::SendToPlayers(const ServerMessage& acServerMessage, const Playe } // NOTE: this doesn't check objects in range, only characters in range. -bool GameServer::SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin, - const Player* apExcludedPlayer) const +bool GameServer::SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin, const Player* apExcludedPlayer) const { if (!m_pWorld->valid(acOrigin)) { @@ -718,8 +732,7 @@ bool GameServer::SendToPlayersInRange(const ServerMessage& acServerMessage, cons return true; } -void GameServer::SendToParty(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, - const Player* apExcludeSender) const +void GameServer::SendToParty(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const Player* apExcludeSender) const { if (!acPartyComponent.JoinedPartyId.has_value()) { @@ -740,8 +753,7 @@ void GameServer::SendToParty(const ServerMessage& acServerMessage, const PartyCo } } -void GameServer::SendToPartyInRange(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, - const entt::entity acOrigin, const Player* apExcludeSender) const +void GameServer::SendToPartyInRange(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const entt::entity acOrigin, const Player* apExcludeSender) const { if (!acPartyComponent.JoinedPartyId.has_value()) { @@ -793,8 +805,7 @@ bool GameServer::ValidateAuthParams(ConnectionId_t aConnectionId, const UniquePt return false; } -void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, - const UniquePtr& acRequest) +void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, const UniquePtr& acRequest) { const auto info = GetConnectionInfo(aConnectionId); @@ -805,7 +816,8 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, serverResponse.Version = BUILD_COMMIT; using RT = AuthenticationResponse::ResponseType; - auto sendKick = [&](const RT type) { + auto sendKick = [&](const RT type) + { serverResponse.Type = type; Send(aConnectionId, serverResponse); // the previous message is a lingering kick, it still gets delivered. @@ -815,8 +827,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, // to make our testing life a bit easier. if (acRequest->Version != BUILD_COMMIT) { - spdlog::info("New player {:x} '{}' tried to connect with client {} - Version mismatch", aConnectionId, - remoteAddress, acRequest->Version.c_str()); + spdlog::info("New player {:x} '{}' tried to connect with client {} - Version mismatch", aConnectionId, remoteAddress, acRequest->Version.c_str()); sendKick(RT::kWrongVersion); return; } @@ -839,8 +850,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, if (mo2Problem) response += "MO2 "; - spdlog::info("New player {:x} '{}' tried to connect, but {}{} disallowed - Kicked.", aConnectionId, - remoteAddress, response.c_str(), skseProblem && mo2Problem ? "are" : "is"); + spdlog::info("New player {:x} '{}' tried to connect, but {}{} disallowed - Kicked.", aConnectionId, remoteAddress, response.c_str(), skseProblem && mo2Problem ? "are" : "is"); serverResponse.SKSEActive = acRequest->SKSEActive; serverResponse.MO2Active = acRequest->MO2Active; @@ -884,8 +894,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, // mods that may exist on the server, but not on the client for (const auto& entry : modsComponent.GetServerMods()) { - const auto it = std::find_if(userMods.begin(), userMods.end(), - [&](const Mods::Entry& it) { return it.Filename == entry.first; }); + const auto it = std::find_if(userMods.begin(), userMods.end(), [&](const Mods::Entry& it) { return it.Filename == entry.first; }); if (it == userMods.end()) { @@ -901,9 +910,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, String text = PrettyPrintModList(modsToRemove.ModList); // "ModPolicy: refusing connection {:x} because essential mods are missing: {}" // for future reference ^ - spdlog::info( - "ModPolicy: refusing connection {:x} because the following mods are installed on the client: {}", - aConnectionId, text.c_str()); + spdlog::info("ModPolicy: refusing connection {:x} because the following mods are installed on the client: {}", aConnectionId, text.c_str()); serverResponse.UserMods.ModList = std::move(modsToRemove.ModList); sendKick(RT::kModsMismatch); @@ -919,8 +926,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, size_t i = 0; for (auto& mod : acRequest->UserMods.ModList) { - const uint32_t id = - mod.IsLite ? modsComponent.AddLite(mod.Filename) : modsComponent.AddStandard(mod.Filename); + const uint32_t id = mod.IsLite ? modsComponent.AddLite(mod.Filename) : modsComponent.AddStandard(mod.Filename); Mods::Entry entry; entry.Filename = mod.Filename; @@ -953,8 +959,7 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, serverResponse.PlayerId = pPlayer->GetId(); auto modList = PrettyPrintModList(acRequest->UserMods.ModList); - spdlog::info("New player '{}' [{:x}] connected with {} mods\n\t: {}", pPlayer->GetUsername().c_str(), - aConnectionId, acRequest->UserMods.ModList.size(), modList.c_str()); + spdlog::info("New player '{}' [{:x}] connected with {} mods\n\t: {}", pPlayer->GetUsername().c_str(), aConnectionId, acRequest->UserMods.ModList.size(), modList.c_str()); serverResponse.Settings = GetSettings(); @@ -1031,8 +1036,7 @@ void GameServer::UpdateTitle() const const auto name = m_info.name.empty() ? "Private server" : m_info.name; const char* playerText = GetClientCount() <= 1 ? " player" : " players"; - const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT, name.c_str(), - GetClientCount(), playerText, GetTickRate()); + const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT, name.c_str(), GetClientCount(), playerText, GetTickRate()); #if TP_PLATFORM_WINDOWS SetConsoleTitleA(title.c_str()); diff --git a/Code/server/GameServer.h b/Code/server/GameServer.h index 799be34b1..d74f2fa27 100644 --- a/Code/server/GameServer.h +++ b/Code/server/GameServer.h @@ -58,30 +58,15 @@ struct GameServer final : Server void Send(ConnectionId_t aConnectionId, const ServerAdminMessage& acServerMessage) const; void SendToLoaded(const ServerMessage& acServerMessage) const; void SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender = nullptr) const; - bool SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin, - const Player* apExcludeSender = nullptr) const; - void SendToParty(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, - const Player* apExcludeSender = nullptr) const; - void SendToPartyInRange(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, - const entt::entity acOrigin, const Player* apExcludeSender = nullptr) const; - - const Info& GetInfo() const noexcept - { - return m_info; - } + bool SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin, const Player* apExcludeSender = nullptr) const; + void SendToParty(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const Player* apExcludeSender = nullptr) const; + void SendToPartyInRange(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const entt::entity acOrigin, const Player* apExcludeSender = nullptr) const; - bool IsRunning() const noexcept - { - return !m_requestStop; - } - bool IsPasswordProtected() const noexcept - { - return m_isPasswordProtected; - } - [[nodiscard]] bool IsPublic() const noexcept - { - return m_isPublic; - } + const Info& GetInfo() const noexcept { return m_info; } + + bool IsRunning() const noexcept { return !m_requestStop; } + bool IsPasswordProtected() const noexcept { return m_isPasswordProtected; } + [[nodiscard]] bool IsPublic() const noexcept { return m_isPublic; } template void ForEachAdmin(const T& aFunctor) { @@ -98,30 +83,18 @@ struct GameServer final : Server }; Uptime GetUptime() const noexcept; - World& GetWorld() const noexcept - { - return *m_pWorld; - } + World& GetWorld() const noexcept { return *m_pWorld; } - [[nodiscard]] const TiltedPhoques::Set& GetAdminSessions() const noexcept - { - return m_adminSessions; - } + [[nodiscard]] const TiltedPhoques::Set& GetAdminSessions() const noexcept { return m_adminSessions; } - void AddAdminSession(ConnectionId_t acSession) noexcept - { - m_adminSessions.insert(acSession); - } + void AddAdminSession(ConnectionId_t acSession) noexcept { m_adminSessions.insert(acSession); } - void RemoveAdminSession(ConnectionId_t acSession) noexcept - { - m_adminSessions.erase(acSession); - } + void RemoveAdminSession(ConnectionId_t acSession) noexcept { m_adminSessions.erase(acSession); } - Player* GetAdminByUsername(const String& acUsername) const noexcept; + Player* GetAdminByUsername(const String& acUsername) const noexcept; Player const* GetAdminByUsername(const String& acUsername) noexcept; - protected: +protected: bool ValidateAuthParams(ConnectionId_t aConnectionId, const UniquePtr& acRequest); void HandleAuthenticationRequest(ConnectionId_t aConnectionId, const UniquePtr& acRequest); @@ -131,11 +104,11 @@ struct GameServer final : Server void OnConnection(ConnectionId_t aHandle) override; void OnDisconnection(ConnectionId_t aConnectionId, EDisconnectReason aReason) override; - private: +private: void UpdateTitle() const; String SanitizeUsername(const String& acUsername) const noexcept; - private: +private: std::chrono::high_resolution_clock::time_point m_startTime; std::chrono::high_resolution_clock::time_point m_lastFrameTime; std::function&, ConnectionId_t)> m_messageHandlers[kClientOpcodeMax]; diff --git a/Code/server/Services/CalendarService.cpp b/Code/server/Services/CalendarService.cpp index 656cd12e5..7014c2853 100644 --- a/Code/server/Services/CalendarService.cpp +++ b/Code/server/Services/CalendarService.cpp @@ -10,7 +10,8 @@ #include "Game/Player.h" -CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher) : m_world(aWorld) +CalendarService::CalendarService(World& aWorld, entt::dispatcher& aDispatcher) + : m_world(aWorld) { m_updateConnection = aDispatcher.sink().connect<&CalendarService::OnUpdate>(this); m_joinConnection = aDispatcher.sink().connect<&CalendarService::OnPlayerJoin>(this);