src/Network/Client.hh
changeset 408 e6cfc44266af
parent 400 d64bf28c4340
child 431 c6d7272a164b
equal deleted inserted replaced
407:443f6f7abcfb 408:e6cfc44266af
     6  *
     6  *
     7  * Game client implementation
     7  * Game client implementation
     8  */
     8  */
     9 
     9 
    10 // forward-declare
    10 // forward-declare
       
    11 class NetworkClientConnect;
    11 class NetworkClient;
    12 class NetworkClient;
    12 class NetworkClientLocalPlayer;
    13 class NetworkClientLocalPlayer;
    13 class NetworkClientRemotePlayer;
    14 class NetworkClientRemotePlayer;
    14 
    15 
    15 #include "../GameState.hh"
    16 #include "../GameState.hh"
    25     protected:
    26     protected:
    26         /**
    27         /**
    27          * The NetworkClient
    28          * The NetworkClient
    28          */
    29          */
    29         NetworkClient &client;
    30         NetworkClient &client;
    30     
    31         
    31     public:
    32     public:
    32         /**
    33         /**
    33          * Control objects on the given client using the client.netsession's NETCHAN_CORE channel
    34          * Control objects on the given client using the client.netsession's NETCHAN_CORE channel
    34          */
    35          */
    35         NetworkClientController (NetworkClient &client);
    36         NetworkClientController (NetworkClient &client);
    84         /**
    85         /**
    85          * The GameState
    86          * The GameState
    86          */
    87          */
    87         GameState &state;
    88         GameState &state;
    88 
    89 
       
    90         /**
       
    91          * The connect()-mode NetworkSession
       
    92          */
       
    93         NetworkSession &netsession;
       
    94 
       
    95         /**
       
    96          * The server NetworkNode from Netsession::connect
       
    97          */
       
    98         NetworkNode *server;
       
    99 
       
   100         /**
       
   101          * Our specialized NetworkObject_ClientController
       
   102          */
       
   103         NetworkClientController controller;
       
   104 
    89         CL_SlotContainer slots;
   105         CL_SlotContainer slots;
    90         
       
    91         /**
       
    92          * The connect()-mode NetworkSession
       
    93          */
       
    94         NetworkSession netsession;
       
    95 
       
    96         /**
       
    97          * The server NetworkNode from Netsession::connect
       
    98          */
       
    99         NetworkNode *server;
       
   100 
       
   101         /**
       
   102          * Our specialized NetworkObject_ClientController
       
   103          */
       
   104         NetworkClientController controller;
       
   105 
   106 
   106     public:
   107     public:
   107         /**
   108         /**
   108          * Create a NetworkClient with the given GameState, connecting a server on the given NetworkEndpoint
   109          * Create a NetworkClient with the given GameState, connecting a server on the given NetworkEndpoint
   109          *
   110          *
   110          * @param engine the Engine we're running as
   111          * @param engine the Engine we're running as
   111          * @param state the GameState to use
   112          * @param state the GameState to use
   112          * @param connect_to the address to connect to
   113          * @param connect_to the address to connect to
   113          */
   114          */
   114         NetworkClient (Engine &engine, GameState &state, const NetworkEndpoint &connect_to);
   115         NetworkClient (Engine &engine, GameState &state, NetworkSession &netsession, NetworkNode *server);
       
   116     
       
   117     public:
       
   118         /**
       
   119          * Called by NetworkClientRemotePlayer when they get disconnected. Doesn't do anything currently
       
   120          */
       
   121         void player_quit (NetworkClientRemotePlayer *player);
       
   122 };
       
   123 
       
   124 /**
       
   125  * This handles the actual connection process to the server, and handles the initial data from the server. Once the
       
   126  * Engine has a game running, we can create the actual NetworkClient object.
       
   127  */
       
   128 class NetworkClientConnect {
       
   129     protected:
       
   130         /**
       
   131          * The Engine we are running under
       
   132          */
       
   133         Engine &engine;
       
   134 
       
   135         /**
       
   136          * The NetworkSession we are using
       
   137          */
       
   138         NetworkSession netsession;
       
   139 
       
   140         /**
       
   141          * The server we've connected to
       
   142          */
       
   143         NetworkNode *server;
       
   144 
       
   145         /**
       
   146          * The NetworkClient that we eventually create
       
   147          */
       
   148         NetworkClient *client;
       
   149         
       
   150         CL_SlotContainer slots;
       
   151 
       
   152     public:
       
   153         /**
       
   154          * Begin the connection process. Once it is complete, we will callback to Engine::networkClientConnected
       
   155          */
       
   156         NetworkClientConnect (Engine &engine, const NetworkEndpoint &connect_to);
   115     
   157     
   116     protected:
   158     protected:
   117         /**
   159         /**
   118          * We have disconnected from the server
   160          * We have disconnected from the server
   119          */
   161          */
   121 
   163 
   122         /**
   164         /**
   123          * Receive the NETCHAN_TERRAIN_ARRAY message from the server and apply it to our GameState::world terrain
   165          * Receive the NETCHAN_TERRAIN_ARRAY message from the server and apply it to our GameState::world terrain
   124          */
   166          */
   125         void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node);
   167         void on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node);
   126     
   168 
   127     public:
   169         /**
   128         /**
   170          * Finished connecting 
   129          * Called by NetworkClientRemotePlayer when they get disconnected. Doesn't do anything currently
   171          */
   130          */
   172         void connectDone (Terrain *terrain);
   131         void player_quit (NetworkClientRemotePlayer *player);
       
   132 };
   173 };
   133 
   174 
   134 /**
   175 /**
   135  * Our base NetworkObject_Client object, containing the NetworkClient and a CL_SlotContainer for conveniance
   176  * Our base NetworkObject_Client object, containing the NetworkClient and a CL_SlotContainer for conveniance
   136  */
   177  */