1
0

Improved Core's WebAmin interface a bit.

Can now kick players through WebAdmin
Can now enable/disable whitelist through WebAdmin
Tick speed is limited in a better way now, instead of always sleeping 50ms before each tick, it now add only sleeps additional time when the tick time was faster than 50ms. Server should run slightly faster because of this (and use more cpu%)


git-svn-id: http://mc-server.googlecode.com/svn/trunk@167 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-01-22 20:15:11 +00:00
parent ec7aacebaa
commit 738b1b3467
7 changed files with 187 additions and 47 deletions

View File

@ -572,15 +572,33 @@ end
function PlayerListWeb:HandleRequest( Request ) function PlayerListWeb:HandleRequest( Request )
local World = cRoot:Get():GetWorld() local World = cRoot:Get():GetWorld()
local Content = "" local Content = ""
Content = Content .. "<br>Connected Players: <b>" .. World:GetNumPlayers() .. "</b><br>"
Content = Content .. "<ul>" if( Request.Params:get("playerlist-kick") ~= "" ) then
local KickPlayerName = Request.Params:get("playerlist-kick")
local Player = World:GetPlayer( KickPlayerName )
if( Player == nil ) then
Content = Content .. "<p>Could not find player " .. KickPlayerName .. " !</p>"
elseif( Player:GetName() == KickPlayerName ) then
Player:GetClientHandle():Kick("You were kicked from the game!")
Content = Content .. "<p>" .. KickPlayerName .. " has been kicked from the game!</p>"
end
end
Content = Content .. "<p>Connected Players: <b>" .. World:GetNumPlayers() .. "</b></p>"
Content = Content .. "<table>"
local PlayerList = World:GetAllPlayers() local PlayerList = World:GetAllPlayers()
for i, Player in ipairs( PlayerList ) do for i, Player in ipairs( PlayerList ) do
Content = Content .. "<li>" .. Player:GetName() Content = Content .. "<tr>"
Content = Content .. "<td style='width: 10px;'>" .. i .. ".</td>"
Content = Content .. "<td>" .. Player:GetName() .. "</td>"
Content = Content .. "<td><a href='?playerlist-kick=" .. Player:GetName() .. "'>Kick</a></td>"
Content = Content .. "</tr>"
end end
Content = Content .. "</ul>" Content = Content .. "</table>"
Content = Content .. "<br>"
return Content return Content
end end
@ -607,12 +625,12 @@ function ReloadWeb:HandleRequest( Request )
if( Request.Params:get("reload") ~= "" ) then if( Request.Params:get("reload") ~= "" ) then
Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"1;././\"></head>" Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"1;././\"></head>"
Content = Content .. "<br>Reloading plugins...<br>" Content = Content .. "<p>Reloading plugins...</p>"
cRoot:Get():GetPluginManager():ReloadPlugins() cRoot:Get():GetPluginManager():ReloadPlugins()
else else
Content = Content .. "<br>Click the reload button to reload all plugins!<br>"
Content = Content .. "<form method=GET>" Content = Content .. "<form method=GET>"
Content = Content .. "<input type=\"submit\" name=\"reload\" value=\"Reload!\">" Content = Content .. "<p>Click the reload button to reload all plugins!<br>"
Content = Content .. "<input type=\"submit\" name=\"reload\" value=\"Reload!\"></p>"
Content = Content .. "</form>" Content = Content .. "</form>"
end end
return Content return Content
@ -661,20 +679,44 @@ function WhiteListWeb:HandleRequest( Request )
WhiteListIni:Erase() -- Empty entire loaded ini first, otherwise weird shit goes down WhiteListIni:Erase() -- Empty entire loaded ini first, otherwise weird shit goes down
WhiteListIni:ReadFile() WhiteListIni:ReadFile()
UpdateMessage = "Loaded from disk" UpdateMessage = "Loaded from disk"
elseif( Request.Params:get("whitelist-setenable") ~= "" ) then
local Enabled = Request.Params:get("whitelist-setenable");
local CreateNewValue = false;
if( WhiteListIni:FindValue( WhiteListIni:FindKey("WhiteListSettings"), "WhiteListOn" ) == cIniFile.noID ) then -- Find out whether the value is in the ini
CreateNewValue = true
end
if( Enabled == "1" ) then
WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", true, CreateNewValue )
else
WhiteListIni:SetValueB("WhiteListSettings", "WhiteListOn", false, CreateNewValue )
end
WhiteListIni:WriteFile()
end end
local Content = "" local Content = ""
local WhiteListEnabled = WhiteListIni:GetValueB("WhiteListSettings", "WhiteListOn", false)
if( WhiteListEnabled == false ) then
Content = Content .. "<p>Whitelist is currently disabled! Click <a href='?whitelist-setenable=1'>here</a> to enable.</p>"
end
Content = Content .. "<h4>Whitelisted players</h4>" Content = Content .. "<h4>Whitelisted players</h4>"
Content = Content .. "<table>" Content = Content .. "<table>"
local KeyNum = WhiteListIni:FindKey("WhiteList") local KeyNum = WhiteListIni:FindKey("WhiteList")
local NumValues = WhiteListIni:GetNumValues(KeyNum) local NumValues = WhiteListIni:GetNumValues(KeyNum)
if( NumValues > 0 ) then
for Num = 0, NumValues-1 do for Num = 0, NumValues-1 do
if( WhiteListIni:GetValue(KeyNum, Num, "0") == "1" ) then if( WhiteListIni:GetValue(KeyNum, Num, "0") == "1" ) then
local PlayerName = WhiteListIni:GetValueName(KeyNum, Num ) local PlayerName = WhiteListIni:GetValueName(KeyNum, Num )
Content = Content .. "<tr><td>" .. PlayerName .. "</td><td>" .. HTMLDeleteButton( PlayerName ) .. "</td></tr>" Content = Content .. "<tr><td>" .. PlayerName .. "</td><td>" .. HTMLDeleteButton( PlayerName ) .. "</td></tr>"
end end
end end
else
Content = Content .. "<tr><td>None</td></tr>"
end
Content = Content .. "</table>" Content = Content .. "</table>"
Content = Content .. "<br><h4>Add player to whitelist</h4>" Content = Content .. "<br><h4>Add player to whitelist</h4>"
Content = Content .. "<form method=\"GET\">" Content = Content .. "<form method=\"GET\">"
@ -684,6 +726,11 @@ function WhiteListWeb:HandleRequest( Request )
Content = Content .. "<input type=\"submit\" name=\"whitelist-reload\" value=\"Reload from disk\">" Content = Content .. "<input type=\"submit\" name=\"whitelist-reload\" value=\"Reload from disk\">"
Content = Content .. "</form>" Content = Content .. "</form>"
Content = Content .. "<br>"..UpdateMessage Content = Content .. "<br>"..UpdateMessage
if( WhiteListEnabled == true ) then
Content = Content .. "<br><br><p>Whitelist is currently enabled, click <a href='?whitelist-setenable=0'>here</a> to disable.</p>"
end
return Content return Content
end end

View File

@ -45,7 +45,7 @@ private:
std::string CheckCase( std::string s) const; std::string CheckCase( std::string s) const;
public: public:
enum errors{ noID = -1}; enum errors{ noID = -1}; //tolua_export
cIniFile( const std::string iniPath = ""); //tolua_export cIniFile( const std::string iniPath = ""); //tolua_export
virtual ~cIniFile() {} virtual ~cIniFile() {}

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/01/12 19:41:18. ** Generated automatically by tolua++-1.0.92 on 01/22/12 20:44:42.
*/ */
#ifndef __cplusplus #ifndef __cplusplus
@ -12820,6 +12820,40 @@ static int tolua_AllToLua_Vector3d_Cross00(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* method: Equals of class Vector3d */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Vector3d_Equals00
static int tolua_AllToLua_Vector3d_Equals00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"const Vector3d",0,&tolua_err) ||
(tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const Vector3d",0,&tolua_err)) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
const Vector3d* self = (const Vector3d*) tolua_tousertype(tolua_S,1,0);
const Vector3d* v = ((const Vector3d*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Equals'", NULL);
#endif
{
bool tolua_ret = (bool) self->Equals(*v);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'Equals'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: operator+ of class Vector3d */ /* method: operator+ of class Vector3d */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Vector3d__add00 #ifndef TOLUA_DISABLE_tolua_AllToLua_Vector3d__add00
static int tolua_AllToLua_Vector3d__add00(lua_State* tolua_S) static int tolua_AllToLua_Vector3d__add00(lua_State* tolua_S)
@ -14628,6 +14662,36 @@ static int tolua_set_cPacket_Login_m_MapSeed(lua_State* tolua_S)
} }
#endif //#ifndef TOLUA_DISABLE #endif //#ifndef TOLUA_DISABLE
/* get function: m_LevelType of class cPacket_Login */
#ifndef TOLUA_DISABLE_tolua_get_cPacket_Login_m_LevelType
static int tolua_get_cPacket_Login_m_LevelType(lua_State* tolua_S)
{
cPacket_Login* self = (cPacket_Login*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'm_LevelType'",NULL);
#endif
tolua_pushcppstring(tolua_S,(const char*)self->m_LevelType);
return 1;
}
#endif //#ifndef TOLUA_DISABLE
/* set function: m_LevelType of class cPacket_Login */
#ifndef TOLUA_DISABLE_tolua_set_cPacket_Login_m_LevelType
static int tolua_set_cPacket_Login_m_LevelType(lua_State* tolua_S)
{
cPacket_Login* self = (cPacket_Login*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'm_LevelType'",NULL);
if (!tolua_iscppstring(tolua_S,2,0,&tolua_err))
tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
#endif
self->m_LevelType = ((std::string) tolua_tocppstring(tolua_S,2,0))
;
return 0;
}
#endif //#ifndef TOLUA_DISABLE
/* get function: m_ServerMode of class cPacket_Login */ /* get function: m_ServerMode of class cPacket_Login */
#ifndef TOLUA_DISABLE_tolua_get_cPacket_Login_m_ServerMode #ifndef TOLUA_DISABLE_tolua_get_cPacket_Login_m_ServerMode
static int tolua_get_cPacket_Login_m_ServerMode(lua_State* tolua_S) static int tolua_get_cPacket_Login_m_ServerMode(lua_State* tolua_S)
@ -15407,6 +15471,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_cclass(tolua_S,"cIniFile","cIniFile","",NULL); tolua_cclass(tolua_S,"cIniFile","cIniFile","",NULL);
#endif #endif
tolua_beginmodule(tolua_S,"cIniFile"); tolua_beginmodule(tolua_S,"cIniFile");
tolua_constant(tolua_S,"noID",cIniFile::noID);
tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00); tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00);
tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local); tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local);
tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local); tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local);
@ -16375,6 +16440,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"SqrLength",tolua_AllToLua_Vector3d_SqrLength00); tolua_function(tolua_S,"SqrLength",tolua_AllToLua_Vector3d_SqrLength00);
tolua_function(tolua_S,"Dot",tolua_AllToLua_Vector3d_Dot00); tolua_function(tolua_S,"Dot",tolua_AllToLua_Vector3d_Dot00);
tolua_function(tolua_S,"Cross",tolua_AllToLua_Vector3d_Cross00); tolua_function(tolua_S,"Cross",tolua_AllToLua_Vector3d_Cross00);
tolua_function(tolua_S,"Equals",tolua_AllToLua_Vector3d_Equals00);
tolua_function(tolua_S,".add",tolua_AllToLua_Vector3d__add00); tolua_function(tolua_S,".add",tolua_AllToLua_Vector3d__add00);
tolua_function(tolua_S,".add",tolua_AllToLua_Vector3d__add01); tolua_function(tolua_S,".add",tolua_AllToLua_Vector3d__add01);
tolua_function(tolua_S,".sub",tolua_AllToLua_Vector3d__sub00); tolua_function(tolua_S,".sub",tolua_AllToLua_Vector3d__sub00);
@ -16474,6 +16540,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_variable(tolua_S,"m_ProtocolVersion",tolua_get_cPacket_Login_m_ProtocolVersion,tolua_set_cPacket_Login_m_ProtocolVersion); tolua_variable(tolua_S,"m_ProtocolVersion",tolua_get_cPacket_Login_m_ProtocolVersion,tolua_set_cPacket_Login_m_ProtocolVersion);
tolua_variable(tolua_S,"m_Username",tolua_get_cPacket_Login_m_Username,tolua_set_cPacket_Login_m_Username); tolua_variable(tolua_S,"m_Username",tolua_get_cPacket_Login_m_Username,tolua_set_cPacket_Login_m_Username);
tolua_variable(tolua_S,"m_MapSeed",tolua_get_cPacket_Login_m_MapSeed,tolua_set_cPacket_Login_m_MapSeed); tolua_variable(tolua_S,"m_MapSeed",tolua_get_cPacket_Login_m_MapSeed,tolua_set_cPacket_Login_m_MapSeed);
tolua_variable(tolua_S,"m_LevelType",tolua_get_cPacket_Login_m_LevelType,tolua_set_cPacket_Login_m_LevelType);
tolua_variable(tolua_S,"m_ServerMode",tolua_get_cPacket_Login_m_ServerMode,tolua_set_cPacket_Login_m_ServerMode); tolua_variable(tolua_S,"m_ServerMode",tolua_get_cPacket_Login_m_ServerMode,tolua_set_cPacket_Login_m_ServerMode);
tolua_variable(tolua_S,"m_Dimension",tolua_get_cPacket_Login_m_Dimension,tolua_set_cPacket_Login_m_Dimension); tolua_variable(tolua_S,"m_Dimension",tolua_get_cPacket_Login_m_Dimension,tolua_set_cPacket_Login_m_Dimension);
tolua_variable(tolua_S,"m_Difficulty",tolua_get_cPacket_Login_m_Difficulty,tolua_set_cPacket_Login_m_Difficulty); tolua_variable(tolua_S,"m_Difficulty",tolua_get_cPacket_Login_m_Difficulty,tolua_set_cPacket_Login_m_Difficulty);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/01/12 19:41:18. ** Generated automatically by tolua++-1.0.92 on 01/22/12 20:44:42.
*/ */
/* Exported function */ /* Exported function */

View File

@ -278,11 +278,9 @@ void cServer::StartListenClient()
bool cServer::Tick(float a_Dt) bool cServer::Tick(float a_Dt)
{ {
//LOG("1. Tick"); //LOG("1. Tick %0.2f", a_Dt);
if( a_Dt > 100.f ) a_Dt = 100.f; // Don't go over 1/10 second if( a_Dt > 100.f ) a_Dt = 100.f; // Don't go over 1/10 second
cSleep::MilliSleep( 50 ); // Don't tick too much
m_Millisecondsf += a_Dt; m_Millisecondsf += a_Dt;
if( m_Millisecondsf > 1.f ) if( m_Millisecondsf > 1.f )
{ {
@ -331,6 +329,7 @@ void ServerTickThread( void * a_Param )
cTimer Timer; cTimer Timer;
long long msPerTick = 50; // TODO - Put this in server config file
long long LastTime = Timer.GetNowTime(); long long LastTime = Timer.GetNowTime();
bool bKeepGoing = true; bool bKeepGoing = true;
@ -339,6 +338,13 @@ void ServerTickThread( void * a_Param )
long long NowTime = Timer.GetNowTime(); long long NowTime = Timer.GetNowTime();
float DeltaTime = (float)(NowTime-LastTime); float DeltaTime = (float)(NowTime-LastTime);
bKeepGoing = CServerObj->Tick( DeltaTime ); bKeepGoing = CServerObj->Tick( DeltaTime );
long long TickTime = Timer.GetNowTime() - NowTime;
if( TickTime < msPerTick ) // Stretch tick time until it's at least msPerTick
{
cSleep::MilliSleep( (unsigned int)( msPerTick - TickTime ) );
}
LastTime = NowTime; LastTime = NowTime;
} }

View File

@ -99,28 +99,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
std::string Menu; std::string Menu;
std::string Content; std::string Content;
std::string Template = WebAdmin->GetTemplate(); std::string Template = WebAdmin->GetTemplate();
std::string FoundPlugin;
Content += "<h3>Current Game</h3>";
Content += "<h4>Server Name:</h4>";
Content += "<p>" + std::string( cRoot::Get()->GetServer()->GetServerID() ) + "</p>";
Content += "<h4>Plugins:</h4><p>";
cPluginManager* PM = cRoot::Get()->GetPluginManager();
const cPluginManager::PluginList & List = PM->GetAllPlugins();
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr )
{
Content += std::string( (*itr)->GetName() ) + "<br>";
}
Content += "</p>";
Content += "<h4>Players:</h4><p>";
cWorld* World = cRoot::Get()->GetWorld(); // TODO - Create a list of worlds and players
cWorld::PlayerList PlayerList = World->GetAllPlayers();
for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
{
Content += std::string( (*itr)->GetName() ) + "<br>";
}
Content += "</p>";
for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr ) for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{ {
@ -133,9 +112,11 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
Request.Params = new cStringMap(r->params_); Request.Params = new cStringMap(r->params_);
Request.Path = r->path_; Request.Path = r->path_;
if( Split.size() > 1 ) if( Split.size() > 1 )
{ {
std::string FoundPlugin = "";
for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr ) for( PluginList::iterator itr = WebAdmin->m_Plugins.begin(); itr != WebAdmin->m_Plugins.end(); ++itr )
{ {
if( (*itr)->GetName() == Split[1] ) if( (*itr)->GetName() == Split[1] )
@ -145,15 +126,41 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
break; break;
} }
} }
if( FoundPlugin.compare("") != 0 ) // Add some header
{
Content = "<h3>" + FoundPlugin + "</h3>\n<p>" + Content + "</p>";
}
} }
delete Request.Params; delete Request.Params;
if( FoundPlugin.empty() ) // Default page
{
Content.clear();
FoundPlugin = "Current Game";
Content += "<h4>Server Name:</h4>";
Content += "<p>" + std::string( cRoot::Get()->GetServer()->GetServerID() ) + "</p>";
Content += "<h4>Plugins:</h4><ul>";
cPluginManager* PM = cRoot::Get()->GetPluginManager();
if( PM )
{
const cPluginManager::PluginList & List = PM->GetAllPlugins();
for( cPluginManager::PluginList::const_iterator itr = List.begin(); itr != List.end(); ++itr )
{
Content += std::string("<li>") + std::string( (*itr)->GetName() ) + "</li>";
}
}
Content += "</ul>";
Content += "<h4>Players:</h4><ul>";
cWorld* World = cRoot::Get()->GetWorld(); // TODO - Create a list of worlds and players
cWorld::PlayerList PlayerList = World->GetAllPlayers();
for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
{
Content += std::string("<li>") + std::string( (*itr)->GetName() ) + "</li>";
}
Content += "</ul><br>";
}
if( Split.size() > 1 ) if( Split.size() > 1 )
{ {
Content += "\n<p><a href='"; Content += "\n<p><a href='";
@ -192,6 +199,7 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
ReplaceString( Template, std::string("{USERNAME}"), r->username_ ); ReplaceString( Template, std::string("{USERNAME}"), r->username_ );
ReplaceString( Template, std::string("{MENU}"), Menu ); ReplaceString( Template, std::string("{MENU}"), Menu );
ReplaceString( Template, std::string("{PLUGIN_NAME}"), FoundPlugin );
ReplaceString( Template, std::string("{CONTENT}"), Content ); ReplaceString( Template, std::string("{CONTENT}"), Content );
ReplaceString( Template, std::string("{TITLE}"), "MCServer" ); ReplaceString( Template, std::string("{TITLE}"), "MCServer" );

View File

@ -253,6 +253,17 @@
margin: 20px 0 10px; margin: 20px 0 10px;
} }
h4 {
padding: 0 0 0 10px;
margin: 20px 0 10px;
}
#main ul {
padding: 0 0 0 10px;
list-style-type: circle;
list-style-position: inside;
}
#main table { #main table {
border-top: 1px solid #ddd; border-top: 1px solid #ddd;
width: 700px; width: 700px;
@ -340,8 +351,9 @@
<h2>Welcome {USERNAME}</h2> <h2>Welcome {USERNAME}</h2>
<div id="main"> <div id="main">
<h3>{PLUGIN_NAME}</h3>
<p>{CONTENT}</p> {CONTENT}
</div> </div>
<!-- // #main --> <!-- // #main -->