summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-03 12:49:58 +0000
committerrubidium <rubidium@openttd.org>2009-04-03 12:49:58 +0000
commit89d0eca6b74e3e2986425991674d3ffc67e9b974 (patch)
treea9a8b85ca45707ad3ca8b3d702645e0741aa5516 /src/network
parentd84fb358f5e8628bc9dc89edf9494248e6fe0a97 (diff)
downloadopenttd-89d0eca6b74e3e2986425991674d3ffc67e9b974.tar.xz
(svn r15931) -Codechange: let the host and ban lists use of SmallVector.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network.cpp31
-rw-r--r--src/network/network_func.h5
-rw-r--r--src/network/network_gamelist.cpp2
-rw-r--r--src/network/network_gui.cpp8
-rw-r--r--src/network/network_server.cpp7
5 files changed, 18 insertions, 35 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 3bbe7b898..06bd53ee9 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -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());
}
}
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 9fdcfa2d5..552abba74 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -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();
diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp
index 3f1db60b3..fc08437f8 100644
--- a/src/network/network_gamelist.cpp
+++ b/src/network/network_gamelist.cpp
@@ -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);
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 3b85b8a03..1f9c756eb 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -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);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 16695c46b..6bf95e2f9 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -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)