From 9a8f2ae01a33989663c10778ec1b06b88e347b78 Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 3 Aug 2009 20:42:32 +0000 Subject: [PATCH] Fixing some ASN.1 related bugs. Playing a game works now, but there is still an issue when the lobby is started after the game. --- src/core/loghelper.h | 12 ++++++------ src/net/common/clientstate.cpp | 8 ++------ src/net/common/netpacket.cpp | 16 ++++++++++++++++ src/net/common/receiverhelper.cpp | 5 ++++- src/net/common/senderhelper.cpp | 1 + src/net/netpacket.h | 3 +++ 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/core/loghelper.h b/src/core/loghelper.h index 5a89d0b8..52c37930 100644 --- a/src/core/loghelper.h +++ b/src/core/loghelper.h @@ -30,27 +30,27 @@ void internal_log_err(const std::string &msg); void internal_log_msg(const std::string &msg); void internal_log_level(const std::string &msg, int logLevel); -#define LOG_ERROR(e) \ +#define LOG_ERROR(_e) \ do \ { \ std::ostringstream outStream; \ - outStream << e << std::endl; \ + outStream << _e << std::endl; \ internal_log_err(outStream.str()); \ } \ while(false) -#define LOG_MSG(e) \ +#define LOG_MSG(_e) \ do \ { \ std::ostringstream outStream; \ - outStream << e << std::endl; \ + outStream << _e << std::endl; \ internal_log_msg(outStream.str()); \ } \ while(false) -#define LOG_VERBOSE(e) \ +#define LOG_VERBOSE(_e) \ do \ { \ std::ostringstream outStream; \ - outStream << e << std::endl; \ + outStream << _e << std::endl; \ internal_log_level(outStream.str(), 2); \ } \ while(false) diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 9c0c2e2e..9a69b9ec 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -830,7 +830,6 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien client->RequestPlayerInfo(playerId); } tmpInfo.players.push_back(playerId); - ++i; } tmpInfo.adminPlayerId = netListNew->adminPlayerId; tmpInfo.isPasswordProtected = netListNew->isPrivate ? true : false; @@ -941,8 +940,8 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien // Show the error. throw ClientException(__FILE__, __LINE__, NetPacket::NetErrorToGameError(netError->errorReason), 0); } - else - InternalHandlePacket(client, tmpPacket); + + InternalHandlePacket(client, tmpPacket); } //----------------------------------------------------------------------------- @@ -1302,8 +1301,6 @@ ClientStateWaitStart::InternalHandlePacket(boost::shared_ptr clien if (!tmpPlayer.get()) throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); tmpPlayer->SetNumber(i); - - ++i; } } else @@ -1602,7 +1599,6 @@ ClientStateRunHand::InternalHandlePacket(boost::shared_ptr client, tmpCards[0] = static_cast(p->allInCard1); tmpCards[1] = static_cast(p->allInCard2); tmpPlayer->setMyCards(tmpCards); - ++i; } client->GetGui().flipHolecardsAllIn(); } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index e8c61024..586b7f74 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -87,6 +87,22 @@ NetPacket::IsClientActivity() const return retVal; } +static int +net_packet_print_to_string(const void *buffer, size_t size, void *packetStr) +{ + string *tmpString = (string *)packetStr; + *tmpString += string((const char *)buffer, size); + return 0; +} + +string +NetPacket::ToString() const +{ + string packetString; + xer_encode(&asn_DEF_PokerTHMessage, m_msg, XER_F_BASIC, &net_packet_print_to_string, &packetString); + return packetString; +} + void NetPacket::SetGameData(const GameData &inData, NetGameInfo_t *outData) { diff --git a/src/net/common/receiverhelper.cpp b/src/net/common/receiverhelper.cpp index 3d257f86..98f6c2a1 100644 --- a/src/net/common/receiverhelper.cpp +++ b/src/net/common/receiverhelper.cpp @@ -61,8 +61,11 @@ ReceiverHelper::ScanPackets(ReceiveBuffer &buf) LOG_ERROR(e.what()); } } - if (tmpPacket.get()) + if (tmpPacket) + { + //cerr << "IN:" << endl << tmpPacket->ToString() << endl; buf.receivedPackets.push_back(tmpPacket); + } else dataAvailable = false; } while(dataAvailable); diff --git a/src/net/common/senderhelper.cpp b/src/net/common/senderhelper.cpp index 8a2226d2..441a5843 100644 --- a/src/net/common/senderhelper.cpp +++ b/src/net/common/senderhelper.cpp @@ -236,6 +236,7 @@ SenderHelper::InternalStorePacket(SendDataManager &tmpManager, boost::shared_ptr unsigned char buf[MAX_PACKET_SIZE]; asn_enc_rval_t e; e = der_encode_to_buffer(&asn_DEF_PokerTHMessage, packet->GetMsg(), buf, MAX_PACKET_SIZE); + //cerr << "OUT:" << endl << packet->ToString() << endl; if (e.encoded == -1) LOG_ERROR("Failed to encode NetPacket: " << packet->GetMsg()->present); else diff --git a/src/net/netpacket.h b/src/net/netpacket.h index 1cd27ad1..aefac290 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -21,6 +21,7 @@ #ifndef _NETPACKET_H_ #define _NETPACKET_H_ +#include #include #include @@ -57,6 +58,8 @@ public: bool IsClientActivity() const; + std::string ToString() const; + static void SetGameData(const GameData &inData, NetGameInfo_t *outData); static void GetGameData(const NetGameInfo_t *inData, GameData &outData);