1
0

Added the possibility of reserved player slots by implementing the HandleHandshake hook!

More info: http://forum.mc-server.org/showthread.php?tid=555

git-svn-id: http://mc-server.googlecode.com/svn/trunk@836 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-09-05 20:30:27 +00:00
parent 692afbca68
commit f94456dd3e
10 changed files with 88 additions and 8 deletions

View File

@ -974,10 +974,9 @@ int cProtocol125::ParseHandshake(void)
LOGD("HANDSHAKE %s", Username.c_str()); LOGD("HANDSHAKE %s", Username.c_str());
if (cRoot::Get()->GetDefaultWorld()->GetNumPlayers() >= cRoot::Get()->GetDefaultWorld()->GetMaxPlayers()) if (!m_Client->HandleHandshake( m_Username ))
{ {
m_Client->Kick("The server is currently full :(-- Try again later"); return PARSE_OK; // Player is not allowed into the server
return PARSE_OK;
} }
SendHandshake(cRoot::Get()->GetServer()->GetServerID()); SendHandshake(cRoot::Get()->GetServer()->GetServerID());

View File

@ -332,6 +332,11 @@ int cProtocol132::ParseHandshake(void)
HANDLE_PACKET_READ(ReadBEInt, int, ServerPort); HANDLE_PACKET_READ(ReadBEInt, int, ServerPort);
m_Username = Username; m_Username = Username;
if (!m_Client->HandleHandshake( m_Username ))
{
return PARSE_OK; // Player is not allowed into the server
}
// Send a 0xFD Encryption Key Request http://wiki.vg/Protocol#0xFD // Send a 0xFD Encryption Key Request http://wiki.vg/Protocol#0xFD
AString key; AString key;
CryptoPP::StringSink sink(key); // GCC won't allow inline instantiation in the following line, damned temporary refs CryptoPP::StringSink sink(key); // GCC won't allow inline instantiation in the following line, damned temporary refs

View File

@ -918,6 +918,23 @@ void cClientHandle::HandleKeepAlive(int a_KeepAliveID)
bool cClientHandle::HandleHandshake(const AString & a_Username)
{
if (!cRoot::Get()->GetPluginManager()->CallHookHandshake(this, a_Username))
{
if (cRoot::Get()->GetDefaultWorld()->GetNumPlayers() >= cRoot::Get()->GetDefaultWorld()->GetMaxPlayers())
{
Kick("The server is currently full :(-- Try again later");
return false;
}
}
return true;
}
void cClientHandle::SendData(const char * a_Data, int a_Size) void cClientHandle::SendData(const char * a_Data, int a_Size)
{ {
{ {

View File

@ -162,6 +162,7 @@ public:
void HandleRespawn (void); void HandleRespawn (void);
void HandleDisconnect (const AString & a_Reason); void HandleDisconnect (const AString & a_Reason);
void HandleKeepAlive (int a_KeepAliveID); void HandleKeepAlive (int a_KeepAliveID);
bool HandleHandshake (const AString & a_Username);
/** Called when the protocol has finished logging the user in. /** Called when the protocol has finished logging the user in.
Return true to allow the user in; false to kick them. Return true to allow the user in; false to kick them.

View File

@ -283,6 +283,17 @@ bool cPlugin::OnWeatherChanged(cWorld * a_World)
bool cPlugin::OnHandshake(cClientHandle * a_Client, const AString & a_Username)
{
UNUSED(a_Client);
UNUSED(a_Username);
return false;
}
void cPlugin::AddCommand(const AString & a_Command, const AString & a_Description, const AString & a_Permission) void cPlugin::AddCommand(const AString & a_Command, const AString & a_Description, const AString & a_Permission)
{ {
CommandStruct Command; CommandStruct Command;

View File

@ -61,6 +61,7 @@ public:
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player); virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player);
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player); virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
virtual bool OnWeatherChanged (cWorld * a_World); virtual bool OnWeatherChanged (cWorld * a_World);
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username);
// Accessors // Accessors
const AString & GetName() const { return m_Name; } const AString & GetName() const { return m_Name; }

View File

@ -627,6 +627,26 @@ bool cPluginManager::CallHookUpdatedSign(cWorld * a_World, int a_BlockX, int a_B
bool cPluginManager::CallHookHandshake(cClientHandle * a_ClientHandle, const AString & a_Username)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_HANDSHAKE);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnHandshake(a_ClientHandle, a_Username))
{
return true;
}
}
return false;
}
cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const cPlugin* cPluginManager::GetPlugin( const AString & a_Plugin ) const
{ {

View File

@ -115,6 +115,7 @@ public: //tolua_export
bool CallHookUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player); bool CallHookUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player);
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player); bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
bool CallHookWeatherChanged (cWorld * a_World); bool CallHookWeatherChanged (cWorld * a_World);
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
void RemoveHooks( cPlugin* a_Plugin ); void RemoveHooks( cPlugin* a_Plugin );
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export

View File

@ -640,6 +640,30 @@ bool cPlugin_NewLua::OnUpdatedSign(
bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Username)
{
cCSLock Lock(m_CriticalSection);
if (!PushFunction("OnHandshake"))
{
return false;
}
tolua_pushusertype(m_LuaState, a_Client, "cClientHandle");
tolua_pushstring (m_LuaState, a_Username.c_str());
if (!CallFunction(2, 1, "OnHandshake"))
{
return false;
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
return bRetVal;
}
cPlugin_NewLua * cPlugin_NewLua::CreateWebPlugin(lua_State * a_LuaState) cPlugin_NewLua * cPlugin_NewLua::CreateWebPlugin(lua_State * a_LuaState)
{ {
LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now. (plugin \"%s\" in folder \"%s\")", LOGWARN("WARNING: Using deprecated function CreateWebPlugin()! A Lua plugin is a WebPlugin by itself now. (plugin \"%s\" in folder \"%s\")",

View File

@ -45,6 +45,7 @@ public: //tolua_export
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player) override; virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player) override;
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override; virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override;
virtual bool OnWeatherChanged (cWorld * a_World) override; virtual bool OnWeatherChanged (cWorld * a_World) override;
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
const AString & GetDirectory(void) const {return m_Directory; } const AString & GetDirectory(void) const {return m_Directory; }