From 0c01de0929e2505173cadd7d87b5ba429dd4ec77 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 18 May 2010 21:49:59 +0000 Subject: [PATCH] (svn r19858) [1.0] -Backport from trunk: - Fix: Compilation for NetBSD [FS#3809, FS#3840] (r19853, r19781) - Fix: Drawing fallback sprites for unavailable NewGRF waypoints failed (r19852) - Fix: Ensure that both texts of the NewGRF gui download button fit (r19823) - Fix: Kicking clients by IP did not work [FS#3784] (r19818) - Fix: Compilation with MinGW GCC 4.5.0 and UNICODE (r19787) --- config.lib | 7 ++ src/console_cmds.cpp | 129 ++++++++++++------------------ src/network/core/os_abstraction.h | 2 +- src/network/network_func.h | 2 +- src/network/network_gui.cpp | 2 +- src/network/network_server.cpp | 15 ++-- src/newgrf_gui.cpp | 8 ++ src/os/unix/crashlog_unix.cpp | 4 + src/station_cmd.cpp | 4 +- src/stdafx.h | 1 + src/string_func.h | 9 ++- src/table/station_land.h | 10 +++ 12 files changed, 104 insertions(+), 89 deletions(-) diff --git a/config.lib b/config.lib index 54c88f4d55..e3fa8578cc 100644 --- a/config.lib +++ b/config.lib @@ -2304,6 +2304,13 @@ detect_library() { if [ -z "$res" ]; then log 2 " trying /usr/local/include/$4$5... no" fi + if [ -z "$res" ] && [ "$os" = "NETBSD" ]; then + eval "$2=`ls -1 /usr/pkg/include/$4*.h 2>/dev/null | egrep \"\/$5\$\"`" + eval "res=\$$2" + if [ -z "$res" ]; then + log 2 " trying /usr/pkg/include/$4$5... no" + fi + fi eval "res=\$$2" if [ -n "$res" ] && ( [ -n "$force_static" ] || ( [ "$enable_static" != "0" ] && [ "$os" != "OSX" ] ) ); then diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index d44fe028ae..833f57d227 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -391,12 +391,59 @@ DEF_CONSOLE_CMD(ConClearBuffer) **********************************/ #ifdef ENABLE_NETWORK +static bool ConKickOrBan(const char *argv, bool ban) +{ + const char *ip = argv; + + if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID + ClientID client_id = (ClientID)atoi(argv); + + if (client_id == CLIENT_ID_SERVER) { + IConsolePrintF(CC_ERROR, "ERROR: Silly boy, you can not %s yourself!", ban ? "ban" : "kick"); + return true; + } + + NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id); + if (ci == NULL) { + IConsoleError("Invalid client"); + return true; + } + + if (!ban) { + /* Kick only this client, not all clients with that IP */ + NetworkServerKickClient(client_id); + return true; + } + + /* When banning, kick+ban all clients with that IP */ + ip = GetClientIP(ci); + } + + uint n = NetworkServerKickOrBanIP(ip, ban); + if (n == 0) { + IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found"); + } else { + IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n); + } + + return true; +} + +DEF_CONSOLE_CMD(ConKick) +{ + if (argc == 0) { + IConsoleHelp("Kick a client from a network game. Usage: 'kick '"); + IConsoleHelp("For client-id's, see the command 'clients'"); + return true; + } + + if (argc != 2) return false; + + return ConKickOrBan(argv[1], false); +} + DEF_CONSOLE_CMD(ConBan) { - NetworkClientInfo *ci; - const char *banip = NULL; - ClientID client_id; - if (argc == 0) { IConsoleHelp("Ban a client from a network game. Usage: 'ban '"); IConsoleHelp("For client-id's, see the command 'clients'"); @@ -406,39 +453,7 @@ DEF_CONSOLE_CMD(ConBan) if (argc != 2) return false; - 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 - ci = NetworkFindClientInfoFromIP(argv[1]); - if (ci == NULL) { - banip = argv[1]; - client_id = (ClientID)-1; - } else { - client_id = ci->client_id; - } - } - - if (client_id == CLIENT_ID_SERVER) { - IConsoleError("Silly boy, you can not ban yourself!"); - return true; - } - - if (client_id == INVALID_CLIENT_ID || (ci == NULL && client_id != (ClientID)-1)) { - IConsoleError("Invalid client"); - return true; - } - - if (ci != NULL) { - IConsolePrint(CC_DEFAULT, "Client banned"); - banip = GetClientIP(ci); - } else { - IConsolePrint(CC_DEFAULT, "Client not online, banned IP"); - } - - NetworkServerBanIP(banip); - - return true; + return ConKickOrBan(argv[1], true); } DEF_CONSOLE_CMD(ConUnBan) @@ -595,46 +610,6 @@ DEF_CONSOLE_CMD(ConClientNickChange) return true; } -DEF_CONSOLE_CMD(ConKick) -{ - NetworkClientInfo *ci; - ClientID client_id; - - if (argc == 0) { - IConsoleHelp("Kick a client from a network game. Usage: 'kick '"); - IConsoleHelp("For client-id's, see the command 'clients'"); - return true; - } - - if (argc != 2) return false; - - if (strchr(argv[1], '.') == NULL) { - client_id = (ClientID)atoi(argv[1]); - ci = NetworkFindClientInfoFromClientID(client_id); - } else { - ci = NetworkFindClientInfoFromIP(argv[1]); - client_id = (ci == NULL) ? INVALID_CLIENT_ID : ci->client_id; - } - - if (client_id == CLIENT_ID_SERVER) { - IConsoleError("Silly boy, you can not kick yourself!"); - return true; - } - - if (client_id == INVALID_CLIENT_ID) { - IConsoleError("Invalid client"); - return true; - } - - if (ci != NULL) { - NetworkServerKickClient(client_id); - } else { - IConsoleError("Client not found"); - } - - return true; -} - DEF_CONSOLE_CMD(ConJoinCompany) { if (argc < 2) { diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 02f9aaca9a..5b789d5cc9 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -127,7 +127,7 @@ static inline void OTTDfreeaddrinfo(struct addrinfo *ai) /* UNIX stuff */ #if defined(UNIX) && !defined(__OS2__) -# if defined(OPENBSD) +# if defined(OPENBSD) || defined(__NetBSD__) # define AI_ADDRCONFIG 0 # endif # define SOCKET int diff --git a/src/network/network_func.h b/src/network/network_func.h index 72539e5011..70fe3afb70 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -79,7 +79,7 @@ void NetworkServerSendError(ClientID client_id, NetworkErrorCode error); void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0); void NetworkServerKickClient(ClientID client_id); -void NetworkServerBanIP(const char *banip); +uint NetworkServerKickOrBanIP(const char *ip, bool ban); void NetworkInitChatMessage(); void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...) WARN_FORMAT(3, 4); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 4ac4204445..04df337713 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1786,7 +1786,7 @@ static void ClientList_Ban(byte client_no) if (ci == NULL) return; - NetworkServerBanIP(GetClientIP(ci)); + NetworkServerKickOrBanIP(GetClientIP(ci), true); } static void ClientList_GiveMoney(byte client_no) diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c6c1a2de57..e7f3a64091 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1808,19 +1808,24 @@ void NetworkServerKickClient(ClientID client_id) NetworkServerSendError(client_id, NETWORK_ERROR_KICKED); } -void NetworkServerBanIP(const char *banip) +uint NetworkServerKickOrBanIP(const char *ip, bool ban) { - NetworkClientInfo *ci; + /* Add address to ban-list */ + if (ban) *_network_ban_list.Append() = strdup(ip); + + uint n = 0; /* There can be multiple clients with the same IP, kick them all */ + NetworkClientInfo *ci; FOR_ALL_CLIENT_INFOS(ci) { - if (ci->client_address.IsInNetmask(const_cast(banip))) { + if (ci->client_id == CLIENT_ID_SERVER) continue; + if (ci->client_address.IsInNetmask(const_cast(ip))) { NetworkServerKickClient(ci->client_id); + n++; } } - /* Add user to ban-list */ - *_network_ban_list.Append() = strdup(banip); + return n; } bool NetworkCompanyHasClients(CompanyID company) diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 96c3d7beac..0c94308121 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -613,6 +613,14 @@ struct NewGRFWindow : public Window { *size = maxdim(d, *size); break; } + + case SNGRFS_CONTENT_DOWNLOAD: { + Dimension d = GetStringBoundingBox(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON); + *size = maxdim(d, GetStringBoundingBox(STR_INTRO_ONLINE_CONTENT)); + size->width += padding.width; + size->height += padding.height; + break; + } } } diff --git a/src/os/unix/crashlog_unix.cpp b/src/os/unix/crashlog_unix.cpp index ee86cb5eeb..5f17fafdb9 100644 --- a/src/os/unix/crashlog_unix.cpp +++ b/src/os/unix/crashlog_unix.cpp @@ -27,6 +27,10 @@ # include #endif +#if defined(__NetBSD__) +#include +#endif + /** * Unix implementation for the crash logger. */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 8357f92181..1a37910ef5 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2379,7 +2379,7 @@ static void DrawTile_Station(TileInfo *ti) palette = PALETTE_TO_GREY; } - if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)]; + if (t == NULL || t->seq == NULL) t = GetStationTileLayout(GetStationType(ti->tile), GetStationGfx(ti->tile)); /* don't show foundation for docks */ if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) { @@ -2501,7 +2501,7 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro { int32 total_offset = 0; PaletteID pal = COMPANY_SPRITE_COLOUR(_local_company); - const DrawTileSprites *t = &_station_display_datas[st][image]; + const DrawTileSprites *t = GetStationTileLayout(st, image); const RailtypeInfo *rti = NULL; if (railtype != INVALID_RAILTYPE) { diff --git a/src/stdafx.h b/src/stdafx.h index b008d0e670..bbf4d34962 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -248,6 +248,7 @@ /* XXX - WinCE without MSVCRT doesn't support wfopen, so it seems */ #if !defined(WINCE) + namespace std { using ::_tfopen; } #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode)) #define unlink(file) _tunlink(OTTD2FS(file)) #endif /* WINCE */ diff --git a/src/string_func.h b/src/string_func.h index 2ff5f04399..942873593a 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -246,13 +246,18 @@ static inline bool IsWhitespace(WChar c) ; } -#ifndef _GNU_SOURCE +/* Needed for NetBSD version (so feature) testing */ +#ifdef __NetBSD__ +#include +#endif + +#if !defined(_GNU_SOURCE) && !(defined(__NetBSD_Version__) && 400000000 < __NetBSD_Version__ ) /* strndup is a GNU extension */ char *strndup(const char *s, size_t len); #endif /* !_GNU_SOURCE */ /* strcasestr is available for _GNU_SOURCE, BSD and some Apple */ -#if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) +#if defined(_GNU_SOURCE) || (defined(__BSD_VISIBLE) && __BSD_VISIBLE) || (defined(__APPLE__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))) || _NETBSD_SOURCE # undef DEFINE_STRCASESTR #else # define DEFINE_STRCASESTR diff --git a/src/table/station_land.h b/src/table/station_land.h index 3eac6b31eb..6668ce6b04 100644 --- a/src/table/station_land.h +++ b/src/table/station_land.h @@ -954,11 +954,21 @@ static const DrawTileSprites _station_display_datas_buoy[] = { static const DrawTileSprites _station_display_datas_waypoint[] = { TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_waypoint_X) TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_waypoint_Y) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_waypoint_X) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_waypoint_Y) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_waypoint_X) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_waypoint_Y) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_X, _station_display_datas_waypoint_X) + TILE_SPRITE_LINE(SPR_RAIL_TRACK_Y, _station_display_datas_waypoint_Y) }; #undef TILE_SPRITE_LINE #undef TILE_SPRITE_NULL +/* Default waypoint is also drawn as fallback for NewGRF waypoints. + * As these are drawn/build like stations, they may use the same number of layouts. */ +assert_compile(lengthof(_station_display_datas_rail) == lengthof(_station_display_datas_waypoint)); + static const DrawTileSprites * const _station_display_datas[] = { _station_display_datas_rail, _station_display_datas_airport,