Skip to content

Commit c7c03ad

Browse files
committedMar 8, 2018
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
1 parent c7656ed commit c7c03ad

File tree

3 files changed

+25
-71
lines changed

3 files changed

+25
-71
lines changed
 

‎src/script/lua_api/l_object.cpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,9 @@ int ObjectRef::l_set_local_animation(lua_State *L)
493493
if (!lua_isnil(L, 6))
494494
frame_speed = lua_tonumber(L, 6);
495495

496-
if (!getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed))
497-
return 0;
498-
496+
getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
499497
lua_pushboolean(L, true);
500-
return 0;
498+
return 1;
501499
}
502500

503501
// get_local_animation(self)
@@ -544,11 +542,9 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
544542
/* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */
545543
offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
546544

547-
if (!getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third))
548-
return 0;
549-
545+
getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
550546
lua_pushboolean(L, true);
551-
return 0;
547+
return 1;
552548
}
553549

554550
// get_eye_offset(self)
@@ -1559,9 +1555,7 @@ int ObjectRef::l_set_sky(lua_State *L)
15591555
if (lua_isboolean(L, 5))
15601556
clouds = lua_toboolean(L, 5);
15611557

1562-
if (!getServer(L)->setSky(player, bgcolor, type, params, clouds))
1563-
return 0;
1564-
1558+
getServer(L)->setSky(player, bgcolor, type, params, clouds);
15651559
lua_pushboolean(L, true);
15661560
return 1;
15671561
}
@@ -1631,14 +1625,7 @@ int ObjectRef::l_set_clouds(lua_State *L)
16311625
}
16321626
lua_pop(L, 1);
16331627

1634-
if (!getServer(L)->setClouds(player, cloud_params.density,
1635-
cloud_params.color_bright, cloud_params.color_ambient,
1636-
cloud_params.height, cloud_params.thickness,
1637-
cloud_params.speed))
1638-
return 0;
1639-
1640-
player->setCloudParams(cloud_params);
1641-
1628+
getServer(L)->setClouds(player, cloud_params);
16421629
lua_pushboolean(L, true);
16431630
return 1;
16441631
}

‎src/server.cpp

+13-37
Original file line numberDiff line numberDiff line change
@@ -1775,17 +1775,11 @@ void Server::SendSetSky(session_t peer_id, const video::SColor &bgcolor,
17751775
Send(&pkt);
17761776
}
17771777

1778-
void Server::SendCloudParams(session_t peer_id, float density,
1779-
const video::SColor &color_bright,
1780-
const video::SColor &color_ambient,
1781-
float height,
1782-
float thickness,
1783-
const v2f &speed)
1778+
void Server::SendCloudParams(session_t peer_id, const CloudParams &params)
17841779
{
17851780
NetworkPacket pkt(TOCLIENT_CLOUD_PARAMS, 0, peer_id);
1786-
pkt << density << color_bright << color_ambient
1787-
<< height << thickness << speed;
1788-
1781+
pkt << params.density << params.color_bright << params.color_ambient
1782+
<< params.height << params.thickness << params.speed;
17891783
Send(&pkt);
17901784
}
17911785

@@ -3113,54 +3107,36 @@ Address Server::getPeerAddress(session_t peer_id)
31133107
return m_con->GetPeerAddress(peer_id);
31143108
}
31153109

3116-
bool Server::setLocalPlayerAnimations(RemotePlayer *player,
3110+
void Server::setLocalPlayerAnimations(RemotePlayer *player,
31173111
v2s32 animation_frames[4], f32 frame_speed)
31183112
{
3119-
if (!player)
3120-
return false;
3121-
3113+
sanity_check(player);
31223114
player->setLocalAnimations(animation_frames, frame_speed);
31233115
SendLocalPlayerAnimations(player->getPeerId(), animation_frames, frame_speed);
3124-
return true;
31253116
}
31263117

3127-
bool Server::setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third)
3118+
void Server::setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third)
31283119
{
3129-
if (!player)
3130-
return false;
3131-
3120+
sanity_check(player);
31323121
player->eye_offset_first = first;
31333122
player->eye_offset_third = third;
31343123
SendEyeOffset(player->getPeerId(), first, third);
3135-
return true;
31363124
}
31373125

3138-
bool Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
3126+
void Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
31393127
const std::string &type, const std::vector<std::string> &params,
31403128
bool &clouds)
31413129
{
3142-
if (!player)
3143-
return false;
3144-
3130+
sanity_check(player);
31453131
player->setSky(bgcolor, type, params, clouds);
31463132
SendSetSky(player->getPeerId(), bgcolor, type, params, clouds);
3147-
return true;
31483133
}
31493134

3150-
bool Server::setClouds(RemotePlayer *player, float density,
3151-
const video::SColor &color_bright,
3152-
const video::SColor &color_ambient,
3153-
float height,
3154-
float thickness,
3155-
const v2f &speed)
3135+
void Server::setClouds(RemotePlayer *player, const CloudParams &params)
31563136
{
3157-
if (!player)
3158-
return false;
3159-
3160-
SendCloudParams(player->getPeerId(), density,
3161-
color_bright, color_ambient, height,
3162-
thickness, speed);
3163-
return true;
3137+
sanity_check(player);
3138+
player->setCloudParams(params);
3139+
SendCloudParams(player->getPeerId(), params);
31643140
}
31653141

31663142
bool Server::overrideDayNightRatio(RemotePlayer *player, bool do_override,

‎src/server.h

+6-15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class EmergeManager;
5959
class ServerScripting;
6060
class ServerEnvironment;
6161
struct SimpleSoundSpec;
62+
struct CloudParams;
6263
class ServerThread;
6364

6465
enum ClientDeletionReason {
@@ -295,19 +296,14 @@ class Server : public con::PeerHandler, public MapEventReceiver,
295296

296297
Address getPeerAddress(session_t peer_id);
297298

298-
bool setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
299+
void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
299300
f32 frame_speed);
300-
bool setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third);
301+
void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third);
301302

302-
bool setSky(RemotePlayer *player, const video::SColor &bgcolor,
303+
void setSky(RemotePlayer *player, const video::SColor &bgcolor,
303304
const std::string &type, const std::vector<std::string> &params,
304305
bool &clouds);
305-
bool setClouds(RemotePlayer *player, float density,
306-
const video::SColor &color_bright,
307-
const video::SColor &color_ambient,
308-
float height,
309-
float thickness,
310-
const v2f &speed);
306+
void setClouds(RemotePlayer *player, const CloudParams &params);
311307

312308
bool overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
313309

@@ -389,12 +385,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
389385
void SendSetSky(session_t peer_id, const video::SColor &bgcolor,
390386
const std::string &type, const std::vector<std::string> &params,
391387
bool &clouds);
392-
void SendCloudParams(session_t peer_id, float density,
393-
const video::SColor &color_bright,
394-
const video::SColor &color_ambient,
395-
float height,
396-
float thickness,
397-
const v2f &speed);
388+
void SendCloudParams(session_t peer_id, const CloudParams &params);
398389
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
399390
void broadcastModChannelMessage(const std::string &channel,
400391
const std::string &message, session_t from_peer);

0 commit comments

Comments
 (0)
Please sign in to comment.