summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-09-17 11:20:10 +0200
committerMattes D <github@xoft.cz>2015-09-17 11:20:10 +0200
commit9871c0b0731446f6c12137502153c24c9f1d9dfa (patch)
tree4b984cbc73628fac3a3e0ed3aff55a65dfaf82f7
parentMerge pull request #2457 from cuberite/log (diff)
downloadcuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar.gz
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar.bz2
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar.lz
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar.xz
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.tar.zst
cuberite-9871c0b0731446f6c12137502153c24c9f1d9dfa.zip
-rw-r--r--circle.yml12
-rw-r--r--src/BlockEntities/CMakeLists.txt7
-rw-r--r--src/BlockEntities/RedstonePoweredEntity.h21
-rw-r--r--src/Blocks/BlockPlant.h5
-rw-r--r--src/Blocks/CMakeLists.txt13
-rw-r--r--src/CMakeLists.txt1
-rwxr-xr-xsrc/CheckBasicStyle.lua6
-rw-r--r--src/Color.h18
-rw-r--r--src/Items/CMakeLists.txt7
-rw-r--r--src/OSSupport/Socket.cpp377
-rw-r--r--src/OSSupport/Socket.h125
11 files changed, 69 insertions, 523 deletions
diff --git a/circle.yml b/circle.yml
new file mode 100644
index 000000000..341c87a1d
--- /dev/null
+++ b/circle.yml
@@ -0,0 +1,12 @@
+# This is the YML file that governs the CI builds at CircleCI.com
+# The CI is used only for style-checking at this moment.
+
+
+dependencies:
+ pre:
+ - sudo apt-get install lua5.1
+
+test:
+ override:
+ - cd src && find . -name \*.cpp -or -name \*.h > AllFiles.lst
+ - cd src && lua CheckBasicStyle.lua
diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt
index b0bfca5e4..0d1776eb5 100644
--- a/src/BlockEntities/CMakeLists.txt
+++ b/src/BlockEntities/CMakeLists.txt
@@ -20,7 +20,8 @@ SET (SRCS
MobHeadEntity.cpp
MobSpawnerEntity.cpp
NoteEntity.cpp
- SignEntity.cpp)
+ SignEntity.cpp
+)
SET (HDRS
BeaconEntity.h
@@ -39,7 +40,9 @@ SET (HDRS
MobHeadEntity.h
MobSpawnerEntity.h
NoteEntity.h
- SignEntity.h)
+ RedstonePoweredEntity.h
+ SignEntity.h
+)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(BeaconEntity.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=conversion -Wno-error=switch-enum")
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
index eac4e35d4..06856f3ea 100644
--- a/src/BlockEntities/RedstonePoweredEntity.h
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -1,13 +1,30 @@
+// RedstonePoweredEntity.h
+
+// Declares the cRedstonePoweredEntity class representing a mix-in for block entities that respond to redstone
+
+
+
+
+
#pragma once
-// Interface class representing a blockEntity that responds to redstone
+
+
+
+
+/** Interface class representing a mix-in for block entities that respond to redstone */
class cRedstonePoweredEntity
{
public:
virtual ~cRedstonePoweredEntity() {}
- /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ /** Sets the internal redstone power flag to "on" or "off", depending on the parameter.
+ Calls Activate() if appropriate */
virtual void SetRedstonePower(bool a_IsPowered) = 0;
};
+
+
+
+
diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h
index 0e6aca7eb..0155dc466 100644
--- a/src/Blocks/BlockPlant.h
+++ b/src/Blocks/BlockPlant.h
@@ -49,13 +49,12 @@ protected:
Light = Blocklight;
}
- // Return true if there is enough light
- // Set m_ShouldDie if the base light amounts are not enough to sustain a plant
+ // Based on light levels, decide between growth, stay and death:
if (Light > 8)
{
return paGrowth;
}
- else if (Blocklight < 9 && SkyLight < 9)
+ else if ((Blocklight < 9) && (SkyLight < 9))
{
return paDeath;
}
diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt
index ed3e321d4..1c12d9fbc 100644
--- a/src/Blocks/CMakeLists.txt
+++ b/src/Blocks/CMakeLists.txt
@@ -9,7 +9,8 @@ SET (SRCS
BlockDoor.cpp
BlockHandler.cpp
BlockPiston.cpp
- ChunkInterface.cpp)
+ ChunkInterface.cpp
+)
SET (HDRS
BlockAnvil.h
@@ -54,12 +55,15 @@ SET (HDRS
BlockLilypad.h
BlockMelon.h
BlockMobHead.h
+ BlockMobSpawner.h
BlockMushroom.h
BlockMycelium.h
+ BlockNetherrack.h
BlockNetherWart.h
BlockOre.h
BlockPiston.h
BlockPlanks.h
+ BlockPlant.h
BlockPluginInterface.h
BlockPortal.h
BlockPressurePlate.h
@@ -72,6 +76,7 @@ SET (HDRS
BlockRedstoneTorch.h
BlockSand.h
BlockSapling.h
+ BlockSeaLantern.h
BlockSideways.h
BlockSignPost.h
BlockSlab.h
@@ -80,8 +85,8 @@ SET (HDRS
BlockStems.h
BlockStone.h
BlockSugarcane.h
- BlockTNT.h
BlockTallGrass.h
+ BlockTNT.h
BlockTorch.h
BlockTrapdoor.h
BlockTripwire.h
@@ -92,8 +97,10 @@ SET (HDRS
BroadcastInterface.h
ChunkInterface.h
ClearMetaOnDrop.h
+ GetHandlerCompileTimeTemplate.h
MetaRotator.h
- WorldInterface.h)
+ WorldInterface.h
+)
if(NOT MSVC)
add_library(Blocks ${SRCS} ${HDRS})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 583ca4d3b..d37ba5419 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -98,6 +98,7 @@ SET (HDRS
ChunkSender.h
ChunkStay.h
ClientHandle.h
+ Color.h
CommandOutput.h
CompositeChat.h
CraftingRecipes.h
diff --git a/src/CheckBasicStyle.lua b/src/CheckBasicStyle.lua
index 9521534a8..f9f8f6b4d 100755
--- a/src/CheckBasicStyle.lua
+++ b/src/CheckBasicStyle.lua
@@ -412,6 +412,12 @@ end
-- Process the files in the list:
for _, fnam in ipairs(ToProcess) do
+
+ -- Remove the optional "./" prefix:
+ if (fnam:sub(1, 2) == "./") then
+ fnam = fnam:sub(3)
+ end
+
ProcessItem(fnam)
end
diff --git a/src/Color.h b/src/Color.h
index 57775b0dd..3680193ab 100644
--- a/src/Color.h
+++ b/src/Color.h
@@ -25,31 +25,31 @@ public:
cColor() { m_Color = static_cast<unsigned int>(COLOR_NONE);}
cColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue) { SetColor(a_Red, a_Green, a_Blue); }
- /// Returns whether the color is a valid color
+ /** Returns whether the color is a valid color */
bool IsValid() const { return m_Color != COLOR_NONE; }
- /// Changes the color
+ /** Changes the color */
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue);
- /// Alters the red value of the color
+ /** Alters the red value of the color */
void SetRed(unsigned char a_Red);
- /// Alters the green value of the color
+ /** Alters the green value of the color */
void SetGreen(unsigned char a_Red);
- /// Alters the blue value of the color
+ /** Alters the blue value of the color */
void SetBlue(unsigned char a_Red);
- /// Returns the red value of the color
+ /** Returns the red value of the color */
unsigned char GetRed() const;
- /// Returns the green value of the color
+ /** Returns the green value of the color */
unsigned char GetGreen() const;
- /// Returns the blue value of the color
+ /** Returns the blue value of the color */
unsigned char GetBlue() const;
- /// Resets the color
+ /** Resets the color */
void Clear() { m_Color = static_cast<unsigned int>(COLOR_NONE); }
// tolua_end
diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt
index 46ff3b4a0..91083d31b 100644
--- a/src/Items/CMakeLists.txt
+++ b/src/Items/CMakeLists.txt
@@ -5,7 +5,8 @@ project (MCServer)
include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
- ItemHandler.cpp)
+ ItemHandler.cpp
+)
SET (HDRS
ItemArmor.h
@@ -26,6 +27,7 @@ SET (HDRS
ItemFishingRod.h
ItemFlowerPot.h
ItemFood.h
+ ItemGoldenApple.h
ItemHandler.h
ItemHoe.h
ItemItemFrame.h
@@ -36,6 +38,7 @@ SET (HDRS
ItemMilk.h
ItemMinecart.h
ItemMobHead.h
+ ItemMushroomSoup.h
ItemNetherWart.h
ItemPainting.h
ItemPickaxe.h
@@ -47,8 +50,8 @@ SET (HDRS
ItemSeeds.h
ItemShears.h
ItemShovel.h
- ItemSlab.h
ItemSign.h
+ ItemSlab.h
ItemSpawnEgg.h
ItemString.h
ItemSugarcane.h
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
deleted file mode 100644
index 5025a09ad..000000000
--- a/src/OSSupport/Socket.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Socket.h"
-
-#ifndef _WIN32
- #include <netdb.h>
- #include <unistd.h>
- #include <arpa/inet.h> // inet_ntoa()
- #include <sys/ioctl.h> // ioctl()
-#else
- #define socklen_t int
-#endif
-
-
-
-
-
-cSocket::cSocket(xSocket a_Socket)
- : m_Socket(a_Socket)
-{
-}
-
-
-
-
-
-cSocket::operator cSocket::xSocket() const
-{
- return m_Socket;
-}
-
-
-
-
-
-cSocket::xSocket cSocket::GetSocket() const
-{
- return m_Socket;
-}
-
-
-
-
-
-bool cSocket::IsValidSocket(cSocket::xSocket a_Socket)
-{
- #ifdef _WIN32
- return (a_Socket != INVALID_SOCKET);
- #else // _WIN32
- return (a_Socket >= 0);
- #endif // else _WIN32
-}
-
-
-
-
-
-void cSocket::CloseSocket()
-{
- #ifdef _WIN32
-
- closesocket(m_Socket);
-
- #else // _WIN32
-
- if (close(m_Socket) != 0)
- {
- LOGWARN("Error closing socket %d (%s): %s", m_Socket, m_IPString.c_str(), GetLastErrorString().c_str());
- }
-
- #endif // else _WIN32
-
- // Invalidate the socket so that this object can be re-used for another connection
- m_Socket = INVALID_SOCKET;
-}
-
-
-
-
-
-void cSocket::ShutdownReadWrite(void)
-{
- #ifdef _WIN32
- int res = shutdown(m_Socket, SD_BOTH);
- #else
- int res = shutdown(m_Socket, SHUT_RDWR);
- #endif
- if (res != 0)
- {
- LOGWARN("%s: Error shutting down socket %d (%s): %d (%s)",
- __FUNCTION__, m_Socket, m_IPString.c_str(), this->GetLastError(), GetLastErrorString().c_str()
- );
- }
-}
-
-
-
-
-int cSocket::GetLastError()
-{
-#ifdef _WIN32
- return WSAGetLastError();
-#else
- return errno;
-#endif
-}
-
-
-
-
-
-bool cSocket::SetReuseAddress(void)
-{
- #if defined(_WIN32) || defined(ANDROID_NDK)
- char yes = 1;
- #else
- int yes = 1;
- #endif
- return (setsockopt(m_Socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == 0);
-}
-
-
-
-
-
-int cSocket::WSAStartup(void)
-{
-#ifdef _WIN32
- WSADATA wsaData;
- memset(&wsaData, 0, sizeof(wsaData));
- return ::WSAStartup(MAKEWORD(2, 2), &wsaData);
-#else
- return 0;
-#endif
-}
-
-
-
-
-
-cSocket cSocket::CreateSocket(eFamily a_Family)
-{
- return socket((int)a_Family, SOCK_STREAM, 0);
-}
-
-
-
-
-
-bool cSocket::BindToAnyIPv4(unsigned short a_Port)
-{
- sockaddr_in local;
- memset(&local, 0, sizeof(local));
-
- local.sin_family = AF_INET;
- local.sin_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr *)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::BindToAnyIPv6(unsigned short a_Port)
-{
- sockaddr_in6 local;
- memset(&local, 0, sizeof(local));
-
- local.sin6_family = AF_INET6;
- local.sin6_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr *)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::BindToLocalhostIPv4(unsigned short a_Port)
-{
- sockaddr_in local;
- memset(&local, 0, sizeof(local));
-
- local.sin_family = AF_INET;;
- local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- local.sin_port = htons((u_short)a_Port);
-
- return (bind(m_Socket, (sockaddr*)&local, sizeof(local)) == 0);
-}
-
-
-
-
-
-bool cSocket::Listen(int a_Backlog)
-{
- return (listen(m_Socket, a_Backlog) == 0);
-}
-
-
-
-
-
-cSocket cSocket::AcceptIPv4(void)
-{
- sockaddr_in from;
- socklen_t fromlen = sizeof(from);
-
- cSocket SClient = accept(m_Socket, (sockaddr *)&from, &fromlen);
-
- if (SClient.IsValid() && (from.sin_addr.s_addr != 0)) // Get IP in string form
- {
- SClient.m_IPString = inet_ntoa(from.sin_addr);
- }
- return SClient;
-}
-
-
-
-
-
-cSocket cSocket::AcceptIPv6(void)
-{
- sockaddr_in6 from;
- socklen_t fromlen = sizeof(from);
-
- cSocket SClient = accept(m_Socket, (sockaddr *)&from, &fromlen);
-
- // Get IP in string form:
- if (SClient.IsValid())
- {
- #if defined(_WIN32)
- // Windows XP doesn't have inet_ntop, so we need to improvise. And MSVC has different headers than GCC
- #ifdef _MSC_VER
- // MSVC version
- Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x",
- from.sin6_addr.u.Word[0],
- from.sin6_addr.u.Word[1],
- from.sin6_addr.u.Word[2],
- from.sin6_addr.u.Word[3],
- from.sin6_addr.u.Word[4],
- from.sin6_addr.u.Word[5],
- from.sin6_addr.u.Word[6],
- from.sin6_addr.u.Word[7]
- );
- #else // _MSC_VER
- // MinGW
- Printf(SClient.m_IPString, "%x:%x:%x:%x:%x:%x:%x:%x",
- from.sin6_addr.s6_addr16[0],
- from.sin6_addr.s6_addr16[1],
- from.sin6_addr.s6_addr16[2],
- from.sin6_addr.s6_addr16[3],
- from.sin6_addr.s6_addr16[4],
- from.sin6_addr.s6_addr16[5],
- from.sin6_addr.s6_addr16[6],
- from.sin6_addr.s6_addr16[7]
- );
- #endif // else _MSC_VER
- #else
- char buffer[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, &(from.sin6_addr), buffer, sizeof(buffer));
- SClient.m_IPString.assign(buffer);
- #endif // _WIN32
- }
- return SClient;
-}
-
-
-
-
-
-bool cSocket::ConnectToLocalhostIPv4(unsigned short a_Port)
-{
- sockaddr_in server;
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- server.sin_port = htons(a_Port);
- return (connect(m_Socket, (sockaddr *)&server, sizeof(server)) == 0);
-}
-
-
-
-
-
-bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port)
-{
- // First try IP Address string to hostent conversion, because it's faster and local:
- unsigned long addr = inet_addr(a_HostNameOrAddr.c_str());
- if (addr == INADDR_NONE)
- {
- // It is not an IP Address string, but rather a regular hostname, resolve:
- hostent * hp = gethostbyname(a_HostNameOrAddr.c_str());
- if (hp == nullptr)
- {
- LOGWARNING("%s: Could not resolve hostname \"%s\"", __FUNCTION__, a_HostNameOrAddr.c_str());
- CloseSocket();
- return false;
- }
- memcpy(&addr, hp->h_addr, hp->h_length);
- }
-
- // If the socket is not created yet, create one:
- if (!IsValid())
- {
- m_Socket = socket((int)IPv4, SOCK_STREAM, 0);
- }
-
- // Connect the socket:
- sockaddr_in server;
- server.sin_addr.s_addr = addr;
- server.sin_family = AF_INET;
- server.sin_port = htons((unsigned short)a_Port);
- return (connect(m_Socket, (sockaddr *)&server, sizeof(server)) == 0);
-}
-
-
-
-
-
-int cSocket::Receive(char * a_Buffer, size_t a_Length, unsigned int a_Flags)
-{
- return recv(m_Socket, a_Buffer, (int)a_Length, a_Flags);
-}
-
-
-
-
-
-int cSocket::Send(const char * a_Buffer, size_t a_Length)
-{
- return send(m_Socket, a_Buffer, (int)a_Length, MSG_NOSIGNAL);
-}
-
-
-
-
-
-unsigned short cSocket::GetPort(void) const
-{
- ASSERT(IsValid());
-
- sockaddr_in Addr;
- socklen_t AddrSize = sizeof(Addr);
- if (getsockname(m_Socket, (sockaddr *)&Addr, &AddrSize) != 0)
- {
- return 0;
- }
- return ntohs(Addr.sin_port);
-}
-
-
-
-
-
-void cSocket::SetNonBlocking(void)
-{
- #ifdef _WIN32
- u_long NonBlocking = 1;
- int res = ioctlsocket(m_Socket, FIONBIO, &NonBlocking);
- #else
- int NonBlocking = 1;
- int res = ioctl(m_Socket, FIONBIO, (char *)&NonBlocking);
- #endif
- if (res != 0)
- {
- LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s",
- res, GetLastError(), GetLastErrorString().c_str()
- );
- abort();
- }
-}
-
-
-
-
diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h
deleted file mode 100644
index 9ec8c1111..000000000
--- a/src/OSSupport/Socket.h
+++ /dev/null
@@ -1,125 +0,0 @@
-
-#pragma once
-
-
-
-
-
-// Windows and MacOSX don't have the MSG_NOSIGNAL flag
-#if ( \
- defined(_WIN32) || \
- (defined(__APPLE__) && defined(__MACH__)) \
-)
- #define MSG_NOSIGNAL (0)
-#endif
-
-
-#include "Errors.h"
-
-
-class cSocket
-{
-public:
- enum eFamily
- {
- IPv4 = AF_INET,
- IPv6 = AF_INET6,
-
- #ifdef _WIN32
- ErrWouldBlock = WSAEWOULDBLOCK,
- #else
- ErrWouldBlock = EWOULDBLOCK,
- #endif
- } ;
-
-#ifdef _WIN32
- typedef SOCKET xSocket;
-#else
- typedef int xSocket;
- static const int INVALID_SOCKET = -1;
-#endif
-
- cSocket(void) : m_Socket(INVALID_SOCKET) {}
- cSocket(xSocket a_Socket);
-
- bool IsValid(void) const { return IsValidSocket(m_Socket); }
- void CloseSocket(void);
-
- /** Notifies the socket that we don't expect any more reads nor writes on it.
- Most TCPIP implementations use this to send the FIN flag in a packet */
- void ShutdownReadWrite(void);
-
- operator xSocket(void) const;
- xSocket GetSocket(void) const;
-
- bool operator == (const cSocket & a_Other) {return m_Socket == a_Other.m_Socket; }
-
- void SetSocket(xSocket a_Socket);
-
- /// Sets the address-reuse socket flag; returns true on success
- bool SetReuseAddress(void);
-
- /// Initializes the network stack. Returns 0 on success, or another number as an error code.
- static int WSAStartup(void);
-
- static int GetLastError();
- static AString GetLastErrorString(void)
- {
- return GetOSErrorString(GetLastError());
- }
-
- /// Creates a new socket of the specified address family
- static cSocket CreateSocket(eFamily a_Family);
-
- inline static bool IsSocketError(int a_ReturnedValue)
- {
- #ifdef _WIN32
- return ((a_ReturnedValue == SOCKET_ERROR) || (a_ReturnedValue == 0));
- #else
- return (a_ReturnedValue <= 0);
- #endif
- }
-
- static bool IsValidSocket(xSocket a_Socket);
-
- static const unsigned short ANY_PORT = 0; // When given to Bind() functions, they will find a free port
- static const int DEFAULT_BACKLOG = 10;
-
- /// Binds to the specified port on "any" interface (0.0.0.0). Returns true if successful.
- bool BindToAnyIPv4(unsigned short a_Port);
-
- /// Binds to the specified port on "any" interface (::/128). Returns true if successful.
- bool BindToAnyIPv6(unsigned short a_Port);
-
- /// Binds to the specified port on localhost interface (127.0.0.1) through IPv4. Returns true if successful.
- bool BindToLocalhostIPv4(unsigned short a_Port);
-
- /// Sets the socket to listen for incoming connections. Returns true if successful.
- bool Listen(int a_Backlog = DEFAULT_BACKLOG);
-
- /// Accepts an IPv4 incoming connection. Blocks if none available.
- cSocket AcceptIPv4(void);
-
- /// Accepts an IPv6 incoming connection. Blocks if none available.
- cSocket AcceptIPv6(void);
-
- /// Connects to a localhost socket on the specified port using IPv4; returns true if successful.
- bool ConnectToLocalhostIPv4(unsigned short a_Port);
-
- /// Connects to the specified host or string IP address and port, using IPv4. Returns true if successful.
- bool ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Port);
-
- int Receive(char * a_Buffer, size_t a_Length, unsigned int a_Flags);
- int Send (const char * a_Buffer, size_t a_Length);
-
- unsigned short GetPort(void) const; // Returns 0 on failure
-
- const AString & GetIPString(void) const { return m_IPString; }
-
- /** Sets the socket into non-blocking mode */
- void SetNonBlocking(void);
-
-private:
- xSocket m_Socket;
- AString m_IPString;
-};