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/ComsPlayMovesMessage.h> 00022 00023 ComsPlayMovesMessage::ComsPlayMovesMessage() : 00024 ComsMessage("ComsPlayMovesMessage"), 00025 playerState_(true, true) 00026 { 00027 } 00028 00029 ComsPlayMovesMessage::~ComsPlayMovesMessage() 00030 { 00031 } 00032 00033 bool ComsPlayMovesMessage::writeMessage(NetBuffer &buffer) 00034 { 00035 if (!playerState_.writeMessage(buffer)) return false; 00036 00037 int size = (int) moves_.size(); 00038 buffer.addToBuffer(size); 00039 00040 std::map<unsigned int, ComsPlayedMoveMessage *>::iterator itor; 00041 for (itor = moves_.begin(); 00042 itor != moves_.end(); 00043 itor++) 00044 { 00045 unsigned int playerId = (*itor).first; 00046 ComsPlayedMoveMessage *message = (*itor).second; 00047 00048 buffer.addToBuffer(playerId); 00049 if (!message->writeMessage(buffer)) return false; 00050 } 00051 buffer.addToBuffer(seed_); 00052 return true; 00053 } 00054 00055 bool ComsPlayMovesMessage::readMessage(NetBufferReader &reader) 00056 { 00057 if (!playerState_.readMessage(reader)) return false; 00058 00059 int size = 0; 00060 if (!reader.getFromBuffer(size)) return false; 00061 00062 for (int s=0; s<size; s++) 00063 { 00064 ComsPlayedMoveMessage *message = new ComsPlayedMoveMessage(); 00065 unsigned int playerId = 0; 00066 00067 if (!reader.getFromBuffer(playerId)) return false; 00068 if (!message->readMessage(reader)) return false; 00069 00070 moves_[playerId] = message; 00071 } 00072 if (!reader.getFromBuffer(seed_)) return false; 00073 return true; 00074 }
1.5.3