#pragma once

#include <Server.h>
#include <Thread.h>
#include <Datei.h>
#include <Text.h>
#include <InitDatei.h>

#include "Game.h"

using namespace Framework;
using namespace Network;

class FCKlient;
class GameClient;

class FactoryCraftServer : virtual public ReferenceCounter
{
private:
    SSLServer *server;
    InitDatei *ini;
    CRITICAL_SECTION cs;
    RCArray< FCKlient > *klients;
    Game *game;
    int klientAnzahl;
    int id;
    int empfangen;
    int gesendet;

public:
    // Konstruktor 
    FactoryCraftServer( InitDatei *zIni );
    // Destruktor 
    virtual ~FactoryCraftServer();
    // nicht constant
    void run();
    void close();
    bool absturzKlient( int accountId );
    bool removeKlient( FCKlient *zKlient );
    void addGesendet( int bytes );
    void addEmpfangen( int bytes );
    bool hatClients() const;
    Game *zGame() const;
};

class FCKlient : public Thread
{
private:
    SSLSKlient *klient;
    unsigned int accountId;
    FactoryCraftServer *ls;
    GameClient *zGameClient;
    NetworkReader *reader;
    NetworkWriter *writer;

public:
    // Konstruktor 
    FCKlient( SSLSKlient *klient, FactoryCraftServer *ls );
    // Destruktor 
    virtual ~FCKlient();
    // nicht constant 
    void absturz();
    void thread();
    // constant
    int getAccountId() const;
    SSLSKlient *zClient() const;
    NetworkWriter *zWriter() const;
};