8 import qualified Data.IntSet as IntSet |
9 import qualified Data.IntSet as IntSet |
9 import Data.Sequence(Seq, empty) |
10 import Data.Sequence(Seq, empty) |
10 import Data.Time |
11 import Data.Time |
11 import Network |
12 import Network |
12 import Data.Function |
13 import Data.Function |
|
14 import Data.ByteString.Char8 as B |
13 |
15 |
14 import RoomsAndClients |
16 import RoomsAndClients |
15 |
17 |
16 type ClientChan = Chan [String] |
18 type ClientChan = Chan [B.ByteString] |
17 |
19 |
18 data ClientInfo = |
20 data ClientInfo = |
19 ClientInfo |
21 ClientInfo |
20 { |
22 { |
21 sendChan :: ClientChan, |
23 sendChan :: ClientChan, |
22 clientHandle :: Handle, |
24 clientSocket :: Socket, |
23 host :: String, |
25 host :: B.ByteString, |
24 connectTime :: UTCTime, |
26 connectTime :: UTCTime, |
25 nick :: String, |
27 nick :: B.ByteString, |
26 webPassword :: String, |
28 webPassword :: B.ByteString, |
27 logonPassed :: Bool, |
29 logonPassed :: Bool, |
28 clientProto :: !Word16, |
30 clientProto :: !Word16, |
29 roomID :: !Int, |
31 roomID :: !Int, |
30 pingsQueue :: !Word, |
32 pingsQueue :: !Word, |
31 isMaster :: Bool, |
33 isMaster :: Bool, |
32 isReady :: Bool, |
34 isReady :: Bool, |
33 isAdministrator :: Bool, |
35 isAdministrator :: Bool, |
34 clientClan :: String, |
36 clientClan :: B.ByteString, |
35 teamsInGame :: Word |
37 teamsInGame :: Word |
36 } |
38 } |
37 |
39 |
38 instance Show ClientInfo where |
40 instance Show ClientInfo where |
39 show ci = " nick: " ++ (nick ci) ++ " host: " ++ (host ci) |
41 show ci = " nick: " ++ (unpack $ nick ci) ++ " host: " ++ (unpack $ host ci) |
40 |
42 |
41 instance Eq ClientInfo where |
43 instance Eq ClientInfo where |
42 (==) = (==) `on` clientHandle |
44 (==) = (==) `on` clientSocket |
43 |
45 |
44 data HedgehogInfo = |
46 data HedgehogInfo = |
45 HedgehogInfo String String |
47 HedgehogInfo B.ByteString B.ByteString |
46 |
48 |
47 data TeamInfo = |
49 data TeamInfo = |
48 TeamInfo |
50 TeamInfo |
49 { |
51 { |
50 teamownerId :: !Int, |
52 teamownerId :: !Int, |
51 teamowner :: String, |
53 teamowner :: B.ByteString, |
52 teamname :: String, |
54 teamname :: B.ByteString, |
53 teamcolor :: String, |
55 teamcolor :: B.ByteString, |
54 teamgrave :: String, |
56 teamgrave :: B.ByteString, |
55 teamfort :: String, |
57 teamfort :: B.ByteString, |
56 teamvoicepack :: String, |
58 teamvoicepack :: B.ByteString, |
57 teamflag :: String, |
59 teamflag :: B.ByteString, |
58 difficulty :: Int, |
60 difficulty :: Int, |
59 hhnum :: Int, |
61 hhnum :: Int, |
60 hedgehogs :: [HedgehogInfo] |
62 hedgehogs :: [HedgehogInfo] |
61 } |
63 } |
62 |
64 |
63 instance Show TeamInfo where |
65 instance Show TeamInfo where |
64 show ti = "owner: " ++ (teamowner ti) |
66 show ti = "owner: " ++ (unpack $ teamowner ti) |
65 ++ "name: " ++ (teamname ti) |
67 ++ "name: " ++ (unpack $ teamname ti) |
66 ++ "color: " ++ (teamcolor ti) |
68 ++ "color: " ++ (unpack $ teamcolor ti) |
67 |
69 |
68 data RoomInfo = |
70 data RoomInfo = |
69 RoomInfo |
71 RoomInfo |
70 { |
72 { |
71 masterID :: !Int, |
73 masterID :: !Int, |
72 name :: String, |
74 name :: B.ByteString, |
73 password :: String, |
75 password :: B.ByteString, |
74 roomProto :: Word16, |
76 roomProto :: Word16, |
75 teams :: [TeamInfo], |
77 teams :: [TeamInfo], |
76 gameinprogress :: Bool, |
78 gameinprogress :: Bool, |
77 playersIn :: !Int, |
79 playersIn :: !Int, |
78 readyPlayers :: !Int, |
80 readyPlayers :: !Int, |
79 playersIDs :: IntSet.IntSet, |
81 playersIDs :: IntSet.IntSet, |
80 isRestrictedJoins :: Bool, |
82 isRestrictedJoins :: Bool, |
81 isRestrictedTeams :: Bool, |
83 isRestrictedTeams :: Bool, |
82 roundMsgs :: Seq String, |
84 roundMsgs :: Seq B.ByteString, |
83 leftTeams :: [String], |
85 leftTeams :: [B.ByteString], |
84 teamsAtStart :: [TeamInfo], |
86 teamsAtStart :: [TeamInfo], |
85 params :: Map.Map String [String] |
87 params :: Map.Map B.ByteString [B.ByteString] |
86 } |
88 } |
87 |
89 |
88 instance Show RoomInfo where |
90 instance Show RoomInfo where |
89 show ri = ", players ids: " ++ show (IntSet.size $ playersIDs ri) |
91 show ri = ", players ids: " ++ show (IntSet.size $ playersIDs ri) |
90 ++ ", players: " ++ show (playersIn ri) |
92 ++ ", players: " ++ show (playersIn ri) |
121 data ServerInfo = |
123 data ServerInfo = |
122 ServerInfo |
124 ServerInfo |
123 { |
125 { |
124 isDedicated :: Bool, |
126 isDedicated :: Bool, |
125 serverMessage :: String, |
127 serverMessage :: String, |
126 serverMessageForOldVersions :: String, |
128 serverMessageForOldVersions :: B.ByteString, |
127 latestReleaseVersion :: Word16, |
129 latestReleaseVersion :: Word16, |
128 listenPort :: PortNumber, |
130 listenPort :: PortNumber, |
129 nextRoomID :: Int, |
131 nextRoomID :: Int, |
130 dbHost :: String, |
132 dbHost :: B.ByteString, |
131 dbLogin :: String, |
133 dbLogin :: B.ByteString, |
132 dbPassword :: String, |
134 dbPassword :: B.ByteString, |
133 lastLogins :: [(String, UTCTime)], |
135 lastLogins :: [(B.ByteString, UTCTime)], |
134 stats :: TMVar StatisticsInfo, |
136 stats :: TMVar StatisticsInfo, |
135 coreChan :: Chan CoreMessage, |
137 coreChan :: Chan CoreMessage, |
136 dbQueries :: Chan DBQuery |
138 dbQueries :: Chan DBQuery |
137 } |
139 } |
138 |
140 |
153 "" |
155 "" |
154 [] |
156 [] |
155 ) |
157 ) |
156 |
158 |
157 data AccountInfo = |
159 data AccountInfo = |
158 HasAccount String Bool |
160 HasAccount B.ByteString Bool |
159 | Guest |
161 | Guest |
160 | Admin |
162 | Admin |
161 deriving (Show, Read) |
163 deriving (Show, Read) |
162 |
164 |
163 data DBQuery = |
165 data DBQuery = |
164 CheckAccount ClientIndex String String |
166 CheckAccount ClientIndex B.ByteString B.ByteString |
165 | ClearCache |
167 | ClearCache |
166 | SendStats Int Int |
168 | SendStats Int Int |
167 deriving (Show, Read) |
169 deriving (Show, Read) |
168 |
170 |
169 data CoreMessage = |
171 data CoreMessage = |
170 Accept ClientInfo |
172 Accept ClientInfo |
171 | ClientMessage (ClientIndex, [String]) |
173 | ClientMessage (ClientIndex, [B.ByteString]) |
172 | ClientAccountInfo (ClientIndex, AccountInfo) |
174 | ClientAccountInfo (ClientIndex, AccountInfo) |
173 | TimerAction Int |
175 | TimerAction Int |
174 | FreeClient ClientIndex |
176 | FreeClient ClientIndex |
175 |
177 |
176 type MRnC = MRoomsAndClients RoomInfo ClientInfo |
178 type MRnC = MRoomsAndClients RoomInfo ClientInfo |