Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the implementation of /kick #2065

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions server/stdinhand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@

#include "stdinhand.h"

#include <set>
#include <string>

#define OPTION_NAME_SPACE 25
#define REG_EXP "\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)"
static enum cmdlevel default_access_level = ALLOW_BASIC;
Expand Down Expand Up @@ -6334,35 +6337,27 @@ static bool kick_command(struct connection *caller, char *name, bool check)
}

if (nullptr != caller && ALLOW_ADMIN > conn_get_access(caller)) {
// Minimum number of unique addresses for /kick to make sense
const int MIN_UNIQUE_CONNS = 3;
const char *unique_ipaddr[MIN_UNIQUE_CONNS];
int i, num_unique_connections = 0;

if (pconn == caller) {
cmd_reply(CMD_KICK, caller, C_FAIL, _("You may not kick yourself."));
return false;
}

// Collect unique IP addresses
std::set<std::string> unique_ipaddr;
conn_list_iterate(game.est_connections, aconn)
{
for (i = 0; i < num_unique_connections; i++) {
if (0 == strcmp(unique_ipaddr[i], aconn->server.ipaddr)) {
// Already listed.
break;
}
}
if (i >= num_unique_connections) {
num_unique_connections++;
if (MIN_UNIQUE_CONNS <= num_unique_connections) {
// We have enought already.
break;
}
unique_ipaddr[num_unique_connections - 1] = aconn->server.ipaddr;
unique_ipaddr.insert(aconn->server.ipaddr);
if (unique_ipaddr.size() >= MIN_UNIQUE_CONNS) {
// We have enough already.
break;
}
}
conn_list_iterate_end;

if (MIN_UNIQUE_CONNS > num_unique_connections) {
if (unique_ipaddr.size() < MIN_UNIQUE_CONNS) {
cmd_reply(CMD_KICK, caller, C_FAIL,
_("There must be at least %d unique connections to the "
"server for this command to be valid."),
Expand Down
Loading