2d-sfml-game-engine / HW4 / Part 1 / Server / Server.hpp
Server.hpp
Raw
#pragma once

#include <string>
#include <chrono>
#include <thread>
#include <iostream>
#include <vector>
#include <zmq.hpp>

#include "Player.hpp"
#include "GameObject.hpp"
#include "Timeline.hpp"

/**
 * @brief Client info represented as a struct including the client's name and player character object.
 */
struct Client {
    std::string name;
    Player* player;
    bool isActive;
};

/**
 * @brief Server class responsible for handling server calls and clients
 */
class Server {
    public:
        /**
         * @brief Construct a new Server object and set up replier and publisher sockets
         */
        Server();

        /**
         * @brief Function to be run by the replier socket
         */
        void replierFunction();

        /**
         * @brief Function to be run by the publisher socket
         * 
         * @param objects objects to publish
         */
        void publishFunction(std::vector<GameObject*>* objects);

    private:
        zmq::context_t context; // ZMQ socket context
        zmq::socket_t replier; // Replier socket
        zmq::socket_t publisher; // Publisher socket
        std::vector<Client> clients; // Clients currently in the server

};