Commit graph

16021 commits

Author SHA1 Message Date
Robert Müller 55b576cd7f Add generic confirm popup to menu, adapt generic message popup
Add a generic popup to confirm an operation to the menu and revise the generic message popup similar to this.

Both popups have a title and a message. The message popup has one button and the confirmation popup has two buttons.
For each button a label, the next popup after clicking the button, and a custom button handler can be set.

From teeworlds/teeworlds#2598.
2022-12-03 13:49:12 +01:00
Robert Müller 077b0eeaab Add "Tools > Remove unused envelopes" to editor
Add a new menu "Tools" next to the "File" menu, with a button to "Remove unused envelopes".

Clicking the button opens a confirmation popup to confirm the operation.

Closes #2576.
2022-12-03 11:04:50 +01:00
Robert Müller f000fcea29 Add generic confirmation popup to editor
Add `CEditor::ShowPopupConfirm` to show a generic confirmation popup.

This popups shows a message and buttons to confirm or cancel an operation. The result will be available to the caller in the given `SConfirmPopupContext`.
2022-12-03 11:04:49 +01:00
Robert Müller 3ba51c476f Extract SSelectionPopupContext::Reset to reduce duplicate code 2022-12-03 11:04:49 +01:00
bors[bot] e2fd30f7d3
Merge #6080
6080: Try using default MariaDB server version (fixes #6079) r=Robyt3 a=def-

<!-- What is the motivation for the changes of this pull request? -->

<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-12-03 09:22:42 +00:00
Dennis Felsing c291fe7eb9 Try using default MariaDB server version (fixes #6079) 2022-12-01 23:38:04 +01:00
Vy0x2 36939475e2 Add logs for moderators 2022-12-01 00:55:52 +01:00
bors[bot] 3012a42ea0
Merge #6075 #6076
6075: Fix key reader text flashing for one frame, refactoring r=def- a=Robyt3

The key reader was displaying the old key for a frame. It now shows the new key immediately without flashing the old one after changing a bind.

Refactoring:

- The if-branches are restructured to be the same as on upstream.
- The function `GetKeyBindModifiersName` can be called without an additional check, because it returns an empty string when no modifier is pressed.
- The unused parameter `Checked` of the `DoButton_KeySelect` function is removed.

From teeworlds/teeworlds#2877.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


6076: Fix stored commands using original callback instead of the chain, fix client crash when launching with `screenshot` command r=def- a=Robyt3



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-11-29 23:06:01 +00:00
bors[bot] c2d5d81df9
Merge #6074
6074: Reset teams when restarting round r=def- a=Robyt3

The state of teams was not reset when restarting a round with `restart`, which led to various issues (#5144):

- Switchers kept their previous state instead of being reset to the initial state after restarting.
- Teams that started racing sometimes could not be joined after restarting.
- Sometimes teams cannot finish a race after restarting. I cannot reproduce this issue, so I don't know if it's fixed by these changes.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [X] Considered possible null pointers and out of bounds array indexing
- [X] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-11-29 22:40:47 +00:00
Robert Müller 9cba213310 Consistently use static const instead of const static 2022-11-29 23:32:32 +01:00
Robert Müller faa9f27808 Declare variables as const when possible
According to cppcheck's `constVariable` error:

```
src\engine\client\backend\opengl\opengl_sl.cpp:74:43: style: Variable 'Define' can be declared as reference to const [constVariable]
  for(CGLSLCompiler::SGLSLCompilerDefine &Define : pCompiler->m_vDefines)
                                          ^

src\engine\client\backend\vulkan\backend_vulkan.cpp:2149:12: style: Variable 'GraphicThreadCommandBuffer' can be declared as reference to const [constVariable]
     auto &GraphicThreadCommandBuffer = m_vvThreadDrawCommandBuffers[i + 1][m_CurImageIndex];
           ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3192:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
  auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3200:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
   auto &DescrSet = m_vTextures[State.m_Texture].m_VKStandard3DTexturedDescrSet;
         ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3810:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
  for(auto &Mode : vPresentModeList)
            ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3818:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
  for(auto &Mode : vPresentModeList)
            ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6511:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
   auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
         ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6555:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
   auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_VKStandard3DTexturedDescrSet;
         ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6660:9: style: Variable 'MemBlock' can be declared as reference to const [constVariable]
  auto &MemBlock = m_vBufferObjects[BufferIndex].m_BufferObject.m_Mem;
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6799:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
  auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6808:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
   auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
         ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6902:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
  auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6907:9: style: Variable 'TextTextureDescr' can be declared as reference to const [constVariable]
  auto &TextTextureDescr = m_vTextures[pCommand->m_TextTextureIndex].m_VKTextDescrSet;
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6961:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
  auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
        ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6970:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
   auto &DescrSet = m_vTextures[State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
         ^

src\game\client\components\hud.cpp:178:8: style: Variable 'aFlagCarrier' can be declared as const array [constVariable]
   int aFlagCarrier[2] = {
       ^
src\game\client\components\hud.cpp:519:16: style: Variable 's_aTextWidth' can be declared as const array [constVariable]
  static float s_aTextWidth[5] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000};
               ^

src\game\client\components\killmessages.cpp:305:30: style: Variable 'Client' can be declared as reference to const [constVariable]
   CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_KillerID];
                             ^
src\game\client\components\killmessages.cpp:314:30: style: Variable 'Client' can be declared as reference to const [constVariable]
   CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_VictimID];
                             ^

src\game\client\components\menus_ingame.cpp:243:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
 for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
           ^
src\game\client\components\menus_ingame.cpp:530:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
 for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
           ^

src\game\client\components\players.cpp:767:44: style: Variable 'CharacterInfo' can be declared as reference to const [constVariable]
  CGameClient::CSnapState::CCharacterInfo &CharacterInfo = m_pClient->m_Snap.m_aCharacters[i];
                                           ^

src\game\client\components\spectator.cpp:122:27: style: Variable 'Snap' can be declared as reference to const [constVariable]
 CGameClient::CSnapState &Snap = pSelf->m_pClient->m_Snap;
                          ^
src\game\client\components\spectator.cpp:221:12: style: Variable 'pInfo' can be declared as reference to const [constVariable]
 for(auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName)
           ^

src\game\client\gameclient.cpp:2220:15: style: Variable 'OwnClientData' can be declared as reference to const [constVariable]
 CClientData &OwnClientData = m_aClients[ownID];
              ^
src\game\client\gameclient.cpp:2227:16: style: Variable 'cData' can be declared as reference to const [constVariable]
  CClientData &cData = m_aClients[i];
               ^

src\game\client\prediction\entities\character.cpp:397:11: style: Variable 'aSpreading' can be declared as const array [constVariable]
    float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
          ^

src\game\client\prediction\entities\laser.cpp:53:9: style: Variable 'HitPos' can be declared as reference to const [constVariable]
  vec2 &HitPos = pHit->Core()->m_Pos;
        ^

src\game\editor\auto_map.cpp:507:18: style: Variable 'Index' can be declared as reference to const [constVariable]
       for(auto &Index : pRule->m_vIndexList)
                 ^
src\game\editor\auto_map.cpp:518:18: style: Variable 'Index' can be declared as reference to const [constVariable]
       for(auto &Index : pRule->m_vIndexList)
                 ^

src\game\editor\editor.cpp:118:12: style: Variable 'Item' can be declared as reference to const [constVariable]
 for(auto &Item : vList)
           ^
src\game\editor\editor.cpp:2983:11: style: Variable 'aAspects' can be declared as const array [constVariable]
    float aAspects[] = {4.0f / 3.0f, 16.0f / 10.0f, 5.0f / 4.0f, 16.0f / 9.0f};
          ^
src\game\editor\editor.cpp:3141:15: style: Variable 's_aShift' can be declared as const array [constVariable]
   static int s_aShift[] = {24, 16, 8, 0};
              ^

src\engine\server\server.cpp:2807:14: style: Variable 'Client' can be declared as reference to const [constVariable]
   for(auto &Client : m_aClients)
             ^

src\engine\server\sql_string_helpers.cpp:51:6: style: Variable 'aTimes' can be declared as const array [constVariable]
 int aTimes[7] =
     ^

src\test\secure_random.cpp:24:6: style: Variable 'BOUNDS' can be declared as const array [constVariable]
 int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
     ^
```
2022-11-29 23:32:32 +01:00
Robert Müller aa321cd887 Move index check before usage, use std::size
According to cppchecker's `arrayIndexThenCheck` error:

```
src\game\client\race.cpp:24:30: style: Array index 'i' is used before limits check. [arrayIndexThenCheck]
  for(int i = 0; isdigit(pStr[i]) && i < 3; i++)
                             ^
```
2022-11-29 23:32:31 +01:00
Robert Müller 98706d79d4 Mark parameters as const when possible
According to cppchecker's `constParameter` error:

```
src\engine\gfx\image_manipulation.cpp:7:58: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void Dilate(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest, unsigned char AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD)
                                                         ^
src\engine\gfx\image_manipulation.cpp:58:67: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void CopyColorValues(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest)
                                                                  ^

src\engine\shared\network_conn.cpp:241:42: style: Parameter 'Addr' can be declared as reference to const [constParameter]
void CNetConnection::DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup)
                                         ^

src\base\system.cpp:4060:71: style: Parameter 'random' can be declared as pointer to const [constParameter]
void generate_password(char *buffer, unsigned length, unsigned short *random, unsigned random_length)
                                                                      ^

src\engine\client\backend\vulkan\backend_vulkan.cpp:263:38: style: Parameter 'AllocatedMemory' can be declared as reference to const [constParameter]
  void Free(SMemoryHeapQueueElement &AllocatedMemory)
                                     ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:1708:47: style: Parameter 'ImgExtent' can be declared as reference to const [constParameter]
 static size_t ImageMipLevelCount(VkExtent3D &ImgExtent)
                                              ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2801:29: style: Parameter 'Image' can be declared as reference to const [constParameter]
 void ImageBarrier(VkImage &Image, size_t MipMapBase, size_t MipMapCount, size_t LayerBase, size_t LayerCount, VkFormat Format, VkImageLayout OldLayout, VkImageLayout NewLayout)
                            ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6495:46: style: Parameter 'ExecBuffer' can be declared as reference to const [constParameter]
 void Cmd_Clear(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_Clear *pCommand)
                                             ^

src\game\client\components\skins.cpp:83:72: style: Parameter 'pImg' can be declared as pointer to const [constParameter]
static void CheckMetrics(CSkin::SSkinMetricVariable &Metrics, uint8_t *pImg, int ImgWidth, int ImgX, int ImgY, int CheckWidth, int CheckHeight)
                                                                       ^

src\game\client\prediction\entities\character.h:106:37: style: Parameter 'pNewInput' can be declared as pointer to const [constParameter]
 void SetInput(CNetObj_PlayerInput *pNewInput)
                                    ^

src\game\client\prediction\gameworld.cpp:245:106: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
                                                                                                         ^
src\game\client\prediction\gameworld.cpp:245:151: style: Parameter 'pThisOnly' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
                                                                                                                                                      ^
src\game\client\prediction\gameworld.cpp:283:116: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
std::list<class CCharacter *> CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, class CEntity *pNotThis)
                                                                                                                   ^

src\game\client\ui.cpp:522:180: style: Parameter 'pReadCursor' can be declared as pointer to const [constParameter]
void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, CTextCursor *pReadCursor)
                                                                                                                                                                                   ^

src\game\client\ui_scrollregion.cpp:23:86: style: Parameter 'pParams' can be declared as pointer to const [constParameter]
void CScrollRegion::Begin(CUIRect *pClipRect, vec2 *pOutOffset, CScrollRegionParams *pParams)
                                                                                     ^

src\game\server\scoreworker.h:239:29: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
 void Set(float Time, float aTimeCp[NUM_CHECKPOINTS])
                            ^

src\game\server\score.cpp:135:80: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible)
                                                                               ^

src\game\server\teeinfo.cpp:40:57: style: Parameter 'pUseCustomColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
                                                        ^
src\game\server\teeinfo.cpp:40:80: style: Parameter 'pSkinPartColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
                                                                               ^
```
2022-11-29 23:32:31 +01:00
Robert Müller 2115c12282 Handle snap ID potentially being out of range
According to cppchecker's `arrayIndexOutOfBoundsCond` error:

```
src\engine\server\server.cpp:117:19: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond]
 dbg_assert(m_aIDs[ID].m_State == ID_ALLOCATED, "id is not allocated");
                  ^
src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant
 if(ID < 0)
       ^
src\engine\server\server.cpp:117:19: note: Array index out of bounds
 dbg_assert(m_aIDs[ID].m_State == ID_ALLOCATED, "id is not allocated");
                  ^
src\engine\server\server.cpp:120:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond]
 m_aIDs[ID].m_State = ID_TIMED;
       ^
src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant
 if(ID < 0)
       ^
src\engine\server\server.cpp:120:8: note: Array index out of bounds
 m_aIDs[ID].m_State = ID_TIMED;
       ^
src\engine\server\server.cpp:121:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond]
 m_aIDs[ID].m_Timeout = time_get() + time_freq() * 5;
       ^
src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant
 if(ID < 0)
       ^
src\engine\server\server.cpp:121:8: note: Array index out of bounds
 m_aIDs[ID].m_Timeout = time_get() + time_freq() * 5;
       ^
src\engine\server\server.cpp:122:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond]
 m_aIDs[ID].m_Next = -1;
       ^
src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant
 if(ID < 0)
       ^
src\engine\server\server.cpp:122:8: note: Array index out of bounds
 m_aIDs[ID].m_Next = -1;
       ^
```
2022-11-29 23:32:31 +01:00
Robert Müller d2868325b6 Fix potential null-pointer dereference in server logger
According to cppchecker's `nullPointerRedundantCheck` error:

```
src\engine\server\server_logger.cpp:29:3: warning: Either the condition 'm_pServer' is redundant or there is possible null pointer dereference: m_pServer. [nullPointerRedundantCheck]
  m_pServer->SendLogLine(pMessage);
  ^
src\engine\server\server_logger.cpp:19:7: note: Assuming that condition 'm_pServer' is not redundant
   if(m_pServer)
      ^
src\engine\server\server_logger.cpp:29:3: note: Null pointer dereference
  m_pServer->SendLogLine(pMessage);
  ^

```
2022-11-29 23:32:30 +01:00
Robert Müller 0f2590801d Clarify operator precedence
According to cppcheck's `clarifyCalculation` error:

```
src\game\client\components\hud.cpp:196:49: style: Clarify calculation precedence for '&' and '?'. [clarifyCalculation]
   float ImageSize = GameFlags & GAMEFLAG_FLAGS ? 16.0f : Split;
                                                ^
src\game\editor\layer_tiles.cpp:544:94: style: Clarify calculation precedence for '&' and '?'. [clarifyCalculation]
    m_pTiles[y * m_Width + x].m_Flags ^= m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE ? TILEFLAG_HFLIP : TILEFLAG_VFLIP;
                                                                                             ^
src\game\editor\layer_tiles.cpp:560:94: style: Clarify calculation precedence for '&' and '?'. [clarifyCalculation]
    m_pTiles[y * m_Width + x].m_Flags ^= m_pTiles[y * m_Width + x].m_Flags & TILEFLAG_ROTATE ? TILEFLAG_VFLIP : TILEFLAG_HFLIP;
                                                                                             ^
```
2022-11-29 23:32:30 +01:00
Robert Müller f46c9f9079 Remove redundant conditional expression before assignment
According to cppcheck's `duplicateConditionalAssign` error:

```
src\game\client\gameclient.cpp:1439:39: style: The statement 'if (m_aFlagDropTick[TEAM_RED]!=0) m_aFlagDropTick[TEAM_RED]=0' is logically equivalent to 'm_aFlagDropTick[TEAM_RED]=0'. [duplicateConditionalAssign]
    else if(m_aFlagDropTick[TEAM_RED] != 0)
                                      ^
src\game\client\gameclient.cpp:1440:32: note: Assignment 'm_aFlagDropTick[TEAM_RED]=0'
     m_aFlagDropTick[TEAM_RED] = 0;
                               ^
src\game\client\gameclient.cpp:1439:39: note: Condition 'm_aFlagDropTick[TEAM_RED]!=0' is redundant
    else if(m_aFlagDropTick[TEAM_RED] != 0)
                                      ^
src\game\client\gameclient.cpp:1446:40: style: The statement 'if (m_aFlagDropTick[TEAM_BLUE]!=0) m_aFlagDropTick[TEAM_BLUE]=0' is logically equivalent to 'm_aFlagDropTick[TEAM_BLUE]=0'. [duplicateConditionalAssign]
    else if(m_aFlagDropTick[TEAM_BLUE] != 0)
                                       ^
src\game\client\gameclient.cpp:1447:33: note: Assignment 'm_aFlagDropTick[TEAM_BLUE]=0'
     m_aFlagDropTick[TEAM_BLUE] = 0;
                                ^
src\game\client\gameclient.cpp:1446:40: note: Condition 'm_aFlagDropTick[TEAM_BLUE]!=0' is redundant
    else if(m_aFlagDropTick[TEAM_BLUE] != 0)
                                       ^
```
2022-11-29 23:32:30 +01:00
Robert Müller 19bf435d6a Remove redundant assignments
According to cppcheck's `redundantInitialization` and `redundantAssignment` errors:

```
src\game\client\ui.cpp:456:5: style: Redundant initialization for 'tw'. The initialized value is overwritten before it is read. [redundantInitialization]
 tw = TextRender()->TextWidth(0, Size, pText, -1, LabelProps.m_MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
    ^
src\game\client\ui.cpp:454:11: note: tw is initialized
 float tw = std::numeric_limits<float>::max();
          ^
src\game\client\ui.cpp:456:5: note: tw is overwritten
 tw = TextRender()->TextWidth(0, Size, pText, -1, LabelProps.m_MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
    ^
src\game\client\ui.cpp:529:5: style: Redundant initialization for 'tw'. The initialized value is overwritten before it is read. [redundantInitialization]
 tw = TextRender()->TextWidth(0, Size, pText, -1, LabelProps.m_MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
    ^
src\game\client\ui.cpp:527:11: note: tw is initialized
 float tw = std::numeric_limits<float>::max();
          ^
src\game\client\ui.cpp:529:5: note: tw is overwritten
 tw = TextRender()->TextWidth(0, Size, pText, -1, LabelProps.m_MaxWidth, &AlignedSize, &MaxCharacterHeightInLine);
    ^

src\game\editor\editor.cpp:6051:19: style: Variable 'm_Map.m_Modified' is reassigned a value before the old one has been used. [redundantAssignment]
 m_Map.m_Modified = false;
                  ^
src\game\editor\editor.cpp:6046:19: note: m_Map.m_Modified is assigned
 m_Map.m_Modified = false;
                  ^
src\game\editor\editor.cpp:6051:19: note: m_Map.m_Modified is overwritten
 m_Map.m_Modified = false;
                  ^

src\game\client\prediction\entities\character.cpp:1148:36: style: Variable 'm_LatestInput' is reassigned a value before the old one has been used. [redundantAssignment]
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                                   ^
src\game\client\prediction\entities\character.cpp:1134:16: note: m_LatestInput is assigned
 m_LatestInput = m_LatestPrevInput = m_PrevInput = m_Input = m_SavedInput;
               ^
src\game\client\prediction\entities\character.cpp:1148:36: note: m_LatestInput is overwritten
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                                   ^
src\game\client\prediction\entities\character.cpp:1148:20: style: Variable 'm_LatestPrevInput' is reassigned a value before the old one has been used. [redundantAssignment]
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                   ^
src\game\client\prediction\entities\character.cpp:1134:36: note: m_LatestPrevInput is assigned
 m_LatestInput = m_LatestPrevInput = m_PrevInput = m_Input = m_SavedInput;
                                   ^
src\game\client\prediction\entities\character.cpp:1148:20: note: m_LatestPrevInput is overwritten
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                   ^
src\game\client\prediction\entities\character.cpp:1148:50: style: Variable 'm_PrevInput' is reassigned a value before the old one has been used. [redundantAssignment]
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                                                 ^
src\game\client\prediction\entities\character.cpp:1134:50: note: m_PrevInput is assigned
 m_LatestInput = m_LatestPrevInput = m_PrevInput = m_Input = m_SavedInput;
                                                 ^
src\game\client\prediction\entities\character.cpp:1148:50: note: m_PrevInput is overwritten
 m_LatestPrevInput = m_LatestInput = m_PrevInput = m_SavedInput = m_Input;
                                                 ^
```
2022-11-29 23:32:29 +01:00
Robert Müller 4197e8d0b0 Fix bool being assigned to float variable
According to cppcheck's `assignBoolToFloat` error:

```
src\game\client\components\menus_settings.cpp:634:13: style: Boolean value assigned to floating point variable. [assignBoolToFloat]
  Highlight = (m_Dummy) ? g_Config.m_ClDummyDefaultEyes == CurrentEyeEmote : g_Config.m_ClPlayerDefaultEyes == CurrentEyeEmote;
            ^
src\game\client\gameclient.cpp:320:23: style: Boolean value assigned to floating point variable. [assignBoolToFloat]
 m_LastDummyConnected = false;
                      ^
src\game\client\gameclient.cpp:563:23: style: Boolean value assigned to floating point variable. [assignBoolToFloat]
 m_LastDummyConnected = false;
                      ^
```
2022-11-29 23:32:28 +01:00
Robert Müller 65aa584b9f Remove redundant conditional expressions
According to cppcheck's `redundantCondition` and `multiCondition` errors:

```
src\engine\client\backend\glsl_shader_compiler.cpp:70:39: style: Redundant condition: The condition '*(pBuff+1)' is redundant since '*(pBuff+1) == 'i'' is sufficient. [redundantCondition]
     if(*pBuff == ' ' && *(pBuff + 1) && *(pBuff + 1) == 'i' && *(pBuff + 2) == 'n')
                                      ^
src\engine\client\backend\glsl_shader_compiler.cpp:98:45: style: Redundant condition: The condition '*(pBuff+1)' is redundant since '*(pBuff+1) == 'u'' is sufficient. [redundantCondition]
      else if(*pBuff == 'o' && *(pBuff + 1) && *(pBuff + 1) == 'u' && *(pBuff + 2) == 't')
                                            ^

src\game\client\gameclient.cpp:1665:62: style: Redundant condition: m_aShowOthers[g_Config.m_ClDummy]!=SHOW_OTHERS_NOT_SET. 'A || (!A && B)' is equivalent to 'A || B' [redundantCondition]
 if(m_aShowOthers[g_Config.m_ClDummy] == SHOW_OTHERS_NOT_SET || (m_aShowOthers[g_Config.m_ClDummy] != SHOW_OTHERS_NOT_SET && m_aShowOthers[g_Config.m_ClDummy] != g_Config.m_ClShowOthers))
                                                             ^

src\game\client\prediction\entities\projectile.cpp:104:34: style: Redundant condition: pTargetChr. '!A || (A && B)' is equivalent to '!A || B' [redundantCondition]
  if(m_Explosive && (!pTargetChr || (pTargetChr && (!m_Freeze || (m_Type == WEAPON_SHOTGUN && Collide)))))
                                 ^

src\engine\client\backend\vulkan\backend_vulkan.cpp:6588:11: style: Expression is always true because 'else if' condition is opposite to previous condition at line 6578. [multiCondition]
  else if(!pCommand->m_ByResize)
          ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6578:14: note: first condition
  if(pCommand->m_ByResize)
             ^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6588:11: note: else if condition is opposite to first condition
  else if(!pCommand->m_ByResize)
          ^
```
2022-11-29 23:32:28 +01:00
Robert Müller ca58bba82f Remove redundant bitwise operand
According to cppcheck's `badBitmaskCheck` error:

```
src\engine\client\client.cpp:422:26: style: Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]
  Packer.AddInt((0 << 1) | (pMsg->m_System ? 1 : 0)); // NETMSG_EX, NETMSGTYPE_EX
                         ^

src\engine\shared\snapshot.cpp:40:45: style: Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]
 int TypeItemIndex = GetItemIndex((0 << 16) | InternalType); // NETOBJTYPE_EX
                                            ^

src\engine\server\server.cpp:777:26: style: Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck]
  Packer.AddInt((0 << 1) | (pMsg->m_System ? 1 : 0)); // NETMSG_EX, NETMSGTYPE_EX
                         ^
```
2022-11-29 23:32:28 +01:00
Robert Müller 45b645f890 Remove assignment of variable to self
According to cppcheck's `selfAssignment` error:

```
src\engine\client\backend\vulkan\backend_vulkan.cpp:5784:23: warning: Redundant assignment of 'DescrSetTextOutline' to itself. [selfAssignment]
  DescrSetTextOutline = DescrSetText;
                      ^
```
2022-11-29 23:32:27 +01:00
Robert Müller 54a13b1c12 Remove check for negative unsigned expression
According to cppcheck's `unsignedLessThanZero` error:

```
src\engine\shared\datafile.cpp:129:13: style: Checking if unsigned expression 'Bytes' is less than zero. [unsignedLessThanZero]
   if(Bytes <= 0)
            ^
```
2022-11-29 23:32:27 +01:00
Robert Müller 8e675878b0 Remove redundant null-checks
According to cppcheck's `nullPointerRedundantCheck` check:

```
src\game\client\components\menus_settings.cpp:729:8: warning: Either the condition 'pSkinToBeSelected==0' is redundant or there is possible null pointer dereference: pSkinToBeSelected. [nullPointerRedundantCheck]
   if((pSkinToBeSelected->GetName()[0] == 'x' && pSkinToBeSelected->GetName()[1] == '_'))
       ^
src\game\client\components\menus_settings.cpp:732:25: note: Assuming that condition 'pSkinToBeSelected==0' is not redundant
   if(pSkinToBeSelected == 0)
                        ^
src\game\client\components\menus_settings.cpp:729:8: note: Null pointer dereference
   if((pSkinToBeSelected->GetName()[0] == 'x' && pSkinToBeSelected->GetName()[1] == '_'))
       ^

src\game\editor\editor.cpp:5034:19: warning: Either the condition 'pEnvelope' is redundant or there is possible null pointer dereference: pEnvelope. [nullPointerRedundantCheck]
  float EndTime = pEnvelope->EndTime();
                  ^
src\game\editor\editor.cpp:5056:7: note: Assuming that condition 'pEnvelope' is not redundant
   if(pEnvelope)
      ^
src\game\editor\editor.cpp:5034:19: note: Null pointer dereference
  float EndTime = pEnvelope->EndTime();
                  ^
src\game\editor\editor.cpp:5038:3: warning: Either the condition 'pEnvelope' is redundant or there is possible null pointer dereference: pEnvelope. [nullPointerRedundantCheck]
  pEnvelope->FindTopBottom(s_ActiveChannels);
  ^
src\game\editor\editor.cpp:5056:7: note: Assuming that condition 'pEnvelope' is not redundant
   if(pEnvelope)
      ^
src\game\editor\editor.cpp:5038:3: note: Null pointer dereference
  pEnvelope->FindTopBottom(s_ActiveChannels);
  ^
src\game\editor\editor.cpp:5039:15: warning: Either the condition 'pEnvelope' is redundant or there is possible null pointer dereference: pEnvelope. [nullPointerRedundantCheck]
  float Top = pEnvelope->m_Top;
              ^
src\game\editor\editor.cpp:5056:7: note: Assuming that condition 'pEnvelope' is not redundant
   if(pEnvelope)
      ^
src\game\editor\editor.cpp:5039:15: note: Null pointer dereference
  float Top = pEnvelope->m_Top;
              ^
src\game\editor\editor.cpp:5040:18: warning: Either the condition 'pEnvelope' is redundant or there is possible null pointer dereference: pEnvelope. [nullPointerRedundantCheck]
  float Bottom = pEnvelope->m_Bottom;
                 ^
src\game\editor\editor.cpp:5056:7: note: Assuming that condition 'pEnvelope' is not redundant
   if(pEnvelope)
      ^
src\game\editor\editor.cpp:5040:18: note: Null pointer dereference
  float Bottom = pEnvelope->m_Bottom;
                 ^
src\game\editor\editor.cpp:5081:23: warning: Either the condition 'pEnvelope' is redundant or there is possible null pointer dereference: pEnvelope. [nullPointerRedundantCheck]
   for(int c = 0; c < pEnvelope->m_Channels; c++)
                      ^
src\game\editor\editor.cpp:5056:7: note: Assuming that condition 'pEnvelope' is not redundant
   if(pEnvelope)
      ^
src\game\editor\editor.cpp:5081:23: note: Null pointer dereference
   for(int c = 0; c < pEnvelope->m_Channels; c++)
                      ^
```
2022-11-29 23:32:27 +01:00
Robert Müller e134e4e488 Remove redundant conditions (always either true or false)
According to cppcheck's `knownConditionTrueFalse` error:

```
src\base\system.cpp:1776:11: style: The comparison 'bytes == 0' is always true. [knownConditionTrueFalse]
 if(bytes == 0 && sock->ipv4sock >= 0)
          ^
src\base\system.cpp:1742:14: note: 'bytes' is assigned value '0' here.
 int bytes = 0;
             ^
src\base\system.cpp:1776:11: note: The comparison 'bytes == 0' is always true.
 if(bytes == 0 && sock->ipv4sock >= 0)
          ^

src\game\editor\io.cpp:887:33: style: Condition 'pSoundsItem->m_Version>=1' is always true [knownConditionTrueFalse]
      if(pSoundsItem->m_Version >= 1)
                                ^
src\game\editor\io.cpp:874:33: note: Assuming that condition 'pSoundsItem->m_Version<1' is not redundant
      if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION)
                                ^
src\game\editor\io.cpp:887:33: note: Condition 'pSoundsItem->m_Version>=1' is always true
      if(pSoundsItem->m_Version >= 1)
                                ^
src\game\editor\io.cpp:914:33: style: Condition 'pSoundsItem->m_Version>=1' is always true [knownConditionTrueFalse]
      if(pSoundsItem->m_Version >= 1)
                                ^
src\game\editor\io.cpp:901:33: note: Assuming that condition 'pSoundsItem->m_Version<1' is not redundant
      if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION)
                                ^
src\game\editor\io.cpp:914:33: note: Condition 'pSoundsItem->m_Version>=1' is always true
      if(pSoundsItem->m_Version >= 1)
                                ^

src\engine\client\backend\opengl\backend_opengl.cpp:207:68: style: Condition '*pStr=='\0'' is always false [knownConditionTrueFalse]
   else if(LastWasNumber && (*pStr == '.' || *pStr == ' ' || *pStr == '\0'))
                                                                   ^

src\game\client\components\maplayers.cpp:851:110: style: Condition 'DoTextureCoords' is always true [knownConditionTrueFalse]
        mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(vec3), vtmpTiles.size() * 4, (DoTextureCoords ? (sizeof(vec2)) : 0));
                                                                                                             ^
src\game\client\components\maplayers.cpp:849:11: note: Assuming that condition 'DoTextureCoords' is not redundant
       if(DoTextureCoords)
          ^

src\game\client\components\maplayers.cpp:851:110: note: Condition 'DoTextureCoords' is always true
        mem_copy_special(pUploadData + sizeof(vec2), pTmpTileTexCoords, sizeof(vec3), vtmpTiles.size() * 4, (DoTextureCoords ? (sizeof(vec2)) : 0));
                                                                                                             ^

src\game\client\prediction\gameworld.cpp:567:5: style: Condition 'm_pParent' is always true [knownConditionTrueFalse]
 if(m_pParent && m_pParent->m_pChild && m_pParent->m_pChild != this)
    ^

src\game\client\components\menu_background.cpp:271:7: style: Condition 'NeedImageLoading' is always true [knownConditionTrueFalse]
   if(NeedImageLoading)
      ^
src\game\client\components\menu_background.cpp:268:23: note: Assignment 'NeedImageLoading=true', assigned value is 1
   NeedImageLoading = true;
                      ^
src\game\client\components\menu_background.cpp:271:7: note: Condition 'NeedImageLoading' is always true
   if(NeedImageLoading)
      ^

src\game\editor\editor.cpp:4991:6: style: Condition 'pEnvelope' is always true [knownConditionTrueFalse]
  if(pEnvelope)
     ^
```
2022-11-29 23:32:26 +01:00
Robert Müller 39749a3ff8 Fix optional arguments of map_create_pixelart tool
According to cppcheck's `knownConditionTrueFalse` error:

```
src\tools\map_create_pixelart.cpp:58:24: style: Condition 'argc>=10' is always true [knownConditionTrueFalse]
 aArtOptions[0] = argc >= 10 ? str_toint(argv[10]) : true; //optimize
                       ^
src\tools\map_create_pixelart.cpp:34:10: note: Assuming that condition 'argc<11' is not redundant
 if(argc < 11 || argc > 12)
         ^
src\tools\map_create_pixelart.cpp:58:24: note: Condition 'argc>=10' is always true
 aArtOptions[0] = argc >= 10 ? str_toint(argv[10]) : true; //optimize
                       ^
src\tools\map_create_pixelart.cpp:59:24: style: Condition 'argc>=11' is always true [knownConditionTrueFalse]
 aArtOptions[1] = argc >= 11 ? str_toint(argv[11]) : false; //centralize
                       ^
src\tools\map_create_pixelart.cpp:34:10: note: Assuming condition 'argc<11' is false
 if(argc < 11 || argc > 12)
         ^
src\tools\map_create_pixelart.cpp:59:24: note: Condition 'argc>=11' is always true
 aArtOptions[1] = argc >= 11 ? str_toint(argv[11]) : false; //centralize
                       ^
```
2022-11-29 23:32:26 +01:00
Robert Müller be74dc9471 Return actual bool from bool function
According to cppcheck's `returnNonBoolInBooleanFunction` error.
2022-11-29 23:32:26 +01:00
Robert Müller fd208eaa1a Remove redundant variable assignments
The assigned values are never used, so the assignments can be removed or variable scopes can be reduced.

According to cppcheck's `unreadVariable` error.
2022-11-29 23:32:26 +01:00
Robert Müller 0a0ddf2145 Pass parameters by const reference instead of value when possible
According to cppcheck's `passedByValue` error.
2022-11-29 23:32:25 +01:00
Robert Müller 78876abd46 Remove unused members CColumn::m_Flags 2022-11-29 23:32:23 +01:00
Robert Müller 554fc19be0 Remove unused member SFontSizeChar::m_TouchTime 2022-11-29 23:28:37 +01:00
Robert Müller 94678ef3a3 Remove unused struct CDatafileData 2022-11-29 23:28:36 +01:00
Robert Müller 2e2cb47674 Fix client crash when launching with screenshot command
The client crashes when launching with `screenshot` in the command line, as the graphics are not available when the command is executed.
This is fixed by storing the command, so it's executed when everything is ready.
2022-11-29 23:08:52 +01:00
Robert Müller e07bd45e27 Fix stored commands using original callback instead of the chain
When stored commands (`CFGFLAG_STORE`) were executed with `CConsole::StoreCommands(false)`, the associated chained commands were not properly executed, if they were chained after the command has been stored (e.g. in `CMenus::OnInit`).
Storing the command saves the current callback and userdata, which were overridden by the chain callback and userdata, but the stored callback and userdata were not updated.
This is fixed by storing a pointer to the command itself, which will be updated when it is chained.

From teeworlds/teeworlds#2572.
2022-11-29 23:06:50 +01:00
Robert Müller 0688355d7b Fix key reader text flashing for one frame, refactoring
The key reader was displaying the old key for a frame. It now shows the new key immediately without flashing the old one after changing a bind.

Refactoring:

- The if-branches are restructured to be the same as on upstream.
- The function `GetKeyBindModifiersName` can be called without an additional check, because it returns an empty string when no modifier is pressed.
- The unused parameter `Checked` of the `DoButton_KeySelect` function is removed.

From teeworlds/teeworlds#2877.
2022-11-29 22:25:47 +01:00
Robert Müller 10433e0c71 Reset teams when restarting round
The state of teams was not reset when restarting a round with `restart`, which led to various issues (#5144):

- Switchers kept their previous state instead of being reset to the initial state after restarting.
- Teams that started racing sometimes could not be joined after restarting.
- Sometimes teams cannot finish a race after restarting. I cannot reproduce this issue, so I don't know if it's fixed by these changes.
2022-11-29 21:56:59 +01:00
bors[bot] d76755db06
Merge #6073
6073: Remove // in ddnet:// url handler r=Jupeyy a=def-

<!-- What is the motivation for the changes of this pull request? -->

<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
2022-11-29 17:21:23 +00:00
Dennis Felsing 9912e44a9a Also remove appended / 2022-11-29 18:18:12 +01:00
Dennis Felsing 3fcf497850 Remove // in ddnet:// url handler 2022-11-29 18:15:09 +01:00
bors[bot] cb5c2c0d02
Merge #6070
6070: Add reason to vote mute, fix vote mute r=def- a=Vy0x2

<!-- What is the motivation for the changes of this pull request? -->
When vote muting a player, the message which notifies the player got send in team chat (should be chat_all) and a second message appeared in rcon. Furthermore you couldnt add a reason to vote mutes.

Fixed those issues.
<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Vy0x2 <denispaul43@gmail.com>
2022-11-28 07:36:59 +00:00
Vy0x2 ce9ad5b603 add reason to vote mutes, fix team chat 2022-11-27 18:58:09 +01:00
bors[bot] d45b84f18c
Merge #6069
6069: Add rust to gitlab CI r=def- a=ChillerDragon



Co-authored-by: ChillerDragon <ChillerDragon@gmail.com>
2022-11-27 09:25:13 +00:00
ChillerDragon c1ddb7af85 Add rust to gitlab CI 2022-11-27 10:20:28 +01:00
bors[bot] 913ccb054e
Merge #6068
6068: Fix client crash when unpacking a sixup packet r=def- a=Robyt3

The client crashes when trying to unpack a packet that has the sixup flag set, as `CNetClient` does not pass pointers for the output parameters `pSecurityToken` and `pResponseToken` to `CNetBase::UnpackPacket`. Since the client does not handle sixup packets, checks are added to return an error and ignore the packet instead of crashing due to a null pointer access.

This was found by fuzzing the data returned by `net_udp_recv` with radamsa.

```
==6200==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f8d0fb8ba56 bp 0x7ffcbf67c7f0 sp 0x7ffcbf67c7a8 T0)
==6200==The signal is caused by a WRITE memory access.
==6200==Hint: address points to the zero page.
    0 0x7f8d0fb8ba56  (/lib/x86_64-linux-gnu/libc.so.6+0xc4a56)
    1 0x563a7e250fbe in mem_copy src/base/system.cpp:208
    2 0x563a7e1bc6b6 in CNetBase::UnpackPacket(unsigned char*, int, CNetPacketConstruct*, bool&, int*, int*) src/engine/shared/network.cpp:263
    3 0x563a7e1bf57e in CNetClient::Recv(CNetChunk*) src/engine/shared/network_client.cpp:100
    4 0x563a7cfa76a2 in CClient::PumpNetwork() src/engine/client/client.cpp:2546
    5 0x563a7cfb7cf6 in CClient::Update() src/engine/client/client.cpp:2838
    6 0x563a7cfcfe47 in CClient::Run() src/engine/client/client.cpp:3214
    7 0x563a7d04c631 in main src/engine/client/client.cpp:4702
    8 0x7f8d0faf0d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    9 0x7f8d0faf0e3f in __libc_start_main_impl ../csu/libc-start.c:392
    10 0x563a7cb28754 in _start (build-asan/DDNet+0x2472754)

==8315==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4accfe5a56 bp 0x7ffcf1318530 sp 0x7ffcf13184e8 T0)
==8315==The signal is caused by a WRITE memory access.
==8315==Hint: address points to the zero page.
    0 0x7f4accfe5a56  (/lib/x86_64-linux-gnu/libc.so.6+0xc4a56)
    1 0x560413603200 in mem_copy src/base/system.cpp:208
    2 0x56041356d9c7 in CNetBase::UnpackPacket(unsigned char*, int, CNetPacketConstruct*, bool&, int*, int*) src/engine/shared/network.cpp:224
    3 0x5604135717c0 in CNetClient::Recv(CNetChunk*) src/engine/shared/network_client.cpp:104
    4 0x5604123597e2 in CClient::PumpNetwork() src/engine/client/client.cpp:2546
    5 0x560412369e36 in CClient::Update() src/engine/client/client.cpp:2838
    6 0x560412381f87 in CClient::Run() src/engine/client/client.cpp:3214
    7 0x5604123fe771 in main src/engine/client/client.cpp:4702
    8 0x7f4accf4ad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    9 0x7f4accf4ae3f in __libc_start_main_impl ../csu/libc-start.c:392
    10 0x560411eda894 in _start (build-asan/DDNet+0x2472894)
```

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [X] Considered possible null pointers and out of bounds array indexing
- [X] Changed no physics that affect existing maps
- [X] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-11-24 22:19:20 +00:00
Robert Müller 0e77be2166 Fix client crash when unpacking a sixup packet
The client crashes when trying to unpack a packet that has the sixup flag set, as `CNetClient` does not pass pointers for the output parameters `pSecurityToken` and `pResponseToken` to `CNetBase::UnpackPacket`.
Since the client does not handle sixup packets, checks are added to return an error and ignore the packet instead of crashing due to a null pointer access.

This was found by fuzzing the data returned by `net_udp_recv` with radamsa.

```
==6200==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f8d0fb8ba56 bp 0x7ffcbf67c7f0 sp 0x7ffcbf67c7a8 T0)
==6200==The signal is caused by a WRITE memory access.
==6200==Hint: address points to the zero page.
    0 0x7f8d0fb8ba56  (/lib/x86_64-linux-gnu/libc.so.6+0xc4a56)
    1 0x563a7e250fbe in mem_copy src/base/system.cpp:208
    2 0x563a7e1bc6b6 in CNetBase::UnpackPacket(unsigned char*, int, CNetPacketConstruct*, bool&, int*, int*) src/engine/shared/network.cpp:263
    3 0x563a7e1bf57e in CNetClient::Recv(CNetChunk*) src/engine/shared/network_client.cpp:100
    4 0x563a7cfa76a2 in CClient::PumpNetwork() src/engine/client/client.cpp:2546
    5 0x563a7cfb7cf6 in CClient::Update() src/engine/client/client.cpp:2838
    6 0x563a7cfcfe47 in CClient::Run() src/engine/client/client.cpp:3214
    7 0x563a7d04c631 in main src/engine/client/client.cpp:4702
    8 0x7f8d0faf0d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    9 0x7f8d0faf0e3f in __libc_start_main_impl ../csu/libc-start.c:392
    10 0x563a7cb28754 in _start (build-asan/DDNet+0x2472754)

==8315==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4accfe5a56 bp 0x7ffcf1318530 sp 0x7ffcf13184e8 T0)
==8315==The signal is caused by a WRITE memory access.
==8315==Hint: address points to the zero page.
    0 0x7f4accfe5a56  (/lib/x86_64-linux-gnu/libc.so.6+0xc4a56)
    1 0x560413603200 in mem_copy src/base/system.cpp:208
    2 0x56041356d9c7 in CNetBase::UnpackPacket(unsigned char*, int, CNetPacketConstruct*, bool&, int*, int*) src/engine/shared/network.cpp:224
    3 0x5604135717c0 in CNetClient::Recv(CNetChunk*) src/engine/shared/network_client.cpp:104
    4 0x5604123597e2 in CClient::PumpNetwork() src/engine/client/client.cpp:2546
    5 0x560412369e36 in CClient::Update() src/engine/client/client.cpp:2838
    6 0x560412381f87 in CClient::Run() src/engine/client/client.cpp:3214
    7 0x5604123fe771 in main src/engine/client/client.cpp:4702
    8 0x7f4accf4ad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    9 0x7f4accf4ae3f in __libc_start_main_impl ../csu/libc-start.c:392
    10 0x560411eda894 in _start (build-asan/DDNet+0x2472894)
```
2022-11-24 21:12:40 +01:00
bors[bot] d94a8ef399
Merge #6067
6067: Implement smooth zoom for editor r=heinrich5991 a=Robyt3

Port the smooth zoom code from the ingame camera to the editor with some minor adjustments.

The smooth zoom animation time can be adjusted with the existing `cl_smooth_zoom_time` config variable.

Closes #2525.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [X] Tested in combination with possibly related configuration options: `cl_smooth_zoom_time`, `cl_limit_max_zoom_level` and `ed_zoom_target`
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-11-23 22:32:12 +00:00
Robert Müller 5e06eefcd2 Implement smooth zoom for editor
Port the smooth zoom code from the ingame camera to the editor with some minor adjustments.

The smooth zoom animation time can be adjusted with the existing `cl_smooth_zoom_time` config variable.

Closes #2525.
2022-11-23 23:06:20 +01:00
bors[bot] 2333f8e353
Merge #6058
6058: Fix invalid demo cutting, Add slice highlighting r=Chairn a=VoxelDoesCode

Before, you could place an end slice before the beginning, creating a "zero second" demo, which doesn't play in client, and renders a corrupt file. I implemented a check where if the playhead is before the beginning slice, it won't place an end slice, and vice versa. 

I also added highlighting in between the slices, so that it's easier to see.
![image](https://user-images.githubusercontent.com/95713843/202870840-216df4d7-975e-496d-b122-c819ce7ae6ee.png)

## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: VoxelDoesCode <bluheadcat@gmail.com>
2022-11-22 10:24:48 +00:00
VoxelDoesCode cc2e40dd90 Reset slice markers if invalid 2022-11-21 20:19:58 -05:00
bors[bot] 7020cbf576
Merge #6064
6064: Fix choppy demo seeking when start/end ticks are very large r=def- a=Robyt3

Demo seeking for percent positions and relative time was choppy, when the first and last ticks of the demo are very large but close together (e.g. with 1308908156 to 1308905658, which are close to integer limit). During the calculation of `WantedTick` both operands were promoted to `float`s, which caused the information of the smaller operand, i.e. the seeked percentage or relative time, to be mostly lost, so seeking was very inaccurate. This is fixed by rounding the `float` operand to `int` before adding it to another `int`.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-11-20 23:34:15 +00:00