author | unc0rr |
Sun, 22 Mar 2009 21:03:59 +0000 | |
changeset 1912 | c3d31fb59f0e |
parent 1847 | 2178c0fc838c |
child 1921 | 2a09f7f786a0 |
permissions | -rw-r--r-- |
1804 | 1 |
module CoreTypes where |
2 |
||
3 |
import System.IO |
|
4 |
import Control.Concurrent.Chan |
|
5 |
import Control.Concurrent.STM |
|
6 |
import Data.Word |
|
7 |
import qualified Data.Map as Map |
|
8 |
import qualified Data.IntMap as IntMap |
|
9 |
import qualified Data.IntSet as IntSet |
|
10 |
import Data.Sequence(Seq, empty) |
|
11 |
import Network |
|
12 |
||
1833 | 13 |
|
1804 | 14 |
data ClientInfo = |
15 |
ClientInfo |
|
16 |
{ |
|
17 |
clientUID :: Int, |
|
18 |
sendChan :: Chan [String], |
|
19 |
clientHandle :: Handle, |
|
20 |
host :: String, |
|
21 |
nick :: String, |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
22 |
webPassword :: String, |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
23 |
logonPassed :: Bool, |
1804 | 24 |
clientProto :: Word16, |
25 |
roomID :: Int, |
|
26 |
isMaster :: Bool, |
|
27 |
isReady :: Bool, |
|
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
28 |
isAdministrator :: Bool, |
1804 | 29 |
forceQuit :: Bool, |
30 |
partRoom :: Bool |
|
31 |
} |
|
32 |
||
33 |
instance Show ClientInfo where |
|
34 |
show ci = show $ clientUID ci |
|
35 |
||
36 |
instance Eq ClientInfo where |
|
37 |
a1 == a2 = clientHandle a1 == clientHandle a2 |
|
38 |
||
39 |
data HedgehogInfo = |
|
40 |
HedgehogInfo String String |
|
41 |
||
42 |
data TeamInfo = |
|
43 |
TeamInfo |
|
44 |
{ |
|
45 |
teamowner :: String, |
|
46 |
teamname :: String, |
|
47 |
teamcolor :: String, |
|
48 |
teamgrave :: String, |
|
49 |
teamfort :: String, |
|
50 |
teamvoicepack :: String, |
|
51 |
difficulty :: Int, |
|
52 |
hhnum :: Int, |
|
53 |
hedgehogs :: [HedgehogInfo] |
|
54 |
} |
|
55 |
||
56 |
data RoomInfo = |
|
57 |
RoomInfo |
|
58 |
{ |
|
59 |
roomUID :: Int, |
|
60 |
name :: String, |
|
61 |
password :: String, |
|
62 |
roomProto :: Word16, |
|
63 |
teams :: [TeamInfo], |
|
64 |
gameinprogress :: Bool, |
|
65 |
playersIn :: !Int, |
|
66 |
readyPlayers :: Int, |
|
67 |
playersIDs :: IntSet.IntSet, |
|
68 |
isRestrictedJoins :: Bool, |
|
69 |
isRestrictedTeams :: Bool, |
|
70 |
roundMsgs :: Seq String, |
|
71 |
leftTeams :: [String], |
|
72 |
teamsAtStart :: [TeamInfo], |
|
73 |
params :: Map.Map String [String] |
|
74 |
} |
|
75 |
||
76 |
instance Show RoomInfo where |
|
77 |
show ri = (show $ roomUID ri) |
|
78 |
++ ", players ids: " ++ (show $ IntSet.size $ playersIDs ri) |
|
79 |
++ ", players: " ++ (show $ playersIn ri) |
|
1824 | 80 |
++ ", ready: " ++ (show $ readyPlayers ri) |
1804 | 81 |
|
82 |
instance Eq RoomInfo where |
|
83 |
a1 == a2 = roomUID a1 == roomUID a2 |
|
84 |
||
85 |
newRoom = ( |
|
86 |
RoomInfo |
|
87 |
0 |
|
88 |
"" |
|
89 |
"" |
|
90 |
0 |
|
91 |
[] |
|
92 |
False |
|
93 |
0 |
|
94 |
0 |
|
95 |
IntSet.empty |
|
96 |
False |
|
97 |
False |
|
98 |
Data.Sequence.empty |
|
99 |
[] |
|
100 |
[] |
|
101 |
(Map.singleton "MAP" ["+rnd+"]) |
|
102 |
) |
|
103 |
||
104 |
data StatisticsInfo = |
|
105 |
StatisticsInfo |
|
106 |
{ |
|
107 |
playersNumber :: Int, |
|
108 |
roomsNumber :: Int |
|
109 |
} |
|
110 |
||
111 |
data ServerInfo = |
|
112 |
ServerInfo |
|
113 |
{ |
|
114 |
isDedicated :: Bool, |
|
115 |
serverMessage :: String, |
|
116 |
listenPort :: PortNumber, |
|
117 |
loginsNumber :: Int, |
|
118 |
nextRoomID :: Int, |
|
1832 | 119 |
dbHost :: String, |
120 |
dbLogin :: String, |
|
121 |
dbPassword :: String, |
|
1833 | 122 |
stats :: TMVar StatisticsInfo, |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
123 |
coreChan :: Chan CoreMessage, |
1833 | 124 |
dbQueries :: Chan DBQuery |
1804 | 125 |
} |
126 |
||
127 |
instance Show ServerInfo where |
|
128 |
show si = "Logins: " ++ (show $ loginsNumber si) |
|
129 |
||
130 |
newServerInfo = ( |
|
131 |
ServerInfo |
|
132 |
True |
|
133 |
"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>" |
|
134 |
46631 |
|
135 |
0 |
|
136 |
0 |
|
1832 | 137 |
"" |
138 |
"" |
|
139 |
"" |
|
1804 | 140 |
) |
141 |
||
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
142 |
data AccountInfo = |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
143 |
HasAccount String Bool |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
144 |
| Guest |
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
145 |
|
1804 | 146 |
data CoreMessage = |
147 |
Accept ClientInfo |
|
148 |
| ClientMessage (Int, [String]) |
|
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
149 |
| ClientAccountInfo Int AccountInfo |
1804 | 150 |
-- | CoreMessage String |
151 |
-- | TimerTick |
|
152 |
||
1833 | 153 |
data DBQuery = |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
154 |
CheckAccount Int String |
1833 | 155 |
|
1804 | 156 |
|
157 |
type Clients = IntMap.IntMap ClientInfo |
|
158 |
type Rooms = IntMap.IntMap RoomInfo |
|
159 |
||
160 |
--type ClientsTransform = [ClientInfo] -> [ClientInfo] |
|
161 |
--type RoomsTransform = [RoomInfo] -> [RoomInfo] |
|
162 |
--type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo] |
|
163 |
--type Answer = ServerInfo -> (HandlesSelector, [String]) |
|
164 |
||
165 |
type ClientsSelector = Clients -> Rooms -> [Int] |