Freeciv-3.1
Loading...
Searching...
No Matches
server
scripting
api_server_base.c
Go to the documentation of this file.
1
/*****************************************************************************
2
Freeciv - Copyright (C) 2005 - The Freeciv Project
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
/* common/scriptcore */
19
#include "
luascript.h
"
20
21
/* server */
22
#include "
score.h
"
23
#include "
settings.h
"
24
#include "
srv_main.h
"
25
26
/* server/sqavegame */
27
#include "
savemain.h
"
28
29
/* server/scripting */
30
#include "
script_server.h
"
31
32
#include "
api_server_base.h
"
33
34
/**********************************************************************/
37
int
api_server_player_civilization_score
(lua_State *L,
Player
*pplayer)
38
{
39
LUASCRIPT_CHECK_STATE
(L, 0);
40
LUASCRIPT_CHECK_SELF
(L, pplayer, 0);
41
42
return
get_civ_score
(pplayer);
43
}
44
45
/**********************************************************************/
48
bool
api_server_was_started
(lua_State *L)
49
{
50
LUASCRIPT_CHECK_STATE
(L,
FALSE
);
51
52
return
game_was_started
();
53
}
54
55
/**********************************************************************/
58
bool
api_server_save
(lua_State *L,
const
char
*filename)
59
{
60
LUASCRIPT_CHECK_STATE
(L,
FALSE
);
61
62
/* Limit the allowed characters in the filename. */
63
if
(filename != NULL && !
is_safe_filename
(filename)) {
64
return
FALSE
;
65
}
66
67
save_game
(filename,
"User request (Lua)"
,
FALSE
);
68
69
return
TRUE
;
70
}
71
72
/**********************************************************************/
75
bool
api_play_music
(lua_State *L,
Player
*pplayer,
const
char
*tag)
76
{
77
struct
packet_play_music
p;
78
79
LUASCRIPT_CHECK_STATE
(L,
FALSE
);
80
LUASCRIPT_CHECK_SELF
(L, pplayer,
FALSE
);
81
LUASCRIPT_CHECK_ARG_NIL
(L,
tag
, 3, API_TYPE_STRING,
FALSE
);
82
83
sz_strlcpy
(p.
tag
,
tag
);
84
85
lsend_packet_play_music
(pplayer->
connections
, &p);
86
87
return
TRUE
;
88
}
89
90
/**********************************************************************/
94
const
char
*
api_server_setting_get
(lua_State *L,
const
char
*sett_name)
95
{
96
struct
setting
*pset;
97
static
char
buf[512];
98
99
LUASCRIPT_CHECK_STATE
(L, NULL);
100
LUASCRIPT_CHECK_ARG_NIL
(L, sett_name, 2, API_TYPE_STRING, NULL);
101
102
pset =
setting_by_name
(sett_name);
103
104
if
(!pset) {
105
return
NULL;
106
}
107
108
return
setting_value_name
(pset,
FALSE
, buf,
sizeof
(buf));
109
}
api_server_setting_get
const char * api_server_setting_get(lua_State *L, const char *sett_name)
Definition
api_server_base.c:94
api_server_was_started
bool api_server_was_started(lua_State *L)
Definition
api_server_base.c:48
api_server_player_civilization_score
int api_server_player_civilization_score(lua_State *L, Player *pplayer)
Definition
api_server_base.c:37
api_play_music
bool api_play_music(lua_State *L, Player *pplayer, const char *tag)
Definition
api_server_base.c:75
api_server_save
bool api_server_save(lua_State *L, const char *filename)
Definition
api_server_base.c:58
api_server_base.h
luascript.h
LUASCRIPT_CHECK_STATE
#define LUASCRIPT_CHECK_STATE(L,...)
Definition
luascript.h:117
LUASCRIPT_CHECK_SELF
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition
luascript.h:146
LUASCRIPT_CHECK_ARG_NIL
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition
luascript.h:138
lsend_packet_play_music
void lsend_packet_play_music(struct conn_list *dest, const struct packet_play_music *packet)
Definition
packets_gen.c:94772
save_game
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition
savemain.c:142
savemain.h
get_civ_score
int get_civ_score(const struct player *pplayer)
Definition
score.c:352
score.h
script_server.h
setting_by_name
struct setting * setting_by_name(const char *name)
Definition
settings.c:3138
setting_value_name
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition
settings.c:4066
settings.h
is_safe_filename
bool is_safe_filename(const char *name)
Definition
shared.c:252
game_was_started
bool game_was_started(void)
Definition
srv_main.c:339
srv_main.h
packet_play_music
Definition
packets_gen.h:1862
packet_play_music::tag
char tag[MAX_LEN_NAME]
Definition
packets_gen.h:1863
player
Definition
player.h:249
player::connections
struct conn_list * connections
Definition
player.h:298
setting
Definition
settings.c:88
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition
support.h:167
TRUE
#define TRUE
Definition
support.h:46
FALSE
#define FALSE
Definition
support.h:47
Generated on Sun Jan 5 2025 22:00:36 for Freeciv-3.1 by
1.9.8