summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bindings/AllToLua.pkg1
-rw-r--r--src/BlockID.cpp51
-rw-r--r--src/BlockID.h3
-rw-r--r--src/ClientHandle.cpp12
-rw-r--r--src/ClientHandle.h9
-rw-r--r--src/Mobs/CMakeLists.txt1
-rw-r--r--src/Mobs/Monster.cpp10
-rw-r--r--src/Mobs/Monster.h3
-rw-r--r--src/Mobs/MonsterTypes.h13
-rw-r--r--src/OSSupport/CMakeLists.txt2
-rw-r--r--src/OSSupport/Event.cpp47
-rw-r--r--src/OSSupport/Event.h4
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp1
-rw-r--r--src/Protocol/ProtocolRecognizer.h2
14 files changed, 98 insertions, 61 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 37e6aecd2..73de98e22 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -27,6 +27,7 @@ $cfile "WebPlugin.h"
$cfile "LuaWindow.h"
$cfile "../BlockID.h"
+$cfile "../Mobs/MonsterTypes.h"
$cfile "../BlockInfo.h"
$cfile "../StringUtils.h"
$cfile "../Defines.h"
diff --git a/src/BlockID.cpp b/src/BlockID.cpp
index 9026d81f2..755c721db 100644
--- a/src/BlockID.cpp
+++ b/src/BlockID.cpp
@@ -253,57 +253,6 @@ AString ItemToFullString(const cItem & a_Item)
-int StringToMobType(const AString & a_MobString)
-{
- static struct
- {
- int m_MobType;
- const char * m_String;
- } MobMap [] =
- {
- {mtCreeper, "Creeper"},
- {mtSkeleton, "Skeleton"},
- {mtSpider, "Spider"},
- {mtGiant, "Giant"},
- {mtZombie, "Zombie"},
- {mtSlime, "Slime"},
- {mtGhast, "Ghast"},
- {mtZombiePigman, "ZombiePigman"},
- {mtEnderman, "Enderman"},
- {mtCaveSpider, "CaveSpider"},
- {mtSilverfish, "SilverFish"},
- {mtBlaze, "Blaze"},
- {mtMagmaCube, "MagmaCube"},
- {mtEnderDragon, "EnderDragon"},
- {mtWither, "Wither"},
- {mtBat, "Bat"},
- {mtWitch, "Witch"},
- {mtPig, "Pig"},
- {mtSheep, "Sheep"},
- {mtCow, "Cow"},
- {mtChicken, "Chicken"},
- {mtSquid, "Squid"},
- {mtWolf, "Wolf"},
- {mtMooshroom, "Mooshroom"},
- {mtSnowGolem, "SnowGolem"},
- {mtOcelot, "Ocelot"},
- {mtIronGolem, "IronGolem"},
- {mtVillager, "Villager"},
- };
- for (size_t i = 0; i < ARRAYCOUNT(MobMap); i++)
- {
- if (NoCaseCompare(MobMap[i].m_String, a_MobString) == 0)
- {
- return MobMap[i].m_MobType;
- }
- } // for i - MobMap[]
- return -1;
-}
-
-
-
-
-
eDimension StringToDimension(const AString & a_DimensionString)
{
// First try decoding as a number
diff --git a/src/BlockID.h b/src/BlockID.h
index 69b5e2fe0..e36843422 100644
--- a/src/BlockID.h
+++ b/src/BlockID.h
@@ -1005,9 +1005,6 @@ extern AString ItemTypeToString(short a_ItemType);
/// Translates a full item into a fully-specified string (including meta and count). If the ItemType is not recognized, the ItemType number is output into the string.
extern AString ItemToFullString(const cItem & a_Item);
-/// Translates a mob string ("ocelot") to mobtype (E_ENTITY_TYPE_OCELOT)
-extern int StringToMobType(const AString & a_MobString);
-
/// Translates a dimension string to dimension enum. Takes either a number or a dimension alias (built-in). Returns dimOverworld on failure
extern eDimension StringToDimension(const AString & a_DimensionString);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index a29bef0c0..3b677460b 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -92,7 +92,8 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_NumBlockChangeInteractionsThisTick(0),
m_UniqueID(0),
m_HasSentPlayerChunk(false),
- m_Locale("en_GB")
+ m_Locale("en_GB"),
+ m_ProtocolVersion(0)
{
m_Protocol = new cProtocolRecognizer(this);
@@ -583,15 +584,22 @@ void cClientHandle::HandlePing(void)
bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Username)
{
+ // If the protocol version hasn't been set yet, set it now:
+ if (m_ProtocolVersion == 0)
+ {
+ m_ProtocolVersion = a_ProtocolVersion;
+ }
+
m_Username = a_Username;
+ // Let the plugins know about this event, they may refuse the player:
if (cRoot::Get()->GetPluginManager()->CallHookLogin(this, a_ProtocolVersion, a_Username))
{
Destroy();
return false;
}
- // Schedule for authentication; until then, let them wait (but do not block)
+ // Schedule for authentication; until then, let the player wait (but do not block)
m_State = csAuthenticating;
cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), GetUsername(), m_Protocol->GetAuthServerID());
return true;
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 20592c190..a9cc29d50 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -316,6 +316,12 @@ public:
/** Called when the player will enchant a Item */
void HandleEnchantItem(Byte & a_WindowID, Byte & a_Enchantment);
+
+ /** Called by the protocol recognizer when the protocol version is known. */
+ void SetProtocolVersion(UInt32 a_ProtocolVersion) { m_ProtocolVersion = a_ProtocolVersion; }
+
+ /** Returns the protocol version number of the protocol that the client is talking. Returns zero if the protocol version is not (yet) known. */
+ UInt32 GetProtocolVersion(void) const { return m_ProtocolVersion; } // tolua_export
private:
@@ -427,6 +433,9 @@ private:
/** The brand identification of the client, as received in the MC|Brand plugin message or set from a plugin. */
AString m_ClientBrand;
+ /** The version of the protocol that the client is talking, or 0 if unknown. */
+ UInt32 m_ProtocolVersion;
+
/** Handles the block placing packet when it is a real block placement (not block-using, item-using or eating) */
void HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, cItemHandler & a_ItemHandler);
diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt
index 2c092c15f..bbbb9287a 100644
--- a/src/Mobs/CMakeLists.txt
+++ b/src/Mobs/CMakeLists.txt
@@ -54,6 +54,7 @@ SET (HDRS
IronGolem.h
MagmaCube.h
Monster.h
+ MonsterTypes.h
Mooshroom.h
Ocelot.h
PassiveAggressiveMonster.h
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 12ca6bbbe..73dbcb3c3 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -62,6 +62,16 @@ static const struct
+eMonsterType StringToMobType(const AString & a_MobString)
+{
+ LOGWARNING("%s: Function is obsolete, use cMonster::StringToMobType() instead", __FUNCTION__);
+ return cMonster::StringToMobType(a_MobString);
+}
+
+
+
+
+
////////////////////////////////////////////////////////////////////////////////
// cMonster:
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index a1f9c4a5b..9fd67d67c 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -25,9 +25,6 @@ class cMonster :
typedef cPawn super;
public:
- // Deprecated
- typedef eMonsterType eType;
-
enum eFamily
{
mfHostile = 0, // Spider, Zombies ...
diff --git a/src/Mobs/MonsterTypes.h b/src/Mobs/MonsterTypes.h
index 7a73e99f4..852eb3446 100644
--- a/src/Mobs/MonsterTypes.h
+++ b/src/Mobs/MonsterTypes.h
@@ -37,5 +37,18 @@ enum eMonsterType
mtZombie = E_META_SPAWN_EGG_ZOMBIE,
mtZombiePigman = E_META_SPAWN_EGG_ZOMBIE_PIGMAN,
} ;
+
+
+
+
+
+/** Translates a mob string ("ocelot") to mobtype (mtOcelot).
+OBSOLETE, use cMonster::StringToMobType() instead.
+Implemented in Monster.cpp. */
+extern eMonsterType StringToMobType(const AString & a_MobString);
+
// tolua_end
+
+
+
diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt
index a42fcbed4..429949c59 100644
--- a/src/OSSupport/CMakeLists.txt
+++ b/src/OSSupport/CMakeLists.txt
@@ -39,6 +39,6 @@ if(NOT MSVC)
add_library(OSSupport ${SRCS} ${HDRS})
if(UNIX)
- target_link_libraries(OSSupport pthread)
+ target_link_libraries(OSSupport pthread rt)
endif()
endif()
diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp
index 74f823216..7cf8a826c 100644
--- a/src/OSSupport/Event.cpp
+++ b/src/OSSupport/Event.cpp
@@ -102,6 +102,53 @@ void cEvent::Wait(void)
+bool cEvent::Wait(int a_TimeoutMSec)
+{
+ #ifdef _WIN32
+ DWORD res = WaitForSingleObject(m_Event, (DWORD)a_TimeoutMSec);
+ switch (res)
+ {
+ case WAIT_OBJECT_0: return true; // Regular event signalled
+ case WAIT_TIMEOUT: return false; // Regular event timeout
+ default:
+ {
+ LOGWARN("cEvent: waiting for the event failed: %u, GLE = %u. Continuing, but server may be unstable.", (unsigned)res, (unsigned)GetLastError());
+ return false;
+ }
+ }
+ #else
+ // Get the current time:
+ timespec timeout;
+ if (clock_gettime(CLOCK_REALTIME, &timeout) == -1)
+ {
+ LOGWARN("cEvent: Getting current time failed: %i, err = %s. Continuing, but the server may be unstable.", errno, GetOSErrorString(errno).c_str());
+ return false;
+ }
+
+ // Add the specified timeout:
+ timeout.tv_sec += a_TimeoutMSec / 1000;
+ timeout.tv_nsec += (a_TimeoutMSec % 1000) * 1000000; // 1 msec = 1000000 usec
+
+ // Wait with timeout:
+ int res = sem_timedwait(m_Event, &timeout);
+ switch (res)
+ {
+ case 0: return true; // Regular event signalled
+ case ETIMEDOUT: return false; // Regular even timeout
+ default:
+ {
+ AString error = GetOSErrorString(errno);
+ LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, error.c_str());
+ return false;
+ }
+ }
+ #endif
+}
+
+
+
+
+
void cEvent::Set(void)
{
#ifdef _WIN32
diff --git a/src/OSSupport/Event.h b/src/OSSupport/Event.h
index 71f418c0c..e2fa65a05 100644
--- a/src/OSSupport/Event.h
+++ b/src/OSSupport/Event.h
@@ -24,6 +24,10 @@ public:
void Wait(void);
void Set (void);
+
+ /** Waits for the event until either it is signalled, or the (relative) timeout is passed.
+ Returns true if the event was signalled, false if the timeout was hit or there was an error. */
+ bool Wait(int a_TimeoutMSec);
private:
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index 4f8eb59db..15bcd03b1 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -905,6 +905,7 @@ bool cProtocolRecognizer::TryRecognizeLengthedProtocol(UInt32 a_PacketLengthRema
{
return false;
}
+ m_Client->SetProtocolVersion(ProtocolVersion);
switch (ProtocolVersion)
{
case PROTO_VERSION_1_7_2:
diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h
index 96a7e17d2..b42cfdec2 100644
--- a/src/Protocol/ProtocolRecognizer.h
+++ b/src/Protocol/ProtocolRecognizer.h
@@ -134,7 +134,7 @@ protected:
/// Tries to recognize protocol based on m_Buffer contents; returns true if recognized
bool TryRecognizeProtocol(void);
- /** Tries to recognize a protocol in the leghted family (1.7+), based on m_Buffer; returns true if recognized.
+ /** Tries to recognize a protocol in the lengthed family (1.7+), based on m_Buffer; returns true if recognized.
The packet length and type have already been read, type is 0
The number of bytes remaining in the packet is passed as a_PacketLengthRemaining
**/