00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D 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 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #include <client/ClientMessageHandler.h> 00022 #include <client/ClientState.h> 00023 #include <client/ScorchedClient.h> 00024 #include <dialogs/ConnectDialog.h> 00025 #include <tank/TankContainer.h> 00026 #include <common/Logger.h> 00027 #include <net/NetInterface.h> 00028 00029 ClientMessageHandler *ClientMessageHandler::instance_ = 0; 00030 00031 ClientMessageHandler *ClientMessageHandler::instance() 00032 { 00033 if (!instance_) 00034 { 00035 instance_ = new ClientMessageHandler; 00036 } 00037 return instance_; 00038 } 00039 00040 ClientMessageHandler::ClientMessageHandler() 00041 { 00042 } 00043 00044 ClientMessageHandler::~ClientMessageHandler() 00045 { 00046 } 00047 00048 void ClientMessageHandler::messageRecv(unsigned int destinationId) 00049 { 00050 } 00051 00052 void ClientMessageHandler::messageSent(unsigned int destinationId) 00053 { 00054 } 00055 00056 void ClientMessageHandler::clientConnected(NetMessage &message) 00057 { 00058 ConnectDialog::instance()->connected(); 00059 } 00060 00061 void ClientMessageHandler::clientDisconnected(NetMessage &message) 00062 { 00063 const char *type = ""; 00064 if (message.getFlags() == NetMessage::TimeoutDisconnect) 00065 { 00066 type = "Timeout"; 00067 } 00068 else if (message.getFlags() == NetMessage::UserDisconnect) 00069 { 00070 type = "User"; 00071 } 00072 00073 Logger::log(S3D::formatStringBuffer("Disconnected %s", type)); 00074 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimDisconnected); 00075 ScorchedClient::instance()->getGameState().checkStimulate(); 00076 ScorchedClient::instance()->getTankContainer().setCurrentDestinationId(0); 00077 } 00078 00079 void ClientMessageHandler::clientError(NetMessage &message, 00080 const char *errorString) 00081 { 00082 Logger::log(S3D::formatStringBuffer("***Client Error*** \"%s\"", errorString)); 00083 ScorchedClient::instance()->getNetInterface().disconnectAllClients(); 00084 }
1.5.3