Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

coreClass Class Reference

The Core Class The Core Class manages various jobs like connecting to the server and authentication. More...

#include <coreClass.h>

List of all members.

Public Methods

 coreClass ( ThreadArgs* targs )
 The constructor for coreClass. More...

 coreClass ( )
 The constructor for coreClass. More...

bool connectNow ( void )
 Does every step neccessary to connect to a server. More...

bool disconnectNow ( void )
 Disconnect from a server. More...

BuffergetBuffer ( int whichbuffer )
 Get the pointer to a specific buffer. More...

void startQuartz ( unsigned int freq )
 Start the Quartz. More...

void setUpdateFreq ( unsigned int freq )
 Change the Quartz' frequency. More...


Private Methods

bool connectTo ( string dotsandnumbers )
 Initiates the connection to a server. More...

bool handshake ( void )
 Does the handshake with the server. More...

bool authenticate ( void )
 Does the authentication using username and password. More...


Private Attributes

string username
 The username for the server. More...

string password
 The password for the server. More...

string realname
 The real name of the user. More...

int mySocket
 The handler for the socket to the server. More...

string serverAddress
 The address of the server. More...

int serverPort
 The port of the server. More...

pthread_t incomingThread
 The thread handler for the IncomingThread. More...

pthread_t outgoingThread
 The thread handler for the OutgoingThread. More...

pthread_t quartzThread
 The thread handler for the QuartzThread. More...

QuartzClassqObj
 The pointer to the object of the QuartzClass - to control the Quartz during runtime. More...

BuffercoreIn
 The buffer to read packages coming from the server. More...

BuffercoreOut
 The buffer to send packages to the server. More...


Detailed Description

The Core Class The Core Class manages various jobs like connecting to the server and authentication.

Author(s):
xandi
Date:
080400

Definition at line 48 of file coreClass.h.

00049 {
00050     private:
00051 
00052         string username;            
00053         string password;            
00054 
00055         string realname;            
00056 
00057         int mySocket;               
00058 
00059         string serverAddress;       
00060         int serverPort;             
00061 
00062         pthread_t   incomingThread; 
00063         pthread_t   outgoingThread; 
00064         pthread_t   quartzThread;   
00065 
00066         QuartzClass* qObj;          
00067 
00068         Buffer*     coreIn;         
00069         Buffer*     coreOut;        
00070 
00071     public:
00072 
00074 
00077         coreClass           ( ThreadArgs* targs );
00078 
00080 
00082         coreClass           ( );
00083 
00085 
00088         bool connectNow     ( void );
00089 
00091 
00094         bool disconnectNow  ( void );
00095 
00096 
00098 
00102         Buffer* getBuffer   ( int whichbuffer );
00103 
00105 
00108         void startQuartz     ( unsigned int freq );
00110 
00113         void setUpdateFreq  ( unsigned int freq );
00114 
00115     private:
00117 
00122         bool connectTo      ( string dotsandnumbers );
00124 
00127         bool handshake      ( void );
00129 
00133         bool authenticate   ( void );
00134 
00135     }

Constructor & Destructor Documentation

coreClass::coreClass ( ThreadArgs * targs)

The constructor for coreClass.

Parameters:
targs   passing the arguments from main()

Definition at line 52 of file coreClass.cpp.

00053 {
00054     fprintf(stderr,"[cC.constructor] parsing %d parameters\n",targs->argc);
00055     mySocket   = 0;
00056     serverPort = 0;
00057     qObj       = 0;
00058     coreIn     = 0;
00059     coreOut    = 0;
00060 
00061     if ( targs->argc >= 4 )
00062         {
00063         username        = targs->argv[1];
00064         password        = targs->argv[2];
00065         serverAddress   = targs->argv[3];
00066 
00067         fprintf(stderr,"\nUsername: %s", username.c_str() );
00068         fprintf(stderr,"\tPassword: %s\n", password.c_str());
00069         fprintf(stderr,"Serveraddress: %s\n",serverAddress.c_str() );
00070 
00071         if ( targs->argc >= 5 )
00072             {
00073             fprintf(stderr,"Too many arguments - *snip* :)\n");
00074             }
00075         }
00076     else
00077         {
00078         username        = "clonewar";
00079         password        = "idpman";
00080         serverAddress   = DEFAULT_HOST;
00081         }
00082 
00083     serverPort = DEFAULT_PORT;
00084     }

coreClass::coreClass ()

The constructor for coreClass.

Definition at line 97 of file coreClass.cpp.

00097 {
00098     mySocket   = 0;
00099     serverPort = 0;
00100     qObj       = 0;
00101     coreIn     = 0;
00102     coreOut    = 0;
00103 
00104     Config* tmpConfig = new Config ();
00105 
00106     tmpConfig->openConfig (CLIENT_CONFIG_FILE);
00107 
00108     if (tmpConfig->searchTag ("User")) {
00109     username = tmpConfig->getCharVariable ("Name");
00110     password = tmpConfig->getCharVariable ("Password");
00111     };
00112     if (tmpConfig->searchTag ("DefaultServer")) {
00113     serverAddress = tmpConfig->getCharVariable ("Adress");
00114     serverPort    = tmpConfig->getIntVariable ("Port");
00115     };
00116 
00117     if (username == "")       username      = "clonewar";
00118     if (password == "")       password      = "idpman";
00119     if (serverAddress == "")  serverAddress = DEFAULT_HOST;
00120     if (serverPort   == -111) serverPort    = DEFAULT_PORT;
00121 }

Member Function Documentation

bool coreClass::authenticate ( void) [private]

Does the authentication using username and password.

Returns:
true on success, false on failure
See also:
username password

Definition at line 284 of file coreClass.cpp.

00285 {
00286     packet* pak = new packet;
00287     bool check = false;
00288 
00289     fprintf (stderr, "[auth.debug] trying authentication using %s and %s...\n",username.c_str(),password.c_str());
00290 
00291     pak->h.header[0] = PROT_AUTHENTICATE;
00292     pak->h.header[1] = AUTH_PASSWORD;
00293     pak->h.header[2] = strlen (username.c_str());
00294     pak->h.header[3] = strlen (password.c_str());
00295 
00296     pak->data = username;
00297     pak->data+= password;
00298 
00299     coreOut->write ( pak );
00300 
00301     while ( coreIn->isEmpty () );
00302 
00303     pak = coreIn->read ();
00304 
00305     check  = ( ( pak->h.header[0] != PROT_AUTHENTICATE) || (pak->h.header[1] != AUTH_PASSWORD ) );
00306     check += !( pak->data == "Authentication successful !" );
00307 
00308 //    qObj   = new QuartzClass ( coreOut, PROT_GET_ALL_CHANGED, 25 );
00309 //    check += pthread_create ( &quartzThread, NULL, QuartzThread, qObj );
00310 
00311     delete pak;
00312     return check;
00313     }

bool coreClass::connectNow ( void)

Does every step neccessary to connect to a server.

Returns:
true on failure, false on success

Definition at line 138 of file coreClass.cpp.

00139 {
00140     fprintf(stderr,"[cC.connectNow] \n");
00141 
00142     ComArgs inArgs;
00143     ComArgs outArgs;
00144 
00145     inArgs.buffer  = coreIn  = new Buffer ( );
00146     outArgs.buffer = coreOut = new Buffer ( );
00147 
00148     bool check = connectTo ( serverAddress );
00149 
00150     inArgs.socket  = mySocket;
00151     outArgs.socket = mySocket;
00152 
00153     check  = pthread_create ( &incomingThread, NULL, IncomingThread, &inArgs );
00154     check += pthread_create ( &outgoingThread, NULL, OutgoingThread, &outArgs );
00155 
00156     check += handshake ( );
00157     check += authenticate ( );
00158 
00159     return check;
00160     }

bool coreClass::connectTo ( string dotsandnumbers) [private]

Initiates the connection to a server.

Parameters:
dotsandnumbers   the ip of the server (and dns later)
Returns:
true on success, false on failure
See also:
serverAddress

Definition at line 196 of file coreClass.cpp.

00197 {
00198     struct sockaddr_in address;
00199 //    struct hostent*    host;
00200 
00201     fprintf(stderr,"[cC.connectTo] \n");
00202     address.sin_addr.s_addr = inet_addr (dotsandnumbers.c_str ());
00203     bzero ( & ( address.sin_zero ), 8 );
00204 
00205 
00206 /*
00207     host = gethostbyname ( hostname );
00208     if (!host)
00209     return false;
00210     }; */
00211 
00212     if ((mySocket = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
00213     return false;
00214     };
00215 
00216     address.sin_family = AF_INET;
00217     address.sin_port = htons (serverPort);
00218 
00219     if (connect (mySocket, (sockaddr *) &address, sizeof (address))) {
00220     return false;
00221     };
00222 
00223     return true;
00224     }

bool coreClass::disconnectNow ( void)

Disconnect from a server.

Returns:
true on failure, false on success

Definition at line 176 of file coreClass.cpp.

00177 {
00178     fprintf(stderr,"Nooo, i don't let you, hahahaa!!\n");
00179     return 0;
00180     }

Buffer * coreClass::getBuffer ( int whichbuffer)

Get the pointer to a specific buffer.

Parameters:
whichbuffer   defines the buffer that shall be returned
Returns:
pointer on success, 0 on failure

Definition at line 318 of file coreClass.cpp.

00319 {
00320     if ( whichbuffer == INCOMING )
00321         return coreIn;
00322     if ( whichbuffer == OUTGOING )
00323         return coreOut;
00324 
00325     fprintf(stderr,"[coreClass::getBuffer] you dumb! (sorry, but i had to say that ;)\n");
00326     return 0;
00327     }

bool coreClass::handshake ( void) [private]

Does the handshake with the server.

Returns:
true on success, false on failure

Definition at line 239 of file coreClass.cpp.

00240 {
00241     packet* pak = new packet;
00242     bool check = false;
00243 
00244     fprintf(stderr,"[cC.handshake] \n");
00245 
00246     pak->h.header[0] = PROT_HANDSHAKE;
00247     pak->h.header[1] = HANDSHAKE_GREETING;
00248     pak->h.header[2] = VERSION_MAJOR;
00249     pak->h.header[3] = VERSION_MINOR;
00250     pak->h.header[4] = PATCH_LEVEL;
00251 
00252     pak->data = "MATRIX?";
00253 
00254     coreOut->write ( pak );
00255 
00256     while ( coreIn->isEmpty () );
00257 
00258     pak = coreIn->read ();
00259 
00260     check  = ( ( pak->h.header[0] != PROT_HANDSHAKE ) || ( pak->h.header[1] != HANDSHAKE_GREETING ) );
00261     check += ( ( pak->h.header[2] > VERSION_MAJOR ) || ( pak->h.header[3] > VERSION_MINOR ) );
00262 
00263     if (!check) fprintf(stderr,"[cC.handshake] successful!\n");
00264 
00265     delete pak;
00266     return check;
00267     }

void coreClass::setUpdateFreq ( unsigned int freq)

Change the Quartz' frequency.

Parameters:
freq   the frequency it shall send packages in

Definition at line 340 of file coreClass.cpp.

00341 {
00342     if ( !framesPerSecond )
00343         {
00344         fprintf(stderr,"[cc.setUpdateFreq] who would do that??\n");
00345         exit (1);
00346         }
00347 
00348     if ( !qObj)
00349         {
00350         fprintf(stderr,"coreClass::setUpdateFreq - THIS FUNCTION MUST NOT BE CALLED BEFORE THE QUARTZTHREAD IS STARTED!!\n");
00351         exit(1);
00352         }
00353     qObj->setFrequency ( framesPerSecond );
00354     fprintf(stderr,"[cc.setUpdateFreq] %d frames per second mean update every %d microseconds\n",framesPerSecond,1000000/framesPerSecond);
00355     }

void coreClass::startQuartz ( unsigned int freq)

Start the Quartz.

Parameters:
freq   the frequency it shall send packages in

Definition at line 330 of file coreClass.cpp.

00331 {
00332     qObj   = new QuartzClass ( coreOut, PROT_GET_ALL_CHANGED, freq );
00333     if ( pthread_create ( &quartzThread, NULL, QuartzThread, qObj ) )
00334         {
00335         cerr << "unable to start quartzthread..\n";
00336         exit(1);
00337         }
00338     }

Member Data Documentation

Buffer * coreClass::coreIn [private]

The buffer to read packages coming from the server.

Definition at line 68 of file coreClass.h.

Buffer * coreClass::coreOut [private]

The buffer to send packages to the server.

Definition at line 69 of file coreClass.h.

pthread_t coreClass::incomingThread [private]

The thread handler for the IncomingThread.

Definition at line 62 of file coreClass.h.

int coreClass::mySocket [private]

The handler for the socket to the server.

Definition at line 57 of file coreClass.h.

pthread_t coreClass::outgoingThread [private]

The thread handler for the OutgoingThread.

Definition at line 63 of file coreClass.h.

string coreClass::password [private]

The password for the server.

Definition at line 53 of file coreClass.h.

QuartzClass * coreClass::qObj [private]

The pointer to the object of the QuartzClass - to control the Quartz during runtime.

Definition at line 66 of file coreClass.h.

pthread_t coreClass::quartzThread [private]

The thread handler for the QuartzThread.

Definition at line 64 of file coreClass.h.

string coreClass::realname [private]

The real name of the user.

Definition at line 55 of file coreClass.h.

string coreClass::serverAddress [private]

The address of the server.

Definition at line 59 of file coreClass.h.

int coreClass::serverPort [private]

The port of the server.

Definition at line 60 of file coreClass.h.

string coreClass::username [private]

The username for the server.

Definition at line 52 of file coreClass.h.


The documentation for this class was generated from the following files:
Generated at Sat May 13 13:50:24 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000