//
// Created by sebastian on 06.08.26.
//

#include "LudoGameServer.h"

#include "spdlog/spdlog.h"

void LudoGameServer::onStart() {
    ApplicationServer::onStart();
    m_gameServer.onClientConnected([](engine::net::ClientId clientId) {
        spdlog::info("Client connected: {}", clientId);
    });

    m_gameServer.onMessageReceived([this](engine::net::ClientId clientId, const nlohmann::json& msg) {
       spdlog::info("Client {}: {}", clientId, msg.dump());
       if (msg.value("type", "") == "Ping") {
           m_gameServer.sendTo(clientId, { {"type", "Pong"}, {"payload", nlohmann::json::object()} });
       }
   });
}

void LudoGameServer::onTick(float deltaTime) {
    ApplicationServer::onTick(deltaTime);
    m_gameServer.update();
}
