Freeciv-3.3
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
/**********************************************************************/
93
bool
api_popup_image
(
lua_State
*
L
,
Player
*pplayer,
const
char
*
tag
)
94
{
95
struct
packet_popup_image
p;
96
97
LUASCRIPT_CHECK_STATE
(
L
,
FALSE
);
98
LUASCRIPT_CHECK_SELF
(
L
, pplayer,
FALSE
);
99
LUASCRIPT_CHECK_ARG_NIL
(
L
,
tag
, 3,
API_TYPE_STRING
,
FALSE
);
100
101
sz_strlcpy
(p.
tag
,
tag
);
102
103
lsend_packet_popup_image
(pplayer->
connections
, &p);
104
105
return
TRUE
;
106
}
107
108
/**********************************************************************/
112
const
char
*
api_server_setting_get
(
lua_State
*
L
,
const
char
*
sett_name
)
113
{
114
struct
setting
*
pset
;
115
static
char
buf
[512];
116
117
LUASCRIPT_CHECK_STATE
(
L
,
NULL
);
118
LUASCRIPT_CHECK_ARG_NIL
(
L
,
sett_name
, 2,
API_TYPE_STRING
,
NULL
);
119
120
pset
=
setting_by_name
(
sett_name
);
121
122
if
(!
pset
) {
123
return
NULL
;
124
}
125
126
return
setting_value_name
(
pset
,
FALSE
,
buf
,
sizeof
(
buf
));
127
}
api_server_setting_get
const char * api_server_setting_get(lua_State *L, const char *sett_name)
Definition
api_server_base.c:112
api_server_was_started
bool api_server_was_started(lua_State *L)
Definition
api_server_base.c:48
api_popup_image
bool api_popup_image(lua_State *L, Player *pplayer, const char *tag)
Definition
api_server_base.c:93
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
incite_cost
char * incite_cost
Definition
comments.c:76
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_popup_image
void lsend_packet_popup_image(struct conn_list *dest, const struct packet_popup_image *packet)
Definition
packets_gen.c:101349
lsend_packet_play_music
void lsend_packet_play_music(struct conn_list *dest, const struct packet_play_music *packet)
Definition
packets_gen.c:101157
save_game
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition
savemain.c:143
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:3309
setting_value_name
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition
settings.c:4267
settings.h
is_safe_filename
bool is_safe_filename(const char *name)
Definition
shared.c:256
game_was_started
bool game_was_started(void)
Definition
srv_main.c:354
srv_main.h
packet_play_music
Definition
packets_gen.h:1851
packet_play_music::tag
char tag[MAX_LEN_NAME]
Definition
packets_gen.h:1852
packet_popup_image
Definition
packets_gen.h:1855
packet_popup_image::tag
char tag[MAX_LEN_NAME]
Definition
packets_gen.h:1856
player
Definition
player.h:249
player::connections
struct conn_list * connections
Definition
player.h:298
setting
Definition
settings.c:92
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition
support.h:195
TRUE
#define TRUE
Definition
support.h:46
FALSE
#define FALSE
Definition
support.h:47
Generated on Sun Dec 22 2024 22:30:37 for Freeciv-3.3 by
1.9.8