Commit Graph

1607 Commits

Author SHA1 Message Date
Rubidium a372c59483 Codechange: replace C-style (stredup) chat completion with std::string_view 2023-05-13 22:33:27 +02:00
Peter Nelson 941dbadf9e Codechange: Add and use GetScrolledItemFromWidget to get a list item.
This function returns an iterator, either to the selected item or the
container's end.

This makes handling the result more robust as indices are not used.
2023-05-12 21:45:32 +01:00
Rubidium 68ff3fd062 Change: include fmt.h C++ headers in stdafx.h
This to prevent compilation issues between runs with and without precompiled
headers. Also remove the headers from the rest of the code base as they are
not needed there anymore, although they do relatively little harm.
2023-05-08 16:49:23 +02:00
Peter Nelson d2034d9c38 Codechange: Scrollbar methods now accept size_t.
This clears up a lot of casts from size_t to int.
2023-05-07 20:25:44 +01:00
Rubidium 877349c13d Codechange: use std::string for text file name resolution 2023-05-05 08:54:29 +02:00
Peter Nelson 61407840c6 Codechange: Remove STR_BLACK_RAW_STRING. 2023-05-05 07:07:54 +01:00
Peter Nelson 0880616851 Codechange: Remove various STRING strings. 2023-05-05 07:07:54 +01:00
Rubidium 3901ef9760 Codechange: use std::string for the GRF filenames 2023-05-04 23:23:32 +02:00
Rubidium a312a6c1b2 Codechange: make md5sumToString std::string compatible 2023-05-04 23:23:32 +02:00
Tyler Trahan 6501f84b4a
Codechange: Move calendar date functions inside TimerGameCalendar (#10753) 2023-05-04 13:14:12 +00:00
Tyler Trahan ba3de0383a
Codechange: Pass more std::string to StringFilter::AddLine() (#10743) 2023-04-30 10:23:05 +02:00
Rubidium c829930440 Codechange: replace strnatcmp with C++ string capable version 2023-04-29 12:07:45 +02:00
Rubidium 4dd5f994be Codechange: replace strncasecmp with case ignoring variant of StrStarts/EndsWith 2023-04-29 10:25:25 +02:00
Patric Stout 36a0818bc5
Remove: buying/selling/owning company shares (#10709) 2023-04-29 10:16:49 +02:00
Rubidium b221fa3c5a Codechange: use fmt::format_to instead of seprintf to create the search URL 2023-04-28 19:53:03 +02:00
Rubidium 3105d0b09e Codechange: replace text-buf printf with fmt::format 2023-04-26 18:46:17 +02:00
Tyler Trahan 930f0a16d8 Codechange: Define Date/Year/Month/Day within TimerGameCalendar class 2023-04-26 07:14:03 -04:00
Rubidium f74e26ca7e Codechange: replace error/usererror printf variant with fmt variant and rename 2023-04-25 17:55:09 +02:00
Patric Stout 7aa2b9ab0a
Codechange: move all date-related variables inside the timer (#10706) 2023-04-24 15:56:01 +00:00
Charles Pigott b282664242 Codechange: Replace all usages of alloca/AllocaM with more modern/less discouraged alternatives 2023-04-15 16:57:00 +01:00
Patric Stout 3ebc7ad16e Codechange: migrate all game-time-related timers to the new framework 2023-04-15 13:58:55 +02:00
Patric Stout 1ba4dcc924 Codechange: migrate all Window-related timers to the new framework
This means we also say goodbye to GUITimers.
2023-04-15 13:58:55 +02:00
rubidium42 730687080a
Fix: Update some network documentation to match the new command system (#10657) 2023-04-15 09:10:09 +00:00
Peter Nelson e5af5907ec Change: Make all dropdown lists extend width if necessary.
This removes the auto_width parameter from ShowDropDown(At).
2023-04-13 20:57:47 +01:00
Peter Nelson 47e12a8790 Codechange: Check that CompanyMask fits into 16 bits during compilation. 2023-04-07 22:09:55 +01:00
Peter Nelson b6609d1833 Fix: Network server highlight invisible with RTL layout. 2023-03-07 22:05:22 +00:00
Zachary e17c82e32b Add: maximum number of companies allowed to the client list 2023-02-28 20:52:46 +01:00
dP c73b88ddca
Fix: Don't send unused tile field over the network (#10507) 2023-02-24 22:50:11 +01: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 0722bb3bf4
Change: try to detect the CA file/path for CURL (#10481)
The default is given compile-time, not run-time. So libcurl is
of no use to us.

Current list is kindly borrowed from
https://go.dev/src/crypto/x509/root_linux.go
2023-02-15 22:58:43 +01:00
Patric Stout ea90fa24f8
Codechange: move curl into a thread so simplify code (#10480)
With a thread, we can just run curl_easy_perform() and let CURL
and threads handle the blocking part.

With async solution there are too many things to keep track of,
and it makes "when to update the GUI" tricky. By using a thread
that all gets a lot simpler, as the game-thread and download-thread
run side-by-side.

This is similar to how the WinHttp backend already works.
2023-02-15 21:56:19 +01:00
frosch d7fcb420c4 Fix: compilation with libcurl from 2013. 2023-02-13 22:45:07 +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
Loïc Guilloux a2c8168924
Fix #10465: Delay closing of network join progress window (#10466) 2023-02-11 12:32:45 +01:00
Rubidium 4e65ec1dc4 Codechange: do not declare functions in blocks 2023-01-29 20:28:45 +01:00
rubidium42 6ba55e663e Codechange: do not hide variables with other variables 2023-01-29 07:21:34 +01:00
Rubidium ed7685910d Codechange: pass large objects by reference instead of value
Especially when they get passed on directly to the next function or via a
constructor into an instance variable
2023-01-28 13:43:21 +01:00
Rubidium 7e1d272397 Cleanup: remove unused static variables 2023-01-27 07:05:49 +01:00
Rubidium fe2bcd2a58 Codechange: migrate size related functions to Map structure 2023-01-21 17:11:40 +01:00
Rubidium 8f9a60893d Fix #10177: company list password padlock showed after switching to single player 2023-01-15 11:52:51 +01:00
Rubidium 6dfd2cad69 Fix: comparison result is always the same warnings 2023-01-15 00:24:20 +01:00
Rubidium 90f1768006 Codechange: add non-nullptr asserts in cases where it should never be nullptr
Though where similar calls are checked for nullptr as in those instances of
the use of that function it can actually return nullptr. In other words, write
down the assumption that the function never returns nullptr in an assert.
2023-01-14 21:15:23 +01:00
Rubidium bcfe0fb076 Codechange: introduce GetMainWindow() to properly account for nullptr checks
Some nullptr checks have been removed as they were not triggered with nullptr
with the null video driver and in dedicated server mode.
2023-01-14 21:15:23 +01:00
Patric Stout 1fb101eabb
Codechange: address CodeQL issue "Multiplication result converted to larger type" (#10306)
Most are very unlikely to ever be triggered in our codebase; two
stand out: linkgraph and money cheat. Those, potentially, could
wrap earlier than expected.
2023-01-02 20:30:02 +00:00
PeterN 131b7f5127
Fix: Vertically centre chat prompt. (#10250) 2022-12-17 12:22:02 +00:00
dP 5e14a20b3b
Feature: [GS] Scriptable league tables (#10001) 2022-11-26 18:03:03 +01:00
Peter Nelson ecb5393c55 Change: Standardize progress bar layout.
Progress bars are drawn differently depending on when it was added, with
different layouts and sizes.

This change adds a standard padding size to use, and makes all progress
bars visually similar, with scaled padding.
2022-11-12 18:28:39 +00:00
Peter Nelson 920e588334 Change: Use standard dimensions instead of custom widths. 2022-11-12 18:28:39 +00:00
Peter Nelson 890b2666d3 Change: Use scaled WidgetDimensions. 2022-11-12 18:28:39 +00:00
Peter Nelson b6ed595176 Codechange: Prefer suggested widget padding. 2022-11-12 18:28:39 +00:00
Peter Nelson dd9f6bc803 Change: Use RectPadding Horizontal()/Vertical() helpers. 2022-11-12 18:28:39 +00:00
Peter Nelson 04cbe57d2a Change: Use RectPadding for widget padding/uz_padding. 2022-11-12 18:28:39 +00:00
Peter Nelson 6f95e04005 Change: Use Rect helpers for widget drawing.
This replaces repetitive and sometimes unwieldy use of constants.
2022-11-12 18:28:39 +00:00
Rubidium d5aafaee15 Codechange: rename and move some strings to make them more consistent with the rest of the strings 2022-11-02 17:58:44 +01:00
Michael Lutz 35d9cea487
Fix: Too many braces make old gcc sad. (#10116) 2022-11-02 00:53:44 +01:00
frosch f4e2a462fe Cleanup: Remove unused flag sprites. 2022-10-16 14:56:52 +02:00
Peter Nelson dc1b84aa1e Cleanup: Text widgets are capable of drawing text without assistance.
Remove custom text drawing of some widgets in favour of standard text
widgets.
2022-10-16 14:24:51 +02:00
Peter Nelson 296af146fb Change: Default widget text colour to black.
TC_FROMSTRING really means blue, and we almost never actually use
blue text.
2022-10-16 14:24:51 +02:00
Peter Nelson fa5e2ca276 Cleanup: Tweak panel layout of Online Players window.
This ensures panel borders not hidden behind other widgets.
2022-09-20 07:51:25 +01:00
Peter Nelson 8e9ca5ebcb Fix: Online Players list mouse hover behaviour.
Hover highlight was visible even if the mouse pointer was in a different
window, and the window refreshed itself every frame if the mouse pointer
was not over its matrix widget.

Resolved by using OnMouseOver() instead of OnMouseLoop(), and only
redrawing if the hover position has changed.
2022-09-20 07:51:25 +01:00
dP 64453cb134
Fix: Incorrect player name in online players window (#10013) 2022-09-12 09:18:41 +01:00
Joel-Milligan 3937953f72
Fix #9363: Rebuild client list on reinit event (#9929) 2022-08-30 14:56:19 +02:00
Aaron Katzin 148695c571
Fix #9736: Duplicate multiplayer window opens upon canceling password entry (#9842) 2022-04-02 10:37:07 +02:00
Rubidium c73f578e8c Codechange: replace magic numbers and C-style arrays with C++-style array for share owners 2022-03-09 18:05:12 +01:00
Michael Lutz b11bd185e3 Fix #9756: Network command unpack proc was not generated in all cases.
The case where the callback proc takes all command results but not any of
the command parameters was not handled properly.
2021-12-20 23:32:23 +01:00
Michael Lutz e67124e174 Change: [Admin] Bump admin port protocol due to command changes.
docs/admin_network.md promised that information in an admin packet
is never removed. It does allow the possibility of using a new packet type
for changed data in combination with a bump of the admin port version.

As the recent command handling changes modified the contents of
ADMIN_PACKET_SERVER_CMD_LOGGING, do exactly that.
2021-12-20 19:30:27 +01:00
Michael Lutz afc3d71fd0 Codechange: Don't generate CommandPacket unpack functions for invalid cmd/callback combinations.
If the arguments of the callback proc don't match with the command parameters,
we can't do the proper command execution anyway. As such, don't even generate
an unpack function in the first place, saving a bit of unnecessary code bloat.

Validate on receive that the cmd/callback combination is supported, rejecting
clients that try to send invalid values.
2021-12-16 22:28:32 +01:00
Michael Lutz 3e85e833a7 Codechange: Add support for additional command result values. 2021-12-16 22:28:32 +01:00
Michael Lutz 8503854655 Codechange: Pass unpacked command arguments to command callbacks (except Script). 2021-12-16 22:28:32 +01:00
Michael Lutz d85348b1d1 Codechange: Template the command callback function type to allow unpacked arguments. 2021-12-16 22:28:32 +01:00
Michael Lutz 13528bfcd0 Codechange: Un-bitstuff all remaining commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 4f3ea3907e Codechange: Un-bitstuff commands taking a ClientID (i.e. CMD_CLIENT_ID). 2021-12-16 22:28:32 +01:00
Michael Lutz ccefa76a46 Codechange: Template DoCommandPInternal. 2021-12-16 22:28:32 +01:00
Michael Lutz 0f64ee5ce1 Codechange: Template DoCommandP to automagically reflect the parameters of the command proc.
When finished, this will allow each command handler to take individually
different parameters, obliviating the need for bit-packing.
2021-12-16 22:28:32 +01:00
Michael Lutz a05fd7aa50 Change: [Network] Transfer command data as serialized byte stream without fixed structure.
The data will be transmitted as the length followed by the serialized data. This allows the command
data to be different for every command type in the future.
2021-12-16 22:28:32 +01:00
Michael Lutz 123c7f99c3 Codechange: Move command callback declarations to the cmd header files. 2021-12-16 22:28:32 +01:00
Michael Lutz a38bbefe1b Codechange: Untangle command code, flags and error string for DoCommand*. 2021-12-16 22:28:32 +01:00
Michael Lutz 549caca39c Codechange: Move command arguments to the back of the networked command function calls. 2021-12-16 22:28:32 +01:00
Rubidium ad89601c49 Codechange: do not use all upper case enumerators in a scoped enum 2021-12-05 21:41:43 +01:00
Patric Stout ea4f6bb8b2
Fix #9730: [Network] connections can use an invalid socket due to a race condition
A race condition happens when an IPv6 connection takes more than
250ms to report an error, but does return before the IPv4 connection
is established.
In result, an invalid socket might be used for that connection.
2021-12-04 20:56:05 +01:00
Patric Stout 9c36c12c85
Codechange: ensure OnConnect() always gets called with a valid socket (#9729)
This should already be the case, but now assert()s will tell us
if this isn't.
2021-12-04 18:32:06 +01:00
Michael Lutz 8c558d74a5 Fix 55a11710: Curly braces need to be double-escaped for (std::)fmt. 2021-11-06 20:21:07 +01:00
dP 80e3397f85
Fix 3a1a915: Every 16th client never reconnects after server restart 2021-11-03 21:33:38 +01:00
glx22 1c0700e0c0 Fix #9624: compilation with RANDOM_DEBUG 2021-10-19 09:05:00 +01:00
Charles Pigott 3b7daca832
Change: Don't use 'server address' string in server list when displaying an invite code (#9615) 2021-10-17 18:14:25 +01:00
Patric Stout e4ad632989
Add: [Network] Keep the refresh button in lowered state while refreshing (#9600)
This gives user visual feedback that the refresh is still pending, and
prevents people from clicking again and again thinking nothing is
happening. This is especially true for connections that fall back to
TURN, as that takes a few seconds to kick in.

Additionally, prevent clicking on the button again while a refresh
is pending. This is only delaying a successful result.
2021-10-03 11:02:28 +02:00
dP 31cf9e888b
Add: [Network] external chat messages for remote admins (#9563) 2021-09-19 23:09:06 +02:00
Patric Stout d9f8ed7bdf
Add: [Network] On join, log the ClientID + IP + Name clearly (#9558)
Additionally, reword the disconnect to match connect / join messages.

Co-authored-by: Berbe <4251220+Berbe@users.noreply.github.com>
2021-09-19 21:52:46 +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
Patric Stout f656b0ae96
Fix: use-after-free after ClientNetworkCoordinatorSocketHandler::CloseAllConnections() (#9534)
The function clears all stun-handlers. This causes all of those
objects to be destroyed.
A handler can have a pending connecter, which was only killed in
case CloseConnection() was called. This is never the case when
the object is destroyed. In result, the connecter could finish
and cause a use-after-free by calling into the (now deleted)
handler.
2021-09-05 18:17:39 +02:00
Rubidium 92559e6f3a Fix #9388: thread unsafe use of NetworkAdminConsole/IConsolePrint 2021-09-01 22:40:44 +02:00
Patric Stout 63116bd59f
Fix a2051bad: SendCmdNames only sent one name per packet (#9528) 2021-08-31 21:40:38 +02:00
Patric Stout d8e870c50c
Fix: when DNS didn't resolve any IPs, the debug message was misleading (#9519) 2021-08-28 21:19:53 +02:00
Patric Stout dc5b7b996c
Fix: [Network] show query errors in the server listing instead of error popup (#9506)
When you are query several servers at once, it is rather unclear
for which server you got a popup. Instead, show any errors on the
server itself.

This is only true for the query-part. Joining a server still gives
an error popup to tell you about any issue.
2021-08-23 20:16:22 +02:00
Patric Stout e31b5d3870
Fix #9490: [Network] a full server couldn't be queried either (#9508)
You can now still query a full server, as long as the maximum
amount of allowed connections isn't reached. This means that as
long as there are not 255 clients connected to a server, you can
always connect to query.
2021-08-23 19:38:02 +02:00
Patric Stout b2f0491a90
Fix #9501: [Network] crash when more than one game-info query was pending (#9502) 2021-08-23 19:37:51 +02:00
Patric Stout 47ce306085
Fix c4b700f1: remove left-over debug statement (#9510) 2021-08-23 14:05:37 +02:00