ComsNewGameMessage.cpp

Go to the documentation of this file.
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 <coms/ComsNewGameMessage.h>
00022 #include <common/OptionsScorched.h>
00023 #include <common/OptionsTransient.h>
00024 #include <weapons/AccessoryStore.h>
00025 #ifndef S3D_SERVER
00026 #include <client/ScorchedClient.h>
00027 #endif
00028 #include <server/ScorchedServer.h>
00029 
00030 ComsNewGameMessage::ComsNewGameMessage() :
00031         ComsMessage("ComsNewGameMessage"),
00032         gameStateEnclosed_(false)
00033 {
00034 
00035 }
00036 
00037 ComsNewGameMessage::~ComsNewGameMessage()
00038 {
00039 
00040 }
00041 
00042 void ComsNewGameMessage::addGameState()
00043 {
00044         gameStateEnclosed_ = true;
00045 }
00046 
00047 bool ComsNewGameMessage::writeMessage(NetBuffer &buffer)
00048 {
00049         if (!levelMessage_.writeMessage(buffer)) return false;
00050         buffer.addToBuffer(gameStateEnclosed_);
00051         if (gameStateEnclosed_)
00052         {
00053                 if (!ScorchedServer::instance()->
00054                         getOptionsGame().getMainOptions().writeToBuffer(buffer, false, false)) return false;
00055         }
00056         if (!ScorchedServer::instance()->
00057                 getOptionsTransient().writeToBuffer(buffer)) return false;
00058 
00059         ComsPlayerStateMessage playerState(false, true);
00060         if (!playerState.writeMessage(playerStateMessage_)) return false;
00061         buffer.addToBuffer(playerStateMessage_);
00062 
00063         if (!ScorchedServer::instance()->getAccessoryStore().
00064                 writeEconomyToBuffer(buffer)) return false;
00065 
00066         return true;
00067 }
00068 
00069 bool ComsNewGameMessage::readMessage(NetBufferReader &reader)
00070 {
00071 #ifndef S3D_SERVER
00072         if (!levelMessage_.readMessage(reader)) return false;
00073         if (!reader.getFromBuffer(gameStateEnclosed_)) return false;
00074         if (gameStateEnclosed_)
00075         {
00076                 if (!ScorchedClient::instance()->
00077                         getOptionsGame().getMainOptions().readFromBuffer(reader, false, false)) return false;
00078         }
00079         ScorchedClient::instance()->getOptionsGame().updateLevelOptions(
00080                 ScorchedClient::instance()->getContext(), levelMessage_.getGroundMapsDefn());
00081         if (!ScorchedClient::instance()->
00082                 getOptionsTransient().readFromBuffer(reader)) return false;
00083         if (!reader.getFromBuffer(playerStateMessage_)) return false;
00084         if (!ScorchedClient::instance()->getAccessoryStore().
00085                 readEconomyFromBuffer(reader)) return false;
00086 #endif
00087 
00088         return true;
00089 }
00090 
00091 bool ComsNewGameMessage::parsePlayerStateMessage()
00092 {
00093         NetBufferReader reader(playerStateMessage_);
00094         ComsPlayerStateMessage playerState(false, true);
00095         if (!playerState.readMessage(reader))
00096         {
00097                 return false;
00098         }
00099         return true;
00100 }
00101 

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3