From: Mircea Kitsune Date: Fri, 28 Oct 2011 13:51:14 +0000 (+0300) Subject: Basic implementation for reading sandbox storage files. Currently, it just prints... X-Git-Tag: xonotic-v0.6.0~35^2~18^2~81 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2ccdf6d13cbf4d22b263eaef1c79a1c13f198040;p=xonotic%2Fxonotic-data.pk3dir.git Basic implementation for reading sandbox storage files. Currently, it just prints each line to the console. Also add an autoload cvar, which will make objects be automatically loaded at startup --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index ff90731aa..15d89491f 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -547,6 +547,7 @@ seta g_balance_cloaked_alpha 0.25 set g_sandbox 0 "allow players to spawn and edit objects around the map" set g_sandbox_info 1 "print object information to the server. 1 prints info about spawned / removed objects, 2 also prints info about edited objects" set g_sandbox_storage_autosave 10 "storage is automatically saved every specified number of seconds" +set g_sandbox_storage_autoload 1 "if a storage file exists for the given map, automatically load it at startup" set g_sandbox_editor_maxobjects 1000 "maximum number of objects that may exist at a time" set g_sandbox_editor_free 0 "when enabled, players can edit any object on the map, not just the objects they've spawned" set g_sandbox_editor_distance_spawn 200 "distance at which objects spawn in front of the player" diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 3641d07b5..c33203bdd 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -1201,6 +1201,7 @@ float autocvar_g_debug_defaultsounds; float autocvar_g_loituma; float autocvar_g_sandbox_info; float autocvar_g_sandbox_storage_autosave; +float autocvar_g_sandbox_storage_autoload; float autocvar_g_sandbox_editor_maxobjects; float autocvar_g_sandbox_editor_free; float autocvar_g_sandbox_editor_distance_spawn; diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index 173faee9b..4a1a52241 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -228,7 +228,28 @@ void sandbox_Storage_DatabaseSave() void sandbox_Storage_DatabaseLoad() { + // loads all objects from the database file + string fn, rf; + float fh; + fn = strcat("sandbox/storage_", GetMapname(), ".txt"); + fh = fopen(fn, FILE_READ); + if(fh < 0) + { } // message comes here + else + { + for(;;) + { + rf = fgets(fh); + if(!rf) + break; + if(substring(rf, 0, 2) == "//") + continue; + if(substring(rf, 0, 1) == "#") + continue; + dprint(strcat(rf, " --------\n")); + } + } } MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand) @@ -572,6 +593,12 @@ MUTATOR_DEFINITION(sandbox) MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY); MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY); + MUTATOR_ONADD + { + if(autocvar_g_sandbox_storage_autoload) + sandbox_Storage_DatabaseLoad(); + } + return FALSE; }