summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-04 00:48:48 +0000
committerrubidium <rubidium@openttd.org>2009-04-04 00:48:48 +0000
commitc9ebf14ba5a4461edd8790a96f13f0d1e87d60e1 (patch)
tree139eee3645f1e8b816308de3439f855da228f89b
parent2fd9f0fffa0d7e13d098f29fc04b8028adce8acf (diff)
downloadopenttd-c9ebf14ba5a4461edd8790a96f13f0d1e87d60e1.tar.xz
(svn r15947) -Codechange: replace uint32 client_ip with NetworkAddress client_address.
-rw-r--r--src/console_cmds.cpp2
-rw-r--r--src/network/network.cpp8
-rw-r--r--src/network/network_base.h2
-rw-r--r--src/network/network_client.cpp2
-rw-r--r--src/network/network_func.h2
-rw-r--r--src/network/network_gui.cpp6
-rw-r--r--src/network/network_server.cpp18
7 files changed, 19 insertions, 21 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 2c63e5fdc..11417cccd 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -385,7 +385,7 @@ DEF_CONSOLE_CMD(ConBan)
if (argc != 2) return false;
- if (strchr(argv[1], '.') == NULL) { // banning with ID
+ if (strchr(argv[1], '.') == NULL && strchr(argv[1], ':') == NULL) { // banning with ID
client_id = (ClientID)atoi(argv[1]);
ci = NetworkFindClientInfoFromClientID(client_id);
} else { // banning IP
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 9dee049f5..5cc15bf69 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -123,10 +123,12 @@ NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id)
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip)
{
NetworkClientInfo *ci;
- uint32 ip_number = inet_addr(ip);
+ NetworkAddress address(ip);
+
+ if (address.GetAddressLength() == 0) return NULL;
FOR_ALL_CLIENT_INFOS(ci) {
- if (ci->client_ip == ip_number) return ci;
+ if (ci->client_address == address) return ci;
}
return NULL;
@@ -526,7 +528,7 @@ static void NetworkAcceptClients()
* the client stays inactive */
cs->status = STATUS_INACTIVE;
- cs->GetInfo()->client_ip = ((sockaddr_in*)&sin)->sin_addr.s_addr; // Save the IP of the client
+ cs->GetInfo()->client_address = address; // Save the IP of the client
}
}
diff --git a/src/network/network_base.h b/src/network/network_base.h
index be3ada0c8..191b6be40 100644
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -17,7 +17,7 @@ struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkCli
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the client
byte client_lang; ///< The language of the client
CompanyID client_playas; ///< As which company is this client playing (CompanyID)
- uint32 client_ip; ///< IP-address of the client (so he can be banned)
+ NetworkAddress client_address; ///< IP-address of the client (so he can be banned)
Date join_date; ///< Gamedate the client has joined
char unique_id[NETWORK_UNIQUE_ID_LENGTH]; ///< Every play sends an unique id so we can indentify him
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 8b24b9849..e50543111 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -1038,7 +1038,7 @@ bool NetworkMaxSpectatorsReached()
*/
void NetworkPrintClients()
{
- const NetworkClientInfo *ci;
+ NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_id,
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 552abba74..faece9093 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -62,7 +62,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index);
NetworkClientInfo *NetworkFindClientInfoFromClientID(ClientID client_id);
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip);
-const char *GetClientIP(const NetworkClientInfo *ci);
+const char *GetClientIP(NetworkClientInfo *ci);
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
void NetworkServerSendRcon(ClientID client_id, ConsoleColour colour_code, const char *string);
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 1f9c756eb..50a902d59 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1554,9 +1554,9 @@ static const WindowDesc _client_list_desc(
);
/* Finds the Xth client-info that is active */
-static const NetworkClientInfo *NetworkFindClientInfo(byte client_no)
+static NetworkClientInfo *NetworkFindClientInfo(byte client_no)
{
- const NetworkClientInfo *ci;
+ NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
if (client_no == 0) return ci;
@@ -1578,7 +1578,7 @@ static void ClientList_Kick(byte client_no)
static void ClientList_Ban(byte client_no)
{
- const NetworkClientInfo *ci = NetworkFindClientInfo(client_no);
+ NetworkClientInfo *ci = NetworkFindClientInfo(client_no);
if (ci == NULL) return;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 6bf95e2f9..f4de01a5c 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -856,7 +856,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
if (cs->has_quit) return;
- const NetworkClientInfo *ci = cs->GetInfo();
+ NetworkClientInfo *ci = cs->GetInfo();
if (err != NULL) {
IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, GetClientIP(ci));
@@ -1143,7 +1143,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
int64 data = p->Recv_uint64();
- const NetworkClientInfo *ci = cs->GetInfo();
+ NetworkClientInfo *ci = cs->GetInfo();
switch (action) {
case NETWORK_ACTION_GIVE_MONEY:
if (!IsValidCompanyID(ci->client_playas)) break;
@@ -1678,12 +1678,9 @@ void NetworkServerChangeOwner(Owner current_owner, Owner new_owner)
}
}
-const char *GetClientIP(const NetworkClientInfo *ci)
+const char *GetClientIP(NetworkClientInfo *ci)
{
- struct in_addr addr;
-
- addr.s_addr = ci->client_ip;
- return inet_ntoa(addr);
+ return ci->client_address.GetHostname();
}
void NetworkServerShowStatusToConsole()
@@ -1702,7 +1699,7 @@ void NetworkServerShowStatusToConsole()
NetworkClientSocket *cs;
FOR_ALL_CLIENT_SOCKETS(cs) {
int lag = NetworkCalculateLag(cs);
- const NetworkClientInfo *ci = cs->GetInfo();
+ NetworkClientInfo *ci = cs->GetInfo();
const char *status;
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
@@ -1787,12 +1784,11 @@ void NetworkServerKickClient(ClientID client_id)
void NetworkServerBanIP(const char *banip)
{
- const NetworkClientInfo *ci;
- uint32 ip_number = inet_addr(banip);
+ NetworkClientInfo *ci;
/* There can be multiple clients with the same IP, kick them all */
FOR_ALL_CLIENT_INFOS(ci) {
- if (ci->client_ip == ip_number) {
+ if (ci->client_address.IsInNetmask((char*)banip)) {
NetworkServerKickClient(ci->client_id);
}
}