From 913841f50115379ebaaba1cb88c3f1cdfed09320 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:31:06 -0600 Subject: Implement favicon for 1.7.2 Favicon data is a png encoded in base64 which is stored in the server and sent in the server response packet --- src/Protocol/Protocol17x.cpp | 13 +++++++++++++ src/Protocol/Protocol17x.h | 1 + src/Server.cpp | 11 +++++++++++ src/Server.h | 3 +++ 4 files changed, 28 insertions(+) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index bbbd5e973..c75fc9878 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -383,6 +383,16 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc +void cProtocol172::SendFavicon(void) +{ + cPacketizer Pkt(*this, 0x0); // Favicon packet + Pkt.WriteString(cRoot::Get()->GetServer()->GetFaviconData()); +} + + + + + void cProtocol172::SendGameMode(eGameMode a_GameMode) { cPacketizer Pkt(*this, 0x2b); // Change Game State packet @@ -1116,6 +1126,9 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) AppendPrintf(Response, "\"description\":{\"text\":\"%s\"}", cRoot::Get()->GetServer()->GetDescription().c_str() ); + AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", + cRoot::Get()->GetServer()->GetFaviconData() + ); Response.append("}"); cPacketizer Pkt(*this, 0x00); // Response packet diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 23ff2365d..29fc75ee4 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -72,6 +72,7 @@ public: virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; + virtual void SendFavicon (void); virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; diff --git a/src/Server.cpp b/src/Server.cpp index 7dedc3904..e5050f321 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -203,6 +203,8 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; + if (cFile::Exists("favicon.png")) m_Favicon = Base64Encode(cFile::ReadWholeFile("favicon.png")); + if (m_bIsConnected) { LOGERROR("ERROR: Trying to initialize server while server is already running!"); @@ -289,6 +291,15 @@ int cServer::GetNumPlayers(void) +AString cServer::GetFaviconData(void) +{ + return m_Favicon; +} + + + + + void cServer::PrepareKeys(void) { // TODO: Save and load key for persistence across sessions diff --git a/src/Server.h b/src/Server.h index e62c4c7b7..e33264277 100644 --- a/src/Server.h +++ b/src/Server.h @@ -106,6 +106,8 @@ public: // tolua_export /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players void PlayerDestroying(const cPlayer * a_Player); + + AString GetFaviconData(void); CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } @@ -183,6 +185,7 @@ private: cRCONServer m_RCONServer; AString m_Description; + AString m_Favicon; int m_MaxPlayers; bool m_bIsHardcore; -- cgit v1.2.3 From 5fd62f9cd7c1a1594b6331a79f2b375bc0dfb9e2 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:38:51 -0600 Subject: Removed unused line --- src/Protocol/Protocol17x.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 29fc75ee4..23ff2365d 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -72,7 +72,6 @@ public: virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityVelocity (const cEntity & a_Entity) override; virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; - virtual void SendFavicon (void); virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; -- cgit v1.2.3 From ede6757f6731fbdabb07092f8785fa09a59c5375 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:40:59 -0600 Subject: A few touch ups --- src/Server.cpp | 5 ++++- src/Server.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Server.cpp b/src/Server.cpp index e5050f321..0afd8958d 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -203,7 +203,10 @@ bool cServer::InitServer(cIniFile & a_SettingsIni) m_PlayerCount = 0; m_PlayerCountDiff = 0; - if (cFile::Exists("favicon.png")) m_Favicon = Base64Encode(cFile::ReadWholeFile("favicon.png")); + if (cFile::Exists("favicon.png")) + { + m_FaviconData = Base64Encode(cFile::ReadWholeFile("favicon.png")); + } if (m_bIsConnected) { diff --git a/src/Server.h b/src/Server.h index e33264277..62fdf225a 100644 --- a/src/Server.h +++ b/src/Server.h @@ -185,7 +185,7 @@ private: cRCONServer m_RCONServer; AString m_Description; - AString m_Favicon; + AString m_FaviconData; int m_MaxPlayers; bool m_bIsHardcore; -- cgit v1.2.3 From 1c2eb4a1c07167e2fb53f9398383d3fda0940b0b Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 09:49:52 -0600 Subject: A few more touch ups --- src/Protocol/Protocol17x.cpp | 12 +----------- src/Server.cpp | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index c75fc9878..2d00776ae 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -383,16 +383,6 @@ void cProtocol172::SendExplosion(double a_BlockX, double a_BlockY, double a_Bloc -void cProtocol172::SendFavicon(void) -{ - cPacketizer Pkt(*this, 0x0); // Favicon packet - Pkt.WriteString(cRoot::Get()->GetServer()->GetFaviconData()); -} - - - - - void cProtocol172::SendGameMode(eGameMode a_GameMode) { cPacketizer Pkt(*this, 0x2b); // Change Game State packet @@ -1127,7 +1117,7 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) cRoot::Get()->GetServer()->GetDescription().c_str() ); AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"", - cRoot::Get()->GetServer()->GetFaviconData() + cRoot::Get()->GetServer()->GetFaviconData().c_str() ); Response.append("}"); diff --git a/src/Server.cpp b/src/Server.cpp index 0afd8958d..30c401d59 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -296,7 +296,7 @@ int cServer::GetNumPlayers(void) AString cServer::GetFaviconData(void) { - return m_Favicon; + return m_FaviconData; } -- cgit v1.2.3 From 5012b81578396154150cb4696d57c455766e22f2 Mon Sep 17 00:00:00 2001 From: Bill Derouin Date: Tue, 7 Jan 2014 10:26:56 -0600 Subject: Avoid making copies of favicon string --- src/Server.cpp | 2 +- src/Server.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Server.cpp b/src/Server.cpp index 30c401d59..e2a73541a 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -294,7 +294,7 @@ int cServer::GetNumPlayers(void) -AString cServer::GetFaviconData(void) +const AString & cServer::GetFaviconData(void) const { return m_FaviconData; } diff --git a/src/Server.h b/src/Server.h index 62fdf225a..2609b6874 100644 --- a/src/Server.h +++ b/src/Server.h @@ -107,7 +107,7 @@ public: // tolua_export /// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players void PlayerDestroying(const cPlayer * a_Player); - AString GetFaviconData(void); + const AString & GetFaviconData(void) const; CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } -- cgit v1.2.3