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 /* utility */
19 #include "log.h"
20
21 /* common */
22 #include "connection.h"
23
24 /* common/scriptcore */
25 #include "luascript.h"
26
27 /* server */
28 #include "auth.h"
29
30 /* server/scripting */
31 #include "script_fcdb.h"
32
33 #include "api_fcdb_auth.h"
34
35 /*****************************************************************************
36 Get the username.
37 *****************************************************************************/
api_auth_get_username(lua_State * L,Connection * pconn)38 const char *api_auth_get_username(lua_State *L, Connection *pconn)
39 {
40 LUASCRIPT_CHECK_STATE(L, NULL);
41 LUASCRIPT_CHECK_SELF(L, pconn, NULL);
42 fc_assert_ret_val(conn_is_valid(pconn), NULL);
43
44 return auth_get_username(pconn);
45 }
46
47 /*****************************************************************************
48 Get the ip address.
49 *****************************************************************************/
api_auth_get_ipaddr(lua_State * L,Connection * pconn)50 const char *api_auth_get_ipaddr(lua_State *L, Connection *pconn)
51 {
52 LUASCRIPT_CHECK_STATE(L, NULL);
53 LUASCRIPT_CHECK_SELF(L, pconn, NULL);
54 fc_assert_ret_val(conn_is_valid(pconn), NULL);
55
56 return auth_get_ipaddr(pconn);
57 }
58
59 /*****************************************************************************
60 Set the password.
61 *****************************************************************************/
api_auth_set_password(lua_State * L,Connection * pconn,const char * password)62 bool api_auth_set_password(lua_State *L, Connection *pconn,
63 const char *password)
64 {
65 LUASCRIPT_CHECK_STATE(L, NULL);
66 LUASCRIPT_CHECK_SELF(L, pconn, FALSE);
67 fc_assert_ret_val(conn_is_valid(pconn), FALSE);
68
69 return auth_set_password(pconn, password);
70 }
71
72 /*****************************************************************************
73 Get the password
74 *****************************************************************************/
api_auth_get_password(lua_State * L,Connection * pconn)75 const char *api_auth_get_password(lua_State *L, Connection *pconn)
76 {
77 LUASCRIPT_CHECK_STATE(L, NULL);
78 LUASCRIPT_CHECK_SELF(L, pconn, NULL);
79 fc_assert_ret_val(conn_is_valid(pconn), NULL);
80
81 return auth_get_password(pconn);
82 }
83