Merge 1.9.0-beta2
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $Id: address.cpp 27092 2014-12-24 17:17:18Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: address.h 22695 2011-07-30 10:28:52Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: config.h 27729 2017-01-14 13:12:49Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -43,7 +43,7 @@ static const uint NETWORK_NAME_LENGTH = 80; ///< The maxim
|
||||
static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0'
|
||||
static const uint NETWORK_HOSTNAME_LENGTH = 80; ///< The maximum length of the host name, in bytes including '\0'
|
||||
static const uint NETWORK_SERVER_ID_LENGTH = 33; ///< The maximum length of the network id of the servers, in bytes including '\0'
|
||||
static const uint NETWORK_REVISION_LENGTH = 15; ///< The maximum length of the revision, in bytes including '\0'
|
||||
static const uint NETWORK_REVISION_LENGTH = 33; ///< The maximum length of the revision, in bytes including '\0'
|
||||
static const uint NETWORK_PASSWORD_LENGTH = 33; ///< The maximum length of the password, in bytes including '\0' (must be >= NETWORK_SERVER_ID_LENGTH)
|
||||
static const uint NETWORK_CLIENTS_LENGTH = 200; ///< The maximum length for the list of clients that controls a company, in bytes including '\0'
|
||||
static const uint NETWORK_CLIENT_NAME_LENGTH = 25; ///< The maximum length of a client's name, in bytes including '\0'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: core.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -64,7 +64,7 @@ bool NetworkCoreInitialize()
|
||||
#endif /* __MORPHOS__ / __AMIGA__ */
|
||||
|
||||
/* Let's load the network in windows */
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
{
|
||||
WSADATA wsa;
|
||||
DEBUG(net, 3, "[core] loading windows socket library");
|
||||
@@ -73,7 +73,7 @@ bool NetworkCoreInitialize()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ void NetworkCoreShutdown()
|
||||
if (SocketBase != NULL) CloseLibrary(SocketBase);
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: core.h 24900 2013-01-08 22:46:42Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: game.h 17699 2009-10-04 20:00:56Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -56,6 +56,8 @@ struct NetworkGameInfo : NetworkServerGameInfo {
|
||||
byte map_set; ///< Graphical set
|
||||
};
|
||||
|
||||
const char * GetNetworkRevisionString();
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
#endif /* NETWORK_CORE_GAME_H */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: host.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -24,12 +24,7 @@
|
||||
*/
|
||||
static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast);
|
||||
|
||||
#if defined(PSP)
|
||||
static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // PSP implementation
|
||||
{
|
||||
}
|
||||
|
||||
#elif defined(BEOS_NET_SERVER) || defined(__HAIKU__) /* doesn't have neither getifaddrs or net/if.h */
|
||||
#if defined(BEOS_NET_SERVER) || defined(__HAIKU__) /* doesn't have neither getifaddrs or net/if.h */
|
||||
/* Based on Andrew Bachmann's netstat+.c. Big thanks to him! */
|
||||
extern "C" int _netstat(int fd, char **output, int verbose);
|
||||
|
||||
@@ -112,7 +107,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE
|
||||
freeifaddrs(ifap);
|
||||
}
|
||||
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Win32 implementation
|
||||
{
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: host.h 18809 2010-01-15 16:41:15Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: os_abstraction.h 27092 2014-12-24 17:17:18Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -21,7 +21,7 @@
|
||||
#ifdef ENABLE_NETWORK
|
||||
|
||||
/* Windows stuff */
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#if defined(_WIN32)
|
||||
#include <errno.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
@@ -38,94 +38,8 @@ typedef unsigned long in_addr_t;
|
||||
typedef SSIZE_T ssize_t;
|
||||
typedef int socklen_t;
|
||||
# define IPPROTO_IPV6 41
|
||||
#else
|
||||
#include "../../os/windows/win32.h"
|
||||
#include "../../core/alloc_func.hpp"
|
||||
|
||||
#define AI_ADDRCONFIG 0x00000400 /* Resolution only if global address configured */
|
||||
#define IPV6_V6ONLY 27
|
||||
|
||||
static inline int OTTDgetnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, DWORD hostlen, char *serv, DWORD servlen, int flags)
|
||||
{
|
||||
static int (WINAPI *getnameinfo)(const struct sockaddr *, socklen_t, char *, DWORD, char *, DWORD, int) = NULL;
|
||||
static bool first_time = true;
|
||||
|
||||
if (first_time) {
|
||||
LoadLibraryList((Function*)&getnameinfo, "ws2_32.dll\0getnameinfo\0\0");
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
if (getnameinfo != NULL) return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
||||
|
||||
strncpy(host, inet_ntoa(((const struct sockaddr_in *)sa)->sin_addr), hostlen);
|
||||
return 0;
|
||||
}
|
||||
#define getnameinfo OTTDgetnameinfo
|
||||
|
||||
static inline int OTTDgetaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
static int (WINAPI *getaddrinfo)(const char *, const char *, const struct addrinfo *, struct addrinfo **) = NULL;
|
||||
static bool first_time = true;
|
||||
|
||||
if (first_time) {
|
||||
LoadLibraryList((Function*)&getaddrinfo, "ws2_32.dll\0getaddrinfo\0\0");
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
if (getaddrinfo != NULL) return getaddrinfo(nodename, servname, hints, res);
|
||||
|
||||
*res = NULL;
|
||||
|
||||
in_addr_t ip = inet_addr(nodename);
|
||||
if (ip == INADDR_NONE) {
|
||||
struct hostent *he = gethostbyname(nodename);
|
||||
if (he == NULL) return EAI_NONAME;
|
||||
ip = (*(struct in_addr *)he->h_addr).s_addr;
|
||||
}
|
||||
|
||||
struct sockaddr_in *sin = CallocT<struct sockaddr_in>(1);
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = htons(strtoul(servname, NULL, 10));
|
||||
sin->sin_addr.s_addr = ip;
|
||||
|
||||
struct addrinfo *ai = CallocT<struct addrinfo>(1);
|
||||
ai->ai_family = PF_INET;
|
||||
ai->ai_addr = (struct sockaddr*)sin;
|
||||
ai->ai_addrlen = sizeof(*sin);
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
|
||||
*res = ai;
|
||||
return 0;
|
||||
}
|
||||
#define getaddrinfo OTTDgetaddrinfo
|
||||
|
||||
static inline void OTTDfreeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
static int (WINAPI *freeaddrinfo)(struct addrinfo *) = NULL;
|
||||
static bool first_time = true;
|
||||
|
||||
if (ai == NULL) return;
|
||||
|
||||
if (first_time) {
|
||||
LoadLibraryList((Function*)&freeaddrinfo, "ws2_32.dll\0freeaddrinfo\0\0");
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
if (freeaddrinfo != NULL) {
|
||||
freeaddrinfo(ai);
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
struct addrinfo *next = ai->ai_next;
|
||||
free(ai->ai_addr);
|
||||
free(ai);
|
||||
ai = next;
|
||||
} while (ai != NULL);
|
||||
}
|
||||
#define freeaddrinfo OTTDfreeaddrinfo
|
||||
#endif /* __MINGW32__ && __CYGWIN__ */
|
||||
#endif /* WIN32 */
|
||||
#endif /* !(__MINGW32__ && __CYGWIN__) */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* UNIX stuff */
|
||||
#if defined(UNIX) && !defined(__OS2__)
|
||||
@@ -194,29 +108,6 @@ static inline void OTTDfreeaddrinfo(struct addrinfo *ai)
|
||||
#define IPV6_V6ONLY 27
|
||||
#endif
|
||||
|
||||
#if defined(PSP)
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <pspnet.h>
|
||||
# include <pspnet_inet.h>
|
||||
# include <pspnet_apctl.h>
|
||||
# include <pspnet_resolver.h>
|
||||
# include <errno.h>
|
||||
# include <unistd.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/fd_set.h>
|
||||
|
||||
# define TCP_NODELAY 1
|
||||
# define SO_NONBLOCK 0x1009
|
||||
# define SOCKET int
|
||||
# define INVALID_SOCKET -1
|
||||
# define INADDR_NONE 0xffffffff
|
||||
# define closesocket close
|
||||
# define GET_LAST_ERROR() sceNetInetGetErrno()
|
||||
#endif /* PSP */
|
||||
|
||||
/* OS/2 stuff */
|
||||
#if defined(__OS2__)
|
||||
# define SOCKET int
|
||||
@@ -313,12 +204,12 @@ typedef unsigned long in_addr_t;
|
||||
*/
|
||||
static inline bool SetNonBlocking(SOCKET d)
|
||||
{
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
u_long nonblocking = 1;
|
||||
#else
|
||||
int nonblocking = 1;
|
||||
#endif
|
||||
#if (defined(__BEOS__) && defined(BEOS_NET_SERVER)) || defined(PSP)
|
||||
#if (defined(__BEOS__) && defined(BEOS_NET_SERVER))
|
||||
return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0;
|
||||
#else
|
||||
return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: packet.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: packet.h 23590 2011-12-18 18:37:54Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp.h 24900 2013-01-08 22:46:42Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_admin.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_admin.h 25588 2013-07-11 20:31:39Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_connect.cpp 27670 2016-10-30 17:29:33Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_content.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_content.h 25597 2013-07-13 09:26:11Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_game.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -45,6 +45,8 @@ NetworkRecvStatus NetworkGameSocketHandler::CloseConnection(bool error)
|
||||
{
|
||||
/* Clients drop back to the main menu */
|
||||
if (!_network_server && _networking) {
|
||||
extern void ClientNetworkEmergencySave(); // from network_client.cpp
|
||||
ClientNetworkEmergencySave();
|
||||
_switch_mode = SM_MENU;
|
||||
_networking = false;
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_game.h 26056 2013-11-22 21:50:43Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_http.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -45,14 +45,14 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s,
|
||||
redirect_depth(depth),
|
||||
sock(s)
|
||||
{
|
||||
size_t bufferSize = strlen(url) + strlen(host) + strlen(_openttd_revision) + (data == NULL ? 0 : strlen(data)) + 128;
|
||||
size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == NULL ? 0 : strlen(data)) + 128;
|
||||
char *buffer = AllocaM(char, bufferSize);
|
||||
|
||||
DEBUG(net, 7, "[tcp/http] requesting %s%s", host, url);
|
||||
if (data != NULL) {
|
||||
seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, _openttd_revision, (int)strlen(data), data);
|
||||
seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, GetNetworkRevisionString(), (int)strlen(data), data);
|
||||
} else {
|
||||
seprintf(buffer, buffer + bufferSize - 1, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\n\r\n", url, host, _openttd_revision);
|
||||
seprintf(buffer, buffer + bufferSize - 1, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\n\r\n", url, host, GetNetworkRevisionString());
|
||||
}
|
||||
|
||||
ssize_t size = strlen(buffer);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_http.h 26509 2014-04-25 15:40:32Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: tcp_listen.h 26046 2013-11-22 21:41:19Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: udp.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -252,8 +252,8 @@ void NetworkUDPSocketHandler::ReceiveNetworkGameInfo(Packet *p, NetworkGameInfo
|
||||
*dst = c;
|
||||
dst = &c->next;
|
||||
}
|
||||
FALLTHROUGH;
|
||||
}
|
||||
FALLTHROUGH;
|
||||
|
||||
case 3:
|
||||
info->game_date = Clamp(p->Recv_uint32(), 0, MAX_DATE);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: udp.h 24900 2013-01-08 22:46:42Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
+57
-2
@@ -1,4 +1,4 @@
|
||||
/* $Id: network.cpp 27400 2015-09-19 16:49:46Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -1101,13 +1101,68 @@ void NetworkShutDown()
|
||||
NetworkCoreShutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* How many hex digits of the git hash to include in network revision string.
|
||||
* Determined as 10 hex digits + 2 characters for -g/-u/-m prefix.
|
||||
*/
|
||||
static const uint GITHASH_SUFFIX_LEN = 12;
|
||||
|
||||
/**
|
||||
* Get the network version string used by this build.
|
||||
* The returned string is guaranteed to be at most NETWORK_REVISON_LENGTH bytes.
|
||||
*/
|
||||
const char * GetNetworkRevisionString()
|
||||
{
|
||||
/* This will be allocated on heap and never free'd, but only once so not a "real" leak. */
|
||||
static char *network_revision = nullptr;
|
||||
|
||||
if (!network_revision) {
|
||||
/* Start by taking a chance on the full revision string. */
|
||||
network_revision = stredup(_openttd_revision);
|
||||
/* Ensure it's not longer than the packet buffer length. */
|
||||
if (strlen(network_revision) >= NETWORK_REVISION_LENGTH) network_revision[NETWORK_REVISION_LENGTH - 1] = '\0';
|
||||
|
||||
/* Release version names are not mangled further. */
|
||||
if (IsReleasedVersion()) return network_revision;
|
||||
|
||||
/* Prepare a prefix of the git hash.
|
||||
* Size is length + 1 for terminator, +2 for -g prefix. */
|
||||
assert(_openttd_revision_modified < 3);
|
||||
char githash_suffix[GITHASH_SUFFIX_LEN + 1] = "-";
|
||||
githash_suffix[1] = "gum"[_openttd_revision_modified];
|
||||
for (uint i = 2; i < GITHASH_SUFFIX_LEN; i++) {
|
||||
githash_suffix[i] = _openttd_revision_hash[i-2];
|
||||
}
|
||||
|
||||
/* Where did the hash start in the original string?
|
||||
* Overwrite from that position, unless that would go past end of packet buffer length. */
|
||||
ptrdiff_t hashofs = strrchr(_openttd_revision, '-') - _openttd_revision;
|
||||
if (hashofs + strlen(githash_suffix) + 1 > NETWORK_REVISION_LENGTH) hashofs = strlen(network_revision) - strlen(githash_suffix);
|
||||
/* Replace the git hash in revision string. */
|
||||
strecpy(network_revision + hashofs, githash_suffix, network_revision + NETWORK_REVISION_LENGTH);
|
||||
assert(strlen(network_revision) < NETWORK_REVISION_LENGTH); // strlen does not include terminator, constant does, hence strictly less than
|
||||
}
|
||||
|
||||
return network_revision;
|
||||
}
|
||||
|
||||
static const char *ExtractNetworkRevisionHash(const char *revstr)
|
||||
{
|
||||
return strrchr(revstr, '-');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given version string is compatible with our version.
|
||||
* First tries to match the full string, if that fails, attempts to compare just git hashes.
|
||||
* @param other the version string to compare to
|
||||
*/
|
||||
bool IsNetworkCompatibleVersion(const char *other)
|
||||
{
|
||||
return strncmp(_openttd_revision, other, NETWORK_REVISION_LENGTH - 1) == 0;
|
||||
if (strncmp(GetNetworkRevisionString(), other, NETWORK_REVISION_LENGTH - 1) == 0) return true;
|
||||
|
||||
const char *hash1 = ExtractNetworkRevisionHash(GetNetworkRevisionString());
|
||||
const char *hash2 = ExtractNetworkRevisionHash(other);
|
||||
return hash1 && hash2 && (strncmp(hash1, hash2, GITHASH_SUFFIX_LEN) == 0);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network.h 26449 2014-04-08 20:19:41Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_admin.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -172,7 +172,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_WELCOME);
|
||||
|
||||
p->Send_string(_settings_client.network.server_name);
|
||||
p->Send_string(_openttd_revision);
|
||||
p->Send_string(GetNetworkRevisionString());
|
||||
p->Send_bool (_network_dedicated);
|
||||
|
||||
p->Send_string(_network_game_info.map_name);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_admin.h 25588 2013-07-11 20:31:39Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_base.h 22423 2011-05-04 20:24:23Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_chat_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_client.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -126,6 +126,19 @@ struct PacketReader : LoadFilter {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an emergency savegame when the network connection is lost.
|
||||
*/
|
||||
void ClientNetworkEmergencySave()
|
||||
{
|
||||
if (!_settings_client.gui.autosave_on_network_disconnect) return;
|
||||
|
||||
const char *filename = "netsave.sav";
|
||||
DEBUG(net, 0, "Client: Performing emergency save (%s)", filename);
|
||||
SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new socket for the client side of the game connection.
|
||||
* @param s The socket to connect with.
|
||||
@@ -272,10 +285,6 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
|
||||
if (_network_first_time) {
|
||||
_network_first_time = false;
|
||||
SendAck();
|
||||
extern bool novahost();
|
||||
if(novahost()) {
|
||||
NetworkClientSendChatToServer("!check 1512"); //check version
|
||||
}
|
||||
}
|
||||
|
||||
_sync_frame = 0;
|
||||
@@ -364,7 +373,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendJoin()
|
||||
p->Send_uint32(_openttd_newgrf_version);
|
||||
}
|
||||
} else {
|
||||
p->Send_string(_openttd_revision);
|
||||
p->Send_string(GetNetworkRevisionString());
|
||||
p->Send_uint32(_openttd_newgrf_version);
|
||||
}
|
||||
p->Send_string(_settings_client.network.client_name); // Client name
|
||||
@@ -713,6 +722,9 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
|
||||
|
||||
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
|
||||
|
||||
/* Perform an emergency save if we had already entered the game */
|
||||
if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
|
||||
|
||||
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
|
||||
|
||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||
@@ -905,7 +917,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||
* the server will give us a client-id and let us in */
|
||||
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
|
||||
ShowJoinStatusWindow();
|
||||
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
|
||||
NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
|
||||
}
|
||||
} else {
|
||||
/* take control over an existing company */
|
||||
@@ -1097,6 +1109,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(Packet
|
||||
ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_SHUTDOWN, INVALID_STRING_ID, WL_CRITICAL);
|
||||
}
|
||||
|
||||
if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
|
||||
|
||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||
}
|
||||
|
||||
@@ -1112,6 +1126,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(Packet
|
||||
ShowErrorMessage(STR_NETWORK_MESSAGE_SERVER_REBOOT, INVALID_STRING_ID, WL_CRITICAL);
|
||||
}
|
||||
|
||||
if (this->status == STATUS_ACTIVE) ClientNetworkEmergencySave();
|
||||
|
||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||
}
|
||||
|
||||
@@ -1201,6 +1217,7 @@ void ClientNetworkGameSocketHandler::CheckConnection()
|
||||
if (lag > 20) {
|
||||
this->NetworkGameSocketHandler::CloseConnection();
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_LOSTCONNECTION, INVALID_STRING_ID, WL_CRITICAL);
|
||||
ClientNetworkEmergencySave();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_client.h 24900 2013-01-08 22:46:42Z planetmaker $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_command.cpp 27571 2016-05-22 10:07:48Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_content.cpp 27576 2016-05-22 10:45:46Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -404,10 +404,14 @@ static bool GunzipFile(const ContentInfo *ci)
|
||||
{
|
||||
#if defined(WITH_ZLIB)
|
||||
bool ret = true;
|
||||
|
||||
/* Need to open the file with fopen() to support non-ASCII on Windows. */
|
||||
FILE *ftmp = fopen(GetFullFilename(ci, true), "rb");
|
||||
if (ftmp == NULL) return false;
|
||||
/* Duplicate the handle, and close the FILE*, to avoid double-closing the handle later. */
|
||||
gzFile fin = gzdopen(dup(fileno(ftmp)), "rb");
|
||||
fclose(ftmp);
|
||||
|
||||
gzFile fin = gzdopen(fileno(ftmp), "rb");
|
||||
FILE *fout = fopen(GetFullFilename(ci, false), "wb");
|
||||
|
||||
if (fin == NULL || fout == NULL) {
|
||||
@@ -444,14 +448,7 @@ static bool GunzipFile(const ContentInfo *ci)
|
||||
}
|
||||
}
|
||||
|
||||
if (fin != NULL) {
|
||||
/* Closes ftmp too! */
|
||||
gzclose(fin);
|
||||
} else if (ftmp != NULL) {
|
||||
/* In case the gz stream was opened correctly this will
|
||||
* be closed by gzclose. */
|
||||
fclose(ftmp);
|
||||
}
|
||||
if (fin != NULL) gzclose(fin);
|
||||
if (fout != NULL) fclose(fout);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_content.h 27468 2015-12-10 18:28:01Z zuu $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_content_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -76,7 +76,7 @@ struct ContentTextfileWindow : public TextfileWindow {
|
||||
|
||||
void ShowContentTextfileWindow(TextfileType file_type, const ContentInfo *ci)
|
||||
{
|
||||
DeleteWindowByClass(WC_TEXTFILE);
|
||||
DeleteWindowById(WC_TEXTFILE, file_type);
|
||||
new ContentTextfileWindow(file_type, ci);
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ public:
|
||||
* Create the content list window.
|
||||
* @param desc the window description to pass to Window's constructor.
|
||||
* @param select_all Whether the select all button is allowed or not.
|
||||
* @param type the main type of content to display or #CONTENT_TYPE_END.
|
||||
* @param types the main type of content to display or #CONTENT_TYPE_END.
|
||||
* When a type other than #CONTENT_TYPE_END is given, dependencies of
|
||||
* other types are only shown when content that depend on them are
|
||||
* selected.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_content_gui.h 27288 2015-05-17 19:49:35Z michi_cc $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_func.h 27400 2015-09-19 16:49:46Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_gamelist.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_gamelist.h 17248 2009-08-21 20:21:05Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_gui.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "../strings_func.h"
|
||||
#include "../date_func.h"
|
||||
#include "../fios.h"
|
||||
#include "../error.h"
|
||||
#include "network_client.h"
|
||||
#include "network_gui.h"
|
||||
#include "network_gamelist.h"
|
||||
@@ -32,7 +31,7 @@
|
||||
#include "../core/geometry_func.hpp"
|
||||
#include "../genworld.h"
|
||||
#include "../map_type.h"
|
||||
#include "../zoom_func.h"
|
||||
#include "../guitimer_func.h"
|
||||
|
||||
#include "../widgets/network_widget.h"
|
||||
|
||||
@@ -40,6 +39,9 @@
|
||||
#include "../table/sprites.h"
|
||||
|
||||
#include "../stringfilter_type.h"
|
||||
|
||||
#include "../error.h"
|
||||
#include "../zoom_func.h"
|
||||
#include "../watch_gui.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
@@ -237,6 +239,7 @@ protected:
|
||||
Scrollbar *vscroll; ///< vertical scrollbar of the list of servers
|
||||
QueryString name_editbox; ///< Client name editbox.
|
||||
QueryString filter_editbox; ///< Editbox for filter on servers
|
||||
GUITimer requery_timer; ///< Timer for network requery
|
||||
bool UDP_CC_queried;
|
||||
|
||||
int lock_offset; ///< Left offset for lock icon.
|
||||
@@ -486,6 +489,8 @@ public:
|
||||
this->server = this->last_joined;
|
||||
if (this->last_joined != NULL) NetworkUDPQueryServer(this->last_joined->address);
|
||||
|
||||
this->requery_timer.SetInterval(MILLISECONDS_PER_TICK);
|
||||
|
||||
this->servers.SetListing(this->last_sorting);
|
||||
this->servers.SetSortFuncs(this->sorter_funcs);
|
||||
this->servers.SetFilterFuncs(this->filter_funcs);
|
||||
@@ -937,8 +942,11 @@ public:
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_NG_MATRIX);
|
||||
}
|
||||
|
||||
virtual void OnTick()
|
||||
virtual void OnRealtimeTick(uint delta_ms)
|
||||
{
|
||||
if (!this->requery_timer.Elapsed(delta_ms)) return;
|
||||
this->requery_timer.SetInterval(MILLISECONDS_PER_TICK);
|
||||
|
||||
NetworkGameListRequery();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_gui.h 18809 2010-01-15 16:41:15Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_internal.h 26488 2014-04-23 21:19:54Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_server.cpp 27893 2017-08-13 18:38:42Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -1115,7 +1115,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(Packet
|
||||
}
|
||||
|
||||
if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
|
||||
IConsolePrintF(CC_ERROR, "WARNING: spectator issuing command from client %d (IP: %s), kicking...", ci->client_id, this->GetClientIP());
|
||||
return this->SendError(NETWORK_ERROR_KICKED);
|
||||
}
|
||||
|
||||
@@ -1675,7 +1675,7 @@ static void NetworkAutoCleanCompanies()
|
||||
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
|
||||
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
|
||||
/* Shut the company down */
|
||||
DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
|
||||
DoCommandP(0, CCA_DELETE | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
|
||||
}
|
||||
/* Is the company empty for autoclean_protected-months, and there is a protection? */
|
||||
@@ -1689,7 +1689,7 @@ static void NetworkAutoCleanCompanies()
|
||||
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
|
||||
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
|
||||
/* Shut the company down */
|
||||
DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
|
||||
DoCommandP(0, CCA_DELETE | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
|
||||
}
|
||||
} else {
|
||||
@@ -2137,7 +2137,7 @@ bool NetworkCompanyHasClients(CompanyID company)
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the client, if the user did not send it yet, Client #<no> is used.
|
||||
* Get the name of the client, if the user did not send it yet, Client ID is used.
|
||||
* @param client_name The variable to write the name to.
|
||||
* @param last The pointer to the last element of the destination buffer
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_server.h 26576 2014-05-11 12:52:21Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_type.h 23780 2012-01-09 21:22:48Z truebrain $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_udp.cpp 27670 2016-10-30 17:29:33Z frosch $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -191,7 +191,7 @@ void ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *p, Networ
|
||||
|
||||
strecpy(ngi.map_name, _network_game_info.map_name, lastof(ngi.map_name));
|
||||
strecpy(ngi.server_name, _settings_client.network.server_name, lastof(ngi.server_name));
|
||||
strecpy(ngi.server_revision, _openttd_revision, lastof(ngi.server_revision));
|
||||
strecpy(ngi.server_revision, GetNetworkRevisionString(), lastof(ngi.server_revision));
|
||||
|
||||
Packet packet(PACKET_UDP_SERVER_RESPONSE);
|
||||
this->SendNetworkGameInfo(&packet, &ngi);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: network_udp.h 23751 2012-01-04 22:08:43Z rubidium $ */
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
|
||||
Reference in New Issue
Block a user