summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/MCSocket.h12
-rw-r--r--source/cBlockingTCPLink.cpp3
-rw-r--r--source/cChunk.cpp15
-rw-r--r--source/cChunk.h3
-rw-r--r--source/cChunkMap.cpp3
-rw-r--r--source/cClientHandle.cpp10
-rw-r--r--source/cHeartBeat.cpp4
-rw-r--r--source/cPlayer.cpp1
-rw-r--r--source/cPlayer.h1
-rw-r--r--source/cPluginManager.h1
-rw-r--r--source/cServer.cpp1
-rw-r--r--source/cSocket.cpp14
-rw-r--r--source/cSocket.h4
-rw-r--r--source/cTCPLink.cpp3
-rw-r--r--source/main.cpp4
-rw-r--r--source/packets/cPacket.cpp4
-rw-r--r--source/packets/cPacket.h4
17 files changed, 63 insertions, 24 deletions
diff --git a/source/MCSocket.h b/source/MCSocket.h
index 554a5f35b..6fcbb069b 100644
--- a/source/MCSocket.h
+++ b/source/MCSocket.h
@@ -1,12 +1,12 @@
#pragma once
#ifdef _WIN32
-
-#include <winsock2.h>
-#define socklen_t int
-#ifdef SendMessage
-#undef SendMessage
-#endif
+#include <Windows.h>
+#include <WinSock.h>
+// #define socklen_t int
+// #ifdef SendMessage
+// #undef SendMessage
+// #endif
#else
// Linux threads http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
diff --git a/source/cBlockingTCPLink.cpp b/source/cBlockingTCPLink.cpp
index a87809857..6a2208084 100644
--- a/source/cBlockingTCPLink.cpp
+++ b/source/cBlockingTCPLink.cpp
@@ -1,5 +1,6 @@
#include "cBlockingTCPLink.h"
#include "packets/cPacket.h"
+#include "MCSocket.h"
#include <string>
#include "cMCLogger.h"
@@ -30,7 +31,7 @@ void cBlockingTCPLink::CloseSocket()
{
if( m_Socket )
{
- closesocket( m_Socket );
+ m_Socket.CloseSocket();
m_Socket = 0;
}
}
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index c6d0fb3b3..a8e8938a0 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -22,6 +22,7 @@
#include "cItem.h"
#include "cNoise.h"
#include "cRoot.h"
+#include "cCriticalSection.h"
#include "cGenSettings.h"
@@ -37,6 +38,10 @@
#include <vector>
#include <map>
+#ifndef _WIN32
+#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
+#endif
+
extern bool g_bWaterPhysics;
@@ -77,8 +82,7 @@ cChunk::~cChunk()
if( m_EntitiesCriticalSection )
{
- DeleteCriticalSection( (CRITICAL_SECTION*)m_EntitiesCriticalSection );
- delete (CRITICAL_SECTION*)m_EntitiesCriticalSection;
+ delete m_EntitiesCriticalSection;
m_EntitiesCriticalSection = 0;
}
delete m_pState;
@@ -102,8 +106,7 @@ cChunk::cChunk(int a_X, int a_Y, int a_Z)
, m_EntitiesCriticalSection( 0 )
{
//LOG("cChunk::cChunk(%i, %i, %i)", a_X, a_Y, a_Z);
- m_EntitiesCriticalSection = new CRITICAL_SECTION;
- InitializeCriticalSection( (CRITICAL_SECTION*)m_EntitiesCriticalSection );
+ m_EntitiesCriticalSection = new cCriticalSection();
}
void cChunk::Initialize()
@@ -1064,12 +1067,12 @@ bool cChunk::RemoveEntity( cEntity & a_Entity, cChunk* a_CalledFrom /* = 0 */ )
void cChunk::LockEntities()
{
- EnterCriticalSection( (CRITICAL_SECTION*)m_EntitiesCriticalSection );
+ m_EntitiesCriticalSection->Lock();
}
void cChunk::UnlockEntities()
{
- LeaveCriticalSection( (CRITICAL_SECTION*)m_EntitiesCriticalSection );
+ m_EntitiesCriticalSection->Unlock();
}
char cChunk::GetBlock( int a_X, int a_Y, int a_Z )
diff --git a/source/cChunk.h b/source/cChunk.h
index 83c14dcfa..d90e817cf 100644
--- a/source/cChunk.h
+++ b/source/cChunk.h
@@ -7,6 +7,7 @@ namespace Json
class Value;
};
+class cCriticalSection;
class cFurnaceEntity;
class cPacket;
class cBlockEntity;
@@ -123,5 +124,5 @@ private:
unsigned int m_BlockTickNum;
unsigned int m_BlockTickX, m_BlockTickY, m_BlockTickZ;
- void* m_EntitiesCriticalSection;
+ cCriticalSection* m_EntitiesCriticalSection;
}; \ No newline at end of file
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index 5e0e39a9c..119af2c76 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -4,9 +4,12 @@
#include "cWorld.h"
#include "cRoot.h"
#include "cMakeDir.h"
+
#ifndef _WIN32
#include <cstring> // memcpy
#include <cstdlib> // abs
+#include <math.h> // floorf
+#include <stdio.h> // sprintf and stuff
#endif
#include "zlib.h"
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index f274795c1..68a70715e 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -4,6 +4,8 @@
#include <errno.h>
#endif
+#include "MCSocket.h"
+
#include "cClientHandle.h"
#include "cServer.h"
#include "cWorld.h"
@@ -68,6 +70,10 @@
#include "packets/cPacket_Ping.h"
+#ifndef _WIN32
+#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
+#endif
+
#define MAX_SEMAPHORES (2000)
typedef std::list<cPacket*> PacketList;
@@ -176,7 +182,7 @@ cClientHandle::~cClientHandle()
Disconnect.m_Reason = "Server shut down? Kthnxbai";
Disconnect.Send( m_pState->Socket );
- closesocket( m_pState->Socket );
+ m_pState->Socket.CloseSocket();
m_pState->Socket = 0;
}
m_pState->SocketCriticalSection.Unlock();
@@ -218,7 +224,7 @@ void cClientHandle::Destroy()
m_pState->SocketCriticalSection.Lock();
if( m_pState->Socket )
{
- closesocket( m_pState->Socket );
+ m_pState->Socket.CloseSocket();
m_pState->Socket = 0;
}
m_pState->SocketCriticalSection.Unlock();
diff --git a/source/cHeartBeat.cpp b/source/cHeartBeat.cpp
index b518a753a..3661b9376 100644
--- a/source/cHeartBeat.cpp
+++ b/source/cHeartBeat.cpp
@@ -8,6 +8,10 @@
#include "cServer.h"
#include "cSleep.h"
+#ifndef _WIN32
+#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
+#endif
+
cHeartBeat::cHeartBeat()
{
m_State = 0;
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 8552abd3e..71fa41d27 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -36,6 +36,7 @@
#ifndef _WIN32 // for mkdir
#include <sys/stat.h>
#include <sys/types.h>
+#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
#endif
extern std::vector< std::string > StringSplit( std::string str, std::string delim);
diff --git a/source/cPlayer.h b/source/cPlayer.h
index 6f05b824d..d5ad6abac 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -2,6 +2,7 @@
#include "cPawn.h"
#include <list>
+#include <string> // TODO - use const char*
class cGroup;
class cWindow;
diff --git a/source/cPluginManager.h b/source/cPluginManager.h
index 32c7b9d3a..6a94060e0 100644
--- a/source/cPluginManager.h
+++ b/source/cPluginManager.h
@@ -1,6 +1,7 @@
#pragma once
#include <list>
+#include <string> // TODO - use const char*
struct lua_State;
class cLuaCommandBinder;
diff --git a/source/cServer.cpp b/source/cServer.cpp
index 966444a25..a5e06d3ec 100644
--- a/source/cServer.cpp
+++ b/source/cServer.cpp
@@ -32,6 +32,7 @@
#include <cstring>
#include <errno.h>
#include <semaphore.h>
+#include "MCSocket.h"
#endif
#include <string>
diff --git a/source/cSocket.cpp b/source/cSocket.cpp
index d2489d48e..edc57c1ce 100644
--- a/source/cSocket.cpp
+++ b/source/cSocket.cpp
@@ -1,5 +1,10 @@
#include "cSocket.h"
+#ifndef _WIN32
+#include <netdb.h>
+#include <unistd.h>
+#endif
+
cSocket::cSocket( xSocket a_Socket )
: m_Socket( a_Socket )
{
@@ -28,3 +33,12 @@ bool cSocket::IsValid()
#endif
}
+void cSocket::CloseSocket()
+{
+#ifdef _WIN32
+ closesocket(m_Socket);
+#else
+ shutdown(m_Socket, SHUT_RDWR);//SD_BOTH);
+ close(m_Socket);
+#endif
+} \ No newline at end of file
diff --git a/source/cSocket.h b/source/cSocket.h
index 4a58ff2c9..cfbc2959f 100644
--- a/source/cSocket.h
+++ b/source/cSocket.h
@@ -6,7 +6,8 @@
#ifdef SendMessage
#undef SendMessage
#endif
-#endif
+#endif // _WIN32
+
class cSocket
{
@@ -23,6 +24,7 @@ public:
~cSocket();
bool IsValid();
+ void CloseSocket();
operator const xSocket() const;
xSocket GetSocket() const;
diff --git a/source/cTCPLink.cpp b/source/cTCPLink.cpp
index 13eb593ef..0efc0254f 100644
--- a/source/cTCPLink.cpp
+++ b/source/cTCPLink.cpp
@@ -2,6 +2,7 @@
#include "cSocket.h"
#include "cEvent.h"
#include "cThread.h"
+#include "MCSocket.h"
#include "cMCLogger.h"
@@ -37,7 +38,7 @@ void cTCPLink::CloseSocket()
{
if( m_Socket )
{
- closesocket( m_Socket );
+ m_Socket.CloseSocket();
m_Socket = 0;
}
}
diff --git a/source/main.cpp b/source/main.cpp
index 393db121e..d17456af1 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -4,9 +4,9 @@
#include "cRoot.h"
#include "cMCLogger.h"
-#ifdef _WIN32
+//#ifdef _WIN32
#include <exception>
-#endif
+//#endif
int main( int argc, char **argv )
{
diff --git a/source/packets/cPacket.cpp b/source/packets/cPacket.cpp
index e49c3e016..7775ede73 100644
--- a/source/packets/cPacket.cpp
+++ b/source/packets/cPacket.cpp
@@ -13,7 +13,7 @@
//*****************************************************************************
// Blocking receive all function
//*****************************************************************************
-int cPacket::RecvAll( SOCKET a_Socket, char* a_Data, unsigned int a_Size, int a_Options )
+int cPacket::RecvAll( cSocket & a_Socket, char* a_Data, unsigned int a_Size, int a_Options )
{
unsigned int RequestSize = a_Size;
while(a_Size != 0)
@@ -30,7 +30,7 @@ int cPacket::RecvAll( SOCKET a_Socket, char* a_Data, unsigned int a_Size, int a_
//*****************************************************************************
// Own implementation of send()
//*****************************************************************************
-int cPacket::SendData( SOCKET a_Socket, const char* a_Message, unsigned int a_Size, int a_Options )
+int cPacket::SendData( cSocket & a_Socket, const char* a_Message, unsigned int a_Size, int a_Options )
{
return send(a_Socket, a_Message, a_Size, a_Options | MSG_NOSIGNAL );
}
diff --git a/source/packets/cPacket.h b/source/packets/cPacket.h
index 3cab5f222..304d6b8d3 100644
--- a/source/packets/cPacket.h
+++ b/source/packets/cPacket.h
@@ -51,6 +51,6 @@ protected:
void AppendData ( char* a_Data, unsigned int a_Size, char* a_Dst, unsigned int & a_Iterator );
public:
- static int SendData( SOCKET a_Socket, const char* a_Message, unsigned int a_Size, int a_Options );
- static int RecvAll( SOCKET a_Socket, char* a_Data, unsigned int a_Size, int a_Options );
+ static int SendData( cSocket & a_Socket, const char* a_Message, unsigned int a_Size, int a_Options );
+ static int RecvAll( cSocket & a_Socket, char* a_Data, unsigned int a_Size, int a_Options );
};