Skip to content

Commit

Permalink
Fix client crash caused by the server sending too many quests
Browse files Browse the repository at this point in the history
The server still allows the client to accept as many as it wants since auto-accept quests would be tricky to handle otherwise, but it will only send up to 25. If the client has accepted more than 25 and slots are freed, we move the quests that have too high of an index to these slots.
  • Loading branch information
bm01 committed Jul 31, 2024
1 parent be5fb59 commit 7a9627a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 12 deletions.
48 changes: 42 additions & 6 deletions GameServer/packets/Server/PacketLib168.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,18 +1539,54 @@ static CheckLosResponseHandler.TimeoutTimer CreateTimer((ushort sourceObjectId,

public virtual void SendQuestListUpdate()
{
HashSet<byte> sentIndexes = new();
// Send up to 25 quests.
byte questIndex;
HashSet<byte> sentIndexes = [];
HashSet<AbstractQuest> questsWithTooHighIndex = null;

foreach (var entry in m_gameClient.Player.QuestList)
{
SendQuestPacket(entry.Key, entry.Value);
sentIndexes.Add(entry.Value);
questIndex = entry.Value;

if (questIndex < 25)
{
SendQuestPacket(entry.Key, questIndex);
sentIndexes.Add(questIndex);
}
else
{
if (questsWithTooHighIndex == null)
questsWithTooHighIndex = [];

questsWithTooHighIndex.Add(entry.Key);
}
}

// If possible, move and send quests which indexes are too high.
if (questsWithTooHighIndex != null)
{
questIndex = 0;

foreach (AbstractQuest questWithTooHighIndex in questsWithTooHighIndex)
{
for ( ; questIndex < 25; questIndex++)
{
if (sentIndexes.Contains(questIndex))
continue;

m_gameClient.Player.QuestList[questWithTooHighIndex] = questIndex;
SendQuestPacket(questWithTooHighIndex, questIndex);
sentIndexes.Add(questIndex);
break;
}
}
}

for (byte i = 0; i < 25; i++)
// Send null for unused indexes.
for (questIndex = 0; questIndex < 25; questIndex++)
{
if (!sentIndexes.Contains(i))
SendQuestPacket(null, i);
if (!sentIndexes.Contains(questIndex))
SendQuestPacket(null, questIndex);
}
}

Expand Down
46 changes: 40 additions & 6 deletions GameServer/packets/Server/PacketLib173.cs
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,53 @@ public override void SendQuestListUpdate()
SendTaskInfo();

byte questIndex;
HashSet<byte> sentIndexes = new();
HashSet<byte> sentIndexes = [];
HashSet<AbstractQuest> questsWithTooHighIndex = null;

// Send up to 25 quests.
foreach (var entry in m_gameClient.Player.QuestList)
{
questIndex = (byte) (entry.Value + 1);
SendQuestPacket(entry.Key, questIndex);
sentIndexes.Add(questIndex);

if (questIndex < 26)
{
SendQuestPacket(entry.Key, questIndex);
sentIndexes.Add(questIndex);
}
else
{
if (questsWithTooHighIndex == null)
questsWithTooHighIndex = [];

questsWithTooHighIndex.Add(entry.Key);
}
}

// If possible, move and send quests which indexes are too high.
if (questsWithTooHighIndex != null)
{
questIndex = 1;

foreach (AbstractQuest questWithTooHighIndex in questsWithTooHighIndex)
{
for ( ; questIndex < 26; questIndex++)
{
if (sentIndexes.Contains(questIndex))
continue;

m_gameClient.Player.QuestList[questWithTooHighIndex] = questIndex;
SendQuestPacket(questWithTooHighIndex, questIndex);
sentIndexes.Add(questIndex);
break;
}
}
}

for (byte i = 1; i < 26; i++)
// Send null for unused indexes.
for (questIndex = 1; questIndex < 26; questIndex++)
{
if (!sentIndexes.Contains(i))
SendQuestPacket(null, i);
if (!sentIndexes.Contains(questIndex))
SendQuestPacket(null, questIndex);
}
}

Expand Down

0 comments on commit 7a9627a

Please sign in to comment.