Skip to content

Commit

Permalink
Remove conn_addr_public
Browse files Browse the repository at this point in the history
There is no point in sending "Xxx has connected from user-xxx-host" to
everyone. Just send "Xxx has connected"...
  • Loading branch information
lmoureaux committed Jul 15, 2022
1 parent 9f2d41d commit fccfbf9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
15 changes: 1 addition & 14 deletions common/networking/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,12 @@ static void free_socket_packet_buffer(struct socket_packet_buffer *buf)
const char *conn_description(const struct connection *pconn, bool is_private)
{
static char buffer[MAX_LEN_NAME * 2 + MAX_LEN_ADDR + 128];

const auto addr = is_private ? pconn->addr : conn_addr_public(pconn);

buffer[0] = '\0';

if (*pconn->username != '\0') {
if (is_private) {
fc_snprintf(buffer, sizeof(buffer), _("%s from %s"), pconn->username,
qUtf8Printable(addr));
qUtf8Printable(pconn->addr));
} else {
fc_snprintf(buffer, sizeof(buffer), "%s", pconn->username);
}
Expand Down Expand Up @@ -460,16 +457,6 @@ const char *conn_description(const struct connection *pconn, bool is_private)
return buffer;
}

/**
* Generate a fake hostname to tell publicly.
*/
const char *conn_addr_public(const struct connection *pconn)
{
static char buf[256];
snprintf(buf, 256, "user-%s-host", pconn->username);
return buf;
}

/**
Return TRUE iff the connection is currently allowed to edit.
*/
Expand Down
1 change: 0 additions & 1 deletion common/networking/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ void conn_list_compression_thaw(const struct conn_list *pconn_list);

const char *conn_description(const struct connection *pconn,
bool is_private = true);
const char *conn_addr_public(const struct connection *pconn);
bool conn_controls_player(const struct connection *pconn);
bool conn_is_global_observer(const struct connection *pconn);
enum cmdlevel conn_get_access(const struct connection *pconn);
Expand Down
12 changes: 5 additions & 7 deletions server/connecthand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,11 @@ void establish_new_connection(struct connection *pconn)
* connection_attach()), otherwise pconn will receive it too. */
if (conn_controls_player(pconn)) {
package_event(&connect_info, nullptr, E_CONNECTION, ftc_server,
_("%s has connected from %s (player %s)."),
pconn->username, conn_addr_public(pconn),
_("%s has connected (player %s)."), pconn->username,
player_name(conn_get_player(pconn)));
} else {
package_event(&connect_info, nullptr, E_CONNECTION, ftc_server,
_("%s has connected from %s."), pconn->username,
conn_addr_public(pconn));
_("%s has connected."), pconn->username);
}
conn_list_iterate(game.est_connections, aconn)
{
Expand Down Expand Up @@ -414,7 +412,7 @@ bool handle_login_request(struct connection *pconn,
fc_snprintf(msg, sizeof(msg), _("Invalid username '%s'"), req->username);
reject_new_connection(msg, pconn);
qInfo(_("%s was rejected: Invalid name [%s]."), req->username,
conn_addr_public(pconn));
qUtf8Printable(pconn->addr));
return false;
}

Expand All @@ -438,7 +436,7 @@ bool handle_login_request(struct connection *pconn,
req->username);
reject_new_connection(msg, pconn);
qInfo(_("%s was rejected: Duplicate login name [%s]."), req->username,
conn_addr_public(pconn));
qUtf8Printable(pconn->addr));
return false;
}
}
Expand Down Expand Up @@ -509,7 +507,7 @@ static void package_conn_info(struct connection *pconn,
packet->access_level = pconn->access_level;

sz_strlcpy(packet->username, pconn->username);
sz_strlcpy(packet->addr, conn_addr_public(pconn));
sz_strlcpy(packet->addr, "");
sz_strlcpy(packet->capability, pconn->capability);
}

Expand Down

0 comments on commit fccfbf9

Please sign in to comment.