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/ComsConnectMessage.h> 00022 #include <common/Defines.h> 00023 00024 ComsConnectMessage::ComsConnectMessage() 00025 : ComsMessage("ComsConnectMessage") 00026 { 00027 00028 } 00029 00030 ComsConnectMessage::~ComsConnectMessage() 00031 { 00032 00033 } 00034 00035 bool ComsConnectMessage::writeMessage(NetBuffer &buffer) 00036 { 00037 buffer.addToBuffer((unsigned int) values_.size()); 00038 std::map<std::string, std::string>::iterator itor; 00039 for (itor = values_.begin(); 00040 itor != values_.end(); 00041 itor++) 00042 { 00043 buffer.addToBuffer((*itor).first.c_str()); 00044 buffer.addToBuffer((*itor).second.c_str()); 00045 } 00046 00047 return true; 00048 } 00049 00050 bool ComsConnectMessage::readMessage(NetBufferReader &reader) 00051 { 00052 unsigned int noV = 0; 00053 values_.clear(); 00054 if (!reader.getFromBuffer(noV)) return false; 00055 for (unsigned int i=0; i<noV; i++) 00056 { 00057 std::string name, value; 00058 00059 if (!reader.getFromBuffer(name)) return false; 00060 if (!reader.getFromBuffer(value)) return false; 00061 00062 // Validate the user strings 00063 if (strlen(value.c_str()) > 50) 00064 { 00065 ((char *)value.c_str())[50] = '\0'; 00066 } 00067 00068 values_[name] = value; 00069 } 00070 00071 return true; 00072 } 00073 00074 const char *ComsConnectMessage::getValue(const char *name) 00075 { 00076 std::map<std::string, std::string>::iterator itor = 00077 values_.find(name); 00078 if (itor == values_.end()) return ""; 00079 00080 return (*itor).second.c_str(); 00081 } 00082 00083 void ComsConnectMessage::setValue(const char *name, const char *value) 00084 { 00085 values_[name] = value; 00086 } 00087
1.5.3