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

commandThread.cpp

Go to the documentation of this file.
00001 /********************************************************************
00002 Description: The Command Thread (should actually become a plugin)
00003 part of the 3Dsia project
00004 created: xandi, 040500
00005 
00006 History:
00007     date,   name,       changes,                    in funtion
00008 
00009 ********************************************************************/
00010 
00011 #include "misc.h"
00012 #include <map>
00013 #include <string>
00014 
00015 #include "commandThread.h"
00016 
00017 /*...................................................................
00018 Description: the commandThread
00019 Args:
00020 Returns:
00021 Created: xandi, 030500
00022 [ToDo:]
00023 [Comments:]
00024 Changes:
00025 -------------------------------------------------------------------*/
00026 
00027 void *CommandThread ( void* targz )
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     }
00106 

Generated at Sat May 13 13:50:18 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000