1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Player data to Database (#5475)

* Player data to Database

Add player data into databases (SQLite3 & PG only)

PostgreSQL & SQLite: better POO Design for databases

Add --migrate-players argument to server + deprecation warning

* Remove players directory if empty
This commit is contained in:
Loïc Blot 2017-04-23 14:35:08 +02:00 committed by GitHub
parent dda171d292
commit 29ab20c272
31 changed files with 1555 additions and 378 deletions

View file

@ -60,6 +60,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/base64.h"
#include "util/sha1.h"
#include "util/hex.h"
#include "database.h"
class ClientNotFoundException : public BaseException
{
@ -2618,9 +2619,8 @@ void Server::RespawnPlayer(u16 peer_id)
bool repositioned = m_script->on_respawnplayer(playersao);
if (!repositioned) {
v3f pos = findSpawnPos();
// setPos will send the new position to client
playersao->setPos(pos);
playersao->setPos(findSpawnPos());
}
SendPlayerHP(peer_id);
@ -3442,8 +3442,8 @@ v3f Server::findSpawnPos()
s32 range = 1 + i;
// We're going to try to throw the player to this position
v2s16 nodepos2d = v2s16(
-range + (myrand() % (range * 2)),
-range + (myrand() % (range * 2)));
-range + (myrand() % (range * 2)),
-range + (myrand() % (range * 2)));
// Get spawn level at point
s16 spawn_level = m_emerge->getSpawnLevelAtPoint(nodepos2d);
@ -3516,8 +3516,6 @@ void Server::requestShutdown(const std::string &msg, bool reconnect, float delay
PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version)
{
bool newplayer = false;
/*
Try to get an existing player
*/
@ -3538,45 +3536,19 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version
return NULL;
}
// Create a new player active object
PlayerSAO *playersao = new PlayerSAO(m_env, peer_id, isSingleplayer());
player = m_env->loadPlayer(name, playersao);
// Create player if it doesn't exist
if (!player) {
newplayer = true;
player = new RemotePlayer(name, this->idef());
// Set player position
infostream<<"Server: Finding spawn place for player \""
<<name<<"\""<<std::endl;
playersao->setBasePosition(findSpawnPos());
// Make sure the player is saved
player->setModified(true);
// Add player to environment
m_env->addPlayer(player);
} else {
// If the player exists, ensure that they respawn inside legal bounds
// This fixes an assert crash when the player can't be added
// to the environment
if (objectpos_over_limit(playersao->getBasePosition())) {
actionstream << "Respawn position for player \""
<< name << "\" outside limits, resetting" << std::endl;
playersao->setBasePosition(findSpawnPos());
}
player = new RemotePlayer(name, idef());
}
playersao->initialize(player, getPlayerEffectivePrivs(player->getName()));
bool newplayer = false;
// Load player
PlayerSAO *playersao = m_env->loadPlayer(player, &newplayer, peer_id, isSingleplayer());
// Complete init with server parts
playersao->finalize(player, getPlayerEffectivePrivs(player->getName()));
player->protocol_version = proto_version;
/* Clean up old HUD elements from previous sessions */
player->clearHud();
/* Add object to environment */
m_env->addActiveObject(playersao);
/* Run scripts */
if (newplayer) {
m_script->on_newplayer(playersao);