Merge branch 'master' into jgrpp
# Conflicts: # src/genworld_gui.cpp # src/group_gui.cpp # src/saveload/saveload.cpp # src/settings_gui.cpp # src/toolbar_gui.cpp # src/vehicle_gui.cpp # src/vehicle_gui_base.h # src/widgets/dropdown.cpp # src/widgets/dropdown_type.h
This commit is contained in:
@@ -156,7 +156,7 @@ bool NetworkAddress::IsFamily(int family)
|
||||
* @note netmask without /n assumes all bits need to match.
|
||||
* @return true if this IP is within the netmask.
|
||||
*/
|
||||
bool NetworkAddress::IsInNetmask(char *netmask)
|
||||
bool NetworkAddress::IsInNetmask(const char *netmask)
|
||||
{
|
||||
/* Resolve it if we didn't do it already */
|
||||
if (!this->IsResolved()) this->GetAddress();
|
||||
@@ -166,17 +166,16 @@ bool NetworkAddress::IsInNetmask(char *netmask)
|
||||
NetworkAddress mask_address;
|
||||
|
||||
/* Check for CIDR separator */
|
||||
char *chr_cidr = strchr(netmask, '/');
|
||||
const char *chr_cidr = strchr(netmask, '/');
|
||||
if (chr_cidr != NULL) {
|
||||
int tmp_cidr = atoi(chr_cidr + 1);
|
||||
|
||||
/* Invalid CIDR, treat as single host */
|
||||
if (tmp_cidr > 0 || tmp_cidr < cidr) cidr = tmp_cidr;
|
||||
|
||||
/* Remove and then replace the / so that NetworkAddress works on the IP portion */
|
||||
*chr_cidr = '\0';
|
||||
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
|
||||
*chr_cidr = '/';
|
||||
/* Remove the / so that NetworkAddress works on the IP portion */
|
||||
std::string ip_str(netmask, chr_cidr - netmask);
|
||||
mask_address = NetworkAddress(ip_str.c_str(), 0, this->address.ss_family);
|
||||
} else {
|
||||
mask_address = NetworkAddress(netmask, 0, this->address.ss_family);
|
||||
}
|
||||
|
@@ -129,7 +129,7 @@ public:
|
||||
}
|
||||
|
||||
bool IsFamily(int family);
|
||||
bool IsInNetmask(char *netmask);
|
||||
bool IsInNetmask(const char *netmask);
|
||||
|
||||
/**
|
||||
* Compare the address of this class with the address of another.
|
||||
|
@@ -54,13 +54,13 @@ public:
|
||||
|
||||
/* Check if the client is banned */
|
||||
bool banned = false;
|
||||
for (char *entry : _network_ban_list) {
|
||||
banned = address.IsInNetmask(entry);
|
||||
for (const auto &entry : _network_ban_list) {
|
||||
banned = address.IsInNetmask(entry.c_str());
|
||||
if (banned) {
|
||||
Packet p(Tban_packet);
|
||||
p.PrepareToSend();
|
||||
|
||||
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry);
|
||||
DEBUG(net, 1, "[%s] Banned ip tried to join (%s), refused", Tsocket::GetName(), entry.c_str());
|
||||
|
||||
if (send(s, (const char*)p.buffer, p.size, 0) < 0) {
|
||||
DEBUG(net, 0, "send failed with error %d", GET_LAST_ERROR());
|
||||
|
@@ -651,8 +651,8 @@ void NetworkAddServer(const char *b)
|
||||
*/
|
||||
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||
{
|
||||
for (char *iter : _network_bind_list) {
|
||||
addresses->emplace_back(iter, port);
|
||||
for (const auto &iter : _network_bind_list) {
|
||||
addresses->emplace_back(iter.c_str(), port);
|
||||
}
|
||||
|
||||
/* No address, so bind to everything. */
|
||||
@@ -666,10 +666,10 @@ void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
|
||||
* by the function that generates the config file. */
|
||||
void NetworkRebuildHostList()
|
||||
{
|
||||
_network_host_list.Clear();
|
||||
_network_host_list.clear();
|
||||
|
||||
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
|
||||
if (item->manually) _network_host_list.push_back(stredup(item->address.GetAddressAsString(false)));
|
||||
if (item->manually) _network_host_list.emplace_back(item->address.GetAddressAsString(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@
|
||||
struct PacketReader : LoadFilter {
|
||||
static const size_t CHUNK = 32 * 1024; ///< 32 KiB chunks of memory.
|
||||
|
||||
AutoFreeSmallVector<byte *> blocks; ///< Buffer with blocks of allocated memory.
|
||||
std::vector<byte *> blocks; ///< Buffer with blocks of allocated memory.
|
||||
byte *buf; ///< Buffer we're going to write to/read from.
|
||||
byte *bufe; ///< End of the buffer we write to/read from.
|
||||
byte **block; ///< The block we're reading from/writing to.
|
||||
@@ -55,6 +55,13 @@ struct PacketReader : LoadFilter {
|
||||
{
|
||||
}
|
||||
|
||||
~PacketReader() override
|
||||
{
|
||||
for (auto p : this->blocks) {
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a packet to this buffer.
|
||||
* @param p The packet to add.
|
||||
|
@@ -1047,8 +1047,8 @@ void ShowNetworkGameWindow()
|
||||
if (first) {
|
||||
first = false;
|
||||
/* Add all servers from the config file to our list. */
|
||||
for (char *iter : _network_host_list) {
|
||||
NetworkAddServer(iter);
|
||||
for (const auto &iter : _network_host_list) {
|
||||
NetworkAddServer(iter.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2094,13 +2094,13 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
|
||||
/* Add address to ban-list */
|
||||
if (ban) {
|
||||
bool contains = false;
|
||||
for (char *iter : _network_ban_list) {
|
||||
if (strcmp(iter, ip) == 0) {
|
||||
for (const auto &iter : _network_ban_list) {
|
||||
if (iter == ip) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) _network_ban_list.push_back(stredup(ip));
|
||||
if (!contains) _network_ban_list.emplace_back(ip);
|
||||
}
|
||||
|
||||
uint n = 0;
|
||||
@@ -2109,7 +2109,7 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban)
|
||||
NetworkClientSocket *cs;
|
||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||
if (cs->client_id == CLIENT_ID_SERVER) continue;
|
||||
if (cs->client_address.IsInNetmask(const_cast<char *>(ip))) {
|
||||
if (cs->client_address.IsInNetmask(ip)) {
|
||||
NetworkServerKickClient(cs->client_id);
|
||||
n++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user