Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #661635 ยป Luadata.patch

Marko Lindqvist, 2017-05-17 08:05 PM

View differences:

freeciv/common/game.c 2017-05-17 22:36:53.933840772 +0300
multipliers_init();
if (is_server()) {
game.server.luadata = NULL;
game.server.ruledit.nationlist = NULL;
game.server.ruledit.embedded_nations = NULL;
game.server.ruledit.embedded_nations_count = 0;
......
}
if (is_server()) {
if (game.server.luadata != NULL) {
secfile_destroy(game.server.luadata);
}
if (game.server.ruledit.description_file != NULL) {
free(game.server.ruledit.description_file);
game.server.ruledit.description_file = NULL;
freeciv/common/game.h 2017-05-17 22:34:26.946959360 +0300
struct rgbcolor_list *plr_colors;
struct section_file *luadata;
struct {
int turns;
int max_size;
freeciv/server/ruleset.c 2017-05-17 22:41:13.751862751 +0300
**************************************************************************/
static const char *valid_ruleset_filename(const char *subdir,
const char *name,
const char *extension)
const char *extension,
bool optional)
{
char filename[512];
const char *dfilename;
......
dfilename = fileinfoname(get_data_dirs(), filename);
if (dfilename) {
return dfilename;
} else {
} else if (!optional) {
ruleset_error(LOG_ERROR,
/* TRANS: message about an installation error. */
_("Could not find a readable \"%s.%s\" ruleset file."),
......
{
char sfilename[512];
const char *dfilename = valid_ruleset_filename(rsdir, whichset,
RULES_SUFFIX);
RULES_SUFFIX, FALSE);
struct section_file *secfile;
if (dfilename == NULL) {
......
char **buffer)
{
const char *dfilename = valid_ruleset_filename(rsdir, whichset,
SCRIPT_SUFFIX);
SCRIPT_SUFFIX, FALSE);
if (dfilename == NULL) {
return FALSE;
......
}
/**************************************************************************
Load optional luadata.txt
**************************************************************************/
static struct section_file *openload_luadata_file(const char *rsdir)
{
struct section_file *secfile;
char sfilename[512];
const char *dfilename = valid_ruleset_filename(rsdir, "luadata",
"txt", TRUE);
if (dfilename == NULL) {
return NULL;
}
/* Need to save a copy of the filename for following message, since
section_file_load() may call datafilename() for includes. */
sz_strlcpy(sfilename, dfilename);
secfile = secfile_load(sfilename, FALSE);
if (secfile == NULL) {
ruleset_error(LOG_ERROR, "Could not load luadata '%s':\n%s",
sfilename, secfile_error());
}
return secfile;
}
/**************************************************************************
Load a requirement list. The list is returned as a static vector
(callers need not worry about freeing anything).
**************************************************************************/
......
nationfile = openload_ruleset_file("nations", rsdir);
effectfile = openload_ruleset_file("effects", rsdir);
gamefile = openload_ruleset_file("game", rsdir);
game.server.luadata = openload_luadata_file(rsdir);
if (techfile == NULL
|| buildfile == NULL
freeciv/server/scripting/api_server_luadata.c 2017-05-17 22:51:44.851055930 +0300
/*****************************************************************************
Freeciv - Copyright (C) 2005 - The Freeciv Project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif
/* utility */
#include "registry_ini.h"
/* common */
#include "game.h"
/* common/scriptcore */
#include "luascript.h"
/* server/scripting */
#include "script_server.h"
#include "api_server_luadata.h"
/*****************************************************************************
Get string value from luadata.
*****************************************************************************/
const char *api_luadata_get_str(lua_State *L, const char *field)
{
LUASCRIPT_CHECK_STATE(L, NULL);
if (game.server.luadata == NULL) {
return NULL;
}
return secfile_lookup_str_default(game.server.luadata, NULL, "%s", field);
}
freeciv/server/scripting/api_server_luadata.h 2017-05-17 22:46:55.857257330 +0300
/*****************************************************************************
Freeciv - Copyright (C) 2005 - The Freeciv Project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*****************************************************************************/
#ifndef FC__API_SERVER_LUADATA_H
#define FC__API_SERVER_LUADATA_H
struct lua_State;
const char *api_luadata_get_str(lua_State *L, const char *field);
#endif /* API_SERVER_LUADATA_H */
freeciv/server/scripting/Makefile.am 2017-05-17 22:48:20.136615366 +0300
api_server_edit.h \
api_server_game_methods.c \
api_server_game_methods.h \
api_server_luadata.c \
api_server_luadata.h \
api_server_notify.c \
api_server_notify.h \
script_server.c \
freeciv/server/scripting/tolua_server.pkg 2017-05-17 22:47:16.005103864 +0300
/* server/scripting */
$#include "api_server_edit.h"
$#include "api_server_base.h"
$#include "api_server_luadata.h"
$#include "api_server_notify.h"
$#include "api_server_game_methods.h"
$#include "script_server.h"
......
@ add_player_history(lua_State *L, Player *self, int amount);
}
/* Luadata module. */
module luadata {
const char *api_luadata_get_str
@ get_str(lua_State *L, const char *field);
}
$[
-- Compatibility functions
-- These top-level functions were exposed prior to Freeciv 2.4. Since then
    (1-1/1)