1
0

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
This commit is contained in:
Bill Derouin 2014-01-07 09:31:06 -06:00
parent db978fc687
commit 913841f501
4 changed files with 28 additions and 0 deletions

View File

@ -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) void cProtocol172::SendGameMode(eGameMode a_GameMode)
{ {
cPacketizer Pkt(*this, 0x2b); // Change Game State packet cPacketizer Pkt(*this, 0x2b); // Change Game State packet
@ -1116,6 +1126,9 @@ void cProtocol172::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
AppendPrintf(Response, "\"description\":{\"text\":\"%s\"}", AppendPrintf(Response, "\"description\":{\"text\":\"%s\"}",
cRoot::Get()->GetServer()->GetDescription().c_str() cRoot::Get()->GetServer()->GetDescription().c_str()
); );
AppendPrintf(Response, "\"favicon\":\"data:image/png;base64,%s\"",
cRoot::Get()->GetServer()->GetFaviconData()
);
Response.append("}"); Response.append("}");
cPacketizer Pkt(*this, 0x00); // Response packet cPacketizer Pkt(*this, 0x00); // Response packet

View File

@ -72,6 +72,7 @@ public:
virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override; virtual void SendEntityStatus (const cEntity & a_Entity, char a_Status) override;
virtual void SendEntityVelocity (const cEntity & a_Entity) 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 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 SendGameMode (eGameMode a_GameMode) override;
virtual void SendHealth (void) override; virtual void SendHealth (void) override;
virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override;

View File

@ -203,6 +203,8 @@ bool cServer::InitServer(cIniFile & a_SettingsIni)
m_PlayerCount = 0; m_PlayerCount = 0;
m_PlayerCountDiff = 0; m_PlayerCountDiff = 0;
if (cFile::Exists("favicon.png")) m_Favicon = Base64Encode(cFile::ReadWholeFile("favicon.png"));
if (m_bIsConnected) if (m_bIsConnected)
{ {
LOGERROR("ERROR: Trying to initialize server while server is already running!"); 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) void cServer::PrepareKeys(void)
{ {
// TODO: Save and load key for persistence across sessions // TODO: Save and load key for persistence across sessions

View File

@ -107,6 +107,8 @@ public: // tolua_export
/// Notifies the server that a player is being destroyed; the server uses this to adjust the number of players /// 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); void PlayerDestroying(const cPlayer * a_Player);
AString GetFaviconData(void);
CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; } CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; } CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; }
@ -183,6 +185,7 @@ private:
cRCONServer m_RCONServer; cRCONServer m_RCONServer;
AString m_Description; AString m_Description;
AString m_Favicon;
int m_MaxPlayers; int m_MaxPlayers;
bool m_bIsHardcore; bool m_bIsHardcore;