aboutsummaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-07-02 23:14:30 -0400
committerkwolekr <kwolekr@minetest.net>2015-07-02 23:14:30 -0400
commit7b171ea2be0e476d7cdc9300b53ba86a9f694161 (patch)
treede1768db2a4dce40738ed96248f29f7c923c527b /src/server.cpp
parent0a0378fecef5c6b4be6d034d8bced2a1568dde81 (diff)
downloadminetest-7b171ea2be0e476d7cdc9300b53ba86a9f694161.tar.gz
minetest-7b171ea2be0e476d7cdc9300b53ba86a9f694161.tar.bz2
minetest-7b171ea2be0e476d7cdc9300b53ba86a9f694161.zip
Fix code style from recent commits and add misc. optimizations
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp143
1 files changed, 68 insertions, 75 deletions
diff --git a/src/server.cpp b/src/server.cpp
index f69c5a935..e9aee47b2 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2838,7 +2838,7 @@ std::string Server::getBanDescription(const std::string &ip_or_name)
void Server::notifyPlayer(const char *name, const std::wstring &msg)
{
Player *player = m_env->getPlayer(name);
- if(!player)
+ if (!player)
return;
if (player->peer_id == PEER_ID_INEXISTENT)
@@ -2847,21 +2847,19 @@ void Server::notifyPlayer(const char *name, const std::wstring &msg)
SendChatMessage(player->peer_id, msg);
}
-bool Server::showFormspec(const char *playername, const std::string &formspec, const std::string &formname)
+bool Server::showFormspec(const char *playername, const std::string &formspec,
+ const std::string &formname)
{
Player *player = m_env->getPlayer(playername);
-
- if(!player)
- {
- infostream<<"showFormspec: couldn't find player:"<<playername<<std::endl;
+ if (!player)
return false;
- }
SendShowFormspecMessage(player->peer_id, formspec, formname);
return true;
}
-u32 Server::hudAdd(Player *player, HudElement *form) {
+u32 Server::hudAdd(Player *player, HudElement *form)
+{
if (!player)
return -1;
@@ -2887,7 +2885,8 @@ bool Server::hudRemove(Player *player, u32 id) {
return true;
}
-bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) {
+bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data)
+{
if (!player)
return false;
@@ -2895,7 +2894,8 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data)
return true;
}
-bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
+bool Server::hudSetFlags(Player *player, u32 flags, u32 mask)
+{
if (!player)
return false;
@@ -2911,7 +2911,8 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
return true;
}
-bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
+bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount)
+{
if (!player)
return false;
if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX)
@@ -2924,13 +2925,15 @@ bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
return true;
}
-s32 Server::hudGetHotbarItemcount(Player *player) {
+s32 Server::hudGetHotbarItemcount(Player *player)
+{
if (!player)
return 0;
return player->getHotbarItemcount();
}
-void Server::hudSetHotbarImage(Player *player, std::string name) {
+void Server::hudSetHotbarImage(Player *player, std::string name)
+{
if (!player)
return;
@@ -2938,13 +2941,15 @@ void Server::hudSetHotbarImage(Player *player, std::string name) {
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
}
-std::string Server::hudGetHotbarImage(Player *player) {
+std::string Server::hudGetHotbarImage(Player *player)
+{
if (!player)
return "";
return player->getHotbarImage();
}
-void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
+void Server::hudSetHotbarSelectedImage(Player *player, std::string name)
+{
if (!player)
return;
@@ -2952,14 +2957,16 @@ void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
}
-std::string Server::hudGetHotbarSelectedImage(Player *player) {
+std::string Server::hudGetHotbarSelectedImage(Player *player)
+{
if (!player)
return "";
return player->getHotbarSelectedImage();
}
-bool Server::setLocalPlayerAnimations(Player *player, v2s32 animation_frames[4], f32 frame_speed)
+bool Server::setLocalPlayerAnimations(Player *player,
+ v2s32 animation_frames[4], f32 frame_speed)
{
if (!player)
return false;
@@ -2981,7 +2988,7 @@ bool Server::setPlayerEyeOffset(Player *player, v3f first, v3f third)
}
bool Server::setSky(Player *player, const video::SColor &bgcolor,
- const std::string &type, const std::vector<std::string> &params)
+ const std::string &type, const std::vector<std::string> &params)
{
if (!player)
return false;
@@ -2992,7 +2999,7 @@ bool Server::setSky(Player *player, const video::SColor &bgcolor,
}
bool Server::overrideDayNightRatio(Player *player, bool do_override,
- float ratio)
+ float ratio)
{
if (!player)
return false;
@@ -3008,9 +3015,9 @@ void Server::notifyPlayers(const std::wstring &msg)
}
void Server::spawnParticle(const char *playername, v3f pos,
- v3f velocity, v3f acceleration,
- float expirationtime, float size, bool
- collisiondetection, bool vertical, std::string texture)
+ v3f velocity, v3f acceleration,
+ float expirationtime, float size, bool
+ collisiondetection, bool vertical, const std::string &texture)
{
Player *player = m_env->getPlayer(playername);
if(!player)
@@ -3020,21 +3027,17 @@ void Server::spawnParticle(const char *playername, v3f pos,
}
void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
- float expirationtime, float size,
- bool collisiondetection, bool vertical, std::string texture)
+ float expirationtime, float size,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
expirationtime, size, collisiondetection, vertical, texture);
}
-u32 Server::addParticleSpawner(const char *playername,
- u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, std::string texture)
+u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawntime,
+ v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
+ float minexptime, float maxexptime, float minsize, float maxsize,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
Player *player = m_env->getPlayer(playername);
if(!player)
@@ -3062,12 +3065,12 @@ u32 Server::addParticleSpawner(const char *playername,
}
u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, std::string texture)
+ v3f minpos, v3f maxpos,
+ v3f minvel, v3f maxvel,
+ v3f minacc, v3f maxacc,
+ float minexptime, float maxexptime,
+ float minsize, float maxsize,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
u32 id = 0;
for(;;) // look for unused particlespawner id
@@ -3128,24 +3131,6 @@ Inventory* Server::createDetachedInventory(const std::string &name)
return inv;
}
-class BoolScopeSet
-{
-public:
- BoolScopeSet(bool *dst, bool val):
- m_dst(dst)
- {
- m_orig_state = *m_dst;
- *m_dst = val;
- }
- ~BoolScopeSet()
- {
- *m_dst = m_orig_state;
- }
-private:
- bool *m_dst;
- bool m_orig_state;
-};
-
// actions: time-reversed list
// Return value: success/failure
bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
@@ -3195,27 +3180,29 @@ bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
// IGameDef interface
// Under envlock
-IItemDefManager* Server::getItemDefManager()
+IItemDefManager *Server::getItemDefManager()
{
return m_itemdef;
}
-INodeDefManager* Server::getNodeDefManager()
+
+INodeDefManager *Server::getNodeDefManager()
{
return m_nodedef;
}
-ICraftDefManager* Server::getCraftDefManager()
+
+ICraftDefManager *Server::getCraftDefManager()
{
return m_craftdef;
}
-ITextureSource* Server::getTextureSource()
+ITextureSource *Server::getTextureSource()
{
return NULL;
}
-IShaderSource* Server::getShaderSource()
+IShaderSource *Server::getShaderSource()
{
return NULL;
}
-scene::ISceneManager* Server::getSceneManager()
+scene::ISceneManager *Server::getSceneManager()
{
return NULL;
}
@@ -3224,44 +3211,50 @@ u16 Server::allocateUnknownNodeId(const std::string &name)
{
return m_nodedef->allocateDummy(name);
}
-ISoundManager* Server::getSoundManager()
+
+ISoundManager *Server::getSoundManager()
{
return &dummySoundManager;
}
-MtEventManager* Server::getEventManager()
+
+MtEventManager *Server::getEventManager()
{
return m_event;
}
-IWritableItemDefManager* Server::getWritableItemDefManager()
+IWritableItemDefManager *Server::getWritableItemDefManager()
{
return m_itemdef;
}
-IWritableNodeDefManager* Server::getWritableNodeDefManager()
+
+IWritableNodeDefManager *Server::getWritableNodeDefManager()
{
return m_nodedef;
}
-IWritableCraftDefManager* Server::getWritableCraftDefManager()
+
+IWritableCraftDefManager *Server::getWritableCraftDefManager()
{
return m_craftdef;
}
-const ModSpec* Server::getModSpec(const std::string &modname) const
+const ModSpec *Server::getModSpec(const std::string &modname) const
{
- for(std::vector<ModSpec>::const_iterator i = m_mods.begin();
- i != m_mods.end(); i++){
- const ModSpec &mod = *i;
- if(mod.name == modname)
+ std::vector<ModSpec>::const_iterator it;
+ for (it = m_mods.begin(); it != m_mods.end(); ++it) {
+ const ModSpec &mod = *it;
+ if (mod.name == modname)
return &mod;
}
return NULL;
}
+
void Server::getModNames(std::vector<std::string> &modlist)
{
- for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++) {
- modlist.push_back(i->name);
- }
+ std::vector<ModSpec>::iterator it;
+ for (it = m_mods.begin(); it != m_mods.end(); ++it)
+ modlist.push_back(it->name);
}
+
std::string Server::getBuiltinLuaPath()
{
return porting::path_share + DIR_DELIM + "builtin";