#include "misc.h"
#include <map>
#include <string>
#include "commandThread.h"
Go to the source code of this file.
Functions | |
void* | CommandThread ( void* targz ) |
The Command Thread. More... |
|
The Command Thread.
targs | the passed arguments from main() |
Definition at line 27 of file commandThread.cpp.
00028 { 00029 ThreadArgs* targs = (ThreadArgs*) targz; 00030 fprintf(stderr,"[command] CommandThread alive...\n"); 00031 00032 Buffer* myBuffer = targs->in; 00033 Buffer* outputBuffer = targs->out; 00034 00035 map<string,int> command; 00036 00037 command["/quit"] = PROT_KILL_CLIENT; 00038 command["/dontshowme"] = PROT_TURN_AVATAR_OFF; 00039 command["/whatever"] = 0; 00040 00041 00042 while (1) 00043 { 00044 if ( !myBuffer->isEmpty() ) 00045 { 00046 #ifdef DEBUG 00047 fprintf(stderr,"[command] getting a packet.. :)\n"); 00048 #endif 00049 00050 packet* pak = myBuffer->read ( ); 00051 00052 switch ( pak->h.header[0] ) 00053 { 00054 case PROT_TEXT_MSG: 00055 { 00056 if ( (pak->data[0] == '/' ) ) 00057 { 00058 typedef map<string,int>::const_iterator commIt; 00059 00060 for ( commIt it = command.begin(); it != command.end(); ++it) 00061 { 00062 if ( it->first == pak->data ) 00063 { 00064 switch ( it->second ) 00065 { 00066 case PROT_KILL_CLIENT: 00067 { 00068 break; 00069 } 00070 case PROT_TURN_AVATAR_OFF: 00071 { 00072 packet* pak = new packet; 00073 pak->h.header[0] = PROT_TURN_AVATAR_OFF; 00074 outputBuffer->write ( pak ); 00075 break; 00076 } 00077 default: 00078 { 00079 break; 00080 } 00081 } 00082 break; 00083 } 00084 } 00085 } 00086 else 00087 { 00088 pak->h.header[0] = PROT_CHAT_MSG; 00089 outputBuffer->write ( pak ); 00090 break; 00091 } 00092 00093 break; 00094 } 00095 00096 default: 00097 { 00098 fprintf(stderr,"[commnad] _THATS_ actually not possible...\n"); 00099 delete pak; 00100 break; 00101 } 00102 } 00103 } 00104 } 00105 }