Skip to content

Commit

Permalink
Merge pull request #735 from Roguelike-Celebration/fix-entry-dc-crashes
Browse files Browse the repository at this point in the history
Fix entry dc crashes
  • Loading branch information
MoyTW authored Oct 22, 2022
2 parents c3c5fff + 69c4e6c commit 1ee6ff0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,15 @@ export const ConnectAction =
(
roomId: string,
roomData: { [roomId: string]: Room },
presenceData?: { [roomId: string]: string[] },
roomNotes?: RoomNote[]
): Thunk<Action, State> =>
async (dispatch, getState) => {
await getState().messageArchiveLoaded.promise
dispatch(UpdatedCurrentRoomAction(roomId, roomData))
if (presenceData) {
dispatch(UpdatedPresenceAction(presenceData))
}
if (roomNotes) {
dispatch(NoteUpdateRoomAction(roomId, roomNotes))
}
Expand Down
3 changes: 1 addition & 2 deletions src/networking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export async function connect (
ConnectAction(
result.roomId,
convertServerRoomData(result.roomData),
result.presenceData,
result.roomNotes
)
)
Expand All @@ -89,8 +90,6 @@ export async function connect (
dispatch(UpdateUnlockableBadgesAction(result.unlockableBadges))
}

dispatch(UpdatedPresenceAction(result.presenceData))

const hubConnection = await connectSignalR(userId, dispatch)
if (hubConnection.state !== SignalR.HubConnectionState.Connected) {
throw Error('SignalR connection could not be established!')
Expand Down
41 changes: 23 additions & 18 deletions src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,17 @@ export default produce((draft: State, action: Action) => {

if (action.type === ActionType.PlayerDisconnected) {
const roomData = draft.roomData[draft.roomId]
roomData.users = roomData.users.filter((u) => u !== action.value)
addMessage(
draft,
createDisconnectedMessage(
action.value,
draft.roomId,
roomData.users.length
if (roomData && roomData.users) {
roomData.users = roomData.users.filter((u) => u !== action.value)
addMessage(
draft,
createDisconnectedMessage(
action.value,
draft.roomId,
roomData.users.length
)
)
)
}
}

if (action.type === ActionType.PlayerEntered) {
Expand All @@ -278,17 +280,20 @@ export default produce((draft: State, action: Action) => {

if (action.type === ActionType.PlayerLeft) {
const roomData = draft.roomData[draft.roomId]
roomData.users = roomData.users.filter((u) => u !== action.value.name)
addMessage(
draft,
createLeftMessage(
action.value.name,
action.value.toId,
action.value.toName,
draft.roomId,
roomData.users.length
// You can get messages for players leaving before your loading finishes - hence the ignore guard here.
if (roomData && roomData.users) {
roomData.users = roomData.users.filter((u) => u !== action.value.name)
addMessage(
draft,
createLeftMessage(
action.value.name,
action.value.toId,
action.value.toName,
draft.roomId,
roomData.users.length
)
)
)
}
}

if (action.type === ActionType.ChatMessage) {
Expand Down

0 comments on commit 1ee6ff0

Please sign in to comment.