mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r15947) -Codechange: replace uint32 client_ip with NetworkAddress client_address.
This commit is contained in:
parent
2fd9f0fffa
commit
c9ebf14ba5
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue