Take game ID with turn into a GameState sub-structure shared between private and public parts to prevent replay-attack

This commit is contained in:
Tissevert 2020-01-13 08:29:40 +01:00
parent 413d6cfc84
commit 509a5c453f

View file

@ -7,6 +7,7 @@
module Hanafuda.Message (
T(..)
, FromClient(..)
, GameState(..)
, PrivateState(..)
, PublicGame(..)
, PublicPlayer(..)
@ -139,8 +140,18 @@ instance FromJSON Hanafuda.Flower
instance ToJSON Hanafuda.Flower where
toEncoding = genericToEncoding defaultOptions
data GameState = GameState {
gameID :: GameID
, turns :: Int
} deriving (Eq, Generic, Show)
instance FromJSON GameState
instance ToJSON GameState where
toEncoding = genericToEncoding defaultOptions
data PrivateState = PrivateState {
hands :: Map PlayerID Hanafuda.Pack
link :: GameState
, hands :: Map PlayerID Hanafuda.Pack
, deck :: [Hanafuda.Card]
} deriving Generic
@ -158,7 +169,8 @@ instance ToJSON PublicPlayer where
toEncoding = genericToEncoding defaultOptions
data PublicState = PublicState {
mode :: KoiKoi.Mode
gameState :: GameState
, mode :: KoiKoi.Mode
, scores :: KoiKoi.Scores
, month :: Hanafuda.Flower
, nextPlayer :: KoiKoi.PlayerTurn
@ -169,7 +181,6 @@ data PublicState = PublicState {
, river :: Hanafuda.Pack
, step :: KoiKoi.Step
, trick :: [Hanafuda.Card]
, turns :: Int
, rounds :: [(PlayerID, KoiKoi.Score)]
} deriving (Generic, Show)
@ -184,8 +195,7 @@ instance ToJSON ByteString where
toEncoding = toEncoding . decodeUtf8 . B64.encode
data PublicGame = PublicGame {
gameID :: GameID
, nonce :: ByteString
nonce :: ByteString
, playerHand :: Hanafuda.Pack
, private :: ByteString
, public :: PublicState