Commit Graph

126 Commits

Author SHA1 Message Date
Rubidium c6411168d8 Cleanup: missing spaces before continuation * in some comments 2023-11-01 22:56:11 +01:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
2023-07-19 19:30:14 +02:00
Rubidium 0ea3e338ab Codechange: replace buffer+strecpy with std::string 2023-06-29 17:32:27 +02:00
Rubidium d9a04ba446 Codechange: make the MD5 hash/digest/checksum variables a std::array 2023-05-19 11:24:44 +02:00
Patric Stout fdfcb09aa3 Fix #10131: actually cancel downloads when pressing cancel 2023-02-15 23:48:06 +01:00
Patric Stout dea2dea881 Fix: reset content download progress to zero if falling back to TCP
Otherwise this chain of events can happen:
- You already have a (partial) file downloaded
- You start the download, and HTTP fails
- This resets the download progress to the current size of the file
- The TCP download starts at a very large value (UINT32_MAX - filesize)

It now resets to 0% done when any negative value is being given.
As added bonus, we no longer have to query how much was already
downloaded.
2023-02-15 23:48:06 +01:00
Patric Stout 1c17556f96 Codechange: replace instance of char * with std::string 2023-02-15 23:48:06 +01:00
Patric Stout 64523709bf
Add: use https:// for content-service connections (#10448)
This requires the use of WinHTTP (for Windows) or libcurl (for all
others except Emscripten). Emscripten does not support http(s)
calls currently.

On Linux it requires ca-certificates to be installed, so the HTTPS
certificate can be validated. It is really likely this is installed
on any modern machine, as most connections these days are HTTPS.

(On MacOS and Windows the certificate store is filled by default)

Reminder: in case the http(s):// connection cannot be established,
OpenTTD falls back to a custom TCP-based connection to fetch the
content from the content-service. Emscripten will always do this.
2023-02-12 12:07:31 +01:00
rubidium42 6ba55e663e Codechange: do not hide variables with other variables 2023-01-29 07:21:34 +01:00
Patric Stout a8641ea44a
Add: support filtering content entries for patchpacks (#9541)
This changes nothing for us, but allows patchpacks to add the
right pieces of code to start filtering content entries on patchpack
only entries.
2021-09-11 15:34:46 +02:00
Jonathan G Rennison 6e3d023e69
Fix #9535: Maintain a reverse dependency map of network content (#9538)
Fixes performance issues with dependency lookup when retrieving
content list from the content server.
2021-09-09 18:06:00 +02:00
Rubidium e99134654b Feature: allow setting (game) coordinator and content server connection strings using environment variables
OTTD_COORDINATOR_CS for the game coordinator defaults to coordinator.openttd.org:3976
OTTD_CONTENT_SERVER_CS for the content server defaults to content.openttd.org:3978
OTTD_CONTENT_MIRROR_CS for the content mirror server defaults to binaries.openttd.org:80
2021-07-10 23:09:45 +02:00
rubidium42 e2417193c9 Cleanup: [ContentInfo] Remove some functions that are not needed anymore 2021-06-10 20:09:44 +02:00
rubidium42 e3717ae903 Codechange: [ContentInfo] Use std::string instead of string buffers 2021-06-10 20:09:44 +02:00
rubidium42 df181bb641 Codechange: [ContentInfo] Use a vector for dependencies instead of custom allocation 2021-06-10 20:09:44 +02:00
rubidium42 9c424ab741 Codechange: [ContentInfo] Use StringList for tags instead of custom allocations 2021-06-10 20:09:44 +02:00
glx22 5799402f7a Codechange: Rename window related DeleteXXX to match new behaviour 2021-05-29 21:08:25 +02:00
rubidium42 b791ffc6de Fix: do not hide parameter by local variable with the same name 2021-05-27 18:30:56 +02:00
Patric Stout a403653805
Codechange: [Network] split CloseSocket and CloseConnection more clearly (#9261)
* Codechange: [Network] split CloseSocket and CloseConnection more clearly

- CloseSocket now closes the actual OS socket.
- CloseConnection frees up the resources to just before CloseSocket.
- dtors call CloseSocket / CloseConnection where needed.
2021-05-13 11:46:51 +02:00
Rubidium 187a3f20bf Codechange: remove pointless close call due to resolving virtual functions statically in destructors
In the destructors of many of the network related classes Close() is called, just like the
top class in that hierarchy. However, due to virtual functions getting resolved statically
in the destructor it would always call the empty Close() of the top class.
Document the other cases where a virtual call is resolved statically.
2021-05-13 10:03:26 +02:00
Rubidium 495d73a67f Fix: leaking file descriptors 2021-05-10 16:03:31 +02:00
Patric Stout f94fb93779
Codechange: use connection_string in favour of NetworkAddress (#9197)
We now resolve the connection_string to a NetworkAddress in a much
later state. This means there are fewer places constructing a NetworkAddress.

The main benefit of this is in later PRs that introduce different types
of NetworkAddresses. Storing this in things like NetworkGameList is
rather complex, especially as NetworkAddress has to be mutable at all
times.

Additionally, the NetworkAddress is a complex object to store simple
information: how to connect to this server.
2021-05-05 23:21:14 +02:00
Rubidium a3c9eca722 Change: use 32 KiB packets to send requests to the content server 2021-04-25 21:27:54 +02:00
Rubidium d6000c2ec5 Codechange: differentiate between UDP, TCP and compatibility MTU values 2021-04-25 21:27:54 +02:00
Rubidium d4f027c03b Codechange: encapsulate writing data from Packets into sockets/files/buffers to prevent packet state modifications outside of the Packet 2021-04-24 20:42:01 +02:00
Patric Stout 53c28a8ec9 Codechange: [Network] replace _realtime_tick with std::chrono 2021-02-27 00:36:14 +01:00
frosch 31d1968004
Fix: Start the inactivity-timeout for the content server only after the connection has been established. (#8530)
When connecting took long due to the first N resolve-addresses timing out, OpenTTD would immediately close the connection, without sending anything.
2021-01-08 20:20:54 +01:00
Charles Pigott 9b800a96ed
Codechange: Remove min/max functions in favour of STL variants (#8502) 2021-01-08 11:16:18 +01:00
Charles Pigott e0161cf8da Fix b408fe7: Don't try to construct a std::string from nullptr 2020-12-27 18:30:53 +00:00
Michael Lutz 5cbb2da794 Codechange: Even more std::string usage in file IO. 2020-12-27 13:19:25 +01:00
Michael Lutz f3326d34e7 Codechange: Use std::string in FIO search path handling. 2020-12-27 13:19:25 +01:00
Byoungchan Lee 0471de2d92
Fix: Remove unnessary reference to suppress warning (#8337)
Apple Clang version 12 (bundled with Xcode 12) complaints about copying
small objects in range loop (-Wrange-loop-analysis introduced by -Wall).
This warning can be easily avoided by removing the reference from
the const pointer type.
2020-12-15 22:39:51 +01:00
Patric Stout d15dc9f40f Add: support for emscripten (play-OpenTTD-in-the-browser)
Emscripten compiles to WASM, which can be loaded via
HTML / JavaScript. This allows you to play OpenTTD inside a
browser.

Co-authored-by: milek7 <me@milek7.pl>
2020-12-15 15:46:39 +01:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
JMcKiern 04f659e768 Fix: Some typos found using codespell 2019-09-29 21:27:32 +01:00
glx 212140b88b Codechange: replace grow() usage in ClientNetworkContentSocketHandler::OnReceiveData() 2019-05-04 19:50:53 +01:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Jonathan G Rennison 01f957c51f Fix: Crash due to use of invalid iterator in ClientNetworkContentSocketHandler
In particular this crash can be observed when using the
bootstrap GUI to download the base graphics.

In ClientNetworkContentSocketHandler::OnReceiveContentInfo
ClientNetworkContentSocketHandler::callbacks is iterated, using an iterator
cb->OnReceiveContentInfo() is called (cb is of type BootstrapAskForDownloadWindow)
This calls new BootstrapContentDownloadStatusWindow()
This inherits from BaseNetworkContentDownloadStatusWindow
The constructor of which calls _network_content_client.AddCallback(this)
This reallocates the std::vector which is being iterated in ClientNetworkContentSocketHandler::OnReceiveContentInfo
This results in iter being invalid, and an assertion failure occurs shortly
afterwards due to its use in the next iteration of cb->OnReceiveContentInfo()

Adjust all locations where ClientNetworkContentSocketHandler::callbacks
is iterated to avoid problematic behaviour
2019-04-09 22:56:23 +02:00
glx22 66dd7c3879
Fix: MSVC warnings (#7423) 2019-03-28 00:09:33 +01:00
Henry Wilson ab711e6942 Codechange: Replaced SmallVector::[Begin|End]() with std alternatives 2019-03-26 20:15:57 +00:00
Henry Wilson 297fd3dda3 Codechange: Replaced SmallVector::Include() with include() 2019-03-26 20:15:57 +00:00
Henry Wilson a0f36a50e6 Codechange: Replaced SmallVector::Append() with std::vector::[push|emplace]_back() 2019-03-26 20:15:57 +00:00
Henry Wilson 5795f66d2e Codechange: Replaced SmallVector::Contains() with std::find() pattern 2019-03-26 20:15:57 +00:00
Henry Wilson f3938fdb83 Codechange: Replaced SmallVector::Reset() with std::vector::clear() + shrink_to_fit() 2019-03-26 20:15:57 +00:00
Henry Wilson a690936ed7 Codechange: Replace SmallVector::Length() with std::vector::size() 2019-03-26 20:15:57 +00:00
Henry Wilson bfd79e59dc Codechange: Replace SmallVector::Clear() with std::vector::clear() 2019-03-26 20:15:57 +00:00
peter1138 07de9d6c3f Codechange: Use override keyword in networking classes. 2019-03-24 17:38:42 +00:00
Patric Stout e3c639a09f Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 19:24:55 +01:00
Niels Martin Hansen db2c0ccae0
Fix fdc2e85: Double close of file handles
When unpacking downloaded content, the downloaded .gz file was being opened with `fopen`, the OS file handle given to zlib, and then afterwards zlib told to close the file.

But the `FILE *` object was never closed with `fclose`, meaning the stdio library would have a hanging file object, whose file handle was now invalid or referred to a different file. This caused asserts during shutdown with Microsoft's C library in debug mode.

Fix this by properly duplicating the OS handle and `fclose`ing the `FILE *` object, before giving the handle to zlib.
2019-02-06 21:09:02 +01:00