forked from Mirrorlandia_minetest/minetest
Cleanup & bugfix
* ObjectRef::set_local_animation: fix wrong lua return (should push a boolean, currently returns nil) * ObjectRef::set_eye_offset: fix wrong lua return (should push a boolean, currently returns nil) * Fix various Server functions which depends on RemotePlayer objet and return true/false when player object is nil whereas it's a caller implementation error. Change those bool functions to void and add sanitize_check call instead. Current callers are always checking player object validity * Optimize Server::setClouds : use CloudParams object ref instead of attribute deserialization from structure & perform RemotePlayer::setCloudParams directly in server class like many other calls * Optimize Server::SendCloudParams: use CloudParams object ref instead of deserialized attributes
This commit is contained in:
parent
c7656edaa5
commit
c7c03ad7a6
@ -493,11 +493,9 @@ int ObjectRef::l_set_local_animation(lua_State *L)
|
|||||||
if (!lua_isnil(L, 6))
|
if (!lua_isnil(L, 6))
|
||||||
frame_speed = lua_tonumber(L, 6);
|
frame_speed = lua_tonumber(L, 6);
|
||||||
|
|
||||||
if (!getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed))
|
getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
|
||||||
return 0;
|
|
||||||
|
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_local_animation(self)
|
// get_local_animation(self)
|
||||||
@ -544,11 +542,9 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
|
|||||||
/* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
|
/* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
|
||||||
offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
|
offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
|
||||||
|
|
||||||
if (!getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third))
|
getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
|
||||||
return 0;
|
|
||||||
|
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_eye_offset(self)
|
// get_eye_offset(self)
|
||||||
@ -1559,9 +1555,7 @@ int ObjectRef::l_set_sky(lua_State *L)
|
|||||||
if (lua_isboolean(L, 5))
|
if (lua_isboolean(L, 5))
|
||||||
clouds = lua_toboolean(L, 5);
|
clouds = lua_toboolean(L, 5);
|
||||||
|
|
||||||
if (!getServer(L)->setSky(player, bgcolor, type, params, clouds))
|
getServer(L)->setSky(player, bgcolor, type, params, clouds);
|
||||||
return 0;
|
|
||||||
|
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1631,14 +1625,7 @@ int ObjectRef::l_set_clouds(lua_State *L)
|
|||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
if (!getServer(L)->setClouds(player, cloud_params.density,
|
getServer(L)->setClouds(player, cloud_params);
|
||||||
cloud_params.color_bright, cloud_params.color_ambient,
|
|
||||||
cloud_params.height, cloud_params.thickness,
|
|
||||||
cloud_params.speed))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
player->setCloudParams(cloud_params);
|
|
||||||
|
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1775,17 +1775,11 @@ void Server::SendSetSky(session_t peer_id, const video::SColor &bgcolor,
|
|||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::SendCloudParams(session_t peer_id, float density,
|
void Server::SendCloudParams(session_t peer_id, const CloudParams ¶ms)
|
||||||
const video::SColor &color_bright,
|
|
||||||
const video::SColor &color_ambient,
|
|
||||||
float height,
|
|
||||||
float thickness,
|
|
||||||
const v2f &speed)
|
|
||||||
{
|
{
|
||||||
NetworkPacket pkt(TOCLIENT_CLOUD_PARAMS, 0, peer_id);
|
NetworkPacket pkt(TOCLIENT_CLOUD_PARAMS, 0, peer_id);
|
||||||
pkt << density << color_bright << color_ambient
|
pkt << params.density << params.color_bright << params.color_ambient
|
||||||
<< height << thickness << speed;
|
<< params.height << params.thickness << params.speed;
|
||||||
|
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3113,54 +3107,36 @@ Address Server::getPeerAddress(session_t peer_id)
|
|||||||
return m_con->GetPeerAddress(peer_id);
|
return m_con->GetPeerAddress(peer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setLocalPlayerAnimations(RemotePlayer *player,
|
void Server::setLocalPlayerAnimations(RemotePlayer *player,
|
||||||
v2s32 animation_frames[4], f32 frame_speed)
|
v2s32 animation_frames[4], f32 frame_speed)
|
||||||
{
|
{
|
||||||
if (!player)
|
sanity_check(player);
|
||||||
return false;
|
|
||||||
|
|
||||||
player->setLocalAnimations(animation_frames, frame_speed);
|
player->setLocalAnimations(animation_frames, frame_speed);
|
||||||
SendLocalPlayerAnimations(player->getPeerId(), animation_frames, frame_speed);
|
SendLocalPlayerAnimations(player->getPeerId(), animation_frames, frame_speed);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third)
|
void Server::setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third)
|
||||||
{
|
{
|
||||||
if (!player)
|
sanity_check(player);
|
||||||
return false;
|
|
||||||
|
|
||||||
player->eye_offset_first = first;
|
player->eye_offset_first = first;
|
||||||
player->eye_offset_third = third;
|
player->eye_offset_third = third;
|
||||||
SendEyeOffset(player->getPeerId(), first, third);
|
SendEyeOffset(player->getPeerId(), first, third);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
|
void Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms,
|
const std::string &type, const std::vector<std::string> ¶ms,
|
||||||
bool &clouds)
|
bool &clouds)
|
||||||
{
|
{
|
||||||
if (!player)
|
sanity_check(player);
|
||||||
return false;
|
|
||||||
|
|
||||||
player->setSky(bgcolor, type, params, clouds);
|
player->setSky(bgcolor, type, params, clouds);
|
||||||
SendSetSky(player->getPeerId(), bgcolor, type, params, clouds);
|
SendSetSky(player->getPeerId(), bgcolor, type, params, clouds);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setClouds(RemotePlayer *player, float density,
|
void Server::setClouds(RemotePlayer *player, const CloudParams ¶ms)
|
||||||
const video::SColor &color_bright,
|
|
||||||
const video::SColor &color_ambient,
|
|
||||||
float height,
|
|
||||||
float thickness,
|
|
||||||
const v2f &speed)
|
|
||||||
{
|
{
|
||||||
if (!player)
|
sanity_check(player);
|
||||||
return false;
|
player->setCloudParams(params);
|
||||||
|
SendCloudParams(player->getPeerId(), params);
|
||||||
SendCloudParams(player->getPeerId(), density,
|
|
||||||
color_bright, color_ambient, height,
|
|
||||||
thickness, speed);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::overrideDayNightRatio(RemotePlayer *player, bool do_override,
|
bool Server::overrideDayNightRatio(RemotePlayer *player, bool do_override,
|
||||||
|
21
src/server.h
21
src/server.h
@ -59,6 +59,7 @@ class EmergeManager;
|
|||||||
class ServerScripting;
|
class ServerScripting;
|
||||||
class ServerEnvironment;
|
class ServerEnvironment;
|
||||||
struct SimpleSoundSpec;
|
struct SimpleSoundSpec;
|
||||||
|
struct CloudParams;
|
||||||
class ServerThread;
|
class ServerThread;
|
||||||
|
|
||||||
enum ClientDeletionReason {
|
enum ClientDeletionReason {
|
||||||
@ -295,19 +296,14 @@ public:
|
|||||||
|
|
||||||
Address getPeerAddress(session_t peer_id);
|
Address getPeerAddress(session_t peer_id);
|
||||||
|
|
||||||
bool setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
|
void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
|
||||||
f32 frame_speed);
|
f32 frame_speed);
|
||||||
bool setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third);
|
void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third);
|
||||||
|
|
||||||
bool setSky(RemotePlayer *player, const video::SColor &bgcolor,
|
void setSky(RemotePlayer *player, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms,
|
const std::string &type, const std::vector<std::string> ¶ms,
|
||||||
bool &clouds);
|
bool &clouds);
|
||||||
bool setClouds(RemotePlayer *player, float density,
|
void setClouds(RemotePlayer *player, const CloudParams ¶ms);
|
||||||
const video::SColor &color_bright,
|
|
||||||
const video::SColor &color_ambient,
|
|
||||||
float height,
|
|
||||||
float thickness,
|
|
||||||
const v2f &speed);
|
|
||||||
|
|
||||||
bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
|
bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
|
||||||
|
|
||||||
@ -389,12 +385,7 @@ private:
|
|||||||
void SendSetSky(session_t peer_id, const video::SColor &bgcolor,
|
void SendSetSky(session_t peer_id, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms,
|
const std::string &type, const std::vector<std::string> ¶ms,
|
||||||
bool &clouds);
|
bool &clouds);
|
||||||
void SendCloudParams(session_t peer_id, float density,
|
void SendCloudParams(session_t peer_id, const CloudParams ¶ms);
|
||||||
const video::SColor &color_bright,
|
|
||||||
const video::SColor &color_ambient,
|
|
||||||
float height,
|
|
||||||
float thickness,
|
|
||||||
const v2f &speed);
|
|
||||||
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
|
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
|
||||||
void broadcastModChannelMessage(const std::string &channel,
|
void broadcastModChannelMessage(const std::string &channel,
|
||||||
const std::string &message, session_t from_peer);
|
const std::string &message, session_t from_peer);
|
||||||
|
Loading…
Reference in New Issue
Block a user