Skip to content

Commit

Permalink
Fixed settings DIR and FLAGS not sending a full client update, minor …
Browse files Browse the repository at this point in the history
…change to client update packet.
  • Loading branch information
cbnolok committed Oct 13, 2024
1 parent e194ba7 commit 621c62d
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 58 deletions.
27 changes: 27 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ constexpr T sign(const T n) noexcept
#define maximum(x,y) ((x)>(y)?(x):(y)) // NOT to be used with functions! Store the result of the function in a variable first, otherwise the function will be executed twice!
#define medium(x,y,z) ((x)>(y)?(x):((z)<(y)?(z):(y))) // NOT to be used with functions! Store the result of the function in a variable first, otherwise the function will be executed twice!

template <typename T>
[[nodiscard]]
constexpr T saturating_sub(T a, T b) noexcept {
// Saturating subtraction.

// Ensure T is an arithmetic type
static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type");

// For unsigned types
if constexpr (std::is_unsigned_v<T>)
return (a > b) ? a - b : 0;
// For signed types
else
{
if (b > 0 && a < std::numeric_limits<T>::min() + b)
return std::numeric_limits<T>::min(); // Saturate to minimum
return a - b;
}
}

#define SATURATING_SUB_SELF(var, val) var = saturating_sub(var, val)

/* End of arithmetic code */

Expand Down Expand Up @@ -197,6 +218,12 @@ constexpr void UnreferencedParameter(T const&) noexcept {
#define FALLTHROUGH [[fallthrough]]
#define NODISCARD [[nodiscard]]

#if defined(__GNUC__) || defined(__clang__)
# define RETURNS_NOTNULL [[gnu::returns_nonnull]]
#else
# define RETURNS_NOTNULL
#endif

#ifdef _DEBUG
#define NOEXCEPT_NODEBUG
#else
Expand Down
6 changes: 3 additions & 3 deletions src/common/resource/sections/CSkillDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ bool CSkillDef::r_LoadVal( CScript &s )
m_vcDelay.Load( s.GetArgStr());
break;
case SKC_FLAGS:
m_dwFlags = s.GetArgVal();
m_dwFlags = s.GetArgDWVal();
break;
case SKC_GROUP:
m_dwGroup = s.GetArgVal();
m_dwGroup = s.GetArgDWVal();
break;
case SKC_EFFECT:
m_vcEffect.Load( s.GetArgStr());
Expand Down Expand Up @@ -246,4 +246,4 @@ bool CSkillDef::r_LoadVal( CScript &s )
EXC_ADD_SCRIPT;
EXC_DEBUG_END;
return false;
}
}
14 changes: 11 additions & 3 deletions src/common/sphere_library/CSObjList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,26 @@ CSObjListRec * CSObjList::GetContentAt( size_t index ) const
void CSObjList::ClearContainer()
{
// delete all entries.
bool fSuccess = false;
EXC_TRY("Deleting objects scheduled for deletion");
for (;;) // iterate the list.
{
CSObjListRec * pRec = GetContainerHead();
if ( pRec == nullptr )
break;
if ( pRec == nullptr ) {
fSuccess = true;
break;
}
ASSERT( pRec->GetParent() == this );
delete pRec;
}
EXC_CATCH;

m_uiCount = 0;
if (fSuccess) {
ASSERT(m_uiCount == 0);
}
else {
m_uiCount = 0;
}
m_pHead = nullptr;
m_pTail = nullptr;
}
Expand Down
6 changes: 4 additions & 2 deletions src/game/CObjBaseTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ class CObjBaseTemplate : public CSObjContRec
virtual int IsWeird() const;

// Parent objects
virtual const CObjBaseTemplate* GetTopLevelObj() const {
[[nodiscard]] RETURNS_NOTNULL
virtual const CObjBaseTemplate* GetTopLevelObj() const {
return this;
}
virtual CObjBaseTemplate* GetTopLevelObj() {
[[nodiscard]] RETURNS_NOTNULL
virtual CObjBaseTemplate* GetTopLevelObj() {
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/CSector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool CSector::r_LoadVal( CScript &s )
SetWeatherChance( false, s.HasArgs() ? s.GetArgVal() : -1 );
return true;
case SC_FLAGS:
m_dwFlags = s.GetArgVal();
m_dwFlags = s.GetArgDWVal();
return true;
case SC_LIGHT:
if ( g_Cfg.m_fAllowLightOverride )
Expand Down
3 changes: 2 additions & 1 deletion src/game/CServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,8 @@ void CServer::_OnTick()
EXC_TRY("Tick");

#ifndef _WIN32
if (g_UnixTerminal.isReady())
// This happens on T_Main, and not on T_UnixTerm.
if (g_UnixTerminal.isReady())
{
tchar c = g_UnixTerminal.read();
if ( OnConsoleKey(m_sConsoleText, c, false) == 2 )
Expand Down
21 changes: 14 additions & 7 deletions src/game/chars/CChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ void CChar::SetID( CREID_TYPE id )
if ( pHand )
GetPackSafe()->ContentAdd(pHand);
}
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
}


Expand Down Expand Up @@ -3828,7 +3828,6 @@ bool CChar::r_LoadVal( CScript & s )
DIR_TYPE dir = static_cast<DIR_TYPE>(s.GetArgVal());
if (dir <= DIR_INVALID || dir >= DIR_QTY)
dir = DIR_SE;
m_dirFace = dir;
UpdateDir( dir );
}
break;
Expand Down Expand Up @@ -3856,8 +3855,16 @@ bool CChar::r_LoadVal( CScript & s )
break;
}
// Don't modify STATF_SAVEPARITY, STATF_PET, STATF_SPAWNED here
_uiStatFlag = (_uiStatFlag & (STATF_SAVEPARITY | STATF_PET | STATF_SPAWNED)) | (s.GetArgLLVal() & ~(STATF_SAVEPARITY | STATF_PET | STATF_SPAWNED));
NotoSave_Update();
static constexpr auto uiFlagsNoChange = (STATF_SAVEPARITY | STATF_PET | STATF_SPAWNED);
static constexpr auto uiFlagsRequireFullUpdate = (STATF_STONE | STATF_HIDDEN | STATF_DEAD);
const auto uiCurFlags = _uiStatFlag;
const auto uiNewFlags = s.GetArgULLVal();
_uiStatFlag = (_uiStatFlag & uiFlagsNoChange) | (uiNewFlags & ~uiFlagsNoChange);
if (uiCurFlags != uiNewFlags)
{
const bool fDoFullUpdate = (uiCurFlags & uiFlagsRequireFullUpdate) != (uiNewFlags & uiFlagsRequireFullUpdate);
NotoSave_Update(fDoFullUpdate);
}
break;
}
case CHC_FONT:
Expand Down Expand Up @@ -4010,7 +4017,7 @@ bool CChar::r_LoadVal( CScript & s )
StatFlag_Mod(STATF_STONE,fSet);
if ( fChange )
{
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
if ( IsClientActive() )
m_pClient->addCharMove(this);
}
Expand Down Expand Up @@ -4636,7 +4643,7 @@ bool CChar::r_Verb( CScript &s, CTextConsole * pSrc ) // Execute command from sc
if ( pSrc )
{
_uiStatFlag = s.GetArgLLFlag( _uiStatFlag, STATF_INSUBSTANTIAL );
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
if ( IsStatFlag(STATF_INSUBSTANTIAL) )
{
if ( IsClientActive() )
Expand Down Expand Up @@ -4923,7 +4930,7 @@ bool CChar::r_Verb( CScript &s, CTextConsole * pSrc ) // Execute command from sc
if ( ! IsPlayableCharacter())
return false;
SetHue( GetHue() ^ HUE_UNDERWEAR /*, false, pSrc*/ ); //call @Dye on underwear?
UpdateMode();
UpdateMode(true, nullptr);
break;
case CHV_UNEQUIP: // uid
return ItemBounce( CUID::ItemFindFromUID(s.GetArgVal()) );
Expand Down
12 changes: 8 additions & 4 deletions src/game/chars/CChar.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,10 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
bool IsVerticalSpace( const CPointMap& ptDest, bool fForceMount = false ) const;

public:
virtual CObjBaseTemplate* GetTopLevelObj() override;
virtual const CObjBaseTemplate* GetTopLevelObj() const override;
[[nodiscard]] RETURNS_NOTNULL
virtual CObjBaseTemplate* GetTopLevelObj() override;
[[nodiscard]] RETURNS_NOTNULL
virtual const CObjBaseTemplate* GetTopLevelObj() const override;

bool IsSwimming() const;
bool MoveToRegion(CRegionWorld* pNewArea, bool fAllowReject);
Expand Down Expand Up @@ -555,7 +557,7 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;
ANIM_TYPE GenerateAnimate(ANIM_TYPE action, bool fTranslate = true, bool fBackward = false, byte iFrameDelay = 0, byte iAnimLen = 7);
bool UpdateAnimate(ANIM_TYPE action, bool fTranslate = true, bool fBackward = false, byte iFrameDelay = 0, byte iAnimLen = 7);

void UpdateMode( CClient * pExcludeClient = nullptr, bool fFull= false );
void UpdateMode( bool fFull, CClient * pExcludeClient = nullptr);
void UpdateSpeedMode();
void UpdateVisualRange();
void UpdateMove( const CPointMap & ptOld, CClient * pClientExclude = nullptr, bool bFull = false );
Expand Down Expand Up @@ -821,8 +823,10 @@ public: void StatFlag_Mod(uint64 uiStatFlag, bool fMod) noexcept;

/**
* @brief Clearing notoriety and update myself so everyone checks my noto again.
*
* @param fCharFullUpdate Should it do a full character entity update instead of a partial one?
*/
void NotoSave_Update();
void NotoSave_Update(bool fCharFullUpdate = false);

/**
* @brief Deleting myself and sending data again for given char.
Expand Down
14 changes: 6 additions & 8 deletions src/game/chars/CCharAct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ bool CChar::UpdateAnimate(ANIM_TYPE action, bool fTranslate, bool fBackward , by

// If character status has been changed
// (Polymorph, war mode or hide), resend him
void CChar::UpdateMode( CClient * pExcludeClient, bool fFull )
void CChar::UpdateMode( bool fFull, CClient * pExcludeClient )
{
ADDTOCALLSTACK("CChar::UpdateMode");

Expand Down Expand Up @@ -3524,7 +3524,7 @@ bool CChar::Reveal( uint64 iFlags )
return false;

m_StepStealth = 0;
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
SysMessageDefault(DEFMSG_HIDING_REVEALED);
return true;
}
Expand Down Expand Up @@ -4222,8 +4222,6 @@ bool CChar::SetPoison( int iSkill, int iHits, CChar * pCharSrc )
}
}



CClient *pClient = GetClientActive();
if ( pClient && IsSetOF(OF_Buffs) )
{
Expand Down Expand Up @@ -4253,7 +4251,7 @@ void CChar::Wake()

RaiseCorpse(pCorpse);
StatFlag_Clear(STATF_SLEEPING);
UpdateMode();
UpdateMode(false, nullptr);
}

// Sleep
Expand All @@ -4277,7 +4275,7 @@ void CChar::SleepStart( bool fFrontFall )
SetID(_iPrev_id);
StatFlag_Set(STATF_SLEEPING);
StatFlag_Clear(STATF_HIDDEN);
UpdateMode();
UpdateMode(false, nullptr);
}

// We died, calling @Death, removing trade windows.
Expand Down Expand Up @@ -4406,7 +4404,7 @@ CChar::DeathRequestResult CChar::Death()
if ( m_pNPC->m_bonded )
{
m_CanMask |= CAN_C_GHOST;
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
return DeathRequestResult::Success;
}

Expand Down Expand Up @@ -5686,7 +5684,7 @@ void CChar::OnTickStatusUpdate()

if ( m_fStatusUpdate & SU_UPDATE_MODE )
{
UpdateMode();
UpdateMode(false, nullptr);
m_fStatusUpdate &= ~SU_UPDATE_MODE;
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/chars/CCharNotoriety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,13 @@ void CChar::NotoSave_Clear()
m_notoSaves.clear();
}

void CChar::NotoSave_Update()
void CChar::NotoSave_Update(bool fCharFullUpdate)
{
//ADDTOCALLSTACK_DEBUG("CChar::NotoSave_Update");
EXC_TRY("NotoSave_Update");

NotoSave_Clear();
UpdateMode();
UpdateMode(fCharFullUpdate, nullptr);
UpdatePropertyFlag();

EXC_CATCH;
Expand Down
2 changes: 1 addition & 1 deletion src/game/chars/CCharSkill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ int CChar::Skill_Hiding( SKTRIG_TYPE stage )
ObjMessage(g_Cfg.GetDefaultMsg(DEFMSG_HIDING_SUCCESS), this);
StatFlag_Set(STATF_HIDDEN);
Reveal(STATF_INVISIBLE); // clear previous invisibility spell effect (this will not reveal the char because STATF_HIDDEN still set)
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
if ( IsClientActive() )
{
GetClientActive()->removeBuff( BI_HIDDEN );
Expand Down
6 changes: 3 additions & 3 deletions src/game/chars/CCharSpell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void CChar::Spell_Effect_Remove(CItem * pSpell)

case LAYER_SPELL_Paralyze:
StatFlag_Clear(STATF_FREEZE);
UpdateMode(); // immediately tell the client that now he's able to move (without this, it will be able to move only on next tick update)
UpdateMode(false, nullptr); // immediately tell the client that now he's able to move (without this, it will be able to move only on next tick update)
if (pClient)
pClient->removeBuff(BI_PARALYZE);
return;
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
StatFlag_Set(STATF_INVISIBLE);
Reveal(STATF_HIDDEN); // clear previous Hiding skill effect (this will not reveal the char because STATF_Invisibility still set)
UpdateModeFlag();
UpdateMode(nullptr, true);
UpdateMode(true, nullptr);
if (pClient && IsSetOF(OF_Buffs))
{
pClient->removeBuff(BI_INVISIBILITY);
Expand All @@ -1192,7 +1192,7 @@ void CChar::Spell_Effect_Add( CItem * pSpell )
return;
case LAYER_SPELL_Paralyze:
StatFlag_Set(STATF_FREEZE);
UpdateMode();
UpdateMode(false, nullptr);
if (pClient && IsSetOF(OF_Buffs))
{
pClient->removeBuff(BI_PARALYZE);
Expand Down
5 changes: 3 additions & 2 deletions src/game/chars/CCharStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,14 @@ int CChar::GetStatPercent(STAT_TYPE i) const
return IMulDiv(Stat_GetVal(i), 100, maxval);
}


[[nodiscard]] RETURNS_NOTNULL
const CObjBaseTemplate* CChar::GetTopLevelObj() const
{
// Get the object that has a location in the world. (Ground level)
return this;
}

[[nodiscard]] RETURNS_NOTNULL
CObjBaseTemplate* CChar::GetTopLevelObj()
{
// Get the object that has a location in the world. (Ground level)
Expand Down Expand Up @@ -692,7 +693,7 @@ byte CChar::GetModeFlag( const CClient *pViewer ) const
iFlags |= STATF_INVISIBLE;

if ( IsStatFlag(iFlags) ) // Checking if I have any of these settings enabled on the ini and I have any of them, if so ... CHARMODE_INVIS is set and color applied.
mode |= CHARMODE_INVIS; //When sending CHARMODE_INVIS state to client, your character anim are grey
mode |= CHARMODE_INVIS; //When sending CHARMODE_INVIS state to client, your character anim are grey

return mode;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/clients/CClientEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ void CClient::Event_CombatMode( bool fWar ) // Only for switching to combat mode
}

addPlayerWarMode();
m_pChar->UpdateMode( this, m_pChar->IsStatFlag( STATF_DEAD ));
m_pChar->UpdateMode(m_pChar->IsStatFlag(STATF_DEAD), this);
}

bool CClient::Event_Command(lpctstr pszCommand, TALKMODE_TYPE mode)
Expand Down
Loading

0 comments on commit 621c62d

Please sign in to comment.