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