author | unc0rr |
Thu, 03 Mar 2011 22:15:13 +0300 | |
changeset 4975 | 31da8979e5b1 |
parent 4622 | 8bdc879ee6b2 |
child 4989 | 4771fed9272e |
permissions | -rw-r--r-- |
3458 | 1 |
module ServerState |
2 |
( |
|
3 |
module RoomsAndClients, |
|
4 |
clientRoomA, |
|
5 |
ServerState(..), |
|
3501 | 6 |
client's, |
3502 | 7 |
allClientsS, |
4601 | 8 |
roomClientsS, |
9 |
io |
|
3458 | 10 |
) where |
11 |
||
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
12 |
import Control.Monad.State.Strict |
3566 | 13 |
import Data.Set as Set |
3458 | 14 |
---------------------- |
15 |
import RoomsAndClients |
|
16 |
import CoreTypes |
|
17 |
||
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
18 |
data ServerState c = ServerState { |
3807 | 19 |
clientIndex :: !(Maybe ClientIndex), |
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
20 |
serverInfo :: !(ServerInfo c), |
3807 | 21 |
removedClients :: !(Set.Set ClientIndex), |
22 |
roomsClients :: !MRnC |
|
3458 | 23 |
} |
24 |
||
25 |
||
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
26 |
clientRoomA :: StateT (ServerState c) IO RoomIndex |
3458 | 27 |
clientRoomA = do |
28 |
(Just ci) <- gets clientIndex |
|
29 |
rnc <- gets roomsClients |
|
4622 | 30 |
io $ clientRoomM rnc ci |
3458 | 31 |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
32 |
client's :: (ClientInfo -> a) -> StateT (ServerState c) IO a |
3501 | 33 |
client's f = do |
3458 | 34 |
(Just ci) <- gets clientIndex |
35 |
rnc <- gets roomsClients |
|
4622 | 36 |
io $ client'sM rnc f ci |
3645 | 37 |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
38 |
allClientsS :: StateT (ServerState c) IO [ClientInfo] |
3502 | 39 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
40 |
||
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
41 |
roomClientsS :: RoomIndex -> StateT (ServerState c) IO [ClientInfo] |
3502 | 42 |
roomClientsS ri = do |
43 |
rnc <- gets roomsClients |
|
4622 | 44 |
io $ roomClientsM rnc ri |
4601 | 45 |
|
4975
31da8979e5b1
Use Data.TConfig to read and store server config in hedgewars.ini (a little bit of hate to the author for not exporting Conf type)
unc0rr
parents:
4622
diff
changeset
|
46 |
io :: IO a -> StateT (ServerState c) IO a |
4601 | 47 |
io = liftIO |