1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-27 16:39:09 +00:00

(svn r15931) -Codechange: let the host and ban lists use of SmallVector.

This commit is contained in:
rubidium
2009-04-03 12:49:58 +00:00
parent d84fb358f5
commit 89d0eca6b7
8 changed files with 41 additions and 78 deletions

View File

@@ -55,8 +55,8 @@ ClientID _redirect_console_to_client;
bool _network_need_advertise;
uint32 _network_last_advertise_frame;
uint8 _network_reconnect;
char *_network_host_list[10];
char *_network_ban_list[25];
StringList _network_host_list;
StringList _network_ban_list;
uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
uint32 _frame_counter_max; // To where we may go with our clients
uint32 _frame_counter;
@@ -492,11 +492,9 @@ static void NetworkAcceptClients()
/* Check if the client is banned */
banned = false;
for (i = 0; i < lengthof(_network_ban_list); i++) {
if (_network_ban_list[i] == NULL) continue;
for (char **iter = _network_ban_list.Begin(); iter != _network_ban_list.End(); iter++) {
/* Check for CIDR separator */
char *chr_cidr = strchr(_network_ban_list[i], '/');
char *chr_cidr = strchr(*iter, '/');
if (chr_cidr != NULL) {
int cidr = atoi(chr_cidr + 1);
@@ -505,7 +503,7 @@ static void NetworkAcceptClients()
/* Remove and then replace the / so that inet_addr() works on the IP portion */
*chr_cidr = '\0';
uint32 ban_ip = inet_addr(_network_ban_list[i]);
uint32 ban_ip = inet_addr(*iter);
*chr_cidr = '/';
/* Convert CIDR to mask in network format */
@@ -513,14 +511,14 @@ static void NetworkAcceptClients()
if ((sin.sin_addr.s_addr & mask) == (ban_ip & mask)) banned = true;
} else {
/* No CIDR used, so just perform a simple IP test */
if (sin.sin_addr.s_addr == inet_addr(_network_ban_list[i])) banned = true;
if (sin.sin_addr.s_addr == inet_addr(*iter)) banned = true;
}
if (banned) {
Packet p(PACKET_SERVER_BANNED);
p.PrepareToSend();
DEBUG(net, 1, "Banned ip tried to join (%s), refused", _network_ban_list[i]);
DEBUG(net, 1, "Banned ip tried to join (%s), refused", *iter);
send(s, (const char*)p.buffer, p.size, 0);
closesocket(s);
@@ -690,19 +688,10 @@ void NetworkAddServer(const char *b)
* by the function that generates the config file. */
void NetworkRebuildHostList()
{
uint i = 0;
const NetworkGameList *item = _network_game_list;
while (item != NULL && i != lengthof(_network_host_list)) {
if (item->manually) {
free(_network_host_list[i]);
_network_host_list[i++] = str_fmt("%s:%i", item->info.hostname, item->address.GetPort());
}
item = item->next;
}
_network_host_list.Clear();
for (; i < lengthof(_network_host_list); i++) {
free(_network_host_list[i]);
_network_host_list[i] = NULL;
for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
if (item->manually) *_network_host_list.Append() = strdup(item->address.GetAddressAsString());
}
}

View File

@@ -11,6 +11,7 @@
#include "network_type.h"
#include "../console_type.h"
#include "../gfx_type.h"
#include "../core/smallvec_type.hpp"
extern NetworkServerGameInfo _network_game_info;
extern NetworkCompanyState *_network_company_states;
@@ -20,8 +21,8 @@ extern ClientID _redirect_console_to_client;
extern bool _network_need_advertise;
extern uint32 _network_last_advertise_frame;
extern uint8 _network_reconnect;
extern char *_network_host_list[10];
extern char *_network_ban_list[25];
extern StringList _network_host_list;
extern StringList _network_ban_list;
byte NetworkSpectatorCount();
void NetworkUpdateClientName();

View File

@@ -50,7 +50,7 @@ static void NetworkGameListHandleDelayedInsert()
strecpy(item->info.hostname, ins_item->info.hostname, lastof(item->info.hostname));
item->online = false;
}
item->manually = ins_item->manually;
item->manually |= ins_item->manually;
UpdateNetworkGameWindow(false);
}
free(ins_item);

View File

@@ -951,13 +951,11 @@ void ShowNetworkGameWindow()
/* Only show once */
if (first) {
char * const *srv;
first = false;
/* add all servers from the config file to our list */
for (srv = &_network_host_list[0]; srv != endof(_network_host_list) && *srv != NULL; srv++) {
NetworkAddServer(*srv);
}
for (char **iter = _network_host_list.Begin(); iter != _network_host_list.End(); iter++) {
NetworkAddServer(*iter);
}
}
new NetworkGameWindow(&_network_game_window_desc);

View File

@@ -1798,12 +1798,7 @@ void NetworkServerBanIP(const char *banip)
}
/* Add user to ban-list */
for (uint index = 0; index < lengthof(_network_ban_list); index++) {
if (_network_ban_list[index] == NULL) {
_network_ban_list[index] = strdup(banip);
break;
}
}
*_network_ban_list.Append() = strdup(banip);
}
bool NetworkCompanyHasClients(CompanyID company)