git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / coms / ComsConnectMessage.cpp
blobb26a413e2cf85175d522168139a225bf9ca2edc4
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 #include <coms/ComsConnectMessage.h>
22 #include <common/Defines.h>
24 ComsConnectMessage::ComsConnectMessage()
25 : ComsMessage("ComsConnectMessage")
30 ComsConnectMessage::~ComsConnectMessage()
35 bool ComsConnectMessage::writeMessage(NetBuffer &buffer)
37 buffer.addToBuffer((unsigned int) values_.size());
38 std::map<std::string, std::string>::iterator itor;
39 for (itor = values_.begin();
40 itor != values_.end();
41 itor++)
43 buffer.addToBuffer((*itor).first.c_str());
44 buffer.addToBuffer((*itor).second.c_str());
47 return true;
50 bool ComsConnectMessage::readMessage(NetBufferReader &reader)
52 unsigned int noV = 0;
53 values_.clear();
54 if (!reader.getFromBuffer(noV)) return false;
55 for (unsigned int i=0; i<noV; i++)
57 std::string name, value;
59 if (!reader.getFromBuffer(name)) return false;
60 if (!reader.getFromBuffer(value)) return false;
62 // Validate the user strings
63 if (strlen(value.c_str()) > 50)
65 ((char *)value.c_str())[50] = '\0';
68 values_[name] = value;
71 return true;
74 const char *ComsConnectMessage::getValue(const char *name)
76 std::map<std::string, std::string>::iterator itor =
77 values_.find(name);
78 if (itor == values_.end()) return "";
80 return (*itor).second.c_str();
83 void ComsConnectMessage::setValue(const char *name, const char *value)
85 values_[name] = value;