1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2011
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20
21
22 #include <coms/ComsDefenseMessage.h>
23 #include <weapons/AccessoryStore.h>
24
25 ComsMessageType ComsDefenseMessage::ComsDefenseMessageType("ComsDefenseMessageType");
26
ComsDefenseMessage()27 ComsDefenseMessage::ComsDefenseMessage() :
28 ComsMessage(ComsDefenseMessageType),
29 playerId_(0),
30 change_(eNoChange),
31 infoId_(0)
32 {
33 }
34
ComsDefenseMessage(unsigned int playerId,DefenseChange change,unsigned int infoId)35 ComsDefenseMessage::ComsDefenseMessage(unsigned int playerId,
36 DefenseChange change,
37 unsigned int infoId) :
38 ComsMessage(ComsDefenseMessageType),
39 playerId_(playerId),
40 change_(change),
41 infoId_(infoId)
42 {
43 }
44
ComsDefenseMessage(ComsDefenseMessage & other)45 ComsDefenseMessage::ComsDefenseMessage(ComsDefenseMessage &other) :
46 ComsMessage(ComsDefenseMessageType),
47 playerId_(other.playerId_),
48 change_(other.change_),
49 infoId_(other.infoId_)
50 {
51 }
52
~ComsDefenseMessage()53 ComsDefenseMessage::~ComsDefenseMessage()
54 {
55 }
56
writeMessage(NetBuffer & buffer)57 bool ComsDefenseMessage::writeMessage(NetBuffer &buffer)
58 {
59 buffer.addToBuffer(playerId_);
60 buffer.addToBuffer((int) change_);
61 buffer.addToBuffer(infoId_);
62 return true;
63 }
64
readMessage(NetBufferReader & reader)65 bool ComsDefenseMessage::readMessage(NetBufferReader &reader)
66 {
67 if (!reader.getFromBuffer(playerId_)) return false;
68 int c = 0;
69 if (!reader.getFromBuffer(c)) return false;
70 change_ = (DefenseChange) c;
71 if (!reader.getFromBuffer(infoId_)) return false;
72 return true;
73 }
74