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`.
Add stricter error handling when converting between UTF-16 (wide characters) and UTF-8 (multi-byte) on Windows.
The `windows_wide_to_utf8` function now returns an `std::optional`, which will be empty if the argument contains invalid UTF-16. Files/folders with names containing invalid UTF-16 are now ignored on Windows. It was previously not possible to use these files either, as converting their names to UTF-8 changed the invalid codepoints to unicode replacement characters.
The `windows_utf8_to_wide` function now fails with an assertion error if the argument contains invalid UTF-8, as this should never happen.
Closes#7486.
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.
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.
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.
Apply the name bans system also to player clans, meaning players joining with banned clan names are kicked and changing the clan to a banned name while ingame has no effect.
Additionally, trim UTF-8 whitespace from beginning and end of clan. This was already done for player names but not for clans.
Closes#7516.
Unify all code for name bans in new class `CNameBans` in the existing `name_ban.cpp/h` files. The previously global function `IsNameBanned` is now the member function `CNameBans::IsBanned`. The existing name ban tests are extended for the `CNameBans` class.
Move `CNameBan` constructor definition to source file to avoid including `system.h` in the header file. Use `bool` instead of `int` for `m_IsSubstring`. Reorder `CNameBan` constructor arguments and remove unnecessary default value.
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.
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.
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.
After you issue a command in the client console or rcon, the command
will first be printed to the console prefixed with a '>' symbol.
Cherry-pick of https://github.com/teeworlds/teeworlds/pull/3185
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.
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.
Call expected server callback functions to simulate clients dynamically connecting and disconnecting when changing the `dbg_dummies` variable. This makes the debug dummies more useful for debugging. Previously, the debug dummies were considered invalid clients, whereas they are now considered to be ingame, so they should behave mostly like real clients being connected to the server. The debug dummies also have correct client names now, e.g. "Debug dummy 42".
The game server code is cleaned up by moving all special handling for debug dummies to the engine server function `CServer::UpdateDebugDummies`.
The left/right direction inputs for debug dummies are now properly added to the client input array, so their input handling should be consistent with normal clients, which fixes some inconsistent prediction with debug dummies.
Greyscale images with alpha channel (i.e. channel count = 2) were incorrectly handled as RGBA images, causing the client to crash when loading such images. Now the images can successfully be loaded with the image loader, but the client still only supports loading RGB and RGBA images like before.
The image data is freed when the image format is unsupported, but `CImageInfo::m_pData` would still point to the freed memory, so double-frees were possible.
Gets rid of more CGameControllerDDRace casts.
Those did not show up during compile time only during runtime
of another active controller when asan is active.
Also update server browser filtering/sorting when changing the community/country/type filter config variables with the console.
Clean the filter config variables when they are changed instead of only when the community filter is rendered.
Ensure that community/country/type filters do not exclude all allowed elements, which can happen when a previously selected community is not available anymore or when arbitrary community filter values are set with the console.
Allows to do this
```C++
for(const CPlayer *pPlayer : GameServer()->m_apPlayers)
{
if(!pPlayer)
continue;
if(!pPlayer->GetCharacter())
continue;
// your code that does not change the character state
}
```
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.
Partially replaces #5690.
POD types are just memset. Other types are either destructed if not
trivial and/or constructed if not trivial. Types need to have a default
constructor.
Virtual classes can be mem_zeroed only if they already have been
constructed, otherwise it is UB.
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.
Previously, the client would hang due to recursive usage of the console backlog lock when a log line is printed via the logger functions while already owning the backlog lock. This could happen when the text render causes log messages to be printed while the console backlog is rendered.
This is fixed by introducing a separate pending backlog to which new log lines are initially added and which is protected by a lock. The pending backlog entries are pumped into the normal backlog before the normal backlog is used, so accesses to the normal backlog do not need to be locked anymore. This means the console backlog lock is not owned when calling any functions that could print log messages, which should prevent the dead lock.
When creating a non ddrace controller and it uses `IGameController::GetMaskForPlayerWorldEvent`
it will crash:
#0 0x00007ffff72ac83c in ?? () from /usr/lib/libc.so.6
#1 0x00007ffff725c668 in raise () from /usr/lib/libc.so.6
#2 0x00007ffff72444b8 in abort () from /usr/lib/libc.so.6
#3 0x00007ffff749ca6f in __gnu_cxx::__verbose_terminate_handler () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#4 0x00007ffff74b011c in __cxxabiv1::__terminate (handler=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#5 0x00007ffff74b0189 in std::terminate () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#6 0x00007ffff74b03ed in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x7ffff766c0e8 <typeinfo for std::out_of_range>, dest=0x7ffff74c85c0 <std::out_of_range::~out_of_range()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98
#7 0x00007ffff74a025f in std::__throw_out_of_range_fmt (__fmt=<optimized out>) at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/functexcept.cc:101
#8 0x00005555555bd4a3 in std::bitset<64ul>::_M_check (this=0x7fffffffbb90, __position=0xffffffffffffffff, __s=0x5555557a9881 "bitset::reset") at /usr/include/c++/13.2.1/bitset:823
#9 0x00005555555f83e0 in std::bitset<64ul>::reset (this=0x7fffffffbb90, __position=0xffffffffffffffff) at /usr/include/c++/13.2.1/bitset:1196
#10 0x000055555560262a in IGameController::GetMaskForPlayerWorldEvent (this=0x555555b113d0, Asker=0x0, ExceptID=0xffffffff) at /home/chiller/Desktop/git/ddnet/src/game/server/gamecontroller.cpp:728
#11 0x000055555560be0f in CPlayer::TryRespawn (this=0x55555592e500 <gs_PoolDataCPlayer>) at /home/chiller/Desktop/git/ddnet/src/game/server/player.cpp:695
#12 0x000055555560a1a6 in CPlayer::Tick (this=0x55555592e500 <gs_PoolDataCPlayer>) at /home/chiller/Desktop/git/ddnet/src/game/server/player.cpp:249
#13 0x00005555555e174b in CGameContext::OnTick (this=0x7ffff477d010) at /home/chiller/Desktop/git/ddnet/src/game/server/gamecontext.cpp:964
#14 0x00005555555a7e34 in CServer::Run (this=0x7ffff57d5010) at /home/chiller/Desktop/git/ddnet/src/engine/server/server.cpp:2893
#15 0x0000555555592a2b in main (argc=0x1, argv=0x7fffffffd178) at /home/chiller/Desktop/git/ddnet/src/engine/server/main.cpp:197
Also increase usage of the `GetDDRaceTeam()` method.
Instead of reimplementing it in place everywhere.
move `m_Teams` from the ddrace controller to `IGameController`
so the ddrace controller casts can go away
This will enable creating another controller instead of the ddrace
controller. Which is useful for community forks.
Also make `m_Teams` private and define a getter for it.
This makes future refactors smoother.
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.
The check for multiple storage locations was using the base path from the previous invocation of the file dialog instead of using the new base path.
Closes#7463.
When the `CGameContext::SendChatTeam` function is used to send a chat message to all members of a DDTeam (e.g. on completed /swap chat command), it was not checked whether the target players are online but only whether they belong to the specified team according to the teams core. However, the default team for unconnected/cleared players is 0 in the teams core, which is the same for players in team 0, so chat messages were being sent to client IDs not corresponding to connected clients when chat messages where supposed to be sent to players in team 0. This was causing the server to crash with the assertion error "erroneous client id" specifically when the server is started with `sv_max_clients` being less than the default, maximum 64.
Closes#7450.
Simplify selecting envelope point colors by showing a color picker button that opens a color picker popup to change the color of the selected envelope point. The existing editbox to change only the selected channel's value is kept, as the color picker popup does not support the same precision to specify the individual color channel values.
Closes#7317.