|
1 module Utils where |
|
2 |
|
3 import Control.Concurrent |
|
4 import Control.Concurrent.STM |
|
5 import Data.Char |
|
6 import Data.Word |
|
7 import qualified Data.Map as Map |
|
8 import qualified Data.IntMap as IntMap |
|
9 ------------------------------------------------- |
|
10 import qualified Codec.Binary.Base64 as Base64 |
|
11 import qualified Codec.Binary.UTF8.String as UTF8 |
|
12 import CoreTypes |
|
13 |
|
14 toEngineMsg :: String -> String |
|
15 toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg)) |
|
16 |
|
17 --tselect :: [ClientInfo] -> STM ([String], ClientInfo) |
|
18 --tselect = foldl orElse retry . map (\ci -> (flip (,) ci) `fmap` readTChan (chan ci)) |
|
19 |
|
20 maybeRead :: Read a => String -> Maybe a |
|
21 maybeRead s = case reads s of |
|
22 [(x, rest)] | all isSpace rest -> Just x |
|
23 _ -> Nothing |
|
24 |
|
25 teamToNet team = [ |
|
26 "ADD_TEAM", |
|
27 teamname team, |
|
28 teamgrave team, |
|
29 teamfort team, |
|
30 teamvoicepack team, |
|
31 teamowner team, |
|
32 show $ difficulty team |
|
33 ] |
|
34 ++ hhsInfo |
|
35 where |
|
36 hhsInfo = concatMap (\(HedgehogInfo name hat) -> [name, hat]) $ hedgehogs team |
|
37 |
|
38 modifyTeam :: TeamInfo -> RoomInfo -> RoomInfo |
|
39 modifyTeam team room = room{teams = replaceTeam team $ teams room} |
|
40 where |
|
41 replaceTeam _ [] = error "modifyTeam: no such team" |
|
42 replaceTeam team (t:teams) = |
|
43 if teamname team == teamname t then |
|
44 team : teams |
|
45 else |
|
46 t : replaceTeam team teams |
|
47 |
|
48 protoNumber2ver :: Word16 -> String |
|
49 protoNumber2ver 17 = "0.9.7-dev" |
|
50 protoNumber2ver 19 = "0.9.7" |
|
51 protoNumber2ver 20 = "0.9.8-dev" |
|
52 protoNumber2ver 21 = "0.9.8" |
|
53 protoNumber2ver 22 = "0.9.9-dev" |
|
54 protoNumber2ver 23 = "0.9.9" |
|
55 protoNumber2ver 24 = "0.9.10-dev" |
|
56 protoNumber2ver 25 = "0.9.10" |
|
57 protoNumber2ver _ = "Unknown" |
|
58 |