Client Class Reference

#include <Client.h>

Inheritance diagram for Client:

Connection List of all members.

Public Member Functions

 Client (TCPsocket socket, Server *server)
virtual ~Client ()
void startListen (ConnectionData *data)
void setAccount (Account *account)
Account * getAccount ()

Private Attributes

ServermyServer
Account * myAccount

Detailed Description

Represents a client.

Waits for messages from a client and manage it.

Definition at line 19 of file Client.h.


Constructor & Destructor Documentation

Client::Client TCPsocket  socket,
Server server
 

Constructs a Client.

It bascally creates a ConnectionData instance and fills it with Client's data, then it creates a new thread to run in.

Author:
stonedz
Since:
pre-alpha
Parameters:
socket The TCP socket created by the server.
server The server in which the client will run.

Definition at line 7 of file Client.cpp.

References ConnectionData::id, ConnectionData::running, ConnectionData::self, ConnectionData::socket, and ConnectionData::thread.

00008         :myServer(server),
00009         myAccount(NULL)
00010 {
00011         this->data->socket = socket;// This is our socket.
00012         this->data->running = true; // The server is running ...
00013         this->data->self = this;        // Pointer to the object itself (useful for threading)
00014         this->data->id= 0;                      // This may be set as the key of clients' map ...
00015 
00016         /*
00017          * Creates a new thread for the server socket.
00018          */
00019          this->data->thread = SDL_CreateThread(startThread, this->data);
00020          if (this->data->thread == NULL) {
00021                 std::cerr << "SDL_CreateThread: " << SDL_GetError() << std::endl;
00022         exit(5);
00023     }
00024 }

Client::~Client  )  [virtual]
 

Virtual destructor.

Definition at line 26 of file Client.cpp.

00026                {
00027     if (myAccount)
00028         delete myAccount;
00029 }


Member Function Documentation

Account* Client::getAccount  )  [inline]
 

Returns a pointer to the Client's account.

Author:
stonedz
Since:
pre-alpha
Returns:
A pointer to the current Client's account.

Definition at line 68 of file Client.h.

Referenced by ClientFSM::move().

00068 {return myAccount;}

void Client::setAccount Account *  account  ) 
 

Attach an account instance to the Client.

Author:
stonedz
Since:
pre-alpha
Parameters:
account An Account pointer.

Definition at line 43 of file Client.cpp.

References myAccount.

Referenced by ClientFSM::authenticate().

00043                                        {
00044     myAccount = account;
00045 }

void Client::startListen ConnectionData data  )  [virtual]
 

Listening routine. Manages the reception of messages from remote host.

Author:
stonedz
Since:
pre-alpha
Parameters:
data Contains the client's data that was initialized in Client's constructor.
Todo:
TODO Check if the way we free resources is correct.

TODO Improve error handling.

Implements Connection.

Definition at line 31 of file Client.cpp.

References ClientFSM::Evolve(), ClientFSM::getStatus(), myServer, Server::removeClient(), and ClientFSM::Start().

00031                                              {
00032         ClientFSM* fsm = new ClientFSM(data, myServer, this);
00033 
00034         fsm->Start();                           // Starts a new finite states machine
00035         while(!(fsm->getStatus())){     // and runs it while requested.
00036                 fsm->Evolve();
00037                 SDL_Delay(100);
00038         }
00039         //Delete the client.
00040         this->myServer->removeClient(this);
00041 }


Member Data Documentation

Account* Client::myAccount [private]
 

Points to Client's account.

Definition at line 73 of file Client.h.

Referenced by setAccount().

Server* Client::myServer [private]
 

Points to the server I'm running in.

Definition at line 72 of file Client.h.

Referenced by startListen().


The documentation for this class was generated from the following files:
Generated on Mon Dec 3 04:30:13 2007 for lo-testserver by  doxygen 1.3.9.1