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)
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 *****************************************************************************/
15 #include <fc_config.h>
18 /* common/scriptcore */
19 #include "luascript.h"
27 /* server/scripting */
28 #include "script_server.h"
30 #include "api_server_base.h"
32 /*****************************************************************************
33 Return the civilization score (total) for player
34 *****************************************************************************/
35 int api_server_player_civilization_score(lua_State
*L
, Player
*pplayer
)
37 LUASCRIPT_CHECK_STATE(L
, 0);
38 LUASCRIPT_CHECK_SELF(L
, pplayer
, 0);
40 return get_civ_score(pplayer
);
43 /*****************************************************************************
44 Returns TRUE if the game was started.
45 *****************************************************************************/
46 bool api_server_was_started(lua_State
*L
)
48 LUASCRIPT_CHECK_STATE(L
, FALSE
);
50 return game_was_started();
53 /*****************************************************************************
54 Save the game (a manual save is triggered).
55 *****************************************************************************/
56 bool api_server_save(lua_State
*L
, const char *filename
)
58 LUASCRIPT_CHECK_STATE(L
, FALSE
);
60 /* Limit the allowed characters in the filename. */
61 if (filename
!= NULL
&& !is_safe_filename(filename
)) {
65 save_game(filename
, "User request (Lua)", FALSE
);
70 /*****************************************************************************
71 Play music track for player
72 *****************************************************************************/
73 bool api_play_music(lua_State
*L
, Player
*pplayer
, const char *tag
)
75 struct packet_play_music p
;
77 LUASCRIPT_CHECK_STATE(L
, FALSE
);
78 LUASCRIPT_CHECK_SELF(L
, pplayer
, FALSE
);
79 LUASCRIPT_CHECK_ARG_NIL(L
, tag
, 3, API_TYPE_STRING
, FALSE
);
81 strncpy(p
.tag
, tag
, sizeof(p
.tag
));
83 lsend_packet_play_music(pplayer
->connections
, &p
);
88 /*****************************************************************************
89 Return the formated value of the setting or NULL if no such setting exists,
90 *****************************************************************************/
91 const char *api_server_setting_get(lua_State
*L
, const char *sett_name
)
96 LUASCRIPT_CHECK_STATE(L
, NULL
);
97 LUASCRIPT_CHECK_ARG_NIL(L
, sett_name
, 2, API_TYPE_STRING
, NULL
);
99 pset
= setting_by_name(sett_name
);
105 return setting_value_name(pset
, FALSE
, buf
, sizeof(buf
));