Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

Client-Server setup

As mentioned game using Ganef will have one server, and one or more clients. To acheive this you will inherit from two classes in Ganef, ClientFramework and ServerFramework. Since we are using C++ you can inherit from more than one class, hence you could let your main game-class (if you have one such) inherit from one of these even though it is already inheriting from an other base class.

Client

The client-class must as mentioned inherit the ClientFramework class as follows:

class MyGameClient : public ClientFramework
{
   // ... your client class members and methods.
};

The ClientFramework class declares several abstract methods:

protected: // These must be implemented in a derived class
   virtual void writeHandshakeInitMessage(FrameworkPacket * fp) = 0; //give first message
   virtual void onHandshakingDiscontinue(FrameworkPacket * fp) = 0; //recieve
   virtual bool onHandshakeDescription(FrameworkPacket * fp, FrameworkPacket * reply) = 0;
   virtual void onDisconnect() = 0;
   virtual void onConnect() = 0;
These must be implemented before you can run your client application, what you should do in each of them will be explained later.

Server

The server class must inherit from the ServerFramework class as follows:

class MyGameServer : public ServerFramework
{
   // ... your server class members and methods.
};
Like the client, the server must implement a few abstract methods, the content of these will be discussed as we explain later:
protected: // These method should be implemented on the GameServer
   /// This method should write it's reply in the reply-packet, and return true or false depending on wether it want's us to continue the handshaking.
   virtual bool onInitialHandshake(FrameworkPacket * handshake, FrameworkPacket * reply) = 0;
   /// This method will be invoked when a new client has passed the handshaking-phase.
   virtual void onClientConnected(Client * client) = 0;
   /// This method will be invoked when a client has timed out.
   virtual void onClientDisconnected(Client * client) = 0;
   /// This method should return some dirivative of the Client-class.
   virtual Client * createClient(ServerFramework *fw, const ost::InetHostAddress &addr, ost::tpport_t port) = 0;
A thing to notice here is that you are forced to implement a method called createClient(...), this method should return an object of the class Client. But if you want to assosiate more data with a connected client, you can just inherit from the Client class and add what ever data you find usefull.


[Next: Gameworld Data ]
Generated on Mon Feb 6 12:24:53 2006 for Ganef by  doxygen 1.4.4