Skip to content

Commit 470de10

Browse files
committedApr 3, 2015
Fix players spawned at (0,0,0) in some rare cases instead of static_spawnpoint, if set
Approved by: @kwoelkr
1 parent aa340fd commit 470de10

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed
 

Diff for: ‎src/server.cpp

+15-20
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,7 @@ void Server::RespawnPlayer(u16 peer_id)
25222522

25232523
bool repositioned = m_script->on_respawnplayer(playersao);
25242524
if(!repositioned){
2525-
v3f pos = findSpawnPos(m_env->getServerMap());
2525+
v3f pos = findSpawnPos();
25262526
// setPos will send the new position to client
25272527
playersao->setPos(pos);
25282528
}
@@ -3179,23 +3179,24 @@ std::string Server::getBuiltinLuaPath()
31793179
return porting::path_share + DIR_DELIM + "builtin";
31803180
}
31813181

3182-
v3f findSpawnPos(ServerMap &map)
3182+
v3f Server::findSpawnPos()
31833183
{
3184-
//return v3f(50,50,50)*BS;
3184+
ServerMap &map = m_env->getServerMap();
3185+
v3f nodeposf;
3186+
if (g_settings->getV3FNoEx("static_spawnpoint", nodeposf)) {
3187+
return nodeposf * BS;
3188+
}
31853189

3186-
v3s16 nodepos;
3190+
// Default position is static_spawnpoint
3191+
// We will return it if we don't found a good place
3192+
v3s16 nodepos(nodeposf.X, nodeposf.Y, nodeposf.Z);
31873193

3188-
#if 0
3189-
nodepos = v2s16(0,0);
3190-
groundheight = 20;
3191-
#endif
3192-
3193-
#if 1
31943194
s16 water_level = map.getWaterLevel();
31953195

3196+
bool is_good = false;
3197+
31963198
// Try to find a good place a few times
3197-
for(s32 i=0; i<1000; i++)
3198-
{
3199+
for(s32 i = 0; i < 1000 && !is_good; i++) {
31993200
s32 range = 1 + i;
32003201
// We're going to try to throw the player to this position
32013202
v2s16 nodepos2d = v2s16(
@@ -3210,7 +3211,7 @@ v3f findSpawnPos(ServerMap &map)
32103211
continue;
32113212

32123213
nodepos = v3s16(nodepos2d.X, groundheight, nodepos2d.Y);
3213-
bool is_good = false;
3214+
32143215
s32 air_count = 0;
32153216
for (s32 i = 0; i < 10; i++) {
32163217
v3s16 blockpos = getNodeBlockPos(nodepos);
@@ -3225,13 +3226,7 @@ v3f findSpawnPos(ServerMap &map)
32253226
}
32263227
nodepos.Y++;
32273228
}
3228-
if(is_good){
3229-
// Found a good place
3230-
//infostream<<"Searched through "<<i<<" places."<<std::endl;
3231-
break;
3232-
}
32333229
}
3234-
#endif
32353230

32363231
return intToFloat(nodepos, BS);
32373232
}
@@ -3274,7 +3269,7 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id)
32743269
// Set player position
32753270
infostream<<"Server: Finding spawn place for player \""
32763271
<<name<<"\""<<std::endl;
3277-
v3f pos = findSpawnPos(m_env->getServerMap());
3272+
v3f pos = findSpawnPos();
32783273
player->setPosition(pos);
32793274

32803275
// Make sure the player is saved

Diff for: ‎src/server.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ enum ClientDeletionReason {
6363
CDR_DENY
6464
};
6565

66-
/*
67-
Some random functions
68-
*/
69-
v3f findSpawnPos(ServerMap &map);
70-
7166
class MapEditEventIgnorer
7267
{
7368
public:
@@ -474,6 +469,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
474469
void DeleteClient(u16 peer_id, ClientDeletionReason reason);
475470
void UpdateCrafting(Player *player);
476471

472+
v3f findSpawnPos();
473+
477474
// When called, connection mutex should be locked
478475
RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active);
479476
RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active);

0 commit comments

Comments
 (0)