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

controlClient.cc

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
00020 
00021 */
00022 
00023 #include <thread.h>
00024 #include <math.h>
00025 #include "controlClient.h"
00026 #include "log.h"
00027 #include "world.h"
00028 
00029 ControlClient::ControlClient(ost::TCPSocket &sock, World *w) : baseClient(sock,w){
00030   ;
00031 }
00032 
00033 void ControlClient::Run(void){
00034   log <<"Running new Control Client"<<endl;
00035 
00036   string st="";
00037   bool quit=false;
00038   while(!quit){ 
00039 
00040     while (stream->isPending(ost::SOCKET_PENDING_INPUT,0)&&!quit){
00041       char a;
00042       if ((a=stream->get())==-1){
00043     log <<"End of stream! Bad way to quit! (or not?)"<<endl;
00044     quit=true;
00045     continue;
00046       }
00047       if (a!=10)
00048     st+=a;
00049       else{
00050     if (st=="QUIT"){
00051       world->setQuit();
00052       *stream <<"OK"<<endl;
00053     }
00054     else if (st=="STAT"){
00055       *stream <<world->getStats()<<endl;
00056       *stream <<"OK"<<endl;
00057     }
00058     else if (st=="BYE"){
00059       quit=true;
00060       *stream <<"OK"<<endl;
00061     }
00062     else if (st!=""){
00063       log <<"unknown message from controlClient: "<<st<<endl;
00064       *stream <<"NOK"<<endl;
00065     }
00066     st="";
00067       }
00068     }
00069     dontWalk();
00070   }
00071   log <<"End of Control Client!"<<endl;
00072   alive=false;
00073 }

Generated on Mon Jun 17 19:53:44 2002 for Svas Server by doxygen1.2.16