#include #include #include #include #include #include #include #include CommandService::CommandService(World& aWorld, entt::dispatcher& aDispatcher) noexcept : m_world(aWorld) { m_setTimeConnection = aDispatcher.sink>().connect<&CommandService::OnSetTimeCommand>(this); m_teleportConnection = aDispatcher.sink>().connect<&CommandService::OnTeleportCommandRequest>(this); } void CommandService::OnSetTimeCommand(const PacketEvent& acMessage) const noexcept { NotifySetTimeResult response{}; const auto cPlayerId = static_cast(acMessage.Packet.PlayerId); // Only set time if player is an admin for (const auto session : GameServer::Get()->GetAdminSessions()) { if (PlayerManager::Get()->GetByConnectionId(session)->GetId() == cPlayerId) { const auto cHours = static_cast(acMessage.Packet.Hours); const auto cMinutes = static_cast(acMessage.Packet.Minutes); m_world.GetCalendarService().SetTime(cHours, cMinutes, m_world.GetCalendarService().GetTimeScale()); response.Result = NotifySetTimeResult::SetTimeResult::kSuccess; acMessage.pPlayer->Send(response); return; } } response.Result = NotifySetTimeResult::SetTimeResult::kNoPermission; acMessage.pPlayer->Send(response); } void CommandService::OnTeleportCommandRequest(const PacketEvent& acMessage) const noexcept { Player* pTargetPlayer = nullptr; for (Player* pPlayer : m_world.GetPlayerManager()) { if (pPlayer->GetUsername() == acMessage.Packet.TargetPlayer) pTargetPlayer = pPlayer; } TeleportCommandResponse response{}; if (pTargetPlayer) { auto character = pTargetPlayer->GetCharacter(); if (character) { const auto* pMovementComponent = m_world.try_get(*character); if (pMovementComponent) { const auto& cellComponent = pTargetPlayer->GetCellComponent(); response.CellId = cellComponent.Cell; response.Position = pMovementComponent->Position; response.WorldSpaceId = cellComponent.WorldSpaceId; } } } acMessage.pPlayer->Send(response); }