Implement proper user renaming + broadcast new name upon receiving a Hello message in a connected state

This commit is contained in:
Tissevert 2020-02-02 19:23:24 +01:00
parent 07a81237b6
commit 465c6981ae

View file

@ -15,7 +15,7 @@ import qualified Messaging (
broadcast, get, notifyPlayers, relay, send, sendTo broadcast, get, notifyPlayers, relay, send, sendTo
) )
import qualified Player (T(..)) 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) import qualified Session (Status, T(..), setPlayer)
receive :: Message.FromClient -> Session.Status -> App.T () receive :: Message.FromClient -> Session.Status -> App.T ()
@ -29,9 +29,11 @@ receive (Message.Hello {Message.name}) Nothing = do
Messaging.broadcast $ Message.LogIn playerID name Messaging.broadcast $ Message.LogIn playerID name
receive (Message.Hello {Message.name}) (Just player) = do receive (Message.Hello {Message.name}) (Just player) = do
sessionID <- asks App.sessionID sessionIDs <- (! playerID) <$> App.get Server.sessionIDsByPlayerID
App.update (Server.update sessionID setName) App.update (\server -> foldr (flip Server.update setName) server sessionIDs)
Messaging.broadcast $ Message.LogIn playerID name
where where
playerID = Player.playerID player
setName session = session {Session.player = Just $ player {Player.name}} setName session = session {Session.player = Just $ player {Player.name}}
receive (Message.Tadaima {Message.myID, Message.name}) Nothing = do receive (Message.Tadaima {Message.myID, Message.name}) Nothing = do