返回提交历史
Modified
src/managers/sessionManager.ts
+40
-8
XFEstudio/XFESpaceNinjaServer
feat: parse legacy sessionUpdate format (#3611)
Closes #3600 Closes #3605 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3611 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
00f8f92d
代码差异
1 个文件
+40
-8
@@ -85,17 +85,49 @@ function getSessionByCreatorID(creatorId: string | Types.ObjectId): ISession | u
85
85
return sessions.find(session => session.creatorId.equals(creatorId));
86
86
}
87
87
88
function updateSession(sessionId: string | Types.ObjectId, sessionData: string): boolean {
89
logger.debug(`session update: ${sessionData}`);
88
function updateSession(sessionId: string | Types.ObjectId, updateData: string): boolean {
89
logger.debug(`session update: ${updateData}`);
90
90
const session = sessions.find(session => session.sessionId.equals(sessionId));
91
if (!session) return false;
92
try {
93
Object.assign(session, JSONParse(sessionData));
94
return true;
95
} catch (error) {
96
logger.error("Invalid JSON string for session update.");
91
if (!session) {
97
92
return false;
98
93
}
94
if (updateData.substring(0, 1) == "{") {
95
try {
96
Object.assign(session, JSONParse(updateData));
97
} catch (error) {
98
logger.error("Invalid JSON string for session update.");
99
return false;
100
}
101
} else {
102
const updates: string[] = updateData.split("&");
103
for (const update of updates) {
104
const arr = update.split("=");
105
if (arr.length == 2) {
106
const [key, value] = arr;
107
switch (key) {
108
case "maxPlayers":
109
case "minPlayers":
110
case "privateSlots":
111
case "scoreLimit":
112
case "timeLimit":
113
case "gameModeId":
114
case "eloRating":
115
case "regionId":
116
case "difficulty":
117
case "freePublic":
118
case "freePrivate":
119
session[key] = parseInt(value);
120
break;
121
122
default:
123
logger.error(`unexpected key in legacy session update format: ${key}`);
124
break;
125
}
126
}
127
}
128
}
129
//logger.debug(`session after update:`, session);
130
return true;
99
131
}
100
132
101
133
function deleteSession(sessionId: string | Types.ObjectId): boolean {