netserver/HWProto.hs
changeset 1396 abb28dcb6d0d
parent 1391 735f6d43780b
child 1401 2087672a2114
equal deleted inserted replaced
1395:46fd70de89e2 1396:abb28dcb6d0d
    60 	if null (room client) then
    60 	if null (room client) then
    61 		(noChangeClients, noChangeRooms, answerQuit)
    61 		(noChangeClients, noChangeRooms, answerQuit)
    62 	else if isMaster client then
    62 	else if isMaster client then
    63 		(noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
    63 		(noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
    64 	else
    64 	else
    65 		(noChangeClients, modifyRoom clRoom{teams = othersTeams}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
    65 		(noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
    66 	where
    66 	where
    67 		clRoom = roomByName (room client) rooms
    67 		clRoom = roomByName (room client) rooms
    68 		answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams
    68 		answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams
    69 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
    69 		(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
    70 
    70 
   105 
   105 
   106 
   106 
   107 -- 'noRoom' clients state command handlers
   107 -- 'noRoom' clients state command handlers
   108 handleCmd_noRoom :: CmdHandler
   108 handleCmd_noRoom :: CmdHandler
   109 handleCmd_noRoom client _ rooms ["LIST"] =
   109 handleCmd_noRoom client _ rooms ["LIST"] =
   110 		(noChangeClients, noChangeRooms, answerServerMessage ++ (answerRoomsList $ map name rooms))
   110 		(noChangeClients, noChangeRooms, answerServerMessage ++ (answerRoomsList $ concat $ map roomInfo rooms))
       
   111 		where
       
   112 			roomInfo room = [name room, show $ playersIn room, show $ gameinprogress room]
   111 
   113 
   112 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] =
   114 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] =
   113 	if (not $ isDedicated globalOptions) && (not $ null rooms) then
   115 	if (not $ isDedicated globalOptions) && (not $ null rooms) then
   114 		(noChangeClients, noChangeRooms, answerCannotCreateRoom)
   116 		(noChangeClients, noChangeRooms, answerCannotCreateRoom)
   115 	else
   117 	else
   127 	if noSuchRoom then
   129 	if noSuchRoom then
   128 		(noChangeClients, noChangeRooms, answerNoRoom)
   130 		(noChangeClients, noChangeRooms, answerNoRoom)
   129 	else if roomPassword /= password clRoom then
   131 	else if roomPassword /= password clRoom then
   130 		(noChangeClients, noChangeRooms, answerWrongPassword)
   132 		(noChangeClients, noChangeRooms, answerWrongPassword)
   131 	else
   133 	else
   132 		(modifyClient client{room = roomName}, noChangeRooms, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
   134 		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
   133 	where
   135 	where
   134 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
   136 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
   135 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
   137 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
   136 		clRoom = roomByName roomName rooms
   138 		clRoom = roomByName roomName rooms
   137 
   139