diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/cMCLogger.cpp | 84 | ||||
-rw-r--r-- | source/cMCLogger.h | 13 | ||||
-rw-r--r-- | source/cPlayer.cpp | 20 | ||||
-rw-r--r-- | source/cServer.cpp | 22 | ||||
-rw-r--r-- | source/cSocket.cpp | 5 | ||||
-rw-r--r-- | source/cSocket.h | 4 |
6 files changed, 103 insertions, 45 deletions
diff --git a/source/cMCLogger.cpp b/source/cMCLogger.cpp index b3f43333f..c1571a195 100644 --- a/source/cMCLogger.cpp +++ b/source/cMCLogger.cpp @@ -22,7 +22,6 @@ cMCLogger* cMCLogger::GetInstance() cMCLogger::cMCLogger()
{
- m_CriticalSection = new cCriticalSection();
AString FileName;
Printf(FileName, "LOG_%d.txt", (int)time(0) );
m_Log = new cLog(FileName);
@@ -37,52 +36,66 @@ cMCLogger::cMCLogger() cMCLogger::cMCLogger( char* a_File )
{
- m_CriticalSection = new cCriticalSection();
m_Log = new cLog( a_File );
}
+
+
+
+
cMCLogger::~cMCLogger()
{
m_Log->Log("--- Stopped Log ---");
delete m_Log;
- delete m_CriticalSection;
- if( this == s_MCLogger )
- s_MCLogger = 0;
+ if (this == s_MCLogger)
+ s_MCLogger = NULL;
}
+
+
+
+
void cMCLogger::LogSimple(const char* a_Text, int a_LogType /* = 0 */ )
{
switch( a_LogType )
{
- case 0:
- Log(a_Text, 0);
- break;
- case 1:
- Info(a_Text, 0);
- break;
- case 2:
- Warn(a_Text, 0);
- break;
- case 3:
- Error(a_Text, 0);
- break;
- default:
- Log(a_Text, 0);
- break;
+ case 0:
+ Log(a_Text, 0);
+ break;
+ case 1:
+ Info(a_Text, 0);
+ break;
+ case 2:
+ Warn(a_Text, 0);
+ break;
+ case 3:
+ Error(a_Text, 0);
+ break;
+ default:
+ Log(a_Text, 0);
+ break;
}
}
+
+
+
+
void cMCLogger::Log(const char* a_Format, va_list a_ArgList)
{
- m_CriticalSection->Lock();
+ cCSLock Lock(m_CriticalSection);
SetColor( 0x7 ); // 0x7 is default grey color
m_Log->Log( a_Format, a_ArgList );
- m_CriticalSection->Unlock();
+ SetColor(0x07); // revert color back
}
+
+
+
+
void cMCLogger::Info(const char* a_Format, va_list a_ArgList)
{
- m_CriticalSection->Lock();
+ cCSLock Lock(m_CriticalSection);
// for( int i = 0; i < 16; i++)
// {
// for( int j = 0; j < 16; j++ )
@@ -95,25 +108,37 @@ void cMCLogger::Info(const char* a_Format, va_list a_ArgList) SetColor( 0xe ); // 0xe is yellow
m_Log->Log( a_Format, a_ArgList );
- m_CriticalSection->Unlock();
+ SetColor(0x07); // revert color back
}
+
+
+
+
void cMCLogger::Warn(const char* a_Format, va_list a_ArgList)
{
- m_CriticalSection->Lock();
+ cCSLock Lock(m_CriticalSection);
SetColor( 0xc ); // 0xc is red
m_Log->Log( a_Format, a_ArgList );
- m_CriticalSection->Unlock();
+ SetColor(0x07); // revert color back
}
+
+
+
+
void cMCLogger::Error(const char* a_Format, va_list a_ArgList)
{
- m_CriticalSection->Lock();
+ cCSLock Lock(m_CriticalSection);
SetColor( 0xc0 ); // 0xc0 is red bg and black text
m_Log->Log( a_Format, a_ArgList );
- m_CriticalSection->Unlock();
+ SetColor(0x07); // revert color back
}
+
+
+
+
void cMCLogger::SetColor( unsigned char a_Color )
{
#ifdef _WIN32
@@ -125,6 +150,9 @@ void cMCLogger::SetColor( unsigned char a_Color ) }
+
+
+
//////////////////////////////////////////////////////////////////////////
// Global functions
void LOG(const char* a_Format, ...)
diff --git a/source/cMCLogger.h b/source/cMCLogger.h index f37c4f642..0d1770e2d 100644 --- a/source/cMCLogger.h +++ b/source/cMCLogger.h @@ -1,7 +1,8 @@ +
#pragma once
#ifndef _WIN32
-#include <stdarg.h>
+ #include <stdarg.h>
#endif
class cLog;
@@ -27,7 +28,7 @@ public: //tolua_export private:
void SetColor( unsigned char a_Color );
- cCriticalSection* m_CriticalSection;
+ cCriticalSection m_CriticalSection;
cLog* m_Log;
static cMCLogger* s_MCLogger;
}; //tolua_export
@@ -35,4 +36,10 @@ private: extern void LOG(const char* a_Format, ...);
extern void LOGINFO(const char* a_Format, ...);
extern void LOGWARN(const char* a_Format, ...);
-extern void LOGERROR(const char* a_Format, ...);
\ No newline at end of file +extern void LOGERROR(const char* a_Format, ...);
+
+#define LOGWARNING LOGWARN
+
+
+
+
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 44b27e14a..d336a4616 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -920,6 +920,10 @@ const cPlayer::GroupList & cPlayer::GetGroups() return m_pState->Groups;
}
+
+
+
+
cPlayer::StringList cPlayer::GetResolvedPermissions()
{
StringList Permissions;
@@ -933,17 +937,31 @@ cPlayer::StringList cPlayer::GetResolvedPermissions() return Permissions;
}
+
+
+
+
const char* cPlayer::GetLoadedWorldName()
{
return m_pState->LoadedWorldName.c_str();
}
+
+
+
+
void cPlayer::UseEquippedItem()
{
if(GetGameMode() != 1) //No damage in creative
+ {
if (GetInventory().GetEquippedItem().DamageItem())
{
LOG("Player %s Broke ID: %i", GetClientHandle()->GetUsername().c_str(), GetInventory().GetEquippedItem().m_ItemID);
GetInventory().RemoveItem( GetInventory().GetEquippedItem());
}
-}
\ No newline at end of file + }
+}
+
+
+
+
diff --git a/source/cServer.cpp b/source/cServer.cpp index 44dd365c2..f14a419a9 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -295,17 +295,23 @@ void cServer::StartListenClient() {
cSocket SClient = m_pState->SListenClient.Accept();
- if( SClient.IsValid() )
+ if (!SClient.IsValid())
{
- char * ClientIP = SClient.GetIPString();
- if( ClientIP == 0 )
- return;
+ return;
+ }
+
+ const AString & ClientIP = SClient.GetIPString();
+ if (ClientIP.empty())
+ {
+ LOGWARN("cServer: A client connected, but didn't present its IP, disconnecting.");
+ SClient.CloseSocket();
+ return;
+ }
- LOG("%s connected!", ClientIP);
+ LOG("%s connected!", ClientIP.c_str());
- cClientHandle *NewHandle = new cClientHandle( SClient );
- m_pState->Clients.push_back( NewHandle ); // TODO - lock list
- }
+ cClientHandle *NewHandle = new cClientHandle( SClient );
+ m_pState->Clients.push_back( NewHandle ); // TODO - lock list
}
diff --git a/source/cSocket.cpp b/source/cSocket.cpp index bd26fb274..0945d170e 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -19,7 +19,6 @@ cSocket::cSocket( xSocket a_Socket )
: m_Socket( a_Socket )
- , m_IPString( 0 )
{
}
@@ -59,9 +58,9 @@ void cSocket::CloseSocket() closesocket(m_Socket);
#else
if( shutdown(m_Socket, SHUT_RDWR) != 0 )//SD_BOTH);
- LOGWARN("Error on shutting down socket (%s)", m_IPString );
+ LOGWARN("Error on shutting down socket (%s)", m_IPString.c_str() );
if( close(m_Socket) != 0 )
- LOGWARN("Error closing socket (%s)", m_IPString );
+ LOGWARN("Error closing socket (%s)", m_IPString.c_str() );
#endif
}
diff --git a/source/cSocket.h b/source/cSocket.h index 44c3bea4b..395815389 100644 --- a/source/cSocket.h +++ b/source/cSocket.h @@ -55,9 +55,9 @@ public: cSocket Accept();
int Receive( char* a_Buffer, unsigned int a_Length, unsigned int a_Flags );
- char* GetIPString() { return m_IPString; }
+ const AString & GetIPString(void) const { return m_IPString; }
private:
xSocket m_Socket;
- char* m_IPString;
+ AString m_IPString;
};
\ No newline at end of file |