Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- added code for new network protocol (disabled by default as i need …
…to test this on arm)
  • Loading branch information
softcoder committed Nov 2, 2012
1 parent f128d40 commit 61c86c1
Show file tree
Hide file tree
Showing 10 changed files with 1,982 additions and 440 deletions.
74 changes: 66 additions & 8 deletions source/glest_game/main/main.cpp
Expand Up @@ -72,6 +72,9 @@
#endif

#include <stdlib.h>

//#include "network_message.h"
//#include "network_protocol.h"
#include "leak_dumper.h"

#ifdef WIN32
Expand Down Expand Up @@ -3076,15 +3079,65 @@ int glestMain(int argc, char** argv) {
printf("%s %s",extractFileFromDirectoryPath(argv[0]).c_str(),getNetworkPlatformFreeVersionString().c_str());
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"));

int8 testVar = 111;
printf("\nEndian value = %d",testVar);
testVar = Shared::PlatformByteOrder::toCommonEndian(testVar);
printf("\nEndian to common value = %d",testVar);
testVar = Shared::PlatformByteOrder::fromCommonEndian(testVar);
printf("\nEndian from common value = %d",testVar);

printf("\nint8 sizeof = %zu",sizeof(int8));
printf("\nSwitchSetupRequest sizeof = %zu",SwitchSetupRequest().getDataSize());
// SwitchSetupRequest data("factionname", 3,-1,2,"softcoder",10, 11,"eng");
//
// unsigned char *buf = data.packMessage();
// printf("\nSend packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags());
// //delete [] buf;
//
// data.unpackMessage(buf);
// printf("\nGot packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags());
// delete [] buf;

// int8 a = 1;
// uint8 b = 2;
// int16 c = 3;
// uint16 d = 4;
// int32 e = 5;
// uint32 f = 6;
//
// printf("\nPack test #1: [%d][%u][%d][%u][%d][%u]\n,",a,b,c,d,e,f);
//
// unsigned char *buf = new unsigned char[100];
// unsigned int packedsize = pack(buf, "cChHlL",
// a,
// b,
// c,
// d,
// e,
// f);
//
// printf("Pack test #2: [%u][%s]\n,",packedsize,buf);
//
// int8 a1 = 0;
// uint8 b1 = 0;
// int16 c1 = 0;
// uint16 d1 = 0;
// int32 e1 = 0;
// uint32 f1 = 0;
//
// unpack(buf, "cChHlL",
// &a1,
// &b1,
// &c1,
// &d1,
// &e1,
// &f1);
//
// printf("UnPack test #3: [%d][%u][%d][%u][%d][%u]\n,",a1,b1,c1,d1,e1,f1);

if(SystemFlags::VERBOSE_MODE_ENABLED == true) {
int8 testVar = 111;
printf("\nEndian value = %d",testVar);
testVar = Shared::PlatformByteOrder::toCommonEndian(testVar);
printf("\nEndian to common value = %d",testVar);
testVar = Shared::PlatformByteOrder::fromCommonEndian(testVar);
printf("\nEndian from common value = %d",testVar);

printf("\nint8 sizeof = %zu",sizeof(int8));
printf("\nSwitchSetupRequest sizeof = %zu",SwitchSetupRequest().getDataSize());
}

printf("\nSVN: [%s]",getSVNRevisionString().c_str());

Expand Down Expand Up @@ -3248,6 +3301,11 @@ int glestMain(int argc, char** argv) {
config.setBool("DebugNetworkPackets",true,true);
}

if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_ENABLE_NEW_PROTOCOL]) == true) {
printf("*NOTE: enabling new newtork protocol.\n");
NetworkMessage::useOldProtocol = false;
}

Socket::setBroadCastPort(config.getInt("BroadcastPort",intToStr(Socket::getBroadCastPort()).c_str()));

Socket::disableNagle = config.getBool("DisableNagle","false");
Expand Down
252 changes: 126 additions & 126 deletions source/glest_game/network/client_interface.cpp

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions source/glest_game/network/network_interface.cpp
Expand Up @@ -19,7 +19,7 @@
#include "platform_util.h"
#include <fstream>
#include "util.h"

#include "network_protocol.h"
#include "leak_dumper.h"

using namespace Shared::Platform;
Expand Down Expand Up @@ -54,16 +54,16 @@ NetworkMessageType NetworkInterface::getNextMessageType()
if(socket != NULL &&
socket->hasDataToRead() == true) {
//peek message type
int dataSize = socket->getDataToRead();
if(dataSize >= sizeof(messageType)) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize);
int dataSize = socket->getDataToRead();
if(dataSize >= sizeof(messageType)) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,dataSize);

int iPeek = socket->peek(&messageType, sizeof(messageType));

if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize);
}

//sanity check new message type
Expand All @@ -72,7 +72,7 @@ NetworkMessageType NetworkInterface::getNextMessageType()
throw megaglest_runtime_error("Invalid message type: " + intToStr(messageType));
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Invalid message type = %d (no packet handshake yet so ignored)\n",__FILE__,__FUNCTION__,__LINE__,messageType);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Invalid message type = %d (no packet handshake yet so ignored)\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,messageType);
}
}
}
Expand All @@ -82,7 +82,7 @@ NetworkMessageType NetworkInterface::getNextMessageType()

bool NetworkInterface::receiveMessage(NetworkMessage* networkMessage){

if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",__FILE__,__FUNCTION__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__);

Socket* socket= getSocket(false);

Expand All @@ -95,10 +95,10 @@ bool NetworkInterface::isConnected(){
}

void NetworkInterface::DisplayErrorMessage(string sErr, bool closeSocket) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sErr [%s]\n",__FILE__,__FUNCTION__,__LINE__,sErr.c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] sErr [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] sErr [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,sErr.c_str());

if(closeSocket == true && getSocket() != NULL)
{
if(closeSocket == true && getSocket() != NULL) {
close();
}

Expand All @@ -124,7 +124,7 @@ std::vector<ChatMsgInfo> NetworkInterface::getChatTextList(bool clearList) {

void NetworkInterface::clearChatInfo() {
if(chatTextList.empty() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatTextList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,chatTextList.size());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] chatTextList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chatTextList.size());
chatTextList.clear();
}
}
Expand All @@ -143,7 +143,7 @@ std::vector<MarkedCell> NetworkInterface::getMarkedCellList(bool clearList) {

void NetworkInterface::clearMarkedCellList() {
if(markedCellList.empty() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,markedCellList.size());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,markedCellList.size());
markedCellList.clear();
}
}
Expand All @@ -162,7 +162,7 @@ std::vector<UnMarkedCell> NetworkInterface::getUnMarkedCellList(bool clearList)

void NetworkInterface::clearUnMarkedCellList() {
if(unmarkedCellList.empty() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unmarkedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,unmarkedCellList.size());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] unmarkedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unmarkedCellList.size());
unmarkedCellList.clear();
}
}
Expand All @@ -181,7 +181,7 @@ std::vector<MarkedCell> NetworkInterface::getHighlightedCellList(bool clearList)

void NetworkInterface::clearHighlightedCellList() {
if(highlightedCellList.empty() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,markedCellList.size());
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] markedCellList.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,markedCellList.size());
highlightedCellList.clear();
}
}
Expand Down

0 comments on commit 61c86c1

Please sign in to comment.