summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-22 16:05:02 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-22 16:05:02 +0200
commitc13cffcd30da6b7f4e040de935d5958a30326f8c (patch)
tree7967052d180cad38d4c10981241f9b98ec5000b9 /src
parentFixed another daylight sensor bug (diff)
parentFixed missing break (diff)
downloadcuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar.gz
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar.bz2
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar.lz
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar.xz
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.tar.zst
cuberite-c13cffcd30da6b7f4e040de935d5958a30326f8c.zip
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp29
-rw-r--r--src/ClientHandle.h11
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator.cpp6
3 files changed, 42 insertions, 4 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index ade7e20ac..46083a8f1 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -232,6 +232,9 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage
AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
{
+ // Online UUIDs are always version 4 (random)
+ // We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
+ // This guarantees that they will never collide with an online UUID and can be distinguished.
// Proper format for a version 3 UUID is:
// xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
@@ -254,6 +257,32 @@ AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
+bool cClientHandle::IsUUIDOnline(const AString & a_UUID)
+{
+ // Online UUIDs are always version 4 (random)
+ // We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
+ // This guarantees that they will never collide with an online UUID and can be distinguished.
+ // The version-specifying char is at pos #12 of raw UUID, pos #14 in dashed-UUID.
+ switch (a_UUID.size())
+ {
+ case 32:
+ {
+ // This is the UUID format without dashes, the version char is at pos #12:
+ return (a_UUID[12] == '4');
+ }
+ case 36:
+ {
+ // This is the UUID format with dashes, the version char is at pos #14:
+ return (a_UUID[14] == '4');
+ }
+ }
+ return false;
+}
+
+
+
+
+
void cClientHandle::Kick(const AString & a_Reason)
{
if (m_State >= csAuthenticating) // Don't log pings
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 0d883f3af..3e18cbdad 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -63,7 +63,7 @@ public:
const AString & GetIPString(void) const { return m_IPString; }
- cPlayer* GetPlayer() { return m_Player; } // tolua_export
+ cPlayer * GetPlayer(void) { return m_Player; } // tolua_export
const AString & GetUUID(void) const { return m_UUID; } // tolua_export
void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; }
@@ -76,9 +76,16 @@ public:
/** Generates an UUID based on the player name provided.
This is used for the offline (non-auth) mode, when there's no UUID source.
- Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */
+ Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same.
+ Returns a 36-char UUID (with dashes). */
static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export
+ /** Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID.
+ We use Version-3 UUIDs for offline UUIDs, online UUIDs are Version-4, thus we can tell them apart.
+ Accepts both 32-char and 36-char UUIDs (with and without dashes).
+ If the string given is not a valid UUID, returns false. */
+ static bool IsUUIDOnline(const AString & a_UUID); // tolua_export
+
/** Formats the type of message with the proper color and prefix for sending to the client. **/
static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData);
diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp
index a54867171..1de0d2c34 100644
--- a/src/Simulator/IncrementalRedstoneSimulator.cpp
+++ b/src/Simulator/IncrementalRedstoneSimulator.cpp
@@ -348,6 +348,7 @@ void cIncrementalRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int
case E_BLOCK_REDSTONE_REPEATER_ON:
{
HandleRedstoneRepeater(dataitr->x, dataitr->y, dataitr->z, dataitr->Data);
+ break;
}
case E_BLOCK_REDSTONE_TORCH_OFF:
case E_BLOCK_REDSTONE_TORCH_ON:
@@ -763,7 +764,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeater(int a_RelBlockX, int
void cIncrementalRedstoneSimulator::HandleRedstoneRepeaterDelays()
{
- for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end(); itr++)
+ for (RepeatersDelayList::iterator itr = m_RepeatersDelayList->begin(); itr != m_RepeatersDelayList->end();)
{
if (itr->a_ElapsedTicks >= itr->a_DelayTicks) // Has the elapsed ticks reached the target ticks?
@@ -809,7 +810,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeaterDelays()
{
m_Chunk->SetBlock(RelBlockX, RelBlockY, RelBlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, Meta);
}
- m_RepeatersDelayList->erase(itr);
+ itr = m_RepeatersDelayList->erase(itr);
}
else
{
@@ -818,6 +819,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneRepeaterDelays()
// I am confounded to say why. Perhaps optimisation failure.
LOGD("Incremented a repeater @ {%i %i %i} | Elapsed ticks: %i | Target delay: %i", itr->a_RelBlockPos.x, itr->a_RelBlockPos.y, itr->a_RelBlockPos.z, itr->a_ElapsedTicks, itr->a_DelayTicks);
itr->a_ElapsedTicks++;
+ itr++;
}
}
}