src/Client.cpp

00001 #include "Client.h"
00002 
00003 #include "Server.h"
00004 #include "Account.h"
00005 #include "Clientfsm.h"
00006 
00007 Client::Client(TCPsocket socket, Server* server)
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 }
00025 
00026 Client::~Client(){
00027     if (myAccount)
00028         delete myAccount;
00029 }
00030 
00031 void Client::startListen(ConnectionData * data){
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 }
00042 
00043 void Client::setAccount(Account* account){
00044     myAccount = account;
00045 }

Generated on Mon Dec 3 04:30:12 2007 for lo-testserver by  doxygen 1.3.9.1