Moved logging specific code to a separate file.

git-svn-id: https://svn.outpostuniverse.org:8443/svn/outpost2@890 7b3b2116-5498-11dd-abe4-fb2d8bf8a5a8
Hooman 2012-04-09 06:59:57 +00:00
parent b1538e6dd9
commit c5899c679f
3 changed files with 89 additions and 70 deletions

View File

@ -0,0 +1,72 @@
#include <winsock2.h>
#include <iostream.h>
#include <fstream.h>
#include <objbase.h>
#include "OPUNetTransportLayer.h"
// Global Debug file
ofstream logFile("log.txt");
void Log(char* string)
{
logFile << string << endl;
}
void DumpIP(unsigned long ip)
{
logFile << (ip & 255)
<< "." << ((ip >> 8) & 255)
<< "." << ((ip >> 16) & 255)
<< "." << ((ip >> 24) & 255);
}
void DumpAddr(sockaddr_in &addr)
{
logFile << "(AF:" << addr.sin_family << ") ";
DumpIP(addr.sin_addr.s_addr);
logFile << ":" << ntohs(addr.sin_port);
}
void DumpPlayerNetID(int playerNetID)
{
logFile << "[" << (playerNetID & ~7) << "." << (playerNetID & 7) << "]";
}
void DumpAddrList(PeerInfo* peerInfo)
{
int i;
for (i = 0; i < MaxRemotePlayers; i++)
{
logFile << " " << i << ") {" << peerInfo[i].status << ", ";
//DumpIP(peerInfo[i].address.sin_addr.s_addr);
DumpAddr(peerInfo[i].address);
logFile << ", ";
DumpPlayerNetID(peerInfo[i].playerNetID);
logFile << "}" << endl;
}
}
void DumpGuid(GUID &guid)
{
int i;
logFile << hex << "{" << guid.Data1 << "-" << guid.Data2 << "-" << guid.Data3 << "-";
for (i = 0; i < 8; i++)
{
logFile << (int)guid.Data4[i];
}
logFile << "}" << dec;
}
void DumpPacket(Packet* packet)
{
logFile << " Source: " << packet->header.sourcePlayerNetID << endl;
logFile << " Dest : " << packet->header.destPlayerNetID << endl;
logFile << " Size : " << (unsigned int)packet->header.sizeOfPayload << endl;
logFile << " type : " << (unsigned int)packet->header.type << endl;
logFile << " checksum : " << hex << packet->Checksum() << dec << endl;
logFile << " commandType : " << packet->tlMessage.tlHeader.commandType << endl;
}

16
NetFix/Client/trunk/Log.h Normal file
View File

@ -0,0 +1,16 @@
#include <fstream.h>
#include "OPUNetTransportLayer.h"
class ofstream;
// Global Debug file
extern ofstream logFile;
void Log(char* string);
void DumpIP(unsigned long ip);
void DumpAddr(sockaddr_in &addr);
void DumpPlayerNetID(int playerNetID);
void DumpAddrList(PeerInfo* peerInfo);
void DumpGuid(GUID &guid);
void DumpPacket(Packet* packet);

View File

@ -6,6 +6,7 @@
#include <mmsystem.h>
#include <objbase.h>
#include "OPUNetTransportLayer.h"
#include "Log.h"
extern char sectionName[];
@ -14,76 +15,6 @@ extern char sectionName[];
bool ValidatePacket(Packet& packet, sockaddr_in& from);
// ** Begin Debug Code
#include <iostream.h>
#include <fstream.h>
#include <objbase.h>
// Global Debug file
ofstream logFile("log.txt");
void DumpIP(unsigned long ip)
{
logFile << (ip & 255)
<< "." << ((ip >> 8) & 255)
<< "." << ((ip >> 16) & 255)
<< "." << ((ip >> 24) & 255);
}
void DumpAddr(sockaddr_in &addr)
{
logFile << "(AF:" << addr.sin_family << ") ";
DumpIP(addr.sin_addr.s_addr);
logFile << ":" << ntohs(addr.sin_port);
}
void DumpPlayerNetID(int playerNetID)
{
logFile << "[" << (playerNetID & ~7) << "." << (playerNetID & 7) << "]";
}
void DumpAddrList(PeerInfo* peerInfo)
{
int i;
for (i = 0; i < MaxRemotePlayers; i++)
{
logFile << " " << i << ") {" << peerInfo[i].status << ", ";
//DumpIP(peerInfo[i].address.sin_addr.s_addr);
DumpAddr(peerInfo[i].address);
logFile << ", ";
DumpPlayerNetID(peerInfo[i].playerNetID);
logFile << "}" << endl;
}
}
void DumpGuid(GUID &guid)
{
int i;
logFile << hex << "{" << guid.Data1 << "-" << guid.Data2 << "-" << guid.Data3 << "-";
for (i = 0; i < 8; i++)
{
logFile << (int)guid.Data4[i];
}
logFile << "}" << dec;
}
void DumpPacket(Packet* packet)
{
logFile << " Source: " << packet->header.sourcePlayerNetID << endl;
logFile << " Dest : " << packet->header.destPlayerNetID << endl;
logFile << " Size : " << (unsigned int)packet->header.sizeOfPayload << endl;
logFile << " type : " << (unsigned int)packet->header.type << endl;
logFile << " checksum : " << hex << packet->Checksum() << dec << endl;
logFile << " commandType : " << packet->tlMessage.tlHeader.commandType << endl;
}
// ** End Debug Code
// Public member functions
// -----------------------