mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-05-09 04:23:01 -05:00
Merge 8cbe8b6b8e into 530765fc12
This commit is contained in:
commit
ad030d70e3
|
|
@ -207,6 +207,7 @@ export class PSConnection {
|
|||
|
||||
static connect() {
|
||||
if (PS.connection?.socket) return;
|
||||
if (PS.connection?.connected) return; // already connected via worker, don't call doAutojoin on live session
|
||||
PS.isOffline = false;
|
||||
if (!PS.connection) {
|
||||
PS.connection = new PSConnection();
|
||||
|
|
|
|||
|
|
@ -614,6 +614,7 @@ class PSUser extends PSStreamModel<PSLoginState | null> {
|
|||
avatar = "lucas";
|
||||
challstr = '';
|
||||
loggingIn: string | null = null;
|
||||
loginKey = 0;
|
||||
initializing = true;
|
||||
gapiLoaded = false;
|
||||
nameRegExp: RegExp | null = null;
|
||||
|
|
@ -674,16 +675,19 @@ class PSUser extends PSStreamModel<PSLoginState | null> {
|
|||
this.update({ success: true });
|
||||
return;
|
||||
}
|
||||
const key = ++this.loginKey;
|
||||
this.loggingIn = name;
|
||||
this.update(null);
|
||||
PSLoginServer.rawQuery(
|
||||
'getassertion', { userid, challstr: this.challstr }
|
||||
).then(res => {
|
||||
if (this.loginKey !== key) return;
|
||||
this.handleAssertion(name, res);
|
||||
this.updateRegExp();
|
||||
});
|
||||
}
|
||||
changeNameWithPassword(name: string, password: string, special: PSLoginState = { needsPassword: true }) {
|
||||
const key = ++this.loginKey;
|
||||
this.loggingIn = name;
|
||||
if (!password && !special) {
|
||||
this.updateLogin({
|
||||
|
|
@ -696,6 +700,7 @@ class PSUser extends PSStreamModel<PSLoginState | null> {
|
|||
PSLoginServer.query(
|
||||
'login', { name, pass: password, challstr: this.challstr }
|
||||
).then(data => {
|
||||
if (this.loginKey !== key) return;
|
||||
this.loggingIn = null;
|
||||
if (data?.curuser?.loggedin) {
|
||||
// success!
|
||||
|
|
@ -1228,8 +1233,8 @@ export class PSRoom extends PSStreamModel<Args | null> implements RoomOptions {
|
|||
return this.errorReply(`You are already connected.`);
|
||||
}
|
||||
|
||||
if (!PS.isOffline) {
|
||||
// connect to room
|
||||
if (!PS.isOffline && PS.connection?.connected) {
|
||||
// server connection is active; attempt room-level reconnection
|
||||
try {
|
||||
this.connect();
|
||||
} catch (err: any) {
|
||||
|
|
|
|||
|
|
@ -177,11 +177,11 @@ export class ChatRoom extends PSRoom {
|
|||
} else {
|
||||
let lines = msg.split('\n');
|
||||
|
||||
// cut off starting lines until we get to PS.lastMessage timestamp
|
||||
// cut off starting lines until we get to this room's last message timestamp
|
||||
// then cut off roomintro from the end
|
||||
let cutOffStart = 0;
|
||||
let cutOffEnd = lines.length;
|
||||
const cutOffTime = parseInt(PS.lastMessageTime);
|
||||
const cutOffTime = (this.lastMessage?.[0] === 'c:') ? parseInt(this.lastMessage[1]) : 0;
|
||||
const cutOffExactLine = this.lastMessage ? '|' + this.lastMessage?.join('|') : '';
|
||||
let reconnectMessage = '|raw|<div class="infobox">You reconnected.</div>';
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
|
|
@ -192,7 +192,7 @@ export class ChatRoom extends PSRoom {
|
|||
cutOffStart = i + 1;
|
||||
} else if (lines[i].startsWith(`|c:|`)) {
|
||||
const time = parseInt(lines[i].split('|')[2] || '');
|
||||
if (time < cutOffTime) cutOffStart = i;
|
||||
if (time < cutOffTime) cutOffStart = i + 1;
|
||||
}
|
||||
if (lines[i].startsWith('|raw|<div class="infobox"> You joined ')) {
|
||||
reconnectMessage = `|raw|<div class="infobox">You reconnected to ${lines[i].slice(38)}`;
|
||||
|
|
@ -200,14 +200,6 @@ export class ChatRoom extends PSRoom {
|
|||
if (!lines[i - 1]) cutOffEnd = i - 1;
|
||||
}
|
||||
}
|
||||
console.log("Reconnection log splice:");
|
||||
console.log([
|
||||
...lines.slice(0, cutOffStart),
|
||||
'====================',
|
||||
...lines.slice(cutOffStart, cutOffEnd),
|
||||
'====================',
|
||||
...lines.slice(cutOffEnd),
|
||||
].join('\n'));
|
||||
lines = lines.slice(cutOffStart, cutOffEnd);
|
||||
|
||||
if (lines.length) {
|
||||
|
|
|
|||
|
|
@ -125,9 +125,12 @@ export class MainMenuRoom extends PSRoom {
|
|||
case 'challstr': {
|
||||
const [, challstr] = args;
|
||||
PS.user.challstr = challstr;
|
||||
PS.user.loginKey++; // stale callbacks check this key and early-return if it no longer matches
|
||||
const upkeepKey = PS.user.loginKey;
|
||||
PSLoginServer.query(
|
||||
'upkeep', { challstr }
|
||||
).then(res => {
|
||||
if (PS.user.loginKey !== upkeepKey) return;
|
||||
if (!res?.username) {
|
||||
PS.user.initializing = false;
|
||||
return;
|
||||
|
|
@ -137,13 +140,15 @@ export class MainMenuRoom extends PSRoom {
|
|||
if (res.loggedin) {
|
||||
PS.user.registered = { name: res.username, userid: toID(res.username) };
|
||||
}
|
||||
PS.user.handleAssertion(res.username, res.assertion);
|
||||
// preserve current nick on reconnect rather than reverting to registered name
|
||||
const nameToUse = PS.user.named ? PS.user.name : res.username;
|
||||
PS.user.handleAssertion(nameToUse, res.assertion);
|
||||
});
|
||||
return;
|
||||
} case 'updateuser': {
|
||||
const [, fullName, namedCode, avatar] = args;
|
||||
const named = namedCode === '1';
|
||||
if (named) PS.user.initializing = false;
|
||||
PS.user.initializing = false;
|
||||
PS.user.setName(fullName, named, avatar);
|
||||
PS.teams.loadRemoteTeams();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user