From 33ca4d5003059d7d1f4b9e29649693ec0e5be262 Mon Sep 17 00:00:00 2001 From: faketruth Date: Thu, 16 Aug 2012 20:28:14 +0000 Subject: MCServer should run just fine on Android now :D The server is also stoppable from Android git-svn-id: http://mc-server.googlecode.com/svn/trunk@743 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Globals.h | 6 ++++++ source/cFile.cpp | 4 ++-- source/cLog.cpp | 12 ++++++------ source/cMakeDir.cpp | 4 ++-- source/cRoot.cpp | 4 ++++ 5 files changed, 20 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/Globals.h b/source/Globals.h index 4816e2769..7d51bd52f 100644 --- a/source/Globals.h +++ b/source/Globals.h @@ -123,6 +123,12 @@ typedef short Int16; #define USE_SQUIRREL #endif +#if defined(ANDROID_NDK) + #define FILE_IO_PREFIX "/sdcard/mcserver/" +#else + #define FILE_IO_PREFIX "" +#endif + diff --git a/source/cFile.cpp b/source/cFile.cpp index 32de28fe0..5558bfd45 100644 --- a/source/cFile.cpp +++ b/source/cFile.cpp @@ -76,14 +76,14 @@ bool cFile::Open(const AString & iFileName, EMode iMode) return false; } } - m_File = fopen(iFileName.c_str(), Mode); + m_File = fopen( (FILE_IO_PREFIX + iFileName).c_str(), Mode); if ((m_File == NULL) && (iMode == fmReadWrite)) { // Fix for MS not following C spec, opening "a" mode files for writing at the end only // The file open operation has been tried with "read update", fails if file not found // So now we know either the file doesn't exist or we don't have rights, no need to worry about file contents. // Simply re-open for read-writing, erasing existing contents: - m_File = fopen(iFileName.c_str(), "wb+"); + m_File = fopen( (FILE_IO_PREFIX + iFileName).c_str(), "wb+"); } return (m_File != NULL); } diff --git a/source/cLog.cpp b/source/cLog.cpp index 372616be8..d1874f7e2 100644 --- a/source/cLog.cpp +++ b/source/cLog.cpp @@ -26,7 +26,7 @@ cLog::cLog(const AString & a_FileName ) // create logs directory cMakeDir::MakeDir("logs"); - OpenLog( (std::string("logs/") + a_FileName).c_str() ); + OpenLog( (FILE_IO_PREFIX + std::string("logs/") + a_FileName).c_str() ); } @@ -100,10 +100,6 @@ void cLog::ClearLog() void cLog::Log(const char * a_Format, va_list argList) { -#if defined(ANDROID_NDK) - __android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); - return; // This is as far as android goes -#endif AString Message; AppendVPrintf(Message, a_Format, argList); @@ -132,8 +128,12 @@ void cLog::Log(const char * a_Format, va_list argList) } // Print to console: +#if defined(ANDROID_NDK) + __android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList); +#else printf("%s", Line.c_str()); - +#endif + #if defined (_WIN32) && defined(_DEBUG) // In a Windows Debug build, output the log to debug console as well: OutputDebugString(Line.c_str()); diff --git a/source/cMakeDir.cpp b/source/cMakeDir.cpp index a9e35cece..478d1d872 100644 --- a/source/cMakeDir.cpp +++ b/source/cMakeDir.cpp @@ -14,9 +14,9 @@ void cMakeDir::MakeDir(const AString & a_Directory) Attrib.nLength = sizeof(SECURITY_ATTRIBUTES); Attrib.lpSecurityDescriptor = NULL; Attrib.bInheritHandle = false; - ::CreateDirectory(a_Directory.c_str(), &Attrib); + ::CreateDirectory( (FILE_IO_PREFIX + a_Directory).c_str(), &Attrib); #else - mkdir(a_Directory.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + mkdir( (FILE_IO_PREFIX + a_Directory).c_str(), S_IRWXU | S_IRWXG | S_IRWXO); #endif } diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 317b03ca3..81e7daccb 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -77,6 +77,9 @@ cRoot::~cRoot() void cRoot::InputThread(void* a_Params) { +#if defined(ANDROID_NDK) + return; +#else cRoot& self = *(cRoot*)a_Params; while( !(self.m_bStop || self.m_bRestart) ) @@ -85,6 +88,7 @@ void cRoot::InputThread(void* a_Params) std::getline(std::cin, Command); self.ServerCommand( Command.c_str() ); } +#endif } -- cgit v1.2.3