Mercurial > hg > openttd
changeset 11578:494219bd4418 draft
(svn r15947) -Codechange: replace uint32 client_ip with NetworkAddress client_address.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 04 Apr 2009 00:48:48 +0000 |
parents | 35fd3c2814d6 |
children | 06e36183a4f8 |
files | src/console_cmds.cpp src/network/network.cpp src/network/network_base.h src/network/network_client.cpp src/network/network_func.h src/network/network_gui.cpp src/network/network_server.cpp |
diffstat | 7 files changed, 19 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -385,7 +385,7 @@ 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
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -123,10 +123,12 @@ 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 @@ * 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 } }
--- a/src/network/network_base.h +++ b/src/network/network_base.h @@ -17,7 +17,7 @@ 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
--- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -1038,7 +1038,7 @@ */ 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,
--- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -62,7 +62,7 @@ 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);
--- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1554,9 +1554,9 @@ ); /* 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_Ban(byte client_no) { - const NetworkClientInfo *ci = NetworkFindClientInfo(client_no); + NetworkClientInfo *ci = NetworkFindClientInfo(client_no); if (ci == NULL) return;
--- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -856,7 +856,7 @@ 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 @@ 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 @@ } } -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 @@ 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 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); } }