Commit graph

5526 commits

Author SHA1 Message Date
heinrich5991 438e04f785 Complain on higher log level that 0.7 support was disabled
Not sure why it was on debug level before.
2024-08-15 14:47:40 +02:00
Robert Müller b4bd13c3aa
Merge pull request #8721 from Rei-Tw/improve-bans
Improve bans rcon command pagination
2024-08-14 17:29:31 +00:00
Rei-Tw 035b4a1447 Make bans command better
Update src/engine/shared/netban.cpp

Remove the word "currently" for the empty ban list message.

Co-authored-by: Dennis Felsing <dennis@felsing.org>

Update src/engine/shared/netban.cpp

Text format refactor, adding "currently"

Co-authored-by: Dennis Felsing <dennis@felsing.org>
2024-08-14 15:29:42 +02:00
Jupeyy e3622f3532
Fix debug hud units 2024-08-14 14:11:04 +02:00
ChillerDragon 7fa2306138 Hide address url for 0.6 ips (Closed #8712) 2024-08-14 18:25:10 +08:00
Dennis Felsing f14ae6bf13
Merge pull request #8725 from ChillerDragon/pr_fix_06_register
Fix 0.6 master server register (closed #8722)
2024-08-14 07:04:38 +00:00
ChillerDragon c16a38b4fa Fix 0.6 master server register (closed #8722) 2024-08-14 12:11:04 +08:00
heinrich5991 4f09d3f7d4
Merge pull request #8701 from Robyt3/Client-Spectate-ClientIds
Improve `cl_show_ids`: support spectator menu, optimize, refactor
2024-08-13 09:50:12 +00:00
Robert Müller 594968fe07 Improve cl_show_ids: support spectator menu, optimize, refactor
Also show client IDs in the spectator menu when `cl_show_ids` is enabled. Previously, this setting applied to scoreboard and chat, although the setting and config variable descriptions were only mentioning the scoreboard.

Extract client ID formatting in `CGameClient::FormatClientId` function to reduce duplicate code and ensure it is consistent.

Correctly indent client IDs also when largest client ID is 100 or larger. Fix scoreboard spectator client ID buffer not being large enough for IDs 100 and larger.

Make client ID formatting more efficient by avoiding `str_format` except for formatting the number itself and appending text directly to the text cursor when possible.
2024-08-12 22:59:32 +02:00
Dennis Felsing 043480b06e server: Handle dnsbl and other non-critical stuff only on new ticks
Less risk of causing microlags then, I think once per second is often enough since it has to iterate through all players
2024-08-12 18:49:17 +02:00
ChillerDragon 21507b51f1 Send the new is ddnet message in 0.7 connections
We already sent the legacy is ddnet message and so far the ddnet
protocol over 0.7 seems to work fine.

But for completeness and correctness it is now also sending the new
ddnet version net message.
2024-08-11 09:25:18 +08:00
ChillerDragon 53b01862d4 Remove netversion from demo editor init 2024-08-10 14:50:43 +02:00
ChillerDragon 8903f49716 Render skins in 0.7 demos 2024-08-10 14:50:43 +02:00
ChillerDragon bae37ab7df Add 0.7 client support
While keeping 0.6 fully working and untouched
This adds the option to connect via 0.7

0.7 servers are now mixed into the server browser list.
And users can also manually connect via 0.7
using a connection url like so:

    ./DDNet "connect tw-0.7+udp://127.0.0.1:8303"

This also adds a "Tee 0.7" section in the menu to pick a 0.7 skin.
The config variables are prefixed with player7_ like for example
player7_color_body
2024-08-10 14:50:42 +02:00
Robert Müller 2fa4c1f603 Remove clang-tidy static variable name exceptions
- Remove `readability-identifier-naming.StaticVariableIgnoredRegexp`.
- Mark `static` variables as `const` and use `UPPER_CASE` for names when possible.
- Use local variables instead of `static` variables when possible.
- Use member variables with correct name instead of `static` variables.
- Pass output buffer for `static` function `GetKeyBindModifiersName` by argument instead of returning pointer to `static` buffer.
2024-08-10 13:27:55 +02:00
Robert Müller 323ccf5a22 Show warning when connect address cannot be resolved
Show warning and disconnect instead of falling back to connecting to `localhost` when the connect address cannot be resolved.
2024-08-09 20:22:00 +02:00
heinrich5991 e97b8e1818
Merge pull request #8690 from def-/pr-dnsbl-info
More dnsbl printing
2024-08-06 16:53:17 +00:00
Dennis Felsing 922e32be0c More dnsbl printing 2024-08-06 17:21:24 +02:00
Dennis Felsing 082580f586 Don't show ban time for vpn bans 2024-08-05 20:27:16 +02:00
heinrich5991 75ec6ed304
Merge pull request #8652 from def-/pr-vpn-ban-1min
Only ban VPNs for a minute
2024-08-05 16:19:50 +00:00
Robert Müller b28bac89d4 Move CBinds::GetKeyId function to IInput::FindKeyByName 2024-08-04 22:05:34 +02:00
Robert Müller 924f8f582b Remove unused TEXLOAD_NOMIPMAPS and TEXLOAD_NO_COMPRESSION
The flag `TEXLOAD_NO_COMPRESSION` is entirely unused.

The flag `TEXLOAD_NOMIPMAPS` is unused and only the respective `CCommandBuffer::TEXFLAG_NOMIPMAPS` is used internally, so the former flag does not need to be exposed to users of `IGraphics`.
2024-08-02 18:16:26 +02:00
Robert Müller 273f3e5bfa Remove unused return value of IGraphics::UnloadTexture function 2024-08-02 18:16:15 +02:00
Robert Müller da8ec6bed9 Remove unused LoadTextureRawSub and CMD_TEXTURE_UPDATE
The `IGraphics::LoadTextureRawSub` function and the respective `CMD_TEXTURE_UPDATE` command are unused. Only text textures are updated after having been uploaded, but there is a separate `CMD_TEXT_TEXTURE_UPDATE` for that.
2024-08-02 18:15:55 +02:00
Robert Müller 9110d393dd Remove unused IGraphics::NullTexture function
It should not be necessary to access the null-texture directly. The `CTextureHandle::IsNullTexture` function can be used to check if a texture handle is the null-texture.
2024-08-02 18:15:34 +02:00
DynamoFox a013372be4 Fix game launch on Wayland-only systems with SDL2.30+ 2024-08-01 16:36:44 +02:00
Robert Müller 7f59a159e4 Refactor, rename IGraphics::IsImageFormatRGBA
Rename `IGraphics::IsImageFormatRGBA` function to `IsImageFormatRgba`.

Rename parameter `pFileName` to `pContextName`, as this name does not necessarily describe a file.

Remove unnecessary check for parameter `pFileName` (now `pContextName`) being unset, which is and should never be the case.

Rename parameter `Img` to `Image` for consistency.
2024-07-30 19:58:53 +02:00
Robert Müller 82bf71e780 Refactor IGraphics::CheckImageDivisibility
Put the context name in quotation marks in the warning message.

Rename parameter `pFileName` to `pContextName`, as this name does not necessarily describe a file.

Rename parameter `Img` to `Image` for consistency.
2024-07-30 19:58:53 +02:00
Robert Müller 92b0b90b29 Remove unused CClient::DirectInput function
The function is unused and because the message is not flushed it would also not have worked correctly. The `NETMSG_INPUT` message is already packed and flushed in the `CClient::SendInput` function.

Closes #8408.
2024-07-29 21:43:50 +02:00
Robert Müller 23fb01f9dd Smoother menu checker background scrolling on loading screens
Update global time also while rendering loading screens and shift the menu checker background based on the global time so it's smoother while loading.
2024-07-28 20:38:51 +02:00
Dennis Felsing 1d92b5acd6
Merge pull request #8658 from Robyt3/Client-Image-Non-Rgba-Leak
Fix memory leak of non-RGBA image data, clear all image info
2024-07-27 22:12:42 +00:00
Dennis Felsing 6911944c57
Merge pull request #8659 from Robyt3/Client-Dummy-Connecting-Improvement
Improve dummy connecting button and error handling
2024-07-27 22:11:47 +00:00
Robert Müller b61005d3e7 Improve dummy connecting button and error handling
Track whether the dummy is currently connecting separately so the dummy being disconnected due to errors can be detected. Show an error message as echo in the chat when the dummy could not be connected, e.g. when the server is full.

Use the global time for limiting the dummy connecting delay instead of using game ticks, so the delay also works correctly when having connection problems (i.e., when ticks do not advance). Handle the dummy connecting being delayed separately from the dummy currently connecting.

Add tooltips for the "Connect dummy"-button when it's disable due to dummy not being allow on the server or when connecting is delayed.

Add console error messages for `dummy_connect` command.
2024-07-27 22:44:15 +02:00
Robert Müller fb832b482c Fix memory leak of non-RGBA image data, clear all image info
The image data was not being freed when `IGraphics::LoadTextureRawMove` is used with images that are not in RGBA format as this falls back to using `IGraphics::LoadTextureRaw` which requires manually freeing the image data.

Also consistently clear all image info in `LoadTextureRawMove`. This makes it necessary to store the size of the preview image in the editor separately, as previously the width and height of the unloaded image info were being used to render the preview image.
2024-07-27 21:24:32 +02:00
Robert Müller 8a3929d48c Support IME composition strings of arbitrary length
Previously, IME composition strings were limited to at most 32 bytes, e.g. 10 Hiragana characters. Now, `SDL_TextEditingExtEvent` (`SDL_TEXTEDITING_EXT`) is supported, which uses heap-allocated composition strings of arbitrary length.

On the other hand, the buffer for input event text was larger than necessary, as SDL text events only contain at most 32 bytes (`SDL_TEXTINPUTEVENT_TEXT_SIZE` is not used directly to avoid the include). With the hint for extended IME handling enabled, long composition text will be sent as multiple text events (without breaking UTF-8).
2024-07-27 17:32:41 +02:00
Robert Müller f79ea492fa Minor refactoring of ResizeImage and related functions
Avoid duplicate code by using arrays and loops.

Move local variable declarations closer to their usages.

Use `mem_copy` instead of for-loops.
2024-07-26 21:10:05 +02:00
Robert Müller bfc4902910 Minor refactoring of DilateImage and related functions
Add constants for BPP and alpha threshold during Dilate, as dilating only works for RGBA images and we only use a fixed alpha threshold.

Move local variable declarations closer to their usages.

Use `mem_copy` instead of for-loop.

Use `nullptr` instead of `NULL`.
2024-07-26 21:10:05 +02:00
Dennis Felsing 36b8d81d1a Only ban VPNs for a minute 2024-07-26 17:23:04 +02:00
furo 8f96584f40 Remove servers_legacy support 2024-07-25 17:24:39 +02:00
Dennis Felsing a84a53c5fe
Merge pull request #8640 from Robyt3/Server-DNSBL-Ban-Only-New
Only apply DNSBL bans once when player joins
2024-07-24 11:08:40 +00:00
Robert Müller 7f2908d822 Only apply DNSBL bans once when player joins
Only ban DNSBL blacklisted players once when joining immediately after the DNSBL result is available, to prevent current players from having their runs ended when the `sv_dnsbl_ban` setting is enabled.

Note that enabling `sv_dnsbl` and `sv_dnsbl_ban` at the same time will still cause the players to be banned immediately. To prevent this, first enable `sv_dnsbl` for at least one tick, then enable `sv_dnsbl_ban`.

Closes #2640.
2024-07-24 12:50:06 +02:00
DynamoFox 9365e1453f Fix 'auto' GPU identification and display
* Refactors the previous code segment
* Fixes 'auto' GPU identification and display in DDNet Graphics tab of
  the settings. The 'auto' GPU is the best one encountered in the VK
  physical device enumeration array until we encounter one that is
  at least "integrated" when accessing them in increasing order
* Selects the first GPU that matches a name when using one by user
  specified name
2024-07-23 21:31:32 +02:00
Jupeyy e96275943b
Check API version before adding GPU to GPU list
Signed-off-by: Jupeyy <jupjopjap@gmail.com>
2024-07-21 13:29:49 +02:00
Robert Müller 36f19f491e Support touch input in engine, UI and console
Add support for touch input to the engine, UI and console. Ingame touch controls require more discussion and will be delivered separately based on this engine implementation.

Engine
------

The state of all currently pressed touch fingers is aggregated based on the SDL touch events and can be retrieved with the `IInput::TouchFingerStates` function. This design is less complex than an event-based system where the touch events are delivered to the individual client components, as each system would then have to keep track of the finger states individually. However, this means that only one component can handle touch fingers at any given time, which seems like a reasonable assumption for our use cases.

Obsolete code for relative mouse handling on Android is removed. Connecting a mouse to an Android device should now also work as expected, as more recent SDL/Android versions support relative mouse input natively.

User Interface
--------------

Support absolute mouse positioning and clicking in the user interfaces (menus, editor, demo player) with touch presses.

Support right clicking by pressing and holding one finger at roughly the same position for 0.5 seconds.

Support scrolling scroll regions up and down with a two finger swiping gesture. Fast scrolling via a two finger flinging gesture is not yet supported and would be a useful future extension.

The menus and demo player are fully usable with touch inputs. The editor is only fully usable with an external keyboard and/or mouse, as panning the map is not currently possible with only touch inputs, which is also left as a possible future extension.

Console
-------

The touch input logic for the user interface is reused for the console. Thereby, text selection in the console with touch input works, although the text can only be copied by pressing Ctrl+C with an external keyboard at the moment. In the future, we could add buttons to the console to activate the search and copy functionalities with touch inputs.

Support scrolling the console history up and down with a two finger swiping gesture.

The local/remote consoles can currently only be opened with an external keyboard. The ingame touch controls will also include buttons to open the consoles.
2024-07-19 13:36:04 +02:00
Robert Müller c30a35a493 Fix assertion when rendering demo with updated ffmpeg library
The `in_channel_count` and `out_channel_count` properties of the `SwrContext` were already deprecated and have been removed in the most recent ffmpeg library version, hence rendering demos was causing an assertion error when these properties were set.

For newer ffmpeg versions, we now set the channel layout with the `in_chlayout` and `out_chlayout` properties instead of setting the number of channels.
2024-07-18 17:23:16 +02:00
Robert Müller d4f47c2a55 Implement client restarting on Android
Restarting the client previously did not work, as the `shell_execute` function on Android uses `fork` which is not supported.

Now, the client is restarted by using an Android intent to restart the main activity. This is triggered by sending a user-defined message from the native code to the SDL main activity thread.
2024-07-16 12:52:19 +02:00
Robert Müller 37756aa389 Ensure that sv_max_clients can only be set when starting server
Changing the `sv_max_clients` config variable while the server is running does not change the maximum number of clients that can connect, as this is determined only once when the `CNetServer` is initialized. The reserved slot check and the calculation of the number of player slots for the `protocol7::CNetMsg_Sv_ServerSettings` message were using the `sv_max_clients` config variable directly, which was causing them to be out-of-sync with the real number of maximum clients.

Existing uses of the `sv_max_clients` config variable, except for the `CNetServer` initialization, are replaced with `MaxClients()`. The config variable `sv_max_clients` is now marked as read-only after reading the initial config and command line argument, so changing it via the remote console is not possible and shows an error message. The unnecessary conchain for `sv_max_clients` is removed.
2024-07-15 14:37:11 +02:00
Robert Müller 325e22d2de Fix crashes with dbg_dummies and sv_max_clients
Use the real number of maximum clients returned by the `MaxClients()` function instead of the `MAX_CLIENTS` constant to calculate the debug dummy client IDs to fix a crash when `sv_max_clients` is below `MAX_CLIENTS`.

Ensure the `dbg_dummies` value does not exceed the maximum number of clients.
2024-07-15 14:36:50 +02:00
Dennis Felsing b0f0292fc9
Merge pull request #8588 from Robyt3/Snapshot-Usage-Cleanup
Simplify usage of `IClient::SnapGetItem` function, remove unnecessary `IClient::SnapGetItem` function
2024-07-14 12:49:07 +00:00
Learath ebd266c419 Reset and regenerate m_aPeerAddrStr appropriately
Hopefully fixes #8587
2024-07-14 14:11:19 +02:00
Robert Müller 2f6c3abc90 Remove unnecessary IClient::SnapItemSize function
The item data size is already returned by the `IClient::SnapGetItem` function and getting only the size is not currently useful, so the additional `IClient::SnapItemSize` function is unnecessary.
2024-07-14 13:18:30 +02:00
Robert Müller e9646ba157 Simplify usage of IClient::SnapGetItem function
Let the `IClient::SnapGetItem` function return an `IClient::CSnapItem` directly instead of passing it as a pointer. Add the item data pointer as a member variable to `IClient::CSnapItem` instead of returning it separately. Therefore, the separate data pointer of the class `CSnapEntities` is also not necessary anymore.

Consistently mark the snapshot items and data as `const`. The C-style cast to `void *` in the `IClient::SnapGetItem` function was previously implicitly casting away the `const` of the snapshot pointers.
2024-07-14 13:15:44 +02:00
Dennis Felsing 108d0dc715 Make FillAntibot faster 2024-07-10 15:06:16 +02:00
Learath 7fa0ef56f3 Include port 2024-07-09 20:27:40 +02:00
Learath 3cb390c6e6 net_addr_str only once 2024-07-09 20:17:34 +02:00
Robert Müller 350a57df60 Fix multiple redirected clients not dropped in the same tick
Closes #8551.
2024-07-09 18:10:42 +02:00
ChillerDragon 7553ea6297 Improve clang variable naming checks
Introduces checks for more variable types.
And fixes false positives in newer clang versions.
2024-07-06 10:10:00 +08:00
Robert Müller b05ca91a15 Use SDL_OpenURL to open links and files on Android
Opening links and files with the `open_link` and `open_file` functions does not work on Android, as the `open_link` function uses `fork` which is not supported on Android. This also seems to cause a strange bug where client networking partially breaks. Currently, after trying to open any link, connecting to servers is not possible anymore but the server browser still works, with the connection getting stuck randomly in the connecting/loading state.

SDL implements URL opening, including of file URIs, with the `SDL_OpenURL` function for most systems including Android. However, using `SDL_OpenURL` for all systems has several downsides:

1. The `SDL_OpenURL` function is only available since SDL 2.0.14, in particular not for the Ubuntu 20 CI runner. Hence, we would either have to conditionally compile the link opening function to a null-implementation or fallback to using the existing `open_link` function.
2. We would be undoing some additional fixes in the `open_link` function for Windows, which are not included in the Windows implementation of `SDL_OpenURL`.
3. This would also replace the use of `open` on UNIX with `xdg-open`.
4. This would move the functionality to open links and files from the base to the engine client, so we could not have tools or the server potentially making use of this functionality in the future (e.g. open a folder for convenience).

Implementing link and file opening for Android ourselves is too much effort and potentially made even harder by SDL already managing all the unique JVM resources in the `SDLActivity`.

Therefore, the `SDL_OpenURL` function is only used for Android, which is always based on the latest SDL2 version. The original `open_link` functionality is kept for the other systems. For this purpose, the `IClient::ViewLink` and `ViewFile` functions are added to wrap `open_link` and `open_file` for the client and also reduce some duplicate code for error logging.

Unfortunately, testing also revealed that `SDL_OpenURL` does not currently support opening file URIs, at least not of files the internal storage location, which all the DDNet client's files would be located in. At least opening URLs works and neither breaks networking anymore.
2024-07-05 17:53:11 +02:00
Dennis Felsing 429777236b Fix integer overflow when computing tilemap size
Cherry-picked from d25869626a
2024-07-04 12:35:33 +02:00
heinrich5991 77054c1134 Use Client()->PlayerName() for copied server info
Fixes #8554.

Alternative to #8555.
2024-07-03 14:22:15 +02:00
Dennis Felsing a0da2d0978 Support new UPNP API
See c0a50ce33e
2024-07-02 00:32:46 +02:00
Robert Müller a17f7b5c2f Rewrite and fix line reader, read entire file into memory
Read the entire file into memory immediately when the line reader is initialized instead of using a fixed size buffer of size 32769, which leads to broken line reading for larger files (closes #8431).

Replace the `CLineReader::Init` function with the `CLineReader::OpenFile` function, which additionally checks whether the file contains any null bytes (indicates that the file is likely not a text file).

As the file will be read into memory entirely in the `OpenFile` function, is can also be closed immediately, since using the `io_read_all_str` function should ensure that nothing more can be read from the file. This also simplifies the usage of the `CLineReader` class, as manually closing the file is inconvenient and error-prone. In fact, the file handle for the `ddnet-serverlist-urls.cfg` file was previously not closed properly.

Benchmarking on Windows did not show any noticeable performance impact of this change both for smaller files (config and language files) and larger files (synthetic ~10 MiB files).

Let the `CLineReader::Get` function return `const char *` instead of `char *`, since users of this class should not modify the internal buffer. Also, since the entire file is read into memory now, the returned strings are now valid until the respective line reader object is destructed, instead of only until the `Get` function is called again. This simplifies the usage in some cases where all lines are handled, since additional temporary buffers are now unnecessary.

Remove the `IOFLAG_SKIP_BOM` flag from the `io_open` function, as this flag was only used together with the line reader. This was inconvenient to use, as any use of the `io_open` function specifically for line readers had to be used with `IOFLAG_SKIP_BOM`. Now, the line reader transparently skips the UTF-8 BOM internally. Skipping the UTF-8 BOM never worked with the `IStorage::ReadFileStr` function, because `io_length` is used in the `io_read_all` function, which rewinds the file position to before the UTF-8 BOM that was skipped by using `IOFLAG_SKIP_BOM`. In any case, as the `ReadFileStr` function is currently unused, this has/had no further effect. The respective test cases for `IOFLAG_SKIP_BOM` are removed.

Add more test cases for the `CLineReader` class. All test cases are checked both with and without the UTF-8 BOM. Additional tests with mixed new lines,  empty lines with different new lines, and internal null bytes are added.

Consistently use the construct `while(const char *pLine = LineReader.Get())` to iterate over all lines of a line reader. In this case, the assignment inside the `while`-loop seems acceptable over the alternatives, e.g. `while(true)` with `break` or adding a function `CLineReader::ForAll(std::function<const char *> Consumer)`.
2024-06-28 22:18:42 +02:00
Robert Müller 905047dd16 Add sv_dnsbl_ban_reason, increase maximum ban reason length
Add `sv_dnsbl_ban_reason` config variable with size 128 to specify the ban reason for `sv_dnsbl_ban`.

Increase the maximum size for ban reasons on the server from 64 to 128 to support this new config variable. Adjust buffer sizes for formatting ban messages accordingly.

Additionally, increase the size of the buffer for unpacking the connection closed message from 128 to 256. Due to this limitation, old clients will see truncated disconnect messages if the entire message is longer than 127, which can now happen with long ban reasons as the ban message additionally contains the duration (e.g. `You have been banned for 10 minutes (Reason)`).

Closes #8518.
2024-06-27 21:49:08 +02:00
Robert Müller 51b37aa240 Fix HTTP progress values being above 100 if total size is unknown
If the total download size is unknown (i.e. zero), return 0% instead of returning a very large value above 100%.
2024-06-23 16:08:54 +02:00
Robert Müller c4b9924b28 Use named enum EUpdaterState instead of int 2024-06-23 16:08:46 +02:00
Robert Müller 80ff5157d0
Merge pull request #8504 from MilkeeyCat/pr_ddnet_trim_strings_in_search_and_exclude_inputs
Trim Strings on Search/Exclude Filter & Add Tooltip
2024-06-23 13:13:31 +00:00
MilkeeyCat 31966d52a6 feat: trim strings in search & exclude inputs 2024-06-23 14:25:31 +03:00
Robert Müller efa069ef80 Ensure sample indices are initialized also with sound disabled
The assertion of #8262 can be reproduced when sound is disabled or failed to be initialized, as the sample indices where not being initialized properly in these cases. It is still necessary to initialized them so sounds can be loaded in the editor also when sound is disabled.

The potential thread-safety issues of the `CSound::AllocSample` function are not yet resolved so the issue remains open.
2024-06-21 17:38:16 +02:00
Robert Müller 4852dc435d Move double-click handling from engine input to UI
Instead of relying on SDL to determine when a click is a double-click, implement double-click handling specifically for the UI, as double-clicks are only supposed to be used there. This allows us to ensure that double-clicks only activate UI elements if both clicks were performed on the same UI element. Previously, only the position of the second click was considered, so UI element would incorrectly activate when double-clicking close to them as long as the second click starts and ends on them.

Implementing double-clicking handling separately is also necessary to support double-clicking in the UI with touch events, as SDL does not provide the double-click information for touch events.

The newly added `CUi::DoDoubleClickLogic` function should be called after a UI element has been clicked. It will return `true` if the current click should be interpreted as a double-click, i.e. if the same UI element was clicked, the click was within 0.5 seconds of the previous click (the default duration for SDL and Windows) and the distance from the previous click is within 32 screen pixels (the default distance for SDL).
2024-06-14 23:34:38 +02:00
Robert Müller fa58909dfe
Merge pull request #8459 from def-/pr-time-cp-diff
Add cl_showhud_time_cp_diff
2024-06-07 17:35:45 +00:00
Dennis Felsing 112e34fefe Add cl_showhud_time_cp_diff 2024-06-08 00:31:08 +08:00
Robert Müller f494826dcf
Merge pull request #8154 from ChillerDragon/pr_worst_style_offenders
Fix worst local variable style offenses
2024-06-06 20:18:19 +00:00
Learath e9d568db5b Fix console search highlighting. Close #8451 2024-06-05 18:01:42 +02:00
Robert Müller 0d9f673b03 Include types.h instead of system.h in input.h 2024-06-04 22:02:49 +02:00
Robert Müller 248225c7c4 Refactor client input event handling
Add `IInput::ConsumeEvents` function accepting a consumer `std::function` to replace the duplicate usage of the `IInput::NumEvents`, `IInput::GetEvent` and `IInput::IsEventValid` functions.

Use an `std::vector` to store the current input events to support any number of input events per client update instead of at most 32.

Use full `uint32_t` range for input counter instead of only using the range 0..0xFFFF. If the range is artificially reduced, then this can result in inputs being handled multiple times with high refresh rates, so the increased range should add future proofing for extremely fast devices.

Split `CInput::AddEvent` function into `CInput::AddKeyEvent` and `CInput::AddTextEvent` functions for readability and to make it easier to add additional input events (i.e. touch events).

Ensure double-click state is cleared at the end of each frame to prevent the double-click from being stored when no UI element consumes it.

Move member variables from `IInput` interface to `CInput` implementation.

Remove separate `CEditor::DispatchInputEvents` function.
2024-06-04 22:01:54 +02:00
Robert Müller bbf54ec625
Merge pull request #8318 from ChillerDragon/pr_clang_tidy_19
Add support for clang tidy 19
2024-06-02 08:52:47 +00:00
Robert Müller 24d12e4820 Consistently use str_copy instead of mem_copy for strings 2024-06-01 13:55:20 +02:00
ChillerDragon 64505273a9 Remove redundant casts 2024-05-26 19:31:54 +08:00
ChillerDragon 0a505c25d7 Don't return from void methods 2024-05-26 19:31:54 +08:00
ChillerDragon c4f68f50ea Remove unnecessary object creation in emplace_front
Fixes

```
/home/chiller/Desktop/git/ddnet/src/engine/client/updater.cpp:186:27: error: unnecessary temporary object created while calling emplace_front [modernize-use-emplace,-warnings-as-errors]
  186 |         m_FileJobs.emplace_front(std::make_pair(pFile, Job));
      |                                  ^~~~~~~~~~~~~~~          ~
```
2024-05-26 19:31:54 +08:00
Robert Müller 986508e091 Improve Android storage usage, faster launch, remove permissions
Split the user storage location and the data folder in the app specific external storage in the folders `data` and `user` instead of writing the user setting directly to the external storage.

Remove unnecessary storage permissions. The client only accesses files in its own external storage location, hence these permissions are not necessary for Android API 19 and higher, which is always given as we only target API 19 and higher.

Only unpack changed assets when their hash in the integrity index is different instead of unpacking all assets again, so the app starts faster after updates. Avoid unpacking the entire integrity index file unless it changed, by initially reading only the first hash directly from the asset, so the app starts faster when the data is up-to-date.

Add error handling for external storage not being accessible and other I/O errors during unpacking of assets.

Add `android_main.h` header to export the `InitAndroid` function and potentially other functions in the future. The `extern "C"` and `__attribute__((visibility("default")))` attributes seem to be unnecessary, as this function is only called directly from the native code like many other functions without these attributes.

Initialize the Android storage after the loggers, so the log message are printed properly.

Add documentation for the use of `std::exit` on Android, which is used to forcefully terminate the entire process, to ensure that static variables will be initialized correctly when the app is started again after quitting. Returning from the main function is not enough, as this only results in the native thread terminating, but the Java thread will continue. Java does not support unloading libraries once they have been loaded, so all static variables will not have their expected initial values anymore when the app is started again after quitting.

Use `fs_chdir` and `fs_makedir` instead of `chdir` and `mkdir`.
2024-05-25 21:09:42 +02:00
heinrich5991 848f4a846b
Merge pull request #8334 from Robyt3/Android-Building-Fix
Fix the Android build and improve the Android building `README.md`
2024-05-22 21:19:40 +00:00
Robert Müller 68d474c81f
Merge pull request #8363 from heinrich5991/pr_ddnet_str_from_int
Optimize `str_format(…, …, "%d", …)` using templates
2024-05-22 21:01:17 +00:00
heinrich5991 612a71f874
Merge pull request #8351 from ChillerDragon/pr_rcon_percentage
Show percentage of loaded rcon commands (closed #7769)
2024-05-22 08:39:40 +00:00
Robert Müller dfae99da76 Fix unused variable Silent in client.cpp on Android 2024-05-21 17:36:46 +02:00
Robert Müller 7da8308c3f Remove cl_ddrace_scoreboard and cl_demo_assume_race settings
Time score will now always be used for any game with the flag `GAMEINFOFLAG_TIMESCORE` set in the `CNetObj_GameInfoEx` object. If the flag is not set, points score is used instead.

Backwards compatibility for old demos, that were recorded without this net object and flag, is removed. For old demos, points score is always assumed now.

Closes #6700.
2024-05-20 11:07:01 +02:00
Robert Müller c0a6f5a927 Revert "Always clear window with black color instead of background color"
This reverts commit caa062c88c.

As this decreased FPS and caused the background quad to be rendered twice when using a map background in entities mode.
2024-05-19 20:01:56 +02:00
Robert Müller 05c825947a Force landscape orientation and hide title bar on Android
Always force landscape orientation to be used for the game on Android.

Hide the title bar so it is not shown when starting the game. There is also a bug with SDL currently that leads to the title bar and status bar being shown permanently after minimizing and reopening the app, which is alleviated by hiding the title bar.
2024-05-19 12:58:33 +02:00
Robert Müller caa062c88c Always clear window with black color instead of background color
Always use black color to clear the window with all graphics backends, instead of using `cl_background_color` or `cl_background_entities_color`, respectively, as the clear color. The respective map background color is rendered using a quad in `CMapLayers` instead, so this should not affect appearance of maps. This does not have any noticeable effect on FPS. Previously, the unused part of the window (when it is resized smaller than 5:4 aspect ratio), was colored using the map background color, whereas now it will be cleared black consistently.

The color parameters of the `IGraphics::Clear` function and of the `SCommand_Clear` command are removed, as we always expect the screen to be cleared black now.

The parameter `ForceClearNow` of the `IGraphics::Clear` function was already unused previously and is also removed.
2024-05-18 15:20:17 +02:00
Dennis Felsing fcacef5fbb
Merge pull request #8362 from Robyt3/Android-Backbutton-Handling
Translate back-button to escape-key on Android, quit if Android back-button is pressed 3 times within 1 second
2024-05-18 01:10:32 +00:00
Robert Müller 91848f0be6 Quit if Android back-button is pressed 3 times within 1 second
Interpret fast repeated presses of the back-button (3 times within 1 second) as a quit-event, so the app can be quit cleanly and quickly without using the UI. The client settings are otherwise not saved if the app is closed by minimizing it using the home button and waiting for the OS to kill it or by discarding it in the recent apps view.
2024-05-17 19:37:44 +02:00
Robert Müller bba606feae Translate back-button to escape-key on Android
Translate the Android back-button to the escape-key, so it can be used to navigate back in menus, open/close the ingame menu, close the editor etc.

Trap the Android back button by setting the `SDL_ANDROID_TRAP_BACK_BUTTON` hint, so it can be handled in our code reliably instead of letting the system handle it.
2024-05-17 19:36:35 +02:00
Robert Müller 554f244ef2 Remove redundant graphics backend functions returning RGBA format
The graphics backends only support the RGBA format with the `SCommand_Texture_Create` and `SCommand_Texture_Update` commands, so the `TexFormatToOpenGLFormat`, `TextureFormatToVulkanFormat` and `TexFormatToNewOpenGLFormat` functions and the command member variables for the format are unnecessary. The `TexFormatToNewOpenGLFormat` function was unused.
2024-05-17 19:36:11 +02:00
heinrich5991 392fc0ba9a str_from_intstr_format 2024-05-14 21:37:02 +02:00
ChillerDragon f3a686bc62 Show percentage of loaded rcon commands
closed #7769
2024-05-14 08:46:17 +08:00
yrrrmmbl a93ad48dce add cl_show_chat_team to only show team members' messages 2024-05-13 19:18:41 +02:00
Robert Müller f3bb5feffc
Merge pull request #8347 from Jupeyy/pr_vk_minirefactor
Fix segfault when swapchain images change (e.g. toggling Vsync)
2024-05-12 20:16:30 +00:00
Robert Müller 74e2e04b7d Remove unused CImageInfo::ImageFormatFromInt
Since the image format is not parsed from maps anymore, this function is unnecessary.
2024-05-10 21:44:49 +02:00
Jupeyy 15afc50865 Don't recreate DescriptorSetLayouts if swapchain image count changes 2024-05-10 18:48:09 +02:00
Jupeyy 128302d726 Cleanup Vulkan now takes SwapchainCount as explicit parameter.
This fixes a crash if the swapchain count changed.
fixes #8328
2024-05-10 18:48:09 +02:00
Jupeyy 2655627a4b Rename m_CurFrames to make clear it's about the sync objects.
Use one more sync object than there are inflight frames.
Remove unused memory sync objects.
2024-05-10 18:48:05 +02:00
heinrich5991 60dbd73ee3
Merge pull request #8333 from BlaiZephyr/change-time-timestamp-type
Change type from int to int64_t
2024-05-09 08:01:17 +00:00
meloƞ aec0dc9e0e Change type from int to int64_t 2024-05-09 08:42:19 +02:00
heinrich5991 c211e874aa Fix 0.7 tokens after #8322
They're also read as big-endian integers now.

Thanks to @ChillerDragon for noticing.

Fixes #8330.
2024-05-08 14:17:02 +02:00
heinrich5991 36712db0f1 Use network tokens in big-endian byte order consistently
Previously, it was handled inconsistently on big-endian machines and
caused connection failures.
2024-05-06 20:33:17 +02:00
ChillerDragon 3c606dd1e4 Don't access static ConCommandStatus with a member
Fixes this clang-tidy 19 warning

```
/home/chiller/Desktop/git/ddnet/src/engine/shared/console.cpp:739:2: error: static member accessed through instance [readability-static-accessed-through-instance,-warnings-as-errors]
  739 |         pConsole->ConCommandStatus(&Result, pConsole);
      |         ^~~~~~~~~~
      |         CConsole::
```
2024-05-06 11:48:47 +08:00
Robert Müller bf2343d60b
Merge pull request #8312 from ChillerDragon/pr_fix_misleading_demo_snap_var_names
Make demo snap variable names more obvious
2024-05-05 09:18:38 +00:00
ChillerDragon 1a3bb727c5 Make demo snap variable names more obvious
Closed #8245
2024-05-05 16:01:55 +08:00
Zwelf af4da41c4c Record Player and Team finishes in Teehistorian 2024-05-04 21:40:06 +02:00
Zwelf fcd8aae388 Record player name in Teehistorian files 2024-05-04 20:44:20 +02:00
Robert Müller e5927d9024 Fix crashes when video recording is not started successfully
Add additional checks to ensure that the `CVideo::Stop` function and the functions called by it will correctly stop the current video also if the video was not started successfully, i.e. if `CVideo::Start` returned `false` from any of the error branches.

In the `CVideo::Stop` function, iterate over the vectors of video and audio threads directly instead of using `m_VideoThreads` and `m_AudioThreads`, which do not reflect the actual count if the initialization failed before the threads were created.

In the `CVideo::Stop` function, only call `av_write_trailer` if the video recording was stated successfully, i.e. only if `avformat_write_header` was called successfully, as this will otherwise cause the client to crash. Closes #6375.

In the `CVideo::Stop` function, only call `avio_closep` if the format context was allocated.

In the `CVideo::FinishFrames` function, ensure that the codec has been allocated and opened, otherwise using it is not allowed.

Add assertions to the `CVideo::Start` and `Stop` functions to ensure that the same video is not started/stopped multiple times.
2024-05-04 13:55:35 +02:00
Robert Müller 3a0e2429d1 Assert that size of image data matches size of video
Crash with assertion when the size of the graphics is different from the video currently being rendered, instead of causing weirder bugs and a corrupted video file.
2024-05-04 13:55:35 +02:00
Robert Müller a0465b67dd Improve various variable and class names of the video recorder
- Rename variable `m_vBuffer` -> `m_vAudioBuffers`
- Rename class `SAudioBuffer` -> `CAudioBuffer`
- Rename variable `m_vPixelHelper` -> `m_vVideoBuffers`
- Add class `CVideoBuffer` as wrapper
- Remove unused variable `m_Vframe`
- Rename variable `m_ASeq` -> `m_AudioFrameIndex`
- Rename variable `m_VSeq` -> `m_VideoFrameIndex`
- Rename variable `m_vVideoThreads` -> `m_vpVideoThreads`
- Rename variable `m_vAudioThreads` -> `m_vpAudioThreads`
- Rename function `ReadRGBFromGL` -> `UpdateVideoBufferFromGraphics`
- Remove unnecessary `ALEN` definition
- Remove unused variable `NextPts`
- Rename class `OutputStream` -> `COutputStream`
- Rename variable `pSt` -> `m_pStream`
- Rename variable `pEnc` -> `m_pCodecContext`
- Rename variable `m_vpSwsCtxs` -> `m_vpSwsContexts`
- Rename variable `m_vpSwrCtxs` -> `m_vpSwrContexts`
- Rename variable `pOC` -> `pFormatContext`
- Rename class `SVideoRecorderThread` -> `CVideoRecorderThread`
- Rename class `SAudioRecorderThread` -> `CAudioRecorderThread`
2024-05-04 13:55:35 +02:00
Robert Müller 5f647b97eb Ensure correct sample and bit rate are used for video recording
The wrong sampling rate was being used for video recording if the client is not restarted after changing the `snd_rate` config variable.

Ensure that the correct bit rate is used if the sample rate was adjusted because the selected value is not supposed.
2024-05-04 13:15:54 +02:00
Robert Müller 9d2c11d7ee Improve error handling and logging of video recorder
Use `log_error` for all errors and consistently format all error messages.

Handle all ffmpeg errors and output the formatted ffmpeg error message when possible.

Register a log callback for ffmpeg log messages to delegate them to our logging system, to fix the log messages being interleaved with our log messages and not using the correct line breaks on Windows.

Stop video and demo immediately and show an error message popup if the video could not be started successfully.

Remove unnecessary debug output from ffmpeg.
2024-05-04 13:15:54 +02:00
Robert Müller 33c5bfb09b Fix indentation of comments 2024-05-04 13:04:58 +02:00
Robert Müller c78eebfc67 Use nullptr instead of 0 and NULL 2024-05-04 13:04:58 +02:00
Robert Müller c4c1518709 Remove dead code 2024-05-04 13:04:58 +02:00
Robert Müller 15bebb8fb6 Remove unnecessary downcast to CGraphics_Threaded 2024-05-04 13:04:58 +02:00
ChillerDragon fcbd1fb1b1 Fix worst local variable style offenses
Removed member prefix m_ used for local variables.
Removed all b, c, i hungarian notation prefixes for boolean, const and integers.
Fixed local variables using lower_snake_case instead of UpperCamelCase.
Renamed all ``float wSearch = TextRender()->TextWidth..`` to ``float SearchWidth = ..``.
2024-05-04 11:17:06 +08:00
heinrich5991 213222b72b
Merge pull request #8289 from Robyt3/Client-Address-Check-Cleanup
Remove unnecessary check excluding packets from wrong server
2024-05-01 15:24:34 +00:00
Robert Müller dd62cda8ba Remove CCommandProcessorFragment_GLBase::Resize delegate
Use `ResizeImage` function directly instead.
2024-05-01 14:56:34 +02:00
Robert Müller 20c28f78ce Remove unnecessary check excluding packets from wrong server
This is already checked for all connection-oriented packets when feeding the connection in

952d3f6631/src/engine/shared/network_conn.cpp (L260-L266)

Closes #8285.
2024-05-01 13:34:19 +02:00
heinrich5991 2cd877f0ce
Merge pull request #8272 from ChillerDragon/pr_fix_snap_uuid_register
Fix ddnet ex snap item registration (closed #8271)
2024-05-01 09:56:42 +00:00
ChillerDragon 3c45134c8d Fix ddnet ex snap item registration (closed #8271) 2024-05-01 09:45:42 +08:00
ChillerDragon 740aada779 Add str_isnum 2024-05-01 09:08:02 +08:00
Robert Müller 3fc6ee4349
Merge pull request #8284 from ChillerDragon/pr_newline_cursor
Always update text cursor y (closed #8282)
2024-04-30 16:10:14 +00:00
ChillerDragon 508b6d1615 Always update text cursor y (closed #8282) 2024-04-29 14:12:38 +08:00
Dennis Felsing 7e857ce37e
Merge pull request #8280 from Robyt3/Client-Redirect-Password-Fix
Fix wrong server address used in password popup when redirected, minor refactoring
2024-04-29 04:23:57 +00:00
Dennis Felsing d265057591
Merge pull request #8278 from Robyt3/Client-Move-Resize-Fixes
Revert screen mode config variables when change not accepted, update screen index config variable after moving window
2024-04-28 15:18:16 +00:00
Robert Müller d2139e4bec Use net_addr_str directly to format address including port 2024-04-28 16:45:56 +02:00
Robert Müller b3bcfd39bc Add no-op logger to fix leak of CFutureLogger pending messages
Fix leak of pending future logger log messages if the future logger is not set, in particular when the `logfile` config variable is not set or the file could not be opened, by setting a logger that discards all log messages in this case.

Closes #8265.
2024-04-28 16:32:24 +02:00
Robert Müller e4dddb95ce Update screen index config variable after moving window
The wrong screen was shown in the settings when moving the window to another screen while in windowed mode.
2024-04-28 15:29:05 +02:00
Robert Müller 86bf5424e3 Revert screen mode config variables when change not accepted
When changing the screen width, height or refresh rate config variables to 0 or negative values, which are not allowed by the backend, automatically revert the config variables to the actual values again to ensure that the config variables stay in sync with the state of the window. This fixes the client crashing in the graphics settings when setting the screen width and height to 0 via the console, which causes a division by zero when calculating the aspect ratio.
2024-04-28 15:25:31 +02:00
Robert Müller 9cf3094934 Also check for incorrect sample index with assertion
Ensure the sample being allocated is not currently used also by checking its next free sample index.
2024-04-27 13:11:35 +02:00
Robert Müller d06f6d3370 Handle failure of op_pcm_total function
According to the documentation, this function returns `0` on success and a negative number (error code) otherwise, which would cause an allocation of an invalid size.
2024-04-27 13:11:35 +02:00
Robert Müller d0e27fdcd4 Fix memory leak of opus file structure
We were not calling `op_free` for `OggOpusFile *` after decoding opus files.
2024-04-27 13:04:05 +02:00
Robert Müller cfb5b15222 Log error code if opus file cannot be opened 2024-04-27 13:03:58 +02:00
Robert Müller 51012bcc1b Fix potential out-of-bounds writes on invalid opus files
The third parameter of the `op_read` function specifies the remaining size of the buffer, but we always passed the total size of the buffer without respecting the position at which the data is written into the buffer.
2024-04-27 13:03:18 +02:00
Robert Müller 4d37775c17 Only change sample variables when it was decoded successfully
Avoid changing the sample member variables until the sample was decoded successfully.
2024-04-27 13:02:36 +02:00
Robert Müller 1153507216 Fix double-free when reading opus file fails
Set the data pointer of the sample only when the sample has been loaded successfully, so the invalid sample data is not freed again when decoding fails.
2024-04-27 13:02:23 +02:00
Dennis Felsing c22ba00b59
Merge pull request #8270 from Robyt3/Image-size_t
Use `size_t` for `CImageInfo::m_Width` and `m_Height`
2024-04-27 04:37:28 +00:00
Robert Müller c5a0d850d2 Use size_t for CImageInfo::m_Width and m_Height 2024-04-26 21:12:39 +02:00
Robert Müller caccf05455 Fix warning because of incorrect format argument for size_t 2024-04-26 19:59:47 +02:00
Robert Müller 0cedcdc3a7
Merge pull request #8236 from ChillerDragon/pr_delta_dump
Add delta debug dump
2024-04-25 16:05:26 +00:00
ChillerDragon 29f6cc67db Add delta debug dump 2024-04-25 08:44:49 +08:00
Robert Müller 5958e9e4c5 Reset last dummy state when disconnecting
Otherwise the snapshots may incorrectly be invalidated because a change of the `cl_dummy` variable is detected when connecting to another server after disconnecting while the dummy is active.
2024-04-22 19:54:21 +02:00
Robert Müller efdd55613c Avoid using cl_dummy for demo playback
The `cl_dummy` config variable is always `0` during demo playback. Using the config variable makes the code less readable.
2024-04-22 19:54:21 +02:00
Robert Müller c7403ef06d Check CNetClient::State instead of SecurityTokenUnknown
Send dummy ready and enter game when connection is online based on its state instead of when the security token is not unknown anymore, which should effectively be the same condition but more understandable. This is also how it's already done for the main connection so the `SecurityTokenUnknown` function can be removed as it's unused now.
2024-04-22 19:54:21 +02:00
Robert Müller 9ffa9d8e0a Do not unpack map data packet if no map download is progress
There is no need to unpack map data packets if the client receives any without expecting them.
2024-04-22 19:33:20 +02:00