aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_server.cpp')
-rw-r--r--src/script/lua_api/l_server.cpp92
1 files changed, 46 insertions, 46 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index f4362dd7f..64ae924d2 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -56,6 +56,7 @@ int ModApiServer::l_get_server_uptime(lua_State *L)
return 1;
}
+
// print(text)
int ModApiServer::l_print(lua_State *L)
{
@@ -115,14 +116,15 @@ int ModApiServer::l_get_player_privs(lua_State *L)
int ModApiServer::l_get_player_ip(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- const char *name = luaL_checkstring(L, 1);
- RemotePlayer *player =
- dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
- if (player == NULL) {
+ const char * name = luaL_checkstring(L, 1);
+ RemotePlayer *player = dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
+ if(player == NULL)
+ {
lua_pushnil(L); // no such player
return 1;
}
- try {
+ try
+ {
Address addr = getServer(L)->getPeerAddress(player->getPeerId());
std::string ip_str = addr.serializeString();
lua_pushstring(L, ip_str.c_str());
@@ -164,19 +166,21 @@ int ModApiServer::l_get_player_information(lua_State *L)
u8 ser_vers, major, minor, patch;
std::string vers_string, lang_code;
- auto getConInfo = [&](con::rtt_stat_type type, float *value) -> bool {
+ auto getConInfo = [&] (con::rtt_stat_type type, float *value) -> bool {
return server->getClientConInfo(player->getPeerId(), type, value);
};
- bool have_con_info = getConInfo(con::MIN_RTT, &min_rtt) &&
- getConInfo(con::MAX_RTT, &max_rtt) &&
- getConInfo(con::AVG_RTT, &avg_rtt) &&
- getConInfo(con::MIN_JITTER, &min_jitter) &&
- getConInfo(con::MAX_JITTER, &max_jitter) &&
- getConInfo(con::AVG_JITTER, &avg_jitter);
-
- bool r = server->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers,
- &prot_vers, &major, &minor, &patch, &vers_string, &lang_code);
+ bool have_con_info =
+ getConInfo(con::MIN_RTT, &min_rtt) &&
+ getConInfo(con::MAX_RTT, &max_rtt) &&
+ getConInfo(con::AVG_RTT, &avg_rtt) &&
+ getConInfo(con::MIN_JITTER, &min_jitter) &&
+ getConInfo(con::MAX_JITTER, &max_jitter) &&
+ getConInfo(con::AVG_JITTER, &avg_jitter);
+
+ bool r = server->getClientInfo(player->getPeerId(), &state, &uptime,
+ &ser_vers, &prot_vers, &major, &minor, &patch, &vers_string,
+ &lang_code);
if (!r) {
dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushnil(L); // error
@@ -186,11 +190,11 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_newtable(L);
int table = lua_gettop(L);
- lua_pushstring(L, "address");
+ lua_pushstring(L,"address");
lua_pushstring(L, addr.serializeString().c_str());
lua_settable(L, table);
- lua_pushstring(L, "ip_version");
+ lua_pushstring(L,"ip_version");
if (addr.getFamily() == AF_INET) {
lua_pushnumber(L, 4);
} else if (addr.getFamily() == AF_INET6) {
@@ -226,11 +230,11 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_settable(L, table);
}
- lua_pushstring(L, "connection_uptime");
+ lua_pushstring(L,"connection_uptime");
lua_pushnumber(L, uptime);
lua_settable(L, table);
- lua_pushstring(L, "protocol_version");
+ lua_pushstring(L,"protocol_version");
lua_pushnumber(L, prot_vers);
lua_settable(L, table);
@@ -243,28 +247,28 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_settable(L, table);
#ifndef NDEBUG
- lua_pushstring(L, "serialization_version");
+ lua_pushstring(L,"serialization_version");
lua_pushnumber(L, ser_vers);
lua_settable(L, table);
- lua_pushstring(L, "major");
+ lua_pushstring(L,"major");
lua_pushnumber(L, major);
lua_settable(L, table);
- lua_pushstring(L, "minor");
+ lua_pushstring(L,"minor");
lua_pushnumber(L, minor);
lua_settable(L, table);
- lua_pushstring(L, "patch");
+ lua_pushstring(L,"patch");
lua_pushnumber(L, patch);
lua_settable(L, table);
- lua_pushstring(L, "version_string");
+ lua_pushstring(L,"version_string");
lua_pushstring(L, vers_string.c_str());
lua_settable(L, table);
- lua_pushstring(L, "state");
- lua_pushstring(L, ClientInterface::state2Name(state).c_str());
+ lua_pushstring(L,"state");
+ lua_pushstring(L,ClientInterface::state2Name(state).c_str());
lua_settable(L, table);
#endif
@@ -283,9 +287,8 @@ int ModApiServer::l_get_ban_list(lua_State *L)
int ModApiServer::l_get_ban_description(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- const char *ip_or_name = luaL_checkstring(L, 1);
- lua_pushstring(L,
- getServer(L)->getBanDescription(std::string(ip_or_name)).c_str());
+ const char * ip_or_name = luaL_checkstring(L, 1);
+ lua_pushstring(L, getServer(L)->getBanDescription(std::string(ip_or_name)).c_str());
return 1;
}
@@ -293,21 +296,19 @@ int ModApiServer::l_get_ban_description(lua_State *L)
int ModApiServer::l_ban_player(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- const char *name = luaL_checkstring(L, 1);
- RemotePlayer *player =
- dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
+ const char * name = luaL_checkstring(L, 1);
+ RemotePlayer *player = dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
if (player == NULL) {
lua_pushboolean(L, false); // no such player
return 1;
}
- try {
+ try
+ {
Address addr = getServer(L)->getPeerAddress(
- dynamic_cast<ServerEnvironment *>(getEnv(L))
- ->getPlayer(name)
- ->getPeerId());
+ dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name)->getPeerId());
std::string ip_str = addr.serializeString();
getServer(L)->setIpBanned(ip_str, name);
- } catch (const con::PeerNotFoundException &) {
+ } catch(const con::PeerNotFoundException &) {
dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushboolean(L, false); // error
return 1;
@@ -327,8 +328,7 @@ int ModApiServer::l_kick_player(lua_State *L)
else
message.append(".");
- RemotePlayer *player =
- dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
+ RemotePlayer *player = dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name);
if (player == NULL) {
lua_pushboolean(L, false); // No such player
return 1;
@@ -359,7 +359,7 @@ int ModApiServer::l_remove_player(lua_State *L)
int ModApiServer::l_unban_player_or_ip(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- const char *ip_or_name = luaL_checkstring(L, 1);
+ const char * ip_or_name = luaL_checkstring(L, 1);
getServer(L)->unsetIpBanned(ip_or_name);
lua_pushboolean(L, true);
return 1;
@@ -373,9 +373,10 @@ int ModApiServer::l_show_formspec(lua_State *L)
const char *formname = luaL_checkstring(L, 2);
const char *formspec = luaL_checkstring(L, 3);
- if (getServer(L)->showFormspec(playername, formspec, formname)) {
+ if(getServer(L)->showFormspec(playername,formspec,formname))
+ {
lua_pushboolean(L, true);
- } else {
+ }else{
lua_pushboolean(L, false);
}
return 1;
@@ -479,8 +480,7 @@ int ModApiServer::l_dynamic_add_media(lua_State *L)
// Reject adding media before the server has started up
if (!getEnv(L))
- throw LuaError("Dynamic media cannot be added before server has started "
- "up");
+ throw LuaError("Dynamic media cannot be added before server has started up");
std::string filepath = readParam<std::string>(L, 1);
CHECK_SECURE_PATH(L, filepath.c_str(), false);
@@ -503,7 +503,7 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
std::string name;
- if (lua_isstring(L, 1))
+ if(lua_isstring(L, 1))
name = readParam<std::string>(L, 1);
getServer(L)->reportPrivsModified(name);
return 0;
@@ -529,7 +529,7 @@ int ModApiServer::l_set_last_run_mod(lua_State *L)
#ifdef SCRIPTAPI_DEBUG
const char *mod = lua_tostring(L, 1);
getScriptApiBase(L)->setOriginDirect(mod);
- // printf(">>>> last mod set from Lua: %s\n", mod);
+ //printf(">>>> last mod set from Lua: %s\n", mod);
#endif
return 0;
}