Freeciv-3.2
Loading...
Searching...
No Matches
modpack.c
Go to the documentation of this file.
1/****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "capability.h"
20#include "registry.h"
21#include "section_file.h"
22#include "shared.h"
23
24/* common */
25#include "game.h"
26
27#include "modpack.h"
28
33
34/* get 'struct modpack_cache_list' and related functions: */
35#define SPECLIST_TAG modpack_cache
36#define SPECLIST_TYPE struct modpack_cache_item
37#include "speclist.h"
38
39#define modpack_cache_iterate(mplist, item) \
40 TYPED_LIST_ITERATE(struct modpack_cache_item, mplist, item)
41#define modpack_cache_iterate_end LIST_ITERATE_END
42
44
45/************************************************************************/
48void modpacks_init(void)
49{
50 if (is_server()) {
52 }
53}
54
55/************************************************************************/
58void modpacks_free(void)
59{
60 if (is_server()) {
62 free(item->modpack_name);
63 free(item->filename);
64 free(item);
66
68 }
69}
70
71/************************************************************************/
74bool modpack_check_capabilities(struct section_file *file, const char *us_capstr,
75 const char *filename, bool verbose)
76{
77 enum log_level level = verbose ? LOG_WARN : LOG_DEBUG;
78
79 const char *file_capstr = secfile_lookup_str(file, "datafile.options");
80
81 if (NULL == file_capstr) {
82 log_base(level, "\"%s\": file doesn't have a capability string",
83 filename);
84 return FALSE;
85 }
87 log_base(level, "\"%s\": file appears incompatible:",
88 filename);
89 log_base(level, " datafile options: %s", file_capstr);
90 log_base(level, " supported options: %s", us_capstr);
91 return FALSE;
92 }
94 log_base(level, "\"%s\": file requires option(s) "
95 "that freeciv doesn't support:", filename);
96 log_base(level, " datafile options: %s", file_capstr);
97 log_base(level, " supported options: %s", us_capstr);
98 return FALSE;
99 }
100
101 return TRUE;
102}
103
104/************************************************************************/
108{
109 struct fileinfo_list *files;
110
111 /* search for modpack files. */
113
114 return files;
115}
116
117/************************************************************************/
121const char *modpack_has_ruleset(struct section_file *sf)
122{
123 if (sf != NULL) {
125 FALSE)) {
126 return NULL;
127 }
128
129 if (secfile_lookup_bool_default(sf, FALSE, "components.ruleset")) {
130 return secfile_lookup_str_default(sf, NULL, "modpack.name");
131 }
132 }
133
134 return NULL;
135}
136
137/************************************************************************/
140const char *modpack_serv_file(struct section_file *sf)
141{
142 if (sf != NULL) {
143 return secfile_lookup_str_default(sf, NULL, "ruleset.serv");
144 }
145
146 return NULL;
147}
148
149/************************************************************************/
152const char *modpack_rulesetdir(struct section_file *sf)
153{
154 if (sf != NULL) {
155 return secfile_lookup_str_default(sf, NULL, "ruleset.rulesetdir");
156 }
157
158 return NULL;
159}
160
161/************************************************************************/
165const char *modpack_cache_ruleset(struct section_file *sf)
166{
167 const char *mp_name = modpack_has_ruleset(sf);
168 struct modpack_cache_item *item;
169
170 if (mp_name == NULL) {
171 return NULL;
172 }
173
174 fc_assert(sf->name != NULL);
175
176 item = fc_malloc(sizeof(struct modpack_cache_item));
177 item->modpack_name = fc_strdup(mp_name);
178 item->filename = fc_strdup(sf->name);
179
181
182 return mp_name;
183}
184
185/************************************************************************/
188const char *modpack_file_from_ruleset_cache(const char *name)
189{
191 if (!fc_strcasecmp(name, item->modpack_name)) {
192 return item->filename;
193 }
195
196 return NULL;
197}
198
199/************************************************************************/
203{
205 cb(item->modpack_name, item->filename, data);
207}
bool has_capabilities(const char *us, const char *them)
Definition capability.c:86
char * incite_cost
Definition comments.c:75
static bool is_server(void)
const char * name
Definition inputfile.c:127
#define fc_assert(condition)
Definition log.h:176
#define log_base(level, message,...)
Definition log.h:94
log_level
Definition log.h:28
@ LOG_DEBUG
Definition log.h:34
@ LOG_WARN
Definition log.h:31
#define fc_strdup(str)
Definition mem.h:43
#define fc_malloc(sz)
Definition mem.h:34
static struct modpack_cache_list * modpack_rulesets
Definition modpack.c:43
void modpacks_free(void)
Definition modpack.c:58
const char * modpack_has_ruleset(struct section_file *sf)
Definition modpack.c:121
void modpack_ruleset_cache_iterate(mrc_cb cb, void *data)
Definition modpack.c:202
bool modpack_check_capabilities(struct section_file *file, const char *us_capstr, const char *filename, bool verbose)
Definition modpack.c:74
const char * modpack_file_from_ruleset_cache(const char *name)
Definition modpack.c:188
#define modpack_cache_iterate_end
Definition modpack.c:41
const char * modpack_serv_file(struct section_file *sf)
Definition modpack.c:140
void modpacks_init(void)
Definition modpack.c:48
const char * modpack_rulesetdir(struct section_file *sf)
Definition modpack.c:152
struct fileinfo_list * get_modpacks_list(void)
Definition modpack.c:107
const char * modpack_cache_ruleset(struct section_file *sf)
Definition modpack.c:165
#define modpack_cache_iterate(mplist, item)
Definition modpack.c:39
void(* mrc_cb)(const char *, const char *, void *data)
Definition modpack.h:39
#define MODPACK_SUFFIX
Definition modpack.h:22
#define MODPACK_CAPSTR
Definition modpack.h:20
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const struct strvec * get_data_dirs(void)
Definition shared.c:893
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)
Definition shared.c:1211
Definition climisc.h:82
char * modpack_name
Definition modpack.c:30
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47