Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong token and sessionID saved when game saves #72

Closed
moonysolari opened this issue Jan 8, 2023 · 0 comments
Closed

Wrong token and sessionID saved when game saves #72

moonysolari opened this issue Jan 8, 2023 · 0 comments
Assignees
Labels
bug Something isn't working! saves Related to saving and loading.

Comments

@moonysolari
Copy link
Member

moonysolari commented Jan 8, 2023

Describe the bug

When /authentication/api/userchannel/ProfileService/UpdateUserSaveFileTable is accessed, the client sends not just one, but an entire list of metadata of multiple saves. This is currently handled by always taking the last item from the list and using its token and sessionID to save the current session. However, this is not always correct, as the list is not sorted with respect to the timestamp.

To reproduce

  • Add log(LogLevel.DEBUG, JSON.stringify(req.body.clientSaveFileList)) at the start of the function that handles the request (attached below).
  • Compile and run Peacock. Start the game with it.
  • Start any mission with saves enabled.
  • Try saving the game at different save slots and observe the output.

Additional context

Peacock version v5.6.2.

A possible solution is to sort the list with respect to the timestamp and use the token and sessionID of the latest save.

profileRouter.post(
"/ProfileService/UpdateUserSaveFileTable",
jsonMiddleware(),
async (req, res) => {
if (req.body.clientSaveFileList.length > 0) {
const save =
req.body.clientSaveFileList[
req.body.clientSaveFileList.length - 1
]
try {
await saveSession(
save.ContractSessionId,
save.Value.LastEventToken,
)
} catch (e) {
log(
LogLevel.WARN,
`Unable to save session ${save?.ContractSessionId}`,
)
if (PEACOCK_DEV) {
log(LogLevel.DEBUG, e.name)
}
}
}
res.status(204).end()
},
)

Sample output in chronological order (tested on The Finishing Line):
Saving in save slot 1 caused the client to send the following SaveFile list

[
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215743,
      "Value":{
         "Name":"QuickSave0",
         "LastEventToken":"598708361135300"
      }
   }
]

After that, saving in save slot 2 caused the client to send the following SaveFile list

[
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215743,
      "Value":{
         "Name":"QuickSave0",
         "LastEventToken":"598708361135300"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215837,
      "Value":{
         "Name":"QuickSave1",
         "LastEventToken":"598800038190100"
      }
   }
]

After that, saving in save slot 3 caused the client to send the following SaveFile list

[
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215743,
      "Value":{
         "Name":"QuickSave0",
         "LastEventToken":"598708361135300"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215837,
      "Value":{
         "Name":"QuickSave1",
         "LastEventToken":"598800038190100"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215872,
      "Value":{
         "Name":"QuickSave2",
         "LastEventToken":"598800038190100"
      }
   }
]

After that, saving in save slot 1 caused the client to send the following SaveFile list (note that the latest save is in QuickSave0 according to the timestamp!)

[
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215905,
      "Value":{
         "Name":"QuickSave0",
         "LastEventToken":"598865889955100"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215837,
      "Value":{
         "Name":"QuickSave1",
         "LastEventToken":"598800038190100"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215872,
      "Value":{
         "Name":"QuickSave2",
         "LastEventToken":"598800038190100"
      }
   }
]

After that, an autosave caused the client to send the following SaveFile list (note that the latest save is in AutoSave 3 according to the timestamp!)

[
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673216128,
      "Value":{
         "Name":"AutoSave3",
         "LastEventToken":"599092639570600"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215905,
      "Value":{
         "Name":"QuickSave0",
         "LastEventToken":"598865889955100"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215837,
      "Value":{
         "Name":"QuickSave1",
         "LastEventToken":"598800038190100"
      }
   },
   {
      "ContractSessionId":"598676657372700-0b3af383-2f2c-4a2a-a13e-7b687dd37a97",
      "TimeStamp":1673215872,
      "Value":{
         "Name":"QuickSave2",
         "LastEventToken":"598800038190100"
      }
   }
]
@moonysolari moonysolari added bug Something isn't working! saves Related to saving and loading. labels Jan 8, 2023
@moonysolari moonysolari changed the title Wrong token and sessionID saved when user saves game Wrong token and sessionID saved when game saves Jan 8, 2023
@moonysolari moonysolari self-assigned this Jan 8, 2023
@moonysolari moonysolari moved this from Todo to In Progress in Fix saving & loading, once and for all Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working! saves Related to saving and loading.
Projects
No open projects
Development

No branches or pull requests

1 participant