#include <coreClass.h>
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... | |
| Buffer* | getBuffer ( 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... | |
| QuartzClass* | qObj |
| The pointer to the object of the QuartzClass - to control the Quartz during runtime. More... | |
| Buffer* | coreIn |
| The buffer to read packages coming from the server. More... | |
| Buffer* | coreOut |
| The buffer to send packages to the server. More... | |
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 }
|
The constructor for coreClass.
| 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 }
|
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 }
|
Does the authentication using username and 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 }
|
Does every step neccessary to connect to a server.
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 }
|
Initiates the connection to a server.
| dotsandnumbers | the ip of the server (and dns later) |
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 }
|
Disconnect from a server.
Definition at line 176 of file coreClass.cpp.
00177 {
00178 fprintf(stderr,"Nooo, i don't let you, hahahaa!!\n");
00179 return 0;
00180 }
|
Get the pointer to a specific buffer.
| whichbuffer | defines the buffer that shall be returned |
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 }
|
Does the handshake with the server.
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 }
|
Change the Quartz' frequency.
| 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 }
|
Start the Quartz.
| 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 }
|
|
|
|
|
|
|
The pointer to the object of the QuartzClass - to control the Quartz during runtime.
Definition at line 66 of file coreClass.h.
|
|
|
|
|
1.1.2 written by Dimitri van Heesch,
© 1997-2000