Commit graph

1941 commits

Author SHA1 Message Date
Robert Müller 93d669143d Use nullptr instead of 0 and 0x0 2023-12-03 12:15:22 +01:00
Robert Müller d70fc84e38 Properly initialize all CClient member variables
Additionally, ensure snapshots are cleared and dummy is disconnected when disconnecting programatically with `DisconnectWithReason`.

Add `NETADDR_ZEROED` and `UUID_ZEROED` for more convenient initialization without using `mem_zero`.
2023-12-02 18:33:46 +01:00
Emir Marincic eba86204db
Merge pull request #7552 from Robyt3/Config-Refactoring
Refactor config manager, move config variable handling
2023-12-01 19:34:44 +00:00
heinrich5991 21cfb01ec3
Merge pull request #7515 from furo321/racefinish-message
Add finish info messages from 0.7
2023-12-01 16:13:06 +00:00
Robert Müller 1d7c0fad49 Check SHA256 of downloaded maps and community icons
Add `CHttpRequest::ExpectSha256` function to specify expected SHA256 for HTTP downloads. If the download completes with a different SHA256 hash than expected, then the download fails and the file is deleted.

Closes #7485.
2023-11-30 21:31:48 +01:00
Robert Müller 159ddf5534 Refactor config manager, move config variable handling
Move all code for handling of config variables from console to config manager. The console no longer depends on the config manager, instead the config manager now depends on the console.

Add `struct`s to manage config variables of different types (int, color and string). The config manager now keeps a list of all config variables, so usage of the preprocessor can be avoided except for code to initially create all config variables. Additionally, a separate list of just the game config variables (config variables with `CFGFLAG_GAME`) is kept to optimize the `ResetGameSettings` function, as this function is called whenever connecting to a server and should be fast. Previously, this function was even less efficient because it preformed a linear search for every individual game config variable to find the respective command data.

Move console commands that opperate only on config variables (`reset`, `toggle` and `+toggle`) to config manager. Ensure that these commands only opperate on the desired config variables (client or server, respectively) by checking `IConsole::FlagMask`.

Add `IConfigManager::SetReadOnly` function to set/unset config variables as read-only instead of manually overriding the command handlers for the `sv_rescue` and `sv_test_cmds` config variables. This also fixes that read-only config variables could still be changed by using the `reset` command. A console message is now printed when trying to change a read-only config variable. Removing the special handling for these two config variables is additionally useful so the console does not need to keep a pointer to config values and manager.

Use a `CHeap` for the config variables, their help texts and the previous values of string config variables to avoid many separate allocations as well usage of static variables. Also use the heap to store the unknown commands instead of using `std::string`s.

Properly trigger command chain when resetting config variables with the `reset` command and when resetting game settings on map loading. Closes #7461.

Format default value for color variables as RGB/RGBA hex with dollar sign prefix. Closes #5523.

Add log message when using `reset` with a variable that does not exist. Use `log_error` instead of `dbg_msg` when saving config file fails.

Support unlimited number of config save callbacks instead of at most 16. The code also becomes more readable by using an `std::vector` instead of a fixed-size array and a separate num variable.

Consistently name `MACRO_CONFIG_*` parameters when declaring the macros.

Add `IConsole::CMDLINE_LENGTH` constant to represent the maximum length of the console input and thereby reduce usage of magic numbers for buffer sizes.
2023-11-30 20:26:00 +01:00
furo eff6361c38 Add settings for info messages 2023-11-26 17:30:49 +01:00
Dennis Felsing c90899cc29
Merge pull request #7549 from Robyt3/Memheap-Refactoring
Refactor `CHeap`
2023-11-26 13:36:30 +00:00
Robert Müller 591c08cf34 Use static_casts instead of C style, remove unnecessary casts 2023-11-26 13:40:01 +01:00
Robert Müller 7a142df580 Move variable declarations closer to usages 2023-11-26 13:29:02 +01:00
Robert Müller ec6d7b48bf Use nullptr instead of 0x0 2023-11-26 13:20:56 +01:00
Robert Müller 41d2c80f21 Add templated CHeap::Allocate function
Add a templated `CHeap::Allocate` function to simplify memory allocation of objects using `CHeap`. The function uses perfect forwarding to construct objects with the specified arguments.
2023-11-26 13:09:23 +01:00
Corantin H fee9b986fb Added possibility to edit chat size and width. Refactored chat preview code. 2023-11-26 12:27:56 +01:00
Dennis Felsing 3e2f8f8a44
Merge pull request #7543 from Robyt3/Console-Interface-Cleanup
Minor refactoring of `IConsole`
2023-11-25 22:21:40 +00:00
Robert Müller 42b952bc6c Move config variables to config_variables.h, remove variables.h
The contents of `variables.h` are moved to `config_variables.h` instead of being included with the preprocessor. The file `variables.h` is removed, so all config variables can be found in a single file instead of being spread over two files without any clear structure. The original declaration order of config variables is preserved. The unnecessary header guard `GAME_VARIABLES_H` from `variables.h` is removed, as the comment `// This file can be included several times.` already serves the same purpose of silencing the header guard check.

A comment is added at the end of `config_variables.h` to mark the location where modders should ideally declare all of their own config variables to avoid merge conflicts with us in the future.

Closes #7472.
2023-11-25 16:40:55 +01:00
Robert Müller e410dd85f8 Replace IConsole::m_Cheated variable with Cheated getter
Interfaces should not have member variables, so the variable is moved to `CConsole`. Only a getter `IConsole::Cheated` is added because the cheated state of the console is never reset.
2023-11-25 11:43:42 +01:00
Robert Müller c216567431 Add IConsole::FlagMask getter function
So other interfaces/components can check which console commands are active. In particular this will be used to refactor the config manager. The respective setter function already exists.
2023-11-25 11:42:56 +01:00
Robert Müller 61c201c37c Fix string game settings not being reset correctly
Due to swapped `str_copy` arguments, the old value for string game variables was being overridden by the current value instead of the other way around in `CConsole::ResetGameSettings`.

There are currently no string game settings affected by this.
2023-11-22 23:16:57 +01:00
Robert Müller d331bcb496 Fix color game settings not being reset correctly
Handling color settings the same as int settings in `CConsole::ResetGameSettings` is not correct, as this causes the color variable data to be cast to int variable data.

There are currently no color game settings affected by this.
2023-11-22 23:12:56 +01:00
Robert Müller ab4e737a57 Fix misaligned int loads in CUnpacker::GetUncompressedInt
Use `mem_copy` instead of dereferencing potentially misaligned address as `int`.
2023-11-21 21:57:06 +01:00
Robert Müller 51e3c37c03 Use mem_copy instead of for-loop in CPacker::AddRaw
Using `memcpy` is faster, assuming the compiler doesn't already transform the loop to `memcpy` automatically.
2023-11-21 21:49:29 +01:00
heinrich5991 b951734c03 Don't allow mem_zero for nontrivial types
Initialize nontrivial types with a constructor instead. Make the
compiler aware that some of our constructors are indeed trivial.

This allows `mem_zero` calls to actually always zero the memory.
2023-11-18 22:55:17 +01:00
Robert Müller fcddc165b2 Remove unnecessary mem_zero of ringbuffer memory
Zeroing the entire ringbuffer memory is unnecessary and inefficient. Only the first item in the ringbuffer has to be initialized properly.

It's unlikely that existing code depends on allocated memory being zeroed, as recycled ringbuffer items where never zeroed.
2023-11-18 17:40:36 +01:00
Robert Müller 5c7bb58457 Ensure filenames are valid UTF-8 on Unix
On Unix, the encoding of filenames is unspecified, although UTF-8 is likely used in most cases. Detecting and converting from several possible encodings to UTF-8 would be too much effort, considering that most systems already use UTF-8 per default. Therefore, any filenames which are not valid UTF-8 will be ignored when listing directories with `fs_listdir(_fileinfo)`, `fs_storage_path` will fail if the storage location is not valid UTF-8 and `fs_getcwd` will fail if the current working directory is not valid UTF-8. Paths specified in `storage.cfg` must also be valid UTF-8.

On Windows, we already ensure that all filenames are converted to UTF-8.
2023-11-17 18:55:28 +01:00
ChillerDragon 9e27a5a107 Fix unused variabled m_WasRecording 2023-11-15 12:11:58 +01:00
Dennis Felsing e74e6770c3
Merge pull request #7325 from Robyt3/Browser-Community-Filter
Add community server filter and icons, remove DDNet and KoG tabs
2023-11-12 00:00:05 +00:00
Dennis Felsing aefa52c6b9
Merge pull request #7432 from Robyt3/Base-Standard-Mutex-Wrapper
Add `CLock` wrapper for `std::mutex` to replace `lock_*` functions, use `CLock` instead of `std::mutex`, add thread-safety annotations
2023-11-11 22:07:02 +00:00
furo 6599b7e14b Save unknown commands from settings_ddnet.cfg 2023-11-11 19:09:13 +01:00
Robert Müller 10470046b7 Use CLock instead of std::mutex, add thread-safety annotations
Use `CLock` and `CLockScope` instead of `std::mutex` and add clang thread-safety analysis annotations everywhere except for usages in engine graphics and video, as those usages also involve `std::condition_variable`.

Fix lock not being unlocked on all code paths in `CFutureLogger::Log`, which is caught by the static analysis.
2023-11-11 00:09:17 +01:00
Robert Müller 3d858c28ee Add CLock wrapper for std::mutex to replace lock_* functions
Replace usages of platform specific `lock_*` functions with `std::mutex` through the wrapper class `CLock`. Move lock classes to `base/lock.h`.

The `CLock` wrapper class is only necessary because the clang thread-safety attributes are not available for `std::mutex` except when explicitly using libc++.
2023-11-11 00:04:57 +01:00
Robert Müller 3e5a2888bc Support writing maps with more items/data
Previously, the client would crash with an assertion when writing more than 1024 items, 1024 data items or 64 extended item types to a map file. This arbitrary limitation is removed by using `std::vector`s, so much larger maps can be written. This was only a limitation when writing map files. Old clients can correctly read the map files having more items/data but will crash when the map is saved in the editor.
2023-11-04 22:54:18 +01:00
Robert Müller d39247f726 Add community server filter and icons, remove DDNet and KoG tabs
Remove the DDNet and KoG tabs and replace them with a community filter, which works like the country and type filters. Community information (ID, name, icon SHA256, countries, types, servers, ranked maps) is loaded dynamically from the DDNet info json.

The official checkmark icon is replaced with community icons. The icons are downloaded to the `communityicons` folder in the config directory from a URL specified in the DDNet info json. The icons are only re-downloaded when their SHA256 has changed.

Per default, the Internet tab with all communities is selected. When starting the client for the first time, only the DDNet community is selected. The community, country and type filters can also be used on the Favorites tab now. The LAN tab remains unchanged.

The country and type filters are refactored. Previously, using these filters changed the total number of servers and players that were displayed, as the filter was implemented as a separate step. Now the community, country and type filters work like the other browser filters. This also has the benefit that the server list and DDNet info json are not reloaded each time these filters are changed, as updating the local filtering/sorting is enough now.

The check for finished maps is made more efficient by using an `std::unordered_set` instead of linear search.

Closes #5654.
2023-11-04 15:32:27 +01:00
Robert Müller 7f694e8fc9 Add IStorage::CalculateHashes
To conveniently calculate the SHA256 and CRC32 hashes of a file without reading the entire file into memory at once.
2023-11-04 15:24:44 +01:00
Robert Müller 9b8eb9d6fc Use for- instead of while-loop, improve comments 2023-11-01 14:07:36 +01:00
Robert Müller 7343ca224c Add CDatafileHeader::SizeOffset to replace magic 16 2023-11-01 14:07:36 +01:00
Robert Müller 64716075f9 Add assertion to ensure correct item IDs are written 2023-11-01 14:07:36 +01:00
Robert Müller 284390cc75 Add assertions to ensure correct map item/data sizes are written
Add assertions to prevent map items and data that are too large to be represented by the map format from being written to maps. Additionally, ensure that the size of the whole map file is not too large to be represented by the map header.

Prevent `malloc` of size 0, which is implementation defined and should be avoided, when adding items without data, which happens for example when adding an empty array of envelope points.
2023-11-01 14:06:28 +01:00
Robert Müller f7722eb016 Remove separate CDataFileWriter::Init/OpenFile functions
Simplify usage of datafile writer by removing duplicate functions for opening file.
2023-11-01 12:54:38 +01:00
BurnyLlama c76352cb9f Altered snd_buffer_size description. Fixes #7229 2023-10-29 19:57:03 +01:00
furo e61ed1c3b4 Small fixes for cl_race_ghost_strict_map
- Better description
- Remove redudant map check
2023-10-28 14:54:35 +02:00
Dennis Felsing 28f4739e46
Merge pull request #7375 from furo321/improve-ghosts
Various improvements to ghosts
2023-10-27 22:06:00 +00:00
furo dadb142f4e Add cl_race_ghost_alpha, add title for ghost settings. 2023-10-27 20:56:57 +02:00
furo b90995da06 Add option to always save ghosts, not only personal bests. 2023-10-27 20:55:35 +02:00
furo c79e4c2de5 Add option to disable ghost map hash check. 2023-10-27 20:51:17 +02:00
Dennis Felsing 80cccaaae9
Merge pull request #7362 from furo321/SvRegionalRankings
Add option to disable printing of regional rankings.
2023-10-27 16:42:23 +00:00
Robert Müller 4845639a00 Fix use of closed demo file when playback stopped due to error
Check whether the demo file has been closed due to a playback error when calling `DoTick` in loops, to prevent crashes on operating systems with assertions for correct C library usage. On Windows, `warning: Invalid parameter passed to C runtime function` was printed to the debug console in this case.
2023-10-25 20:10:15 +02:00
Robert Müller a0d154a841 Bump maximum server password length from 128 to 256
Ensure server password can fit username and password separated by colon, so there is no discrepancy where some passwords work in rcon but not for reserved slots.
2023-10-24 21:44:53 +02:00
Robert Müller 3116fb4bcf Fix ec_output_level default/min/max values, update description
To ensure that all `*_output_level` variables have the same default, minimum and maximum values.
2023-10-24 20:17:09 +02:00
furo bf98eec518 Add option to disable regional rankings.
Set config to true in tests

Add test for `´sv_regional_rankings`
2023-10-23 14:02:22 +02:00
Robert Müller bea7aea431 Encapsulate CHostLookup member variables
The host lookup job is currently only used for the DNSBL lookup on the server-side and in tests.
2023-10-22 13:38:56 +02:00