From 465c6981ae9907e268ce587cab6c0e4fb938490e Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sun, 2 Feb 2020 19:23:24 +0100 Subject: [PATCH] Implement proper user renaming + broadcast new name upon receiving a Hello message in a connected state --- src/Automaton.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Automaton.hs b/src/Automaton.hs index 3153bc4..bc2b360 100644 --- a/src/Automaton.hs +++ b/src/Automaton.hs @@ -15,7 +15,7 @@ import qualified Messaging ( broadcast, get, notifyPlayers, relay, send, sendTo ) import qualified Player (T(..)) -import qualified Server (logIn, register, room, update) +import qualified Server (T(..), logIn, register, room, update) import qualified Session (Status, T(..), setPlayer) receive :: Message.FromClient -> Session.Status -> App.T () @@ -29,9 +29,11 @@ receive (Message.Hello {Message.name}) Nothing = do Messaging.broadcast $ Message.LogIn playerID name receive (Message.Hello {Message.name}) (Just player) = do - sessionID <- asks App.sessionID - App.update (Server.update sessionID setName) + sessionIDs <- (! playerID) <$> App.get Server.sessionIDsByPlayerID + App.update (\server -> foldr (flip Server.update setName) server sessionIDs) + Messaging.broadcast $ Message.LogIn playerID name where + playerID = Player.playerID player setName session = session {Session.player = Just $ player {Player.name}} receive (Message.Tadaima {Message.myID, Message.name}) Nothing = do