Implement proper user renaming + broadcast new name upon receiving a Hello message in a connected state
This commit is contained in:
parent
07a81237b6
commit
465c6981ae
1 changed files with 5 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue