git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / coms / ComsConnectAcceptMessage.cpp
blob7914631f67543f15784258cc8d3d3f88ed83068b
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
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.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #ifndef S3D_SERVER
22 #include <client/ScorchedClient.h>
23 #endif
24 #include <server/ScorchedServer.h>
25 #include <coms/ComsConnectAcceptMessage.h>
26 #include <weapons/AccessoryStore.h>
27 #include <common/OptionsScorched.h>
29 ComsConnectAcceptMessage::ComsConnectAcceptMessage(unsigned int destinationId,
30 const char *serverName,
31 const char *publishAddress,
32 const char *uniqueId) :
33 ComsMessage("ComsConnectAcceptMessage"),
34 destinationId_(destinationId),
35 serverName_(serverName),
36 publishAddress_(publishAddress),
37 uniqueId_(uniqueId)
42 ComsConnectAcceptMessage::~ComsConnectAcceptMessage()
47 bool ComsConnectAcceptMessage::writeMessage(NetBuffer &buffer)
49 buffer.addToBuffer(destinationId_);
50 buffer.addToBuffer(serverName_);
51 buffer.addToBuffer(publishAddress_);
52 buffer.addToBuffer(uniqueId_);
53 buffer.addToBuffer(serverPng_.getBufferUsed());
54 buffer.addDataToBuffer(serverPng_.getBuffer(), serverPng_.getBufferUsed());
55 if (!ScorchedServer::instance()->getOptionsGame().getMainOptions().
56 writeToBuffer(buffer, false, false)) return false;
57 return true;
60 bool ComsConnectAcceptMessage::readMessage(NetBufferReader &reader)
62 if (!reader.getFromBuffer(destinationId_)) return false;
63 if (!reader.getFromBuffer(serverName_)) return false;
64 if (!reader.getFromBuffer(publishAddress_)) return false;
65 if (!reader.getFromBuffer(uniqueId_)) return false;
66 unsigned int used;
67 if (!reader.getFromBuffer(used)) return false;
68 serverPng_.allocate(used);
69 serverPng_.reset();
70 serverPng_.setBufferUsed(used);
71 reader.getDataFromBuffer(serverPng_.getBuffer(), used);
72 #ifndef S3D_SERVER
73 if (!ScorchedClient::instance()->getOptionsGame().getMainOptions().
74 readFromBuffer(reader, false, false)) return false;
75 #endif // #ifndef S3D_SERVER
76 return true;