Skip to content

Commit

Permalink
Fixed a critical bug in background save mechanism where an unsaved of…
Browse files Browse the repository at this point in the history
…fline player character disappears from worldsave when moved to an already saved sector.
  • Loading branch information
ares committed Oct 8, 2016
1 parent 8fd7592 commit d66893b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/graysvr/CCharact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3511,7 +3511,7 @@ bool CChar::MoveToChar(CPointMap pt, bool bForceFix)

// We cannot put this char in non-disconnect state.
SetDisconnected();
pSector->m_Chars_Disconnect.InsertHead(this);
pSector->MoveDisconnectedCharToSector(this);
SetUnkPoint(pt);
return true;
}
Expand Down
46 changes: 38 additions & 8 deletions src/graysvr/CSector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,16 +798,15 @@ void CSector::MoveItemToSector( CItem * pItem, bool fActive )
}
}

bool CSector::MoveCharToSector( CChar * pChar )
{
ADDTOCALLSTACK("CSector::MoveCharToSector");
// Move a CChar into this CSector.
// ASSUME: called from CChar.MoveToChar() assume ACtive char.

if ( IsCharActiveIn(pChar) )
return false; // already here
void CSector::CheckSaveParity(CChar* pChar)
{
ADDTOCALLSTACK("CSector::CheckSaveParity");
// NOTE:
// pChar is not yet added to any charlist of this sector
// ASSUME: called from CSector.MoveCharToSector() or CSector.MoveDisconnectedCharToSector().

// Check my save parity vs. this sector's
// Check my save parity vs. this sector's and save out if not saved yet
if ( pChar->IsStatFlag( STATF_SaveParity ) != m_fSaveParity )
{
if ( g_World.IsSaving())
Expand All @@ -827,8 +826,39 @@ bool CSector::MoveCharToSector( CChar * pChar )
}
}
}
}

bool CSector::MoveCharToSector(CChar * pChar)
{
ADDTOCALLSTACK("CSector::MoveCharToSector");
// Move a CChar into this CSector.
// NOTE:
// m_pt is still the old location. Not moved yet!
// ASSUME: called from CChar.MoveToChar() assume Active char.

if (IsCharActiveIn(pChar))
return false; // already here

CheckSaveParity(pChar);

m_Chars_Active.AddCharToSector(pChar); // remove from previous spot.
return(true);
}

bool CSector::MoveDisconnectedCharToSector(CChar * pChar)
{
ADDTOCALLSTACK("CSector::MoveDisconnectedCharToSector");
// Move a CChar into this CSector.
// NOTE:
// m_pt is still the old location. Not moved yet!
// ASSUME: called from CChar.MoveToChar() assume disconnected char.

if (IsCharDisconnectedIn(pChar))
return false; // already here

CheckSaveParity(pChar);

m_Chars_Disconnect.InsertHead(pChar); // remove from previous spot.
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/graysvr/CWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ class CSector : public CScriptObj, public CSectorBase // square region of the wo
m_Chars_Active.ClientDetach();
}
bool MoveCharToSector( CChar * pChar );
bool MoveDisconnectedCharToSector(CChar * pChar);
private:
void CheckSaveParity(CChar* pChar);

public:
// General.
virtual bool r_LoadVal( CScript & s );
virtual bool r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc );
Expand Down

0 comments on commit d66893b

Please sign in to comment.