#include <iostream>

#include "server/commands/CommandTypes.h"
#include "server/GameServer.h"
#include "server/commands/ConsoleEditor.h"
#include "server/commands/CommandManager.h"

GameServer::GameServer(const Clock& tps) : tps(tps) {
}

void GameServer::tick() {
}

void GameServer::handleCommands(ServerCommands& serverCommands) {
    RawCommand rawCommand;
    while(ConsoleEditor::readCommand(rawCommand)) {
        commandManager.execute(serverCommands, rawCommand);
    }
}

void GameServer::onFullServerClientConnect(Client& client) {
    (void) client;
    std::cout << "full\n";
}

void GameServer::onClientConnect(Client& client) {
    (void) client;
    std::cout << "connected\n";
}

void GameServer::onClientPackage(Client& client, Packet& packet) {
    (void) client;
    StringBuffer<256> s;
    while(packet.hasData()) {
        s.append(packet.read8());
    }
    std::cout << "Packet: " << s << "\n";
}

void GameServer::onClientDisconnect(Client& client) {
    (void) client;
    std::cout << "disconnected\n";
}