Commit graph

3711 commits

Author SHA1 Message Date
ChillerDragon f8ca16c50e Use real ClientID to lookup authed state and score
The variable `Id` is translated for old clients and is not guranteed to
be the real id. While `m_ClientID` is the real ID. That can also be used
to index the CServer::m_aClients[] array to get the authed state.

closed #7599

Fixes

```
valgrind ./DDNet-Server "dbg_dummies 1"
[..]
2023-12-07 18:01:33 I chat: *** 'Debug dummy 1' entered and joined the
game
==75634== Conditional jump or move depends on uninitialised value(s)
==75634==    at 0x2DAA83: CVariableInt::Pack(unsigned char*, int, int)
(compression.cpp:17)
==75634==    by 0x2DAD79: CVariableInt::Compress(void const*, int,
void*, int) (compression.cpp:98)
==75634==    by 0x23EC50: CServer::DoSnapshot() (server.cpp:1046)
==75634==    by 0x247D2D: CServer::Run() (server.cpp:2994)
==75634==    by 0x230173: main (main.cpp:193)
==75634==
==75634== Conditional jump or move depends on uninitialised value(s)
==75634==    at 0x2DAAF7: CVariableInt::Pack(unsigned char*, int, int)
(compression.cpp:25)
==75634==    by 0x2DAD79: CVariableInt::Compress(void const*, int,
void*, int) (compression.cpp:98)
==75634==    by 0x23EC50: CServer::DoSnapshot() (server.cpp:1046)
==75634==    by 0x247D2D: CServer::Run() (server.cpp:2994)
==75634==    by 0x230173: main (main.cpp:193)
==75634==
==75634== Conditional jump or move depends on uninitialised value(s)
==75634==    at 0x2DAA83: CVariableInt::Pack(unsigned char*, int, int)
(compression.cpp:17)
==75634==    by 0x32E812: CPacker::AddInt(int) (packer.cpp:20)
==75634==    by 0x23ED51: CServer::DoSnapshot() (server.cpp:1059)
==75634==    by 0x247D2D: CServer::Run() (server.cpp:2994)
==75634==    by 0x230173: main (main.cpp:193)
==75634==
==75634== Conditional jump or move depends on uninitialised value(s)
==75634==    at 0x2DAAF7: CVariableInt::Pack(unsigned char*, int, int)
(compression.cpp:25)
==75634==    by 0x32E812: CPacker::AddInt(int) (packer.cpp:20)
==75634==    by 0x23ED51: CServer::DoSnapshot() (server.cpp:1059)
==75634==    by 0x247D2D: CServer::Run() (server.cpp:2994)
==75634==    by 0x230173: main (main.cpp:193)
==75634==
```

Which is using ID 0 as index in the m_aClients array but only ID 63 was
ever initialized.
2023-12-07 18:40:16 +01:00
furo d9a726eb48 Stop all recording of server demos on shutdown. 2023-12-02 11:10:20 +01:00
ChillerDragon cd9fc2964d Use SetEmote() 2023-12-01 22:50:00 +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
Robert Müller 44aac623fa
Merge pull request #7512 from furo321/telecursor-fixes2
Scale `TargetX` and `TargetY` by zoom level.
2023-12-01 16:36:30 +00:00
furo a87db4f026 Move tele cursor behaviour to /tc and /telecursor 2023-11-30 22:34:36 +01:00
furo 7a6e368b7f Scale TargetX and TargetY with camera zoom 2023-11-30 22:34:36 +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 2cb948a57b Add finish info messages. 2023-11-26 17:29:40 +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 794e6b750b Also apply name bans to clans, trim space from clans
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.
2023-11-25 23:00:57 +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
Dennis Felsing 9f20636952
Merge pull request #7532 from furo321/magic-50
Replace `50` with `SERVER_TICK_SPEED` or `TickSpeed()`
2023-11-23 22:07:37 +00:00
furo 36a029c622 Set correct race precision value for 0.7 2023-11-23 18:37:02 +01:00
furo b9fd612ef5 Replace 50 with SERVER_TICK_SPEED or TickSpeed() 2023-11-23 14:42:30 +01:00
Learath b9f786c14f Revert the mess-chain #7247. Apply #7171
Co-authored-by: Valentin Bashkirov <valenteen3d@ya.ru>
2023-11-22 18:34:42 +01:00
Robert Müller 0d8a0d3b1d Dynamically connect/disconnect debug dummies, cleanup
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.
2023-11-21 19:59:20 +01:00
Dennis Felsing 375dd7da8b
Merge pull request #7511 from furo321/telecursor-fixes
Account for zoom when teleporting to cursor.
2023-11-20 12:25:54 +00:00
furo c2d02ad45c Account for zoom when teleporting to cursor. 2023-11-20 12:33:08 +01:00
Dennis Felsing 472c9f070b
Merge pull request #7507 from dobrykafe/pr-replace-sizeof
replace `sizeof x` with `sizeof(x)`
2023-11-19 21:56:15 +00:00
dobrykafe 904abae6ac replace sizeof x with sizeof(x) 2023-11-19 22:36:47 +01:00
Chairn 5b27062ded Remove unused members 2023-11-19 17:36:16 +01:00
Chairn d6c7bcdbdc Init vec2 members to 0 following #6256 2023-11-19 17:36:16 +01:00
ChillerDragon 16c5a60b53 Move m_pLoadBestTimeResult to IGameController
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.
2023-11-19 16:23:17 +01:00
heinrich5991 28b00892f6 Allow more complex interaction with the antibot via the console
Allows the antibot to receive arbitrary console commands.
2023-11-19 04:41:56 +01:00
heinrich5991 9b024fcf97
Merge pull request #7476 from ChillerDragon/pr_const_char
Overload GetCharacter with const version
2023-11-19 03:08:03 +00:00
heinrich5991 d4713cbfe2
Merge pull request #7475 from ChillerDragon/pr_gametype_mod
Add sv_gametype and sample mod
2023-11-19 03:07:24 +00:00
ChillerDragon becffb9377 Add sv_gametype and sample mod 2023-11-19 03:00:21 +01:00
ChillerDragon d42513e843 Overload GetCharacter() with const version
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
}
```
2023-11-19 02:00:28 +01:00
Chairn 5cdae502b8 Fix code scanning && clang-tidy false positive? 2023-11-18 22:55:17 +01:00
ChillerDragon f0aae73b1f Fix crash in mod controller
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
2023-11-18 15:56:10 +01:00
heinrich5991 2dbfc72a4d
Merge pull request #7464 from ChillerDragon/pr_use_ddr_wrapper
Use GetDDRaceTeam() and move m_Teams to igamecontroller
2023-11-18 13:41:45 +00:00
ChillerDragon 83af6c0a36 Move m_Teams to IGameController
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.
2023-11-18 13:55:48 +01:00
Dennis Felsing 8ab9e72240
Merge pull request #7491 from furo321/fix-lastkickvote
Fix some issues with `sv_vote_kick_delay`.
2023-11-18 12:31:35 +00:00
furo 045915eab5 Fix some issues with sv_vote_kick_delay. 2023-11-18 13:09:13 +01:00
ChillerDragon 60e6025e7a Move m_TeleOuts from ddr controller to game controller
#7127
2023-11-17 23:52:31 +01:00
Robert Müller b8d38f7f49 Fix server crash on DDTeam message with lower sv_max_clients
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.
2023-11-13 23:16:21 +01:00
Dennis Felsing 32f3f9e03a
Merge pull request #7449 from furo321/lasttp-save
Save entire character with `/lasttp`.
2023-11-12 23:14:12 +00:00
furo f9b9480291 Save entire character with /lasttp. 2023-11-12 23:48:36 +01:00
Robert Müller 188462ea27 Add new contributors to credits
Thanks everyone!
2023-11-12 12:20:10 +01:00
Alexander Akulich b886b93cf2 CPlayer: Remove unused variable 2023-11-03 21:36:33 +03:00
Alexander Akulich 17c90fc061 CCharacter::IsSnappingCharacterInView: Add missing const 2023-11-03 21:36:33 +03:00
Dennis Felsing 80c4940b7f
Merge pull request #7403 from Robyt3/Datafile-Writer-Refactoring
Add more assertions to datafile writer, refactoring
2023-11-01 22:02:45 +00:00
Robert Müller 75debadd34 Add freeze/unfreeze testing commands
See #7370.
2023-11-01 17:26:29 +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
Dennis Felsing 7000b97425
Merge pull request #7396 from BurnyLlama/add-underline_top_five
Added back underline for `sv_regional_rankings 0`.
2023-10-30 23:10:50 +00:00
Dennis Felsing 2eff91083d
Merge pull request #7394 from furo321/fix-setafk
Fix afk timer not working.
2023-10-30 23:03:17 +00:00
BurnyLlama 817ef6eb58 Added back underline for sv_regional_rankings 0. 2023-10-30 22:40:04 +01:00
furo 0ecc50ae0f Fix afk timer not working. 2023-10-30 19:43:35 +01:00
Dennis Felsing 3235e3eac9
Merge pull request #7392 from furo321/fix-demo-ending-early
Delay server race demo ending by 1 second.
2023-10-30 09:40:00 +00:00