author | nemo |
Sun, 09 Mar 2014 20:53:11 -0400 | |
changeset 10188 | e8f2dbabd01b |
parent 10094 | d3a2fe9f04f2 |
child 10194 | 7025bd3c3131 |
permissions | -rw-r--r-- |
8519
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
1 |
{-# LANGUAGE CPP, OverloadedStrings, DeriveDataTypeable #-} |
1804 | 2 |
module CoreTypes where |
3 |
||
4579
4e61c2a42121
Explicitly kill listening thread in try to prevent messages recieving bugs
unc0rr
parents:
4337
diff
changeset
|
4 |
import Control.Concurrent |
1804 | 5 |
import Data.Word |
6 |
import qualified Data.Map as Map |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
7 |
import Data.Time |
1804 | 8 |
import Network |
2352 | 9 |
import Data.Function |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
10 |
import Data.ByteString.Char8 as B |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4907
diff
changeset
|
11 |
import Data.Unique |
4959 | 12 |
import Control.Exception |
13 |
import Data.Typeable |
|
4989 | 14 |
import Data.TConfig |
8519
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
15 |
import Control.DeepSeq |
4959 | 16 |
----------------------- |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
17 |
import RoomsAndClients |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
18 |
|
8519
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
19 |
#if __GLASGOW_HASKELL__ < 706 |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
20 |
instance NFData B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
21 |
#endif |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
22 |
|
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
23 |
instance NFData (Chan a) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
24 |
|
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
25 |
instance NFData Action where |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
26 |
rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` () |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
27 |
rnf a = a `seq` () |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
28 |
|
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
29 |
data Action = |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
30 |
AnswerClients ![ClientChan] ![B.ByteString] |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
31 |
| SendServerMessage |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
32 |
| SendServerVars |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
33 |
| MoveToRoom RoomIndex |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
34 |
| MoveToLobby B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
35 |
| RemoveTeam B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
36 |
| SendTeamRemovalMessage B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
37 |
| RemoveRoom |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
38 |
| FinishGame |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
39 |
| UnreadyRoomClients |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
40 |
| JoinLobby |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
41 |
| ProtocolError B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
42 |
| Warning B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
43 |
| NoticeMessage Notice |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
44 |
| ByeClient B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
45 |
| KickClient ClientIndex |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
46 |
| KickRoomClient ClientIndex |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
47 |
| BanClient NominalDiffTime B.ByteString ClientIndex |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
48 |
| BanIP B.ByteString NominalDiffTime B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
49 |
| BanNick B.ByteString NominalDiffTime B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
50 |
| BanList |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
51 |
| Unban B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
52 |
| ChangeMaster (Maybe ClientIndex) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
53 |
| RemoveClientTeams |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
54 |
| ModifyClient (ClientInfo -> ClientInfo) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
55 |
| ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
56 |
| ModifyRoomClients (ClientInfo -> ClientInfo) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
57 |
| ModifyRoom (RoomInfo -> RoomInfo) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
58 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
59 |
| AddRoom B.ByteString B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
60 |
| SendUpdateOnThisRoom |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
61 |
| CheckRegistered |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
62 |
| ClearAccountsCache |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
63 |
| ProcessAccountInfo AccountInfo |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
64 |
| AddClient ClientInfo |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
65 |
| DeleteClient ClientIndex |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
66 |
| PingAll |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
67 |
| StatsAction |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
68 |
| RestartServer |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
69 |
| AddNick2Bans B.ByteString B.ByteString UTCTime |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
70 |
| AddIP2Bans B.ByteString B.ByteString UTCTime |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
71 |
| CheckBanned Bool |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
72 |
| SaveReplay |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
73 |
| Stats |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
74 |
| CheckRecord |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
75 |
| CheckFailed B.ByteString |
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
76 |
| CheckSuccess [B.ByteString] |
9035
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
77 |
| Random [ClientChan] [B.ByteString] |
9446 | 78 |
| QueryReplay B.ByteString |
79 |
| ShowReplay B.ByteString |
|
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
9884
diff
changeset
|
80 |
| Cleanup |
10090 | 81 |
| RegisterEvent Event |
82 |
||
83 |
||
84 |
data Event = LobbyChatMessage |
|
85 |
| EngineMessage |
|
86 |
| RoomJoin |
|
10094 | 87 |
|
88 |
type EventsInfo = [(Int, UTCTime)] |
|
8519
98e2dbdda8c0
Workaround desync issue if I correctly understand its roots (barely tested)
unc0rr
parents:
8509
diff
changeset
|
89 |
|
10093 | 90 |
newEventsInfo :: EventsInfo |
91 |
newEventsInfo = [] |
|
92 |
||
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
93 |
type ClientChan = Chan [B.ByteString] |
3435 | 94 |
|
8507 | 95 |
data CheckInfo = |
96 |
CheckInfo |
|
97 |
{ |
|
8509 | 98 |
recordFileName :: String, |
8507 | 99 |
recordTeams :: [TeamInfo] |
100 |
} |
|
101 |
||
1804 | 102 |
data ClientInfo = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
103 |
ClientInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
104 |
{ |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4907
diff
changeset
|
105 |
clUID :: Unique, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
106 |
sendChan :: ClientChan, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
107 |
clientSocket :: Socket, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
108 |
host :: B.ByteString, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
109 |
connectTime :: UTCTime, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
110 |
nick :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
111 |
webPassword :: B.ByteString, |
10076 | 112 |
serverSalt :: B.ByteString, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
113 |
logonPassed :: Bool, |
8372
3c193ec03e09
Logon procedure for checkers, introduce invisible clients
unc0rr
parents:
8371
diff
changeset
|
114 |
isVisible :: Bool, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
115 |
clientProto :: !Word16, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
116 |
pingsQueue :: !Word, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
117 |
isMaster :: Bool, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
118 |
isReady :: !Bool, |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
119 |
isInGame :: Bool, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
120 |
isAdministrator :: Bool, |
8371 | 121 |
isChecker :: Bool, |
9435 | 122 |
isContributor :: Bool, |
8245 | 123 |
isKickedFromServer :: Bool, |
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9086
diff
changeset
|
124 |
isJoinedMidGame :: Bool, |
8433 | 125 |
clientClan :: !(Maybe B.ByteString), |
8507 | 126 |
checkInfo :: Maybe CheckInfo, |
10093 | 127 |
eiLobbyChat, |
128 |
eiEM, |
|
129 |
eiJoin :: EventsInfo, |
|
8897
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8519
diff
changeset
|
130 |
teamsInGame :: Word |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
131 |
} |
1804 | 132 |
|
133 |
instance Eq ClientInfo where |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
134 |
(==) = (==) `on` clientSocket |
1804 | 135 |
|
136 |
data HedgehogInfo = |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
137 |
HedgehogInfo B.ByteString B.ByteString |
5143
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
5007
diff
changeset
|
138 |
deriving (Show, Read) |
1804 | 139 |
|
140 |
data TeamInfo = |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
141 |
TeamInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
142 |
{ |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
143 |
teamownerId :: ClientIndex, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
144 |
teamowner :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
145 |
teamname :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
146 |
teamcolor :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
147 |
teamgrave :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
148 |
teamfort :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
149 |
teamvoicepack :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
150 |
teamflag :: B.ByteString, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
151 |
difficulty :: Int, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
152 |
hhnum :: Int, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
153 |
hedgehogs :: [HedgehogInfo] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
154 |
} |
5143
649d87819682
Start implementation of archivements/ratings on server side: replay saving routine
unc0rr
parents:
5007
diff
changeset
|
155 |
deriving (Show, Read) |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
156 |
|
8431 | 157 |
instance Eq TeamInfo where |
158 |
(==) = (==) `on` teamname |
|
8479
8d71109b04d2
Some work on loading replay and interaction with checker
unc0rr
parents:
8433
diff
changeset
|
159 |
|
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
160 |
data GameInfo = |
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
161 |
GameInfo |
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
162 |
{ |
8369 | 163 |
roundMsgs :: [B.ByteString], |
9304
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9109
diff
changeset
|
164 |
lastFilteredTimedMsg :: Maybe B.ByteString, |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
165 |
leftTeams :: [B.ByteString], |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
166 |
teamsAtStart :: [TeamInfo], |
6756
344d32bb1328
Also consider game finished when the last player reports ROUNDFINISHED despite the correctness parameter.
unc0rr
parents:
6737
diff
changeset
|
167 |
teamsInGameNumber :: Int, |
8428 | 168 |
allPlayersHaveRegisteredAccounts :: !Bool, |
6069 | 169 |
giMapParams :: Map.Map B.ByteString B.ByteString, |
170 |
giParams :: Map.Map B.ByteString [B.ByteString] |
|
171 |
} deriving (Show, Read) |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
172 |
|
7766 | 173 |
newGameInfo :: [TeamInfo] |
174 |
-> Int |
|
175 |
-> Bool |
|
176 |
-> Map.Map ByteString ByteString |
|
177 |
-> Map.Map ByteString [ByteString] |
|
178 |
-> GameInfo |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
179 |
newGameInfo = |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
180 |
GameInfo |
8369 | 181 |
[] |
9304
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9109
diff
changeset
|
182 |
Nothing |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
183 |
[] |
1804 | 184 |
|
185 |
data RoomInfo = |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
186 |
RoomInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
187 |
{ |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
188 |
masterID :: Maybe ClientIndex, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
189 |
name :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
190 |
password :: B.ByteString, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
191 |
roomProto :: Word16, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
192 |
teams :: [TeamInfo], |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
193 |
gameInfo :: Maybe GameInfo, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
194 |
playersIn :: !Int, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
195 |
readyPlayers :: !Int, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
196 |
isRestrictedJoins :: Bool, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
197 |
isRestrictedTeams :: Bool, |
8232 | 198 |
isRegisteredOnly :: Bool, |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
199 |
isSpecial :: Bool, |
9787 | 200 |
greeting :: B.ByteString, |
10041 | 201 |
voting :: Maybe Voting, |
8002 | 202 |
roomBansList :: ![B.ByteString], |
4941 | 203 |
mapParams :: Map.Map B.ByteString B.ByteString, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
204 |
params :: Map.Map B.ByteString [B.ByteString] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
205 |
} |
1804 | 206 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
207 |
newRoom :: RoomInfo |
4932 | 208 |
newRoom = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
209 |
RoomInfo |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
210 |
Nothing |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
211 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
212 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
213 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
214 |
[] |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5210
diff
changeset
|
215 |
Nothing |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
216 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
217 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
218 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
219 |
False |
8232 | 220 |
False |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
221 |
False |
9787 | 222 |
"" |
10041 | 223 |
Nothing |
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
224 |
[] |
4941 | 225 |
( |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
226 |
Map.fromList $ Prelude.zip |
4941 | 227 |
["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"] |
228 |
["+rnd+", "0", "0", "seed", "0"] |
|
229 |
) |
|
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
230 |
( |
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
231 |
Map.fromList $ Prelude.zip |
10066 | 232 |
["AMMO", "SCHEME", "SCRIPT", "THEME"] |
233 |
[["Default"], ["Default"], ["Normal"], ["avematan"]] |
|
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
234 |
) |
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9528
diff
changeset
|
235 |
|
1804 | 236 |
|
237 |
data StatisticsInfo = |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
238 |
StatisticsInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
239 |
{ |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
240 |
playersNumber :: Int, |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
241 |
roomsNumber :: Int |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
242 |
} |
1804 | 243 |
|
4989 | 244 |
data ServerInfo = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
245 |
ServerInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
246 |
{ |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
247 |
isDedicated :: Bool, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
248 |
serverMessage :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
249 |
serverMessageForOldVersions :: B.ByteString, |
3260
b44b88908758
Allow to set motd for old client versions (not used yet, as server needs some refactoring)
unc0rr
parents:
2868
diff
changeset
|
250 |
latestReleaseVersion :: Word16, |
4988 | 251 |
earliestCompatibleVersion :: Word16, |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
252 |
listenPort :: PortNumber, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
253 |
dbHost :: B.ByteString, |
4982
3572eaf14340
Add dbName parameter to .ini file, fix some warnings
unc0rr
parents:
4975
diff
changeset
|
254 |
dbName :: B.ByteString, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
255 |
dbLogin :: B.ByteString, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
256 |
dbPassword :: B.ByteString, |
5007 | 257 |
bans :: [BanInfo], |
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5143
diff
changeset
|
258 |
shutdownPending :: Bool, |
5210 | 259 |
runArgs :: [String], |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
260 |
coreChan :: Chan CoreMessage, |
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:
4960
diff
changeset
|
261 |
dbQueries :: Chan DBQuery, |
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5143
diff
changeset
|
262 |
serverSocket :: Maybe Socket, |
4989 | 263 |
serverConfig :: Maybe Conf |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
264 |
} |
1804 | 265 |
|
266 |
||
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5143
diff
changeset
|
267 |
newServerInfo :: Chan CoreMessage -> Chan DBQuery -> Maybe Socket -> Maybe Conf -> ServerInfo |
4932 | 268 |
newServerInfo = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
269 |
ServerInfo |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
270 |
True |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
271 |
"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>" |
9086 | 272 |
"<font color=yellow><h3 align=center>Hedgewars 0.9.19 is out! Please update.</h3><p align=center><a href=http://hedgewars.org/download.html>Download page here</a></font>" |
9884 | 273 |
47 -- latestReleaseVersion |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7766
diff
changeset
|
274 |
41 -- earliestCompatibleVersion |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
275 |
46631 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
276 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
277 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
278 |
"" |
4982
3572eaf14340
Add dbName parameter to .ini file, fix some warnings
unc0rr
parents:
4975
diff
changeset
|
279 |
"" |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
280 |
[] |
4955 | 281 |
False |
5210 | 282 |
[] |
1804 | 283 |
|
10041 | 284 |
data Voting = Voting { |
285 |
voteTTL :: Int, |
|
286 |
entitledToVote :: [Unique], |
|
287 |
votes :: [(Unique, Bool)], |
|
288 |
voteType :: VoteType |
|
289 |
} |
|
290 |
||
291 |
||
292 |
data VoteType = VoteKick B.ByteString |
|
293 |
||
294 |
||
10058 | 295 |
newVoting :: VoteType -> Voting |
296 |
newVoting = Voting 2 [] [] |
|
10041 | 297 |
|
298 |
||
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
299 |
data AccountInfo = |
9435 | 300 |
HasAccount B.ByteString Bool Bool |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
301 |
| Guest |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
302 |
| Admin |
9446 | 303 |
| ReplayName B.ByteString |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
304 |
deriving (Show, Read) |
2116
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
305 |
|
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
306 |
data DBQuery = |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4907
diff
changeset
|
307 |
CheckAccount ClientIndex Int B.ByteString B.ByteString |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
308 |
| ClearCache |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
309 |
| SendStats Int Int |
9868 | 310 |
| StoreAchievements Word16 B.ByteString [(B.ByteString, B.ByteString)] [B.ByteString] |
9446 | 311 |
| GetReplayName ClientIndex Int B.ByteString |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
312 |
deriving (Show, Read) |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
313 |
|
1804 | 314 |
data CoreMessage = |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
315 |
Accept ClientInfo |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
316 |
| ClientMessage (ClientIndex, [B.ByteString]) |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4907
diff
changeset
|
317 |
| ClientAccountInfo ClientIndex Int AccountInfo |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
318 |
| TimerAction Int |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
319 |
| Remove ClientIndex |
1804 | 320 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
321 |
type MRnC = MRoomsAndClients RoomInfo ClientInfo |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
322 |
type IRnC = IRoomsAndClients RoomInfo ClientInfo |
1804 | 323 |
|
4622 | 324 |
data Notice = |
325 |
NickAlreadyInUse |
|
326 |
| AdminLeft |
|
6912
831416764d2d
Allow LIST command while in room to not annoy old frontends (0.9.17 or less) with warnings
unc0rr
parents:
6756
diff
changeset
|
327 |
| WrongPassword |
4959 | 328 |
deriving Enum |
329 |
||
4960 | 330 |
data ShutdownException = |
331 |
ShutdownException |
|
4959 | 332 |
deriving (Show, Typeable) |
333 |
||
334 |
instance Exception ShutdownException |
|
4996
76ef3d8bd78e
Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents:
4989
diff
changeset
|
335 |
|
5000
72d8fb26223d
- Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents:
4996
diff
changeset
|
336 |
data ShutdownThreadException = ShutdownThreadException String |
72d8fb26223d
- Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents:
4996
diff
changeset
|
337 |
deriving Typeable |
4996
76ef3d8bd78e
Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents:
4989
diff
changeset
|
338 |
|
5000
72d8fb26223d
- Don't pretend client sent some message from sending thread (fixes crash when client is already deleted by recieveng thread)
unc0rr
parents:
4996
diff
changeset
|
339 |
instance Show ShutdownThreadException where |
5001 | 340 |
show (ShutdownThreadException s) = s |
4996
76ef3d8bd78e
Fix crash (accessing already deleted client record) by reverting to old client removing handling + throwTo
unc0rr
parents:
4989
diff
changeset
|
341 |
instance Exception ShutdownThreadException |
5006 | 342 |
|
343 |
data BanInfo = |
|
5007 | 344 |
BanByIP B.ByteString B.ByteString UTCTime |
345 |
| BanByNick B.ByteString B.ByteString UTCTime |
|
5006 | 346 |
deriving (Show, Read) |