Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no sq] Server code cleanups / refactors #14438

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ set(common_SRCS
serialization.cpp
server.cpp
serverenvironment.cpp
servermap.cpp
settings.cpp
staticobject.cpp
terminal_chat_console.cpp
Expand Down
5 changes: 4 additions & 1 deletion src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "network/peerhandler.h"
#include "gameparams.h"
#include "clientdynamicinfo.h"
#include <fstream>
#include "util/numeric.h"

#ifdef SERVER
#error Do not include in server builds
#endif

#define CLIENT_CHAT_MESSAGE_LIMIT_PER_10S 10.0f

struct ClientEvent;
Expand Down
4 changes: 4 additions & 0 deletions src/client/clientenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "activeobjectmgr.h" // client::ActiveObjectMgr
#include <set>

#ifdef SERVER
#error Do not include in server builds
#endif

class ClientSimpleObject;
class ClientMap;
class ClientScripting;
Expand Down
10 changes: 3 additions & 7 deletions src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,11 @@ class ClientMap : public Map, public scene::ISceneNode
s32 id
);

virtual ~ClientMap();

bool maySaveBlocks() override
{
return false;
}

void drop() override
{
ISceneNode::drop(); // calls destructor
}

void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset, video::SColor light_color);

/*
Expand Down Expand Up @@ -122,6 +115,9 @@ class ClientMap : public Map, public scene::ISceneNode
void onSettingChanged(const std::string &name);

protected:
// use drop() instead
virtual ~ClientMap();

void reportMetrics(u64 save_time_us, u32 saved_blocks, u32 all_blocks) override;
private:
bool isMeshOccluded(MapBlock *mesh_block, u16 mesh_size, v3s16 cam_pos_nodes);
Expand Down
4 changes: 4 additions & 0 deletions src/client/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h"
#include <string>

#ifdef SERVER
#error Do not include in server builds
#endif

class InputHandler;
class ChatBackend;
class RenderingEngine;
Expand Down
4 changes: 4 additions & 0 deletions src/client/renderingengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// include the shadow mapper classes too
#include "client/shadows/dynamicshadowsrender.h"

#ifdef SERVER
#error Do not include in server builds
#endif

struct VideoDriverInfo {
std::string name;
std::string friendly_name;
Expand Down
4 changes: 4 additions & 0 deletions src/client/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <unordered_set>
#include <vector>

#ifdef SERVER
#error Do not include in server builds
#endif

struct SoundSpec;

class SoundFallbackPathProvider
Expand Down
2 changes: 1 addition & 1 deletion src/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static inline v3f truncate(const v3f& vec, const f32 factor)
// The time after which the collision occurs is stored in dtime.
CollisionAxis axisAlignedCollision(
const aabb3f &staticbox, const aabb3f &movingbox,
const v3f &speed, f32 *dtime)
const v3f speed, f32 *dtime)
{
//TimeTaker tt("axisAlignedCollision");

Expand Down
2 changes: 1 addition & 1 deletion src/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ collisionMoveResult collisionMoveSimple(Environment *env,IGameDef *gamedef,
// dtime receives time until first collision, invalid if -1 is returned
CollisionAxis axisAlignedCollision(
const aabb3f &staticbox, const aabb3f &movingbox,
const v3f &speed, f32 *dtime);
v3f speed, f32 *dtime);

// Helper function:
// Checks if moving the movingbox up by the given distance would hit a ceiling.
Expand Down
1 change: 1 addition & 0 deletions src/database/database-files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h"
#include "server/player_sao.h"
#include "util/string.h"
#include <json/json.h>
#include <cassert>

// !!! WARNING !!!
Expand Down
1 change: 0 additions & 1 deletion src/database/database-files.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class ModStorageDatabaseFiles : public ModStorageDatabase

private:
Json::Value *getOrCreateJson(const std::string &modname);
bool writeJson(const std::string &modname, const Json::Value &json);

std::string m_storage_dir;
std::unordered_map<std::string, Json::Value> m_mod_storage;
Expand Down
4 changes: 2 additions & 2 deletions src/emerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlicht_changes/printing.h"
#include "filesys.h"
#include "log.h"
#include "map.h"
#include "servermap.h"
#include "mapblock.h"
#include "mapgen/mg_biome.h"
#include "mapgen/mg_ore.h"
Expand Down Expand Up @@ -646,7 +646,7 @@ void *EmergeThread::run()
std::map<v3s16, MapBlock *> modified_blocks;

m_map = &m_server->m_env->getServerMap();
m_emerge = m_server->m_emerge;
m_emerge = m_server->getEmergeManager();
m_mapgen = m_emerge->m_mapgens[id];
enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info;

Expand Down
2 changes: 1 addition & 1 deletion src/emerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class EmergeThread;
class NodeDefManager;
class Settings;

class MapSettingsManager;
class BiomeManager;
class OreManager;
class DecorationManager;
Expand Down
29 changes: 12 additions & 17 deletions src/httpfetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "httpfetch.h"
#include "porting.h" // for sleep_ms(), get_sysinfo(), secure_rand_fill_buf()
#include <iostream>
#include <sstream>
#include <list>
#include <unordered_map>
#include <cerrno>
Expand Down Expand Up @@ -152,9 +150,9 @@ bool httpfetch_async_get(u64 caller, HTTPFetchResult &fetch_result)
static size_t httpfetch_writefunction(
char *ptr, size_t size, size_t nmemb, void *userdata)
{
std::ostringstream *stream = (std::ostringstream*)userdata;
auto *dest = reinterpret_cast<std::string*>(userdata);
size_t count = size * nmemb;
stream->write(ptr, count);
dest->append(ptr, count);
return count;
}

Expand Down Expand Up @@ -215,7 +213,6 @@ class HTTPFetchOngoing
CURLM *multi = nullptr;
HTTPFetchRequest request;
HTTPFetchResult result;
std::ostringstream oss;
struct curl_slist *http_header = nullptr;
curl_mime *multipart_mime = nullptr;
};
Expand All @@ -225,13 +222,11 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
CurlHandlePool *pool_):
pool(pool_),
request(request_),
result(request_),
oss(std::ios::binary)
result(request_)
{
curl = pool->alloc();
if (curl == NULL) {
if (!curl)
return;
}

// Set static cURL options
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
Expand Down Expand Up @@ -278,16 +273,15 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());

// Set up a write callback that writes to the
// ostringstream ongoing->oss, unless the data
// is to be discarded
// result struct, unless the data is to be discarded
if (request.caller == HTTPFETCH_DISCARD) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_discardfunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
} else {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_writefunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result.data);
}

// Set data from fields or raw_data
Expand Down Expand Up @@ -373,7 +367,6 @@ const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res)
{
result.succeeded = (res == CURLE_OK);
result.timeout = (res == CURLE_OPERATION_TIMEDOUT);
result.data = oss.str();

// Get HTTP/FTP response code
result.response_code = 0;
Expand Down Expand Up @@ -417,10 +410,12 @@ HTTPFetchOngoing::~HTTPFetchOngoing()
// Set safe options for the reusable cURL handle
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_discardfunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
curl_easy_setopt(curl, CURLOPT_USERAGENT, nullptr);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, nullptr);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, nullptr);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, nullptr);
if (http_header) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, nullptr);
curl_slist_free_all(http_header);
}
if (multipart_mime) {
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "irrlichttypes.h" // must be included before anything irrlicht, see comment in the file
#include "irrlichttypes_bloated.h"
#include "irrlicht.h" // createDevice
#include "irrlichttypes_extrabloated.h"
#include "irrlicht_changes/printing.h"
#include "benchmark/benchmark.h"
#include "chat_interface.h"
Expand All @@ -28,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "filesys.h"
#include "version.h"
#include "client/game.h"
#include "defaultsettings.h"
#include "gettext.h"
#include "log.h"
Expand Down