END_DEBUG_EXCEPTION_HANDLER
- return NULL;
+ return nullptr;
}
v3f ServerSoundParams::getPos(ServerEnvironment *env, bool *pos_exists) const
{
m_lag = g_settings->getFloat("dedicated_server_step");
- if(path_world == "")
+ if (path_world.empty())
throw ServerError("Supplied empty world path");
if(!gamespec.isValid())
// Apply texture overrides from texturepack/override.txt
std::string texture_path = g_settings->get("texture_path");
- if (texture_path != "" && fs::IsDir(texture_path))
+ if (!texture_path.empty() && fs::IsDir(texture_path))
m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
m_nodedef->setNodeRegistrationStatus(true);
reconnect = m_shutdown_ask_reconnect;
kick_msg = m_shutdown_msg;
}
- if (kick_msg == "") {
+ if (kick_msg.empty()) {
kick_msg = g_settings->get("kick_msg_shutdown");
}
m_env->kickAllPlayers(SERVER_ACCESSDENIED_SHUTDOWN,
m_clients.lock();
try {
RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id, CS_InitDone);
- if (client != NULL) {
+ if (client) {
playername = client->getName();
playersao = emergePlayer(playername.c_str(), peer_id, client->net_proto_version);
}
RemotePlayer *player = m_env->getPlayer(playername.c_str());
// If failed, cancel
- if ((playersao == NULL) || (player == NULL)) {
+ if (!playersao || !player) {
if (player && player->peer_id != 0) {
actionstream << "Server: Failed to emerge player \"" << playername
<< "\" (player allocated to an another client)" << std::endl;
verbosestream<<"Server::peerAdded(): peer->id="
<<peer->id<<std::endl;
- con::PeerChange c;
- c.type = con::PEER_ADDED;
- c.peer_id = peer->id;
- c.timeout = false;
- m_peer_change_queue.push(c);
+ m_peer_change_queue.push(con::PeerChange(con::PEER_ADDED, peer->id, false));
}
void Server::deletingPeer(con::Peer *peer, bool timeout)
<<peer->id<<", timeout="<<timeout<<std::endl;
m_clients.event(peer->id, CSE_Disconnect);
- con::PeerChange c;
- c.type = con::PEER_REMOVED;
- c.peer_id = peer->id;
- c.timeout = timeout;
- m_peer_change_queue.push(c);
+ m_peer_change_queue.push(con::PeerChange(con::PEER_REMOVED, peer->id, timeout));
}
bool Server::getClientConInfo(u16 peer_id, con::rtt_stat_type type, float* retval)
m_clients.lock();
RemoteClient* client = m_clients.lockedGetClientNoEx(peer_id, CS_Invalid);
- if (client == NULL) {
+ if (!client) {
m_clients.unlock();
return false;
}
pkt << p;
std::vector<u16> clients = m_clients.getClientIDs();
- for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
+ for (u16 client_id : clients) {
if (far_players) {
// Get player
- if (RemotePlayer *player = m_env->getPlayer(*i)) {
+ if (RemotePlayer *player = m_env->getPlayer(client_id)) {
PlayerSAO *sao = player->getPlayerSAO();
if (!sao)
continue;
// If player is far away, only set modified blocks not sent
v3f player_pos = sao->getBasePosition();
if (player_pos.getDistanceFrom(p_f) > maxd) {
- far_players->push_back(*i);
+ far_players->push_back(client_id);
continue;
}
}
}
// Send as reliable
- m_clients.send(*i, 0, &pkt, true);
+ m_clients.send(client_id, 0, &pkt, true);
}
}
PrioritySortedBlockTransfer q = queue[i];
- MapBlock *block = NULL;
- try
- {
+ MapBlock *block = nullptr;
+ try {
block = m_env->getMap().getBlockNoCreate(q.pos);
- }
- catch(InvalidPositionException &e)
- {
+ } catch(const InvalidPositionException &e) {
continue;
}
RemoteClient *client = m_clients.lockedGetClientNoEx(q.peer_id, CS_Active);
-
- if(!client)
+ if (!client)
continue;
SendBlockNoLock(q.peer_id, block, client->serialization_version, client->net_proto_version);
RemotePlayer *player = m_env->getPlayer(peer_id);
/* Run scripts and remove from environment */
- if (player != NULL) {
+ if (player) {
PlayerSAO *playersao = player->getPlayerSAO();
assert(playersao);
Print out action
*/
{
- if(player != NULL && reason != CDR_DENY) {
+ if (player && reason != CDR_DENY) {
std::ostringstream os(std::ios_base::binary);
std::vector<u16> clients = m_clients.getClientIDs();
if (player && player->protocol_version >= 29)
peer_id_to_avoid_sending = PEER_ID_INEXISTENT;
- for (u16 i = 0; i < clients.size(); i++) {
- u16 cid = clients[i];
+ for (u16 cid : clients) {
if (cid != peer_id_to_avoid_sending)
SendChatMessage(cid, ChatMessage(line));
}
std::string Server::getPlayerName(u16 peer_id)
{
RemotePlayer *player = m_env->getPlayer(peer_id);
- if (player == NULL)
+ if (!player)
return "[id="+itos(peer_id)+"]";
return player->getName();
}
PlayerSAO* Server::getPlayerSAO(u16 peer_id)
{
RemotePlayer *player = m_env->getPlayer(peer_id);
- if (player == NULL)
+ if (!player)
return NULL;
return player->getPlayerSAO();
}
bool first = true;
os<<L", clients={";
std::vector<u16> clients = m_clients.getClientIDs();
- for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
+ for (u16 client_id : clients) {
// Get player
- RemotePlayer *player = m_env->getPlayer(*i);
+ RemotePlayer *player = m_env->getPlayer(client_id);
// Get name of player
std::wstring name = L"unknown";
- if (player != NULL)
+ if (player)
name = narrow_to_wide(player->getName());
// Add name to information string
if(!first)
RemotePlayer *player = m_env->getPlayer(name);
// If player is already connected, cancel
- if (player != NULL && player->peer_id != 0) {
+ if (player && player->peer_id != 0) {
infostream<<"emergePlayer(): Player already connected"<<std::endl;
return NULL;
}
/*
If player with the wanted peer_id already exists, cancel.
*/
- if (m_env->getPlayer(peer_id) != NULL) {
+ if (m_env->getPlayer(peer_id)) {
infostream<<"emergePlayer(): Player with wrong name but same"
" peer_id already exists"<<std::endl;
return NULL;