mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- added some debug code for network protocol
This commit is contained in:
parent
63ad898c72
commit
b6a25c8212
@ -73,8 +73,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include "network_message.h"
|
||||
//#include "network_protocol.h"
|
||||
#include "network_message.h"
|
||||
#include "network_protocol.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
#ifdef WIN32
|
||||
@ -139,7 +139,7 @@ void cleanupCRCThread() {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("D - shutting down crc threads\n");
|
||||
|
||||
if(preCacheThread->canShutdown(false) == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
delete preCacheThread;
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("E - shutting down crc threads\n");
|
||||
@ -3080,6 +3080,18 @@ int glestMain(int argc, char** argv) {
|
||||
printf("\nCompiled using: %s on: %s platform: %s endianness: %s",getCompilerNameString().c_str(),getCompileDateTime().c_str(),getPlatformNameString().c_str(),(Shared::PlatformByteOrder::isBigEndian() == true ? "big" : "little"));
|
||||
|
||||
|
||||
Config::getInstance().setBool("DebugNetworkPackets",true,true);
|
||||
NetworkMessageIntro data(424336, "mg_version_x","player_x", 3, nmgstOk,444444, 555555, "english");
|
||||
unsigned char *buf = data.packMessage();
|
||||
printf("\nSend packet size = %u\n%s\n",data.getPackedSize(),data.toString().c_str());
|
||||
data.dump_packet("Send data", buf, data.getPackedSize());
|
||||
//delete [] buf;
|
||||
|
||||
data.unpackMessage(buf);
|
||||
printf("\nReceive packet size = %u\n%s\n",data.getPackedSize(),data.toString().c_str());
|
||||
data.dump_packet("nReceive data", buf, data.getPackedSize());
|
||||
delete [] buf;
|
||||
|
||||
// SwitchSetupRequest data("factionname", 3,-1,2,"softcoder",10, 11,"eng");
|
||||
//
|
||||
// unsigned char *buf = data.packMessage();
|
||||
|
@ -180,6 +180,30 @@ unsigned char * NetworkMessageIntro::packMessage() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
string NetworkMessageIntro::toString() const {
|
||||
|
||||
int8 messageType;
|
||||
int32 sessionId;
|
||||
NetworkString<maxVersionStringSize> versionString;
|
||||
NetworkString<maxNameSize> name;
|
||||
int16 playerIndex;
|
||||
int8 gameState;
|
||||
uint32 externalIp;
|
||||
uint32 ftpPort;
|
||||
NetworkString<maxLanguageStringSize> language;
|
||||
|
||||
string result = "messageType = " + intToStr(data.messageType);
|
||||
result += " sessionId = " + intToStr(data.sessionId);
|
||||
result += " versionString = " + data.versionString.getString();
|
||||
result += " name = " + data.name.getString();
|
||||
result += " playerIndex = " + intToStr(data.playerIndex);
|
||||
result += " gameState = " + intToStr(data.gameState);
|
||||
result += " externalIp = " + uIntToStr(data.externalIp);
|
||||
result += " ftpPort = " + uIntToStr(data.ftpPort);
|
||||
result += " language = " + data.language.getString();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool NetworkMessageIntro::receive(Socket* socket) {
|
||||
bool result = false;
|
||||
if(useOldProtocol == true) {
|
||||
|
@ -73,13 +73,13 @@ public:
|
||||
virtual void send(Socket* socket) = 0;
|
||||
virtual size_t getDataSize() const = 0;
|
||||
|
||||
void dump_packet(string label, const void* data, int dataSize);
|
||||
|
||||
protected:
|
||||
//bool peek(Socket* socket, void* data, int dataSize);
|
||||
bool receive(Socket* socket, void* data, int dataSize,bool tryReceiveUntilDataSizeMet);
|
||||
void send(Socket* socket, const void* data, int dataSize);
|
||||
|
||||
void dump_packet(string label, const void* data, int dataSize);
|
||||
|
||||
virtual const char * getPackedMessageFormat() const = 0;
|
||||
virtual unsigned int getPackedSize() = 0;
|
||||
virtual void unpackMessage(unsigned char *buf) = 0;
|
||||
@ -118,10 +118,6 @@ private:
|
||||
Data data;
|
||||
|
||||
protected:
|
||||
virtual const char * getPackedMessageFormat() const;
|
||||
virtual unsigned int getPackedSize();
|
||||
virtual void unpackMessage(unsigned char *buf);
|
||||
virtual unsigned char * packMessage();
|
||||
|
||||
public:
|
||||
NetworkMessageIntro();
|
||||
@ -129,6 +125,13 @@ public:
|
||||
const string &name, int playerIndex, NetworkGameStateType gameState,
|
||||
uint32 externalIp, uint32 ftpPort, const string &playerLanguage);
|
||||
|
||||
|
||||
virtual const char * getPackedMessageFormat() const;
|
||||
virtual unsigned int getPackedSize();
|
||||
virtual void unpackMessage(unsigned char *buf);
|
||||
virtual unsigned char * packMessage();
|
||||
|
||||
|
||||
virtual size_t getDataSize() const { return sizeof(Data); }
|
||||
|
||||
int32 getSessionId() const { return data.sessionId;}
|
||||
@ -142,6 +145,8 @@ public:
|
||||
|
||||
virtual bool receive(Socket* socket);
|
||||
virtual void send(Socket* socket);
|
||||
|
||||
string toString() const;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user