35 #define GUEST_NAME "guest"
37 #define MIN_PASSWORD_LEN 6
38 #define MAX_AUTH_TRIES 3
39 #define MAX_WAIT_TIME 300
68 _(
"Warning: the guest name '%s' has been "
69 "taken, renaming to user '%s'."),
78 qInfo(
_(
"%s was rejected: Guests not allowed."), username);
95 qCritical(
"Error reading database; connection -> guest");
98 _(
"There was an error reading the user "
99 "database, logging in as guest connection '%s'."),
104 _(
"There was an error reading the user database "
105 "and guest logins are not allowed. Sorry"),
107 qInfo(
_(
"%s was rejected: Database error and guests not "
114 fc_snprintf(buffer,
sizeof(buffer),
_(
"Enter password for %s:"),
117 pconn->
server.auth_settime = time(
nullptr);
126 _(
"First time login. Set a new password and confirm it."));
128 pconn->
server.auth_settime = time(
nullptr);
134 qInfo(
_(
"%s was rejected: Only preregistered users allowed."),
156 qInfo(
_(
"%s was rejected: Too many wrong password "
157 "verifies for new user."),
169 _(
"Warning: There was an error in saving to the database. "
170 "Continuing, but your stats will not be saved."));
171 qCritical(
"Error writing to database for: %s", pconn->
username);
176 bool success =
false;
182 pconn->
server.auth_tries++;
183 pconn->
server.auth_settime =
187 qDebug(
"%s is sending unrequested auth packets", pconn->
username);
199 switch (pconn->
server.status) {
206 if (pconn->
server.auth_settime > 0
207 && time(
nullptr) >= pconn->
server.auth_settime) {
211 qInfo(
_(
"%s was rejected: Too many wrong password tries."),
215 struct packet_authentication_req request;
220 _(
"Your password is incorrect. Try again."));
221 send_packet_authentication_req(pconn, &request);
231 qInfo(
_(
"%s was rejected: Connection timeout waiting for "
296 _(
"Your password is too short, the minimum length is %d. "
304 _(
"Your password contains illegal characters. Try again."));
333 return pconn->
server.ipaddr;
static bool is_good_password(const char *password, char *msg)
Verifies that a password is valid.
const char * auth_get_username(struct connection *pconn)
Get username for connection.
bool auth_handle_reply(struct connection *pconn, char *password)
Receives a password from a client and verifies it.
static bool is_guest_name(const char *name)
See if the name qualifies as a guest login name.
static const int auth_fail_wait[]
void auth_process_status(struct connection *pconn)
Checks on where in the authentication process we are.
bool auth_user(struct connection *pconn, char *username)
Handle authentication of a user; called by handle_login_request() if authentication is enabled.
const char * auth_get_ipaddr(struct connection *pconn)
Get connection ip address.
static void get_unique_guest_name(char *name)
Return a unique guest name WARNING: do not pass pconn->username to this function: it won't return!
void reject_new_connection(const char *msg, struct connection *pconn)
send the rejection packet to the client.
void connection_close_server(struct connection *pconn, const QString &reason)
Close a connection.
void establish_new_connection(struct connection *pconn)
This is used when a new player joins a server, before the game has started.
struct connection * conn_by_user(const char *user_name)
Find connection by exact user name, from game.all_connections, case-insensitve.
bool conn_is_valid(const struct connection *pconn)
Returns TRUE if the connection is valid, i.e.
const struct ft_color ftc_warning
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
void notify_conn_early(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
bool script_fcdb_user_save(connection *pconn, const char *password)
Save a new user.
bool script_fcdb_user_exists(connection *pconn, bool &exists)
Check if the user exists.
bool script_fcdb_user_verify(connection *pconn, const char *username, bool &success)
Check the credentials of the user.
bool is_ascii_name(const char *name)
This is used in sundry places to make sure that names of cities, players etc.
struct server_arguments srvarg
struct connection::@55::@61 server
char username[MAX_LEN_NAME]
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
Compare strings like strncmp(), but ignoring case.
#define sz_strlcpy(dest, src)