Skip to content

Commit

Permalink
hotfix: Check username loaded from save.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Reder committed Jun 4, 2018
1 parent a9cf522 commit 6ee33f8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "net64plus",
"version": "2.0.2",
"version": "2.0.3",
"compatVersion": "1.0.0",
"description": "Net64+ client",
"main": "index.js",
Expand Down Expand Up @@ -56,7 +56,7 @@
"dompurify": "^1.0.4",
"electron": "1.8",
"history": "^4.7.2",
"immer": "^0.8.1",
"immer": "^1.3.1",
"marked": "^0.4.0",
"node-emoji": "^1.8.1",
"protobufjs": "^6.8.4",
Expand Down
6 changes: 0 additions & 6 deletions src/declarations/immer.d.ts

This file was deleted.

11 changes: 6 additions & 5 deletions src/models/State.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export interface ChatStateDraft {
}
export type ChatState = Readonly<ChatStateDraft>

export interface State {
readonly save: SaveState
readonly router: RouterState
readonly connection: ConnectionState
readonly chat: ChatState
export interface StateDraft {
save: SaveState
router: RouterState
connection: ConnectionState
chat: ChatState
}
export type State = Readonly<StateDraft>
4 changes: 2 additions & 2 deletions src/renderer/components/views/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ interface SettingsViewState {
warning: string
}

const MIN_LENGTH_USERNAME = 3
const MAX_LENGTH_USERNAME = 24
export const MIN_LENGTH_USERNAME = 3
export const MAX_LENGTH_USERNAME = 24

class View extends React.PureComponent<SettingsViewProps, SettingsViewState> {
constructor (public props: SettingsViewProps) {
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createStore, applyMiddleware, combineReducers, Store, ReducersMapObject } from 'redux'
import { routerMiddleware, RouterState } from 'react-router-redux'
import { History } from 'history'
import produce from 'immer'

import { save } from './save'
import { router } from './router'
import { connection } from './connection'
import { chat } from './chat'
import { State, SaveState, ElectronSaveData } from '../../models/State.model'
import { MIN_LENGTH_USERNAME, MAX_LENGTH_USERNAME } from '../components/views/SettingsView'
import { State, SaveState, ElectronSaveData, StateDraft } from '../../models/State.model'

export let initialState: State

Expand All @@ -21,7 +23,15 @@ const APP_SAVE_DATA: ElectronSaveData = {
}

export function initReducer (history: History, electronSave: SaveState): Store<State> {
const appSaveData: ElectronSaveData = Object.assign({}, APP_SAVE_DATA, electronSave.appSaveData)
let appSaveData: ElectronSaveData = Object.assign({}, APP_SAVE_DATA, electronSave.appSaveData)
const username = appSaveData.username.replace(/\W/g, '')
if (
username !== appSaveData.username ||
username.length < MIN_LENGTH_USERNAME ||
username.length > MAX_LENGTH_USERNAME
) {
appSaveData = Object.assign({}, APP_SAVE_DATA)
}
const appSavePath: string = electronSave.appSavePath || ''
initialState = {
save: {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/utils/chat.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as marked from 'marked'
import { emojify } from 'node-emoji'

import { store } from '..'
import { MAX_LENGTH_USERNAME } from '../components/views/SettingsView'
import { addGlobalChatMessage, clearGlobalChatMessages } from '../actions/chat'
import { ChatMessage } from '../../models/State.model'

Expand All @@ -14,7 +15,7 @@ export function addGlobalMessage (message: string, username: string) {
key: date.getUTCMilliseconds(),
time: `${String(date.getHours()).padStart(2, '00')}:${String(date.getMinutes()).padStart(2, '00')}:${String(date.getSeconds()).padStart(2, '00')}`,
message: sanitizedMessage,
username
username: sanitize(username).substr(0, MAX_LENGTH_USERNAME)
}
store.dispatch(addGlobalChatMessage(chatMessage))
}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3740,9 +3740,9 @@ ignore@^3.0.11, ignore@^3.0.9, ignore@^3.2.0, ignore@^3.3.3, ignore@^3.3.6:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"

immer@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/immer/-/immer-0.8.1.tgz#44d7d0779947da32eb34314addaac5a82c9ec5ad"
immer@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/immer/-/immer-1.3.1.tgz#3a8c18d9d618c8b7169760a79beec24a1da6a43e"

import-local@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit 6ee33f8

Please sign in to comment.