diff options
-rw-r--r-- | src/ClientHandle.cpp | 162 | ||||
-rw-r--r-- | src/ClientHandle.h | 3 | ||||
-rw-r--r-- | src/MCLogger.cpp | 4 | ||||
-rw-r--r-- | src/MCLogger.h | 1 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 17 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 2 | ||||
-rw-r--r-- | src/World.cpp | 9 | ||||
-rw-r--r-- | src/WorldStorage/NBTChunkSerializer.cpp | 8 |
8 files changed, 104 insertions, 102 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 63ae98be4..7bfae9ca7 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -186,6 +186,82 @@ void cClientHandle::GenerateOfflineUUID(void) +AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData) +{ + switch (a_ChatPrefix) + { + case mtCustom: return AString(); + case mtFailure: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtInformation: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtSuccess: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Green.c_str()); + } + case mtWarning: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtFatal: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Red.c_str()); + } + case mtDeath: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Gray.c_str()); + } + case mtPrivateMessage: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + else + return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); + } + case mtJoin: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtLeave: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + } + ASSERT(!"Unhandled chat prefix type!"); +} + + + + + AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) { // Proper format for a version 3 UUID is: @@ -1849,7 +1925,7 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { bool ShouldAppendChatPrefixes = true; - + if (GetPlayer()->GetWorld() == NULL) { cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); @@ -1868,89 +1944,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi ShouldAppendChatPrefixes = false; } - AString Message; - - switch (a_ChatPrefix) - { - case mtCustom: break; - case mtFailure: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtInformation: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtSuccess: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Green.c_str()); - break; - } - case mtWarning: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtFatal: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Red.c_str()); - break; - } - case mtDeath: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Gray.c_str()); - break; - } - case mtPrivateMessage: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); - else - Message = Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); - break; - } - case mtJoin: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtLeave: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - default: ASSERT(!"Unhandled chat prefix type!"); return; - } - - Message.append(a_Message); + AString Message = FormatMessageType(ShouldAppendChatPrefixes, a_ChatPrefix, a_AdditionalData); - m_Protocol->SendChat(Message); + m_Protocol->SendChat(Message.append(a_Message)); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 3d01d8034..e2b44ce8a 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -77,6 +77,9 @@ public: 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. */ static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export + + // Formats the type of message with the proper color and prefix for sending to the client. + AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData); void Kick(const AString & a_Reason); // tolua_export void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication diff --git a/src/MCLogger.cpp b/src/MCLogger.cpp index 80fa7b173..ca47b29db 100644 --- a/src/MCLogger.cpp +++ b/src/MCLogger.cpp @@ -9,7 +9,6 @@ cMCLogger * cMCLogger::s_MCLogger = NULL; -bool g_ShouldColorOutput = false; #ifdef _WIN32 #include <io.h> // Needed for _isatty(), not available on Linux @@ -33,7 +32,8 @@ cMCLogger * cMCLogger::GetInstance(void) -cMCLogger::cMCLogger(void) +cMCLogger::cMCLogger(void): + g_ShouldColorOutput(false) { AString FileName; Printf(FileName, "LOG_%d.txt", (int)time(NULL)); diff --git a/src/MCLogger.h b/src/MCLogger.h index c0150c124..34955ea16 100644 --- a/src/MCLogger.h +++ b/src/MCLogger.h @@ -52,6 +52,7 @@ private: cCriticalSection m_CriticalSection; cLog * m_Log; static cMCLogger * s_MCLogger; + bool g_ShouldColorOutput; /// Sets the specified color scheme in the terminal (TODO: if coloring available) diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index eb8480268..f68d2ef75 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -763,6 +763,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtCreeper: return mfHostile; case mtEnderman: return mfHostile; case mtGhast: return mfHostile; + case mtGiant: return mfHostile; case mtHorse: return mfPassive; case mtIronGolem: return mfPassive; case mtMagmaCube: return mfHostile; @@ -781,9 +782,11 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) case mtWolf: return mfHostile; case mtZombie: return mfHostile; case mtZombiePigman: return mfHostile; - } ; + + case mtInvalidType: break; + } ASSERT(!"Unhandled mob type"); - return mfMaxplusone; + return mfUnhandled; } @@ -794,10 +797,11 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) { switch (a_MobFamily) { - case mfHostile: return 40; - case mfPassive: return 40; - case mfAmbient: return 40; - case mfWater: return 400; + case mfHostile: return 40; + case mfPassive: return 40; + case mfAmbient: return 40; + case mfWater: return 400; + case mfUnhandled: break; } ASSERT(!"Unhandled mob family"); return -1; @@ -866,6 +870,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) case mtEnderDragon: toReturn = new cEnderDragon(); break; case mtEnderman: toReturn = new cEnderman(); break; case mtGhast: toReturn = new cGhast(); break; + case mtGiant: toReturn = new cGiant(); break; case mtIronGolem: toReturn = new cIronGolem(); break; case mtMooshroom: toReturn = new cMooshroom(); break; case mtOcelot: toReturn = new cOcelot(); break; diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 70b3783fc..0243f6637 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -66,7 +66,7 @@ public: mfAmbient = 2, // Bats mfWater = 3, // Squid - mfMaxplusone, // Nothing. Be sure this is the last and the others are in order + mfUnhandled, // Nothing. Be sure this is the last and the others are in order } ; // tolua_end diff --git a/src/World.cpp b/src/World.cpp index 25ac9b021..21cabe434 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -316,12 +316,9 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) { return 2400 + (m_TickRand.randInt() % 4800); // 2 - 6 minutes } - default: - { - LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather); - return -1; - } - } // switch (Weather) + } + LOGWARNING("%s: Missing default weather interval for weather %d.", __FUNCTION__, a_Weather); + return -1; } diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index b6c14db9c..27631eded 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -621,10 +621,10 @@ void cNBTChunkSerializer::AddHangingEntity(cHangingEntity * a_Hanging) m_Writer.AddInt("TileZ", a_Hanging->GetTileZ()); switch (a_Hanging->GetDirection()) { - case 0: m_Writer.AddByte("Dir", (unsigned char)2); break; - case 1: m_Writer.AddByte("Dir", (unsigned char)1); break; - case 2: m_Writer.AddByte("Dir", (unsigned char)0); break; - case 3: m_Writer.AddByte("Dir", (unsigned char)3); break; + case BLOCK_FACE_YM: m_Writer.AddByte("Dir", (unsigned char)2); break; + case BLOCK_FACE_YP: m_Writer.AddByte("Dir", (unsigned char)1); break; + case BLOCK_FACE_ZM: m_Writer.AddByte("Dir", (unsigned char)0); break; + case BLOCK_FACE_ZP: m_Writer.AddByte("Dir", (unsigned char)3); break; } } |