diff --git a/play.pokemonshowdown.com/src/client-connection.ts b/play.pokemonshowdown.com/src/client-connection.ts index 503db7f15f..7557b38d23 100644 --- a/play.pokemonshowdown.com/src/client-connection.ts +++ b/play.pokemonshowdown.com/src/client-connection.ts @@ -208,12 +208,15 @@ export class PSConnection { static connect() { if (PS.connection?.socket) return; PS.isOffline = false; + const isReconnecting = !!PS.connection; if (!PS.connection) { PS.connection = new PSConnection(); } else { PS.connection.reconnect(); } - PS.prefs.doAutojoin(); + if (!isReconnecting) { + PS.prefs.doAutojoin(); + } } } diff --git a/play.pokemonshowdown.com/src/panel-chat.tsx b/play.pokemonshowdown.com/src/panel-chat.tsx index 4869a7bc97..5a26158d32 100644 --- a/play.pokemonshowdown.com/src/panel-chat.tsx +++ b/play.pokemonshowdown.com/src/panel-chat.tsx @@ -176,24 +176,22 @@ export class ChatRoom extends PSRoom { } else { let lines = msg.split('\n'); - // cut off starting lines until we get to PS.lastMessage timestamp - // then cut off roomintro from the end let cutOffStart = 0; let cutOffEnd = lines.length; const cutOffTime = parseInt(PS.lastMessageTime); const cutOffExactLine = this.lastMessage ? '|' + this.lastMessage?.join('|') : ''; let reconnectMessage = '|raw|
You reconnected.
'; + let hasJoinMessage = false; for (let i = 0; i < lines.length; i++) { if (lines[i].startsWith('|users|')) { this.add(lines[i]); - } - if (lines[i] === cutOffExactLine) { 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|
You joined ')) { + hasJoinMessage = true; reconnectMessage = `|raw|
You reconnected to ${lines[i].slice(38)}`; cutOffEnd = i; if (!lines[i - 1]) cutOffEnd = i - 1; @@ -201,10 +199,14 @@ export class ChatRoom extends PSRoom { } lines = lines.slice(cutOffStart, cutOffEnd); - if (lines.length) { - this.receiveLine([`raw`, `
You disconnected.
`]); - for (const line of lines) this.receiveLine(BattleTextParser.parseLine(line)); - this.receiveLine(BattleTextParser.parseLine(reconnectMessage)); + if (lines.length || hasJoinMessage) { + if (lines.length) { + this.receiveLine([`raw`, `
You disconnected.
`]); + for (const line of lines) this.receiveLine(BattleTextParser.parseLine(line)); + } + if (hasJoinMessage) { + this.receiveLine(BattleTextParser.parseLine(reconnectMessage)); + } } this.update(null); return true; diff --git a/play.pokemonshowdown.com/src/panel-mainmenu.tsx b/play.pokemonshowdown.com/src/panel-mainmenu.tsx index 297fa05ee8..cbfbb52269 100644 --- a/play.pokemonshowdown.com/src/panel-mainmenu.tsx +++ b/play.pokemonshowdown.com/src/panel-mainmenu.tsx @@ -132,11 +132,14 @@ export class MainMenuRoom extends PSRoom { PS.user.initializing = false; return; } - // | , ; are not valid characters in names res.username = res.username.replace(/[|,;]+/g, ''); if (res.loggedin) { PS.user.registered = { name: res.username, userid: toID(res.username) }; } + if (PS.user.named && PS.user.userid !== toID(res.username)) { + PS.user.initializing = false; + return; + } PS.user.handleAssertion(res.username, res.assertion); }); return;