Skip to content

Commit

Permalink
fix: check server session when login/refresh and disconnect - fix #83
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru committed Sep 30, 2024
1 parent 45428d7 commit 6465628
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions app/server/src/system/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ export const sessions = () => {

const $checkSessions = async () => {
const currentSessions = Object.keys(sessionMap);
const targetSessions = await getServerSessionList();
const targetSessions = (await getServerSessionList()).map<string>(
({ key: [, accountId] }) => accountId,
);
console.log(
`Checking sessions... (${currentSessions.length}..${targetSessions.length})`,
);

const toDeleteSessions = currentSessions.filter(
(accountId) => !targetSessions.includes(accountId),
);

//remove not active sessions
for (const accountId of toDeleteSessions) {
$disconnectFromLastServer(accountId, sessionMap[accountId].server);
delete sessionMap[accountId];
}

const accountCheckList = [
...new Set([
...currentSessions,
...targetSessions.map<string>(({ key: [, accountId] }) => accountId),
]),
];
...new Set([...currentSessions, ...targetSessions]),
].filter((accountId) => toDeleteSessions.includes(accountId));

//check accounts
for (const accountId of accountCheckList) checkAccountSession(accountId);
Expand All @@ -50,8 +59,6 @@ export const sessions = () => {
"serverSessionByAccount",
accountId,
]);
//check if is server claimed the session
const isFoundSessionClaimed = foundSession?.value?.claimed;
const session = sessionMap[accountId];

console.warn(
Expand All @@ -63,15 +70,6 @@ export const sessions = () => {
"<<<<",
);

//if account has no active session or old session
if (!isFoundSessionClaimed && !session) return;

//account is disconnected, disconnect from last server
if (!isFoundSessionClaimed) {
$disconnectFromLastServer(accountId, session.server);
return;
}

const currentSession = foundSession.value;

//check if session server exists and changed if so disconnect from last server
Expand Down

0 comments on commit 6465628

Please sign in to comment.