Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Jun 8, 2017
1 parent 009926c commit e30cec1
Show file tree
Hide file tree
Showing 284 changed files with 90,903 additions and 1 deletion.
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Unity Proxy Server

2.0.1f1 (25 Feb 2011)

- (common) Added option for launching to background (daemon mode) on Linux.
- (common) PID file now written after launch.
- (common) Launch script for Linux added (start/stop/restart), see config/unity-proxyserver.
- (common) Command line parameters modified to match the other servers.
- (common) All servers now use same logging facility
- Problem when parsing server proxied RPC messages fixed.

2.0.0f1 (22 Sep 2011)

- (common) Upgraded to use RakNet version 3.72
149 changes: 149 additions & 0 deletions Common/Log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include "Log.h"
#include <time.h>
#include <stdio.h>
#include <stdarg.h>

int Log::sDebugLevel = kFullDebug;
FILE* Log::outputStream = stdout;
char* Log::logfile;
bool Log::printStats;

Log::~Log()
{
if (outputStream)
fclose(outputStream);
}

void Log::print_timestamp(const char* msg)
{
if (!outputStream)
return;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
fprintf(outputStream, "%02d-%02d-%d %02d:%02d:%02d\t%s\t",timeinfo->tm_mday, 1+timeinfo->tm_mon, 1900+timeinfo->tm_year, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, msg);
}

void Log::print_log(const char* format, ...)
{
if (!outputStream)
return;
print_timestamp("LOG");;
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}

void Log::warn_log(const char* format, ...)
{
if (sDebugLevel >= kWarnings)
{
if (!outputStream)
return;
print_timestamp("WARN");;
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}
}

void Log::info_log(const char* format, ...)
{
if (sDebugLevel >= kInformational)
{
if (!outputStream)
return;
print_timestamp("INFO");;
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}
}

void Log::debug_log(const char* format, ...)
{
if (sDebugLevel >= kFullDebug)
{
if (!outputStream)
return;
print_timestamp("DEBUG");
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}
}

void Log::stats_log(const char* format, ...)
{
if (sDebugLevel >= kOnlyErrors && printStats)
{
if (!outputStream)
return;
print_timestamp("STATS");
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}
}


void Log::startup_log(const char* format, ...)
{
if (!outputStream)
return;
print_timestamp("");
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}

void Log::error_log(const char* format, ...)
{
if (!outputStream)
return;
print_timestamp("ERROR");
va_list va;
va_start( va, format );
vfprintf(outputStream, format, va);
}

bool Log::EnableFileLogging(char* file)
{
logfile = file;
outputStream = fopen(logfile, "a");
#ifndef WIN32
setlinebuf(outputStream);
#endif
return true;
}

void Log::RotateLogFile(int sig)
{
if (logfile != NULL)
{
char savedLogFile[MAX_LOG_NAME_SIZE];
fclose(outputStream); // Does a flush internally
time_t currentTime = time(0);
if (strftime( savedLogFile, MAX_LOG_NAME_SIZE, "masterserver_%d%m%y%H%M%S.log", localtime(&currentTime) ) == 0)
print_log("Error creating new log file");
rename(logfile, savedLogFile);
outputStream = fopen(logfile, "a");
#ifndef WIN32
setlinebuf(outputStream);
#endif
}
else
{
print_log("Log file name not set, cannot rotate");
}
}

long Log::GetLogSize()
{
//int position = 0;
//if (fgetpos(outputStream, (fpos_t*)&position) != 0)
// Log::error_log("Error reading log file size\n");
return ftell(outputStream);
//return position;
}
46 changes: 46 additions & 0 deletions Common/Log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
#include <stdio.h>

class Log
{
private:
static char* logfile;
static FILE* outputStream;
static const int MAX_LOG_NAME_SIZE = 50;

public:
static int sDebugLevel;
static bool printStats;

Log();
~Log();

static void print_log(const char* format, ...);

static void error_log(const char* format, ...);
static void info_log(const char* format, ...);
static void warn_log(const char* format, ...);
static void debug_log(const char* format, ...);
static void stats_log(const char* format, ...);

static void startup_log(const char* format, ...);
static bool EnableFileLogging(char* file);
static void RotateLogFile(int sig);
static long GetLogSize();

private:
static void print_timestamp(const char* msg);
};

// Debug levels used when logging
enum {
// Only print critical error messages (nice clean log)
kOnlyErrors,
// Print probably harmless warning messages
kWarnings,
// Print various informational messages
kInformational,
// Print a lot of per event log messages (logs will be huge)
kFullDebug
};

34 changes: 34 additions & 0 deletions Common/Utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Log.h"
#ifndef WIN32
#include <string.h>
#include <unistd.h>

bool WriteProcessID(char* processFullPath, char* pidFile, int bufSize)
{
int pid = getpid();
int lastSlash = -1;
for (size_t i=0; i<strlen(processFullPath); ++i)
{
if (processFullPath[i] == '/')
lastSlash = i;
}
if (lastSlash != -1)
{
snprintf(pidFile, bufSize, "%s.pid", processFullPath+lastSlash+1);
Log::info_log("Writing PID to %s\n", pidFile);
FILE* pidHandle = fopen(pidFile, "w");
if (!pidHandle)
{
fprintf(stderr, "Failed to open %s\n", pidFile);
return false;
}
if (!(fprintf(pidHandle, "%d", pid) > 0))
{
perror("Failed to write to pid file\n");
return false;
}
fclose(pidHandle);
}
return true;
}
#endif
2 changes: 2 additions & 0 deletions Common/Utility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

bool WriteProcessID(char* processFullPath, char* pidFile, int bufSize);
12 changes: 12 additions & 0 deletions MRB-ChangeList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Sept. 26, 2012:
- Makefile: Build ProxyServer.cpp with no debug symbols by default as it may affect performance.

Sept. 18, 2012:
- RakPeer.cpp: Allow up to 256 (arbitrary higher number) server listen ports instead of just 32
- ProxyServer.cpp: Few more fixes: 1. Specifying a larger range of ports other than the default works now 2. Use array delete when deleting array 3. Allocate correct number of sockets for the number of ports requested (needed one more for the listen port)

Aug. 24, 2012:
- ProxyServer.cpp,h: Close proxy connections to clients when host of that port disconnects.

Aug. 22, 2012:
- ProxyServer.cpp: ProxyServer bug fixes: 1. Use the correct Receive function so we don't sometimes miss RPCs. 2. Immediately fetch next packet after processing packets from clients, so we don't slowly build more and more latency as unprocessed packets build up. 3. Deallocate client packets after they are processed.
105 changes: 105 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Unity Proxy Server Makefile
# -------------------------------------

CC = g++
DEFINES = -DUNITY_PROXYSERVER
CFLAGS = -Wall -lpthread $(DEFINES)
DEBUG = -ggdb
INCLUDE = .
PROGRAMNAME = ProxyServer
PROGRAMSOURCES = ProxyServer.cpp

# -------------------------------------

RAKNET_INCLUDE = RakNet/Sources

RAKNET_SOURCES = \
$(RAKNET_INCLUDE)/RakNetworkFactory.cpp\
$(RAKNET_INCLUDE)/BitStream.cpp\
$(RAKNET_INCLUDE)/GetTime.cpp\
$(RAKNET_INCLUDE)/RakPeer.cpp\
$(RAKNET_INCLUDE)/BitStream_NoTemplate.cpp\
$(RAKNET_INCLUDE)/RakSleep.cpp\
$(RAKNET_INCLUDE)/CheckSum.cpp\
$(RAKNET_INCLUDE)/Rand.cpp\
$(RAKNET_INCLUDE)/ReliabilityLayer.cpp\
$(RAKNET_INCLUDE)/LinuxStrings.cpp\
$(RAKNET_INCLUDE)/ConsoleServer.cpp\
$(RAKNET_INCLUDE)/Router.cpp\
$(RAKNET_INCLUDE)/DS_BytePool.cpp\
$(RAKNET_INCLUDE)/MessageFilter.cpp\
$(RAKNET_INCLUDE)/SHA1.cpp\
$(RAKNET_INCLUDE)/DS_ByteQueue.cpp\
$(RAKNET_INCLUDE)/SimpleMutex.cpp\
$(RAKNET_INCLUDE)/DS_HuffmanEncodingTree.cpp\
$(RAKNET_INCLUDE)/NetworkIDManager.cpp\
$(RAKNET_INCLUDE)/SocketLayer.cpp\
$(RAKNET_INCLUDE)/DS_Table.cpp\
$(RAKNET_INCLUDE)/NetworkIDObject.cpp\
$(RAKNET_INCLUDE)/StringCompressor.cpp\
$(RAKNET_INCLUDE)/DataBlockEncryptor.cpp\
$(RAKNET_INCLUDE)/StringTable.cpp\
$(RAKNET_INCLUDE)/DataCompressor.cpp\
$(RAKNET_INCLUDE)/PacketFileLogger.cpp\
$(RAKNET_INCLUDE)/SystemAddressList.cpp\
$(RAKNET_INCLUDE)/DirectoryDeltaTransfer.cpp\
$(RAKNET_INCLUDE)/PacketLogger.cpp\
$(RAKNET_INCLUDE)/TCPInterface.cpp\
$(RAKNET_INCLUDE)/EmailSender.cpp\
$(RAKNET_INCLUDE)/TableSerializer.cpp\
$(RAKNET_INCLUDE)/EncodeClassName.cpp\
$(RAKNET_INCLUDE)/RPCMap.cpp\
$(RAKNET_INCLUDE)/TelnetTransport.cpp\
$(RAKNET_INCLUDE)/ExtendedOverlappedPool.cpp\
$(RAKNET_INCLUDE)/RakNetCommandParser.cpp\
$(RAKNET_INCLUDE)/ThreadsafePacketLogger.cpp\
$(RAKNET_INCLUDE)/FileList.cpp\
$(RAKNET_INCLUDE)/RakNetStatistics.cpp\
$(RAKNET_INCLUDE)/_FindFirst.cpp\
$(RAKNET_INCLUDE)/FileListTransfer.cpp\
$(RAKNET_INCLUDE)/RakNetTransport.cpp\
$(RAKNET_INCLUDE)/rijndael.cpp\
$(RAKNET_INCLUDE)/FileOperations.cpp\
$(RAKNET_INCLUDE)/RakNetTypes.cpp\
$(RAKNET_INCLUDE)/BigInt.cpp\
$(RAKNET_INCLUDE)/CCRakNetUDT.cpp\
$(RAKNET_INCLUDE)/RakNetSocket.cpp\
$(RAKNET_INCLUDE)/RakString.cpp\
$(RAKNET_INCLUDE)/RSACrypt.cpp\
$(RAKNET_INCLUDE)/RakMemoryOverride.cpp\
$(RAKNET_INCLUDE)/SignaledEvent.cpp\
$(RAKNET_INCLUDE)/SuperFastHash.cpp\
$(RAKNET_INCLUDE)/PluginInterface2.cpp\
$(RAKNET_INCLUDE)/Itoa.cpp\
$(RAKNET_INCLUDE)/RakThread.cpp\
$(RAKNET_INCLUDE)/NatPunchthroughClient.cpp

RAKNET_OBJECTS = $(RAKNET_SOURCES:.cpp=.o)

COMMON_INCLUDE = Common

COMMON_SOURCES = \
$(COMMON_INCLUDE)/Log.cpp\
$(COMMON_INCLUDE)/Utility.cpp

COMMON_OBJECTS = $(COMMON_SOURCES:.cpp=.o)

all: $(COMMON_SOURCES) $(RAKNET_SOURCES) $(PROGRAMNAME)

$(PROGRAMNAME): $(COMMON_OBJECTS) $(RAKNET_OBJECTS)
# $(CC) $(DEBUG) -I$(INCLUDE) -I$(RAKNET_INCLUDE) -I$(COMMON_INCLUDE) $(CFLAGS) $(COMMON_OBJECTS) $(RAKNET_OBJECTS) $(PROGRAMSOURCES) -o $(PROGRAMNAME)
$(CC) -I$(INCLUDE) -I$(RAKNET_INCLUDE) -I$(COMMON_INCLUDE) $(CFLAGS) $(COMMON_OBJECTS) $(RAKNET_OBJECTS) $(PROGRAMSOURCES) -o $(PROGRAMNAME)
chmod +x $(PROGRAMNAME)

clean:
rm -f $(PROGRAMNAME)

cleanall:
rm -f $(PROGRAMNAME)
rm -f $(RAKNET_OBJECTS)
rm -f $(COMMON_OBJECTS)

# Compile all RakNet cpp source files (use commented line instead for DEBUG symbols!)
.cpp.o:
$(CC) -c -Wall -I$(INCLUDE) -I$(COMMON_INCLUDE) $(DEFINES) $< -o $@
# $(CC) $(DEBUG) -c -Wall -I$(INCLUDE) -I$(COMMON_INCLUDE) $(DEFINES) $< -o $@
Loading

0 comments on commit e30cec1

Please sign in to comment.