Freeciv-3.3
Loading...
Searching...
No Matches
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/**********************************************************************/
38{
40 LUASCRIPT_CHECK_SELF(L, pplayer, 0);
41
42 return get_civ_score(pplayer);
43}
44
45/**********************************************************************/
54
55/**********************************************************************/
58bool api_server_save(lua_State *L, const char *filename)
59{
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/**********************************************************************/
75bool api_play_music(lua_State *L, Player *pplayer, const char *tag)
76{
77 struct packet_play_music p;
78
80 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
82
83 sz_strlcpy(p.tag, tag);
84
86
87 return TRUE;
88}
89
90/**********************************************************************/
93bool api_popup_image(lua_State *L, Player *pplayer, const char *tag)
94{
95 struct packet_popup_image p;
96
98 LUASCRIPT_CHECK_SELF(L, pplayer, FALSE);
100
101 sz_strlcpy(p.tag, tag);
102
104
105 return TRUE;
106}
107
108/**********************************************************************/
112const char *api_server_setting_get(lua_State *L, const char *sett_name)
113{
114 struct setting *pset;
115 static char buf[512];
116
119
121
122 if (!pset) {
123 return NULL;
124 }
125
126 return setting_value_name(pset, FALSE, buf, sizeof(buf));
127}
const char * api_server_setting_get(lua_State *L, const char *sett_name)
bool api_server_was_started(lua_State *L)
bool api_popup_image(lua_State *L, Player *pplayer, const char *tag)
int api_server_player_civilization_score(lua_State *L, Player *pplayer)
bool api_play_music(lua_State *L, Player *pplayer, const char *tag)
bool api_server_save(lua_State *L, const char *filename)
char * incite_cost
Definition comments.c:76
#define LUASCRIPT_CHECK_STATE(L,...)
Definition luascript.h:117
#define LUASCRIPT_CHECK_SELF(L, value,...)
Definition luascript.h:146
#define LUASCRIPT_CHECK_ARG_NIL(L, value, narg, type,...)
Definition luascript.h:138
void lsend_packet_popup_image(struct conn_list *dest, const struct packet_popup_image *packet)
void lsend_packet_play_music(struct conn_list *dest, const struct packet_play_music *packet)
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:143
int get_civ_score(const struct player *pplayer)
Definition score.c:352
struct setting * setting_by_name(const char *name)
Definition settings.c:3309
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4267
bool is_safe_filename(const char *name)
Definition shared.c:256
bool game_was_started(void)
Definition srv_main.c:354
char tag[MAX_LEN_NAME]
char tag[MAX_LEN_NAME]
struct conn_list * connections
Definition player.h:298
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47