src/Network/Server.hh
author terom
Sun, 07 Dec 2008 21:10:04 +0000
changeset 263 8c999cf4c182
parent 241 e95b1602d836
child 274 c35307e8645c
permissions -rw-r--r--
weapon projectile radiuses and fix network play (local_player == NULL, Rope releasing upon being hit
#ifndef NETWORKSERVER_HH
#define NETWORKSERVER_HH

#include "../GameState.hh"
#include "Session.hh"
#include "Object.hh"

#include <list>
#include <map>
#include <ClanLib/core.h>

// forward-declare
class NetworkServerPlayer;

class NetworkServer {
    friend class NetworkServerPlayer;
    friend class NetworkServerProjectile;

    protected:
        GameState &state;
        CL_SlotContainer slots;

        NetworkSession netsession;
        NetworkObject_ServerController netobjs;
        std::list<NetworkServerPlayer *> players;

    public:
        NetworkServer (GameState &state, const NetworkAddress &listen_addr);
    
    protected:
        void handle_disconnect (NetworkServerPlayer *player);

    private:
        void on_node_connected (NetworkNode *node);
};

class NetworkServerPlayer : public LocalPlayer {
    private:
        NetworkServer &server;
        NetworkObject_Server obj;
        NetworkNode *node;

        CL_SlotContainer slots;
        
    public:
        NetworkServerPlayer (NetworkServer &server, NetworkNode *node);
    
    protected:    
        // override from Player to replicate side effects of events to clients
        virtual void handleDig (Vector position, float radius);
        virtual void handleCreateProjectile (Weapon *weapon, Vector position, Vector velocity);
        virtual void handleChangeWeapon (unsigned int weaponIndex);
        virtual void handleRopeState (RopeState state);
        virtual void handleRopeLength (float length);

    private:
        void on_disconnected (void);
        void on_input (NetworkNode *node, NetworkPacketInput &pkt);
        
        void send_terrain_data (void);
        void send_position_update (void);
};

class NetworkServerProjectile : public Projectile {
    private:
        NetworkServer &server;
        NetworkObject_Server obj;
    
    public:
        NetworkServerProjectile (NetworkServer &server, Vector position, Vector velocity, float explosionRadius, float radius, TickCount age);
    
    protected:
        virtual void onDestroy (Vector position, bool removeGround);
};

#endif