steamutils 1.5.12 → 1.5.14
Sign up to get free protection for your applications and to get access to all the features.
- package/SteamClient.js +3129 -3142
- package/package.json +5 -5
- package/remote.js +2249 -2249
- package/utils.js +69 -0
package/utils.js
CHANGED
@@ -1148,3 +1148,72 @@ export function logNow(...msg) {
|
|
1148
1148
|
const formattedDate = `${fmt(localDate.getUTCDate())}/${fmt(localDate.getUTCMonth() + 1)}/${localDate.getUTCFullYear()} ${fmt(localDate.getUTCHours())}:${fmt(localDate.getUTCMinutes())}:${fmt(localDate.getUTCSeconds())}`;
|
1149
1149
|
console.log(`[${formattedDate}]`, ...msg);
|
1150
1150
|
}
|
1151
|
+
|
1152
|
+
export function formatFriendState(data) {
|
1153
|
+
if (!data) {
|
1154
|
+
return;
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
function formatUndefined(value) {
|
1158
|
+
if (value === "" || value === null || value === undefined || (typeof value === "number" && isNaN(value))) {
|
1159
|
+
return null;
|
1160
|
+
}
|
1161
|
+
return value;
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
const { player_name, gameid, persona_state, rich_presence = [] } = data;
|
1165
|
+
const avatar_hash = data.avatar_hash ? (typeof data.avatar_hash === "string" ? data.avatar_hash : Buffer.from(data.avatar_hash).toString("hex")) : "fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb";
|
1166
|
+
|
1167
|
+
let onlineStatus = "offline";
|
1168
|
+
let score = "";
|
1169
|
+
const scoreDetails = rich_presence.find((r) => r.key === "game:score")?.value;
|
1170
|
+
const mode = rich_presence.find((r) => r.key === "game:mode")?.value;
|
1171
|
+
const map = rich_presence.find((r) => r.key === "game:map")?.value;
|
1172
|
+
const numPlayers = formatUndefined(parseInt(rich_presence.find((r) => r.key === "members:numPlayers")?.value)); //include this friend, 2,3,4,5
|
1173
|
+
const steam_player_group = formatUndefined(parseInt(rich_presence.find?.((r) => r.key === "steam_player_group")?.value));
|
1174
|
+
const steam_player_group_size = formatUndefined(parseInt(rich_presence.find?.((r) => r.key === "steam_player_group_size")?.value));
|
1175
|
+
|
1176
|
+
if (gameid !== null && gameid !== undefined && gameid !== "") {
|
1177
|
+
if (gameid === 0 || gameid === "0") {
|
1178
|
+
if ([1, 2, 3, 4].includes(persona_state)) {
|
1179
|
+
onlineStatus = "online";
|
1180
|
+
} else if (persona_state === 0) {
|
1181
|
+
onlineStatus = "offline";
|
1182
|
+
} else {
|
1183
|
+
// console.log(data)
|
1184
|
+
onlineStatus = "online";
|
1185
|
+
}
|
1186
|
+
} else {
|
1187
|
+
onlineStatus = "ingame";
|
1188
|
+
}
|
1189
|
+
|
1190
|
+
if (rich_presence.some((r) => r.key === "game:state" && r.value === "lobby")) {
|
1191
|
+
score = data.rich_presence_string || "In Lobby";
|
1192
|
+
} else {
|
1193
|
+
score = rich_presence.find?.((r) => r.key === "status")?.value || data.rich_presence_string || "";
|
1194
|
+
}
|
1195
|
+
if (score === "not found") {
|
1196
|
+
score = "";
|
1197
|
+
}
|
1198
|
+
if (score.startsWith("Premier") && !score.startsWith("Premier Competitive") && data.rich_presence_string?.startsWith("Premier Competitive")) {
|
1199
|
+
score = data.rich_presence_string;
|
1200
|
+
}
|
1201
|
+
} else if (persona_state === null && rich_presence.length === 0) {
|
1202
|
+
onlineStatus = "offline";
|
1203
|
+
}
|
1204
|
+
|
1205
|
+
return {
|
1206
|
+
onlineStatus,
|
1207
|
+
score: formatUndefined(score),
|
1208
|
+
scoreDetails: formatUndefined(scoreDetails),
|
1209
|
+
mode: formatUndefined(mode),
|
1210
|
+
map: formatUndefined(map),
|
1211
|
+
player_name,
|
1212
|
+
gameid: formatUndefined(parseInt(gameid)),
|
1213
|
+
numPlayers,
|
1214
|
+
steam_player_group,
|
1215
|
+
steam_player_group_size,
|
1216
|
+
avatar_hash,
|
1217
|
+
rich_presence,
|
1218
|
+
};
|
1219
|
+
}
|