From: <hi...@us...> - 2013-07-18 17:56:35
|
Revision: 13272 http://sourceforge.net/p/supertuxkart/code/13272 Author: hilnius Date: 2013-07-18 17:56:32 +0000 (Thu, 18 Jul 2013) Log Message: ----------- stupid mistake in a line was making everything bug Modified Paths: -------------- main/branches/hilnius/src/network/event.cpp main/branches/hilnius/src/network/network_string.hpp main/branches/hilnius/src/network/protocols/client_lobby_room_protocol.cpp main/branches/hilnius/src/network/protocols/kart_update_protocol.cpp main/branches/hilnius/src/network/protocols/server_lobby_room_protocol.cpp main/branches/hilnius/src/network/stk_peer.cpp Modified: main/branches/hilnius/src/network/event.cpp =================================================================== --- main/branches/hilnius/src/network/event.cpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/event.cpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -42,7 +42,7 @@ } if (type == EVENT_TYPE_MESSAGE) { - data = std::string((char*)(event->packet->data), event->packet->dataLength-1); + data = NetworkString(std::string((char*)(event->packet->data), event->packet->dataLength-1)); } else if (event->data) { Modified: main/branches/hilnius/src/network/network_string.hpp =================================================================== --- main/branches/hilnius/src/network/network_string.hpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/network_string.hpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -4,6 +4,7 @@ #include "utils/types.hpp" #include <string> +#include <vector> #include <stdarg.h> #include <assert.h> @@ -21,54 +22,54 @@ } d_as_i; // double as integer public: NetworkString() { } - NetworkString(const uint8_t& value) { m_string = (char)(value); } + NetworkString(const uint8_t& value) { m_string.push_back(value); } NetworkString(NetworkString const& copy) { m_string = copy.m_string; } - NetworkString(std::string str) { m_string = str; } + NetworkString(const std::string & value) { m_string = std::vector<uint8_t>(value.begin(), value.end()); } NetworkString& removeFront(int size) { - m_string.erase(0, size); + m_string.erase(m_string.begin(), m_string.begin()+size); return *this; } NetworkString& remove(int pos, int size) { - m_string.erase(pos, size); + m_string.erase(m_string.begin()+pos, m_string.begin()+pos+size); return *this; } - uint8_t operator[](const int& pos) + uint8_t operator[](const int& pos) const { return getUInt8(pos); } NetworkString& addUInt8(const uint8_t& value) { - m_string += (char)(value); + m_string.push_back(value); return *this; } inline NetworkString& ai8(const uint8_t& value) { return addUInt8(value); } NetworkString& addUInt16(const uint16_t& value) { - m_string += (char)((value>>8)&0xff); - m_string += (char)(value&0xff); + m_string.push_back((value>>8)&0xff); + m_string.push_back(value&0xff); return *this; } inline NetworkString& ai16(const uint16_t& value) { return addUInt16(value); } NetworkString& addUInt32(const uint32_t& value) { - m_string += (char)((value>>24)&0xff); - m_string += (char)((value>>16)&0xff); - m_string += (char)((value>>8)&0xff); - m_string += (char)(value&0xff); + m_string.push_back((value>>24)&0xff); + m_string.push_back((value>>16)&0xff); + m_string.push_back((value>>8)&0xff); + m_string.push_back(value&0xff); return *this; } inline NetworkString& ai32(const uint32_t& value) { return addUInt32(value); } NetworkString& addInt(const int& value) { - m_string += (char)((value>>24)&0xff); - m_string += (char)((value>>16)&0xff); - m_string += (char)((value>>8)&0xff); - m_string += (char)(value&0xff); + m_string.push_back((value>>24)&0xff); + m_string.push_back((value>>16)&0xff); + m_string.push_back((value>>8)&0xff); + m_string.push_back(value&0xff); return *this; } inline NetworkString& ai(const int& value) { return addInt(value); } @@ -76,10 +77,10 @@ { assert(sizeof(float)==4); f_as_i.f = value; - m_string += (char)(f_as_i.i[0]); - m_string += (char)(f_as_i.i[1]); - m_string += (char)(f_as_i.i[2]); - m_string += (char)(f_as_i.i[3]); + m_string.push_back(f_as_i.i[0]); + m_string.push_back(f_as_i.i[1]); + m_string.push_back(f_as_i.i[2]); + m_string.push_back(f_as_i.i[3]); return *this; } inline NetworkString& af(const float& value) { return addFloat(value); } @@ -87,34 +88,36 @@ { assert(sizeof(double)==8); d_as_i.d = value; - m_string += (char)(d_as_i.i[0]); - m_string += (char)(d_as_i.i[1]); - m_string += (char)(d_as_i.i[2]); - m_string += (char)(d_as_i.i[3]); - m_string += (char)(d_as_i.i[4]); - m_string += (char)(d_as_i.i[5]); - m_string += (char)(d_as_i.i[6]); - m_string += (char)(d_as_i.i[7]); + m_string.push_back(d_as_i.i[0]); + m_string.push_back(d_as_i.i[1]); + m_string.push_back(d_as_i.i[2]); + m_string.push_back(d_as_i.i[3]); + m_string.push_back(d_as_i.i[4]); + m_string.push_back(d_as_i.i[5]); + m_string.push_back(d_as_i.i[6]); + m_string.push_back(d_as_i.i[7]); return *this; } inline NetworkString& ad(const double& value) { return addDouble(value); } NetworkString& addString(const std::string& value) { - m_string += value; + for (unsigned int i = 0; i < value.size(); i++) + m_string.push_back((uint8_t)(value[i])); return *this; } inline NetworkString& as(const std::string& value) { return addString(value); } NetworkString& operator+=(NetworkString const& value) { - m_string += value.m_string; + m_string.insert( m_string.end(), value.m_string.begin(), value.m_string.end() ); return *this; } const char* c_str() const { - return m_string.c_str(); + std::string str(m_string.begin(), m_string.end()); + return str.c_str(); } int size() const { @@ -122,7 +125,7 @@ } template<typename T, size_t n> - T get(int pos) + T get(int pos) const { int a = n; T result = 0; @@ -134,23 +137,23 @@ return result; } - inline int getInt(int pos = 0) { return get<int,4>(pos); } - inline uint32_t getUInt(int pos = 0) { return get<uint32_t,4>(pos); } - inline uint32_t getUInt32(int pos = 0) { return get<uint32_t,4>(pos); } - inline uint16_t getUInt16(int pos = 0) { return get<uint16_t,2>(pos); } - inline uint8_t getUInt8(int pos = 0) { return get<uint8_t,1>(pos); } - inline char getChar(int pos = 0) { return get<char,1>(pos); } - inline unsigned char getUChar(int pos = 0) { return get<unsigned char,1>(pos); } - std::string getString(int pos = 0) { return std::string(m_string.c_str()+pos); } + inline int getInt(int pos = 0) const { return get<int,4>(pos); } + inline uint32_t getUInt(int pos = 0) const { return get<uint32_t,4>(pos); } + inline uint32_t getUInt32(int pos = 0) const { return get<uint32_t,4>(pos); } + inline uint16_t getUInt16(int pos = 0) const { return get<uint16_t,2>(pos); } + inline uint8_t getUInt8(int pos = 0) const { return get<uint8_t,1>(pos); } + inline char getChar(int pos = 0) const { return get<char,1>(pos); } + inline unsigned char getUChar(int pos = 0) const { return get<unsigned char,1>(pos); } + std::string getString(int pos, int len) const { return std::string(m_string.begin()+pos, m_string.begin()+pos+len); } - inline int gi(int pos = 0) { return get<int,4>(pos); } - inline uint32_t gui(int pos = 0) { return get<uint32_t,4>(pos); } - inline uint32_t gui32(int pos = 0) { return get<uint32_t,4>(pos); } - inline uint16_t gui16(int pos = 0) { return get<uint16_t,2>(pos); } - inline uint8_t gui8(int pos = 0) { return get<uint8_t,1>(pos); } - inline char gc(int pos = 0) { return get<char,1>(pos); } - inline unsigned char guc(int pos = 0) { return get<unsigned char,1>(pos); } - std::string gs(int pos = 0) { return std::string(m_string.c_str()+pos); } + inline int gi(int pos = 0) const { return get<int,4>(pos); } + inline uint32_t gui(int pos = 0) const { return get<uint32_t,4>(pos); } + inline uint32_t gui32(int pos = 0) const { return get<uint32_t,4>(pos); } + inline uint16_t gui16(int pos = 0) const { return get<uint16_t,2>(pos); } + inline uint8_t gui8(int pos = 0) const { return get<uint8_t,1>(pos); } + inline char gc(int pos = 0) const { return get<char,1>(pos); } + inline unsigned char guc(int pos = 0) const { return get<unsigned char,1>(pos); } + std::string gs(int pos, int len) const { return std::string(m_string.begin()+pos, m_string.begin()+pos+len); } double getDouble(int pos = 0) //!< BEWARE OF PRECISION { @@ -213,7 +216,7 @@ inline NetworkString& gf(float* dst) { *dst = getAndRemoveFloat(0); return *this; } protected: - std::string m_string; + std::vector<uint8_t> m_string; }; NetworkString operator+(NetworkString const& a, NetworkString const& b); Modified: main/branches/hilnius/src/network/protocols/client_lobby_room_protocol.cpp =================================================================== --- main/branches/hilnius/src/network/protocols/client_lobby_room_protocol.cpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/protocols/client_lobby_room_protocol.cpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -117,6 +117,8 @@ m_state = EXITING; m_listener->requestTerminate(this); break; + case EXITING: + break; } } @@ -347,7 +349,7 @@ } uint8_t player_id = event->data[1]; uint8_t kart_name_length = event->data[2]; - std::string data = event->data.getString(3); + std::string data = event->data.getString(3, kart_name_length); if (data.size() != kart_name_length) { Log::error("ClientLobbyRoomProtocol", "Kart names sizes differ: told: %d, real: %d.", kart_name_length, data.size()); Modified: main/branches/hilnius/src/network/protocols/kart_update_protocol.cpp =================================================================== --- main/branches/hilnius/src/network/protocols/kart_update_protocol.cpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/protocols/kart_update_protocol.cpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -38,12 +38,12 @@ Log::info("KartUpdateProtocol", "Message too short."); return; } - float game_time = event->data.getFloat(0); + float game_time = ns.getFloat(0); ns.removeFront(4); int nb_updates = 0; while(ns.size() >= 16) { - uint32_t kart_id = event->data.getUInt32(0); + uint32_t kart_id = ns.getUInt32(0); float a,b,c; a = ns.getFloat(4); @@ -93,6 +93,7 @@ ns.ai32( kart->getWorldKartId()); ns.af(v[0]).af(v[1]).af(v[2]); Log::info("KartUpdateProtocol", "Sending %d's positions %f %f %f", kart->getWorldKartId(), v[0], v[1], v[2]); + Log::info("KartUpdateProtocol", "Sending %d's positions %f %f %f", ns.gui32(4), v[0], v[1], v[2]); m_listener->sendMessage(this, ns, false); } } Modified: main/branches/hilnius/src/network/protocols/server_lobby_room_protocol.cpp =================================================================== --- main/branches/hilnius/src/network/protocols/server_lobby_room_protocol.cpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/protocols/server_lobby_room_protocol.cpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -304,7 +304,7 @@ return; } uint8_t kart_name_size = event->data.gui8(5); - std::string kart_name = event->data.gs(6); + std::string kart_name = event->data.gs(6, kart_name_size); if (kart_name.size() != kart_name_size) { Log::error("ServerLobbyRoomProtocol", "Kart names sizes differ: told:" Modified: main/branches/hilnius/src/network/stk_peer.cpp =================================================================== --- main/branches/hilnius/src/network/stk_peer.cpp 2013-07-18 16:37:40 UTC (rev 13271) +++ main/branches/hilnius/src/network/stk_peer.cpp 2013-07-18 17:56:32 UTC (rev 13272) @@ -98,6 +98,13 @@ ENetPacket* packet = enet_packet_create(data.c_str(), data.size()+1, (reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED)); + printf("STKPeer: "); + for (unsigned int i = 0; i < data.size(); i++) + { + printf("%d ", (uint8_t)(data[i])); + } + printf("\n"); + enet_peer_send(m_peer, 0, packet); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |