author | szczur |
Tue, 30 Oct 2012 00:13:22 +0100 | |
branch | 0.9.18 |
changeset 7891 | 77faa4b96771 |
parent 7775 | 835ad028fb66 |
child 7898 | ba735701ce7f |
permissions | -rw-r--r-- |
6012 | 1 |
{-# LANGUAGE CPP, OverloadedStrings #-} |
7766 | 2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
5184 | 3 |
module Actions where |
4 |
||
5 |
import Control.Concurrent |
|
6 |
import qualified Data.Set as Set |
|
7 |
import qualified Data.Sequence as Seq |
|
8 |
import qualified Data.List as L |
|
9 |
import qualified Control.Exception as Exception |
|
10 |
import System.Log.Logger |
|
11 |
import Control.Monad |
|
12 |
import Data.Time |
|
13 |
import Data.Maybe |
|
14 |
import Control.Monad.Reader |
|
15 |
import Control.Monad.State.Strict |
|
16 |
import qualified Data.ByteString.Char8 as B |
|
17 |
import Control.DeepSeq |
|
18 |
import Data.Unique |
|
19 |
import Control.Arrow |
|
20 |
import Control.Exception |
|
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
21 |
import System.Process |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
22 |
import Network.Socket |
5184 | 23 |
----------------------------- |
7766 | 24 |
#if defined(OFFICIAL_SERVER) |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5426
diff
changeset
|
25 |
import OfficialServer.GameReplayStore |
7766 | 26 |
#endif |
5184 | 27 |
import CoreTypes |
28 |
import Utils |
|
29 |
import ClientIO |
|
30 |
import ServerState |
|
31 |
import Consts |
|
32 |
import ConfigFile |
|
6068 | 33 |
import EngineInteraction |
5184 | 34 |
|
35 |
data Action = |
|
36 |
AnswerClients ![ClientChan] ![B.ByteString] |
|
37 |
| SendServerMessage |
|
38 |
| SendServerVars |
|
39 |
| MoveToRoom RoomIndex |
|
40 |
| MoveToLobby B.ByteString |
|
41 |
| RemoveTeam B.ByteString |
|
6753
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
42 |
| SendTeamRemovalMessage B.ByteString |
5184 | 43 |
| RemoveRoom |
6758
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
44 |
| FinishGame |
5184 | 45 |
| UnreadyRoomClients |
46 |
| JoinLobby |
|
47 |
| ProtocolError B.ByteString |
|
48 |
| Warning B.ByteString |
|
49 |
| NoticeMessage Notice |
|
50 |
| ByeClient B.ByteString |
|
51 |
| KickClient ClientIndex |
|
52 |
| KickRoomClient ClientIndex |
|
53 |
| BanClient NominalDiffTime B.ByteString ClientIndex |
|
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
54 |
| BanIP B.ByteString NominalDiffTime B.ByteString |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
55 |
| BanList |
7748 | 56 |
| Unban B.ByteString |
5184 | 57 |
| ChangeMaster |
58 |
| RemoveClientTeams ClientIndex |
|
59 |
| ModifyClient (ClientInfo -> ClientInfo) |
|
60 |
| ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
|
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
61 |
| ModifyRoomClients (ClientInfo -> ClientInfo) |
5184 | 62 |
| ModifyRoom (RoomInfo -> RoomInfo) |
63 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
|
64 |
| AddRoom B.ByteString B.ByteString |
|
65 |
| CheckRegistered |
|
66 |
| ClearAccountsCache |
|
67 |
| ProcessAccountInfo AccountInfo |
|
68 |
| AddClient ClientInfo |
|
69 |
| DeleteClient ClientIndex |
|
70 |
| PingAll |
|
71 |
| StatsAction |
|
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
72 |
| RestartServer |
5184 | 73 |
| AddNick2Bans B.ByteString B.ByteString UTCTime |
74 |
| AddIP2Bans B.ByteString B.ByteString UTCTime |
|
75 |
| CheckBanned |
|
76 |
| SaveReplay |
|
77 |
||
78 |
||
79 |
type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
|
80 |
||
81 |
instance NFData Action where |
|
82 |
rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` () |
|
83 |
rnf a = a `seq` () |
|
84 |
||
85 |
instance NFData B.ByteString |
|
86 |
instance NFData (Chan a) |
|
87 |
||
88 |
||
89 |
othersChans :: StateT ServerState IO [ClientChan] |
|
90 |
othersChans = do |
|
91 |
cl <- client's id |
|
92 |
ri <- clientRoomA |
|
93 |
liftM (map sendChan . filter (/= cl)) $ roomClientsS ri |
|
94 |
||
95 |
processAction :: Action -> StateT ServerState IO () |
|
96 |
||
97 |
||
98 |
processAction (AnswerClients chans msg) = |
|
99 |
io $ mapM_ (`writeChan` (msg `deepseq` msg)) (chans `deepseq` chans) |
|
100 |
||
101 |
||
102 |
processAction SendServerMessage = do |
|
103 |
chan <- client's sendChan |
|
104 |
protonum <- client's clientProto |
|
105 |
si <- liftM serverInfo get |
|
106 |
let message = if protonum < latestReleaseVersion si then |
|
107 |
serverMessageForOldVersions si |
|
108 |
else |
|
109 |
serverMessage si |
|
110 |
processAction $ AnswerClients [chan] ["SERVER_MESSAGE", message] |
|
111 |
||
112 |
||
113 |
processAction SendServerVars = do |
|
114 |
chan <- client's sendChan |
|
115 |
si <- gets serverInfo |
|
116 |
io $ writeChan chan ("SERVER_VARS" : vars si) |
|
117 |
where |
|
118 |
vars si = [ |
|
119 |
"MOTD_NEW", serverMessage si, |
|
120 |
"MOTD_OLD", serverMessageForOldVersions si, |
|
121 |
"LATEST_PROTO", showB $ latestReleaseVersion si |
|
122 |
] |
|
123 |
||
124 |
||
125 |
processAction (ProtocolError msg) = do |
|
126 |
chan <- client's sendChan |
|
127 |
processAction $ AnswerClients [chan] ["ERROR", msg] |
|
128 |
||
129 |
||
130 |
processAction (Warning msg) = do |
|
131 |
chan <- client's sendChan |
|
132 |
processAction $ AnswerClients [chan] ["WARNING", msg] |
|
133 |
||
134 |
processAction (NoticeMessage n) = do |
|
135 |
chan <- client's sendChan |
|
136 |
processAction $ AnswerClients [chan] ["NOTICE", showB . fromEnum $ n] |
|
137 |
||
138 |
processAction (ByeClient msg) = do |
|
139 |
(Just ci) <- gets clientIndex |
|
140 |
ri <- clientRoomA |
|
141 |
||
142 |
chan <- client's sendChan |
|
143 |
clNick <- client's nick |
|
144 |
loggedIn <- client's logonPassed |
|
145 |
||
146 |
when (ri /= lobbyId) $ do |
|
147 |
processAction $ MoveToLobby ("quit: " `B.append` msg) |
|
148 |
return () |
|
149 |
||
150 |
clientsChans <- liftM (Prelude.map sendChan . Prelude.filter logonPassed) $! allClientsS |
|
151 |
io $ |
|
152 |
infoM "Clients" (show ci ++ " quits: " ++ B.unpack msg) |
|
153 |
||
154 |
when loggedIn $ processAction $ AnswerClients clientsChans ["LOBBY:LEFT", clNick, msg] |
|
155 |
||
7465
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
156 |
mapM processAction |
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
157 |
[ |
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
158 |
AnswerClients [chan] ["BYE", msg] |
7735
4c7e282b5732
Reset nickname so it may be reused while old connection is still hanging
unc0rr
parents:
7710
diff
changeset
|
159 |
, ModifyClient (\c -> c{nick = "", logonPassed = False}) -- this will effectively hide client from others while he isn't deleted from list |
7465
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
160 |
] |
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
161 |
|
5184 | 162 |
s <- get |
163 |
put $! s{removedClients = ci `Set.insert` removedClients s} |
|
164 |
||
165 |
processAction (DeleteClient ci) = do |
|
166 |
io $ debugM "Clients" $ "DeleteClient: " ++ show ci |
|
167 |
||
168 |
rnc <- gets roomsClients |
|
169 |
io $ removeClient rnc ci |
|
170 |
||
171 |
s <- get |
|
172 |
put $! s{removedClients = ci `Set.delete` removedClients s} |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
173 |
|
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
174 |
sp <- gets (shutdownPending . serverInfo) |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
175 |
cls <- allClientsS |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
176 |
io $ when (sp && null cls) $ throwIO ShutdownException |
5184 | 177 |
|
178 |
processAction (ModifyClient f) = do |
|
179 |
(Just ci) <- gets clientIndex |
|
180 |
rnc <- gets roomsClients |
|
181 |
io $ modifyClient rnc f ci |
|
182 |
return () |
|
183 |
||
184 |
processAction (ModifyClient2 ci f) = do |
|
185 |
rnc <- gets roomsClients |
|
186 |
io $ modifyClient rnc f ci |
|
187 |
return () |
|
188 |
||
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
189 |
processAction (ModifyRoomClients f) = do |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
190 |
rnc <- gets roomsClients |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
191 |
ri <- clientRoomA |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
192 |
roomClIDs <- io $ roomClientsIndicesM rnc ri |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
193 |
io $ mapM_ (modifyClient rnc f) roomClIDs |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
194 |
|
5184 | 195 |
|
196 |
processAction (ModifyRoom f) = do |
|
197 |
rnc <- gets roomsClients |
|
198 |
ri <- clientRoomA |
|
199 |
io $ modifyRoom rnc f ri |
|
200 |
return () |
|
201 |
||
202 |
||
203 |
processAction (ModifyServerInfo f) = do |
|
204 |
modify (\s -> s{serverInfo = f $ serverInfo s}) |
|
205 |
si <- gets serverInfo |
|
206 |
io $ writeServerConfig si |
|
207 |
||
208 |
||
209 |
processAction (MoveToRoom ri) = do |
|
210 |
(Just ci) <- gets clientIndex |
|
211 |
rnc <- gets roomsClients |
|
212 |
||
213 |
io $ do |
|
214 |
modifyClient rnc (\cl -> cl{teamsInGame = 0, isReady = False, isMaster = False}) ci |
|
215 |
modifyRoom rnc (\r -> r{playersIn = playersIn r + 1}) ri |
|
216 |
moveClientToRoom rnc ri ci |
|
217 |
||
218 |
chans <- liftM (map sendChan) $ roomClientsS ri |
|
219 |
clNick <- client's nick |
|
220 |
||
221 |
processAction $ AnswerClients chans ["JOINED", clNick] |
|
222 |
||
223 |
||
224 |
processAction (MoveToLobby msg) = do |
|
225 |
(Just ci) <- gets clientIndex |
|
226 |
ri <- clientRoomA |
|
227 |
rnc <- gets roomsClients |
|
7766 | 228 |
playersNum <- io $ room'sM rnc playersIn ri |
5184 | 229 |
master <- client's isMaster |
230 |
-- client <- client's id |
|
231 |
clNick <- client's nick |
|
232 |
chans <- othersChans |
|
233 |
||
234 |
if master then |
|
7521 | 235 |
if playersNum > 1 then |
7351
34efdd1f230f
- Check ready status only after deleting player's teams (should fix the bug when you're unable to start game)
unc0rr
parents:
7321
diff
changeset
|
236 |
mapM_ processAction [ChangeMaster, NoticeMessage AdminLeft, RemoveClientTeams ci, AnswerClients chans ["LEFT", clNick, msg]] |
5184 | 237 |
else |
238 |
processAction RemoveRoom |
|
239 |
else |
|
7351
34efdd1f230f
- Check ready status only after deleting player's teams (should fix the bug when you're unable to start game)
unc0rr
parents:
7321
diff
changeset
|
240 |
mapM_ processAction [RemoveClientTeams ci, AnswerClients chans ["LEFT", clNick, msg]] |
5184 | 241 |
|
242 |
-- when not removing room |
|
7351
34efdd1f230f
- Check ready status only after deleting player's teams (should fix the bug when you're unable to start game)
unc0rr
parents:
7321
diff
changeset
|
243 |
ready <- client's isReady |
7521 | 244 |
when (not master || playersNum > 1) . io $ do |
5184 | 245 |
modifyRoom rnc (\r -> r{ |
246 |
playersIn = playersIn r - 1, |
|
247 |
readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r |
|
248 |
}) ri |
|
249 |
moveClientToLobby rnc ci |
|
250 |
||
7710
fd5bcbd698a5
- Keep track of room name so correct name is displayed when you become room admin
unc0rr
parents:
7682
diff
changeset
|
251 |
|
5184 | 252 |
processAction ChangeMaster = do |
253 |
(Just ci) <- gets clientIndex |
|
7710
fd5bcbd698a5
- Keep track of room name so correct name is displayed when you become room admin
unc0rr
parents:
7682
diff
changeset
|
254 |
proto <- client's clientProto |
5184 | 255 |
ri <- clientRoomA |
256 |
rnc <- gets roomsClients |
|
257 |
newMasterId <- liftM (head . filter (/= ci)) . io $ roomClientsIndicesM rnc ri |
|
258 |
newMaster <- io $ client'sM rnc id newMasterId |
|
6733 | 259 |
oldRoomName <- io $ room'sM rnc name ri |
7682 | 260 |
oldMaster <- client's nick |
7668
4cb423f42105
Show who is the room admin on join (no tested, also I don't like how it is done via server warnings, but it seems there's no other solution compatible with .17)
unc0rr
parents:
7664
diff
changeset
|
261 |
thisRoomChans <- liftM (map sendChan) $ roomClientsS ri |
7710
fd5bcbd698a5
- Keep track of room name so correct name is displayed when you become room admin
unc0rr
parents:
7682
diff
changeset
|
262 |
let newRoomName = if proto < 42 then nick newMaster else oldRoomName |
5184 | 263 |
mapM_ processAction [ |
7775 | 264 |
ModifyRoom (\r -> r{masterID = newMasterId |
265 |
, name = newRoomName |
|
266 |
, isRestrictedJoins = False |
|
267 |
, isRestrictedTeams = False |
|
268 |
, readyPlayers = if isReady newMaster then readyPlayers r else readyPlayers r + 1}) |
|
269 |
, ModifyClient2 newMasterId (\c -> c{isMaster = True, isReady = True}) |
|
7682 | 270 |
, AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"] |
271 |
, AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster] |
|
272 |
, AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster] |
|
7775 | 273 |
, AnswerClients thisRoomChans ["CLIENT_FLAGS", "+hr", nick newMaster] |
5184 | 274 |
] |
275 |
||
7766 | 276 |
newRoom' <- io $ room'sM rnc id ri |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
277 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
7766 | 278 |
processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo newRoomName newRoom') |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
279 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
280 |
|
5184 | 281 |
processAction (AddRoom roomName roomPassword) = do |
282 |
Just clId <- gets clientIndex |
|
283 |
rnc <- gets roomsClients |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
284 |
proto <- client's clientProto |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
285 |
n <- client's nick |
5184 | 286 |
|
287 |
let rm = newRoom{ |
|
288 |
masterID = clId, |
|
289 |
name = roomName, |
|
290 |
password = roomPassword, |
|
291 |
roomProto = proto |
|
292 |
} |
|
293 |
||
294 |
rId <- io $ addRoom rnc rm |
|
295 |
||
296 |
processAction $ MoveToRoom rId |
|
297 |
||
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
298 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
5184 | 299 |
|
300 |
mapM_ processAction [ |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
301 |
AnswerClients chans ("ROOM" : "ADD" : roomInfo n rm) |
5184 | 302 |
] |
303 |
||
304 |
||
305 |
processAction RemoveRoom = do |
|
306 |
Just clId <- gets clientIndex |
|
307 |
rnc <- gets roomsClients |
|
308 |
ri <- io $ clientRoomM rnc clId |
|
309 |
roomName <- io $ room'sM rnc name ri |
|
310 |
others <- othersChans |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
311 |
proto <- client's clientProto |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
312 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
5184 | 313 |
|
314 |
mapM_ processAction [ |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6191
diff
changeset
|
315 |
AnswerClients chans ["ROOM", "DEL", roomName], |
5184 | 316 |
AnswerClients others ["ROOMABANDONED", roomName] |
317 |
] |
|
318 |
||
319 |
io $ removeRoom rnc ri |
|
320 |
||
321 |
||
6758
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
322 |
processAction UnreadyRoomClients = do |
5184 | 323 |
ri <- clientRoomA |
324 |
roomPlayers <- roomClientsS ri |
|
325 |
pr <- client's clientProto |
|
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
326 |
mapM_ processAction [ |
7775 | 327 |
AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr . map nick . filter (not . isMaster) $ roomPlayers |
328 |
, ModifyRoomClients (\cl -> cl{isReady = isMaster cl}) |
|
329 |
, ModifyRoom (\r -> r{readyPlayers = 1}) |
|
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
330 |
] |
5184 | 331 |
where |
332 |
notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks |
|
333 |
||
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
334 |
|
6758
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
335 |
processAction FinishGame = do |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
336 |
rnc <- gets roomsClients |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
337 |
ri <- clientRoomA |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
338 |
thisRoomChans <- liftM (map sendChan) $ roomClientsS ri |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
339 |
answerRemovedTeams <- io $ |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
340 |
room'sM rnc (map (\t -> AnswerClients thisRoomChans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo) ri |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
341 |
|
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
342 |
mapM_ processAction $ |
7124 | 343 |
SaveReplay |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
344 |
: ModifyRoom |
6758
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
345 |
(\r -> r{ |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
346 |
gameInfo = Nothing, |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
347 |
readyPlayers = 0 |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
348 |
} |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
349 |
) |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
350 |
: UnreadyRoomClients |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
351 |
: answerRemovedTeams |
5184 | 352 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
353 |
|
6753
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
354 |
processAction (SendTeamRemovalMessage teamName) = do |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
355 |
chans <- othersChans |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
356 |
mapM_ processAction [ |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
357 |
AnswerClients chans ["EM", rmTeamMsg], |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
358 |
ModifyRoom (\r -> r{ |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
359 |
gameInfo = liftM (\g -> g{ |
7124 | 360 |
teamsInGameNumber = teamsInGameNumber g - 1 |
361 |
, roundMsgs = roundMsgs g Seq.|> rmTeamMsg |
|
6753
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
362 |
}) $ gameInfo r |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
363 |
}) |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
364 |
] |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
365 |
|
6758
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
366 |
rnc <- gets roomsClients |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
367 |
ri <- clientRoomA |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
368 |
gi <- io $ room'sM rnc gameInfo ri |
26bf919aeb57
Oh, should also check for game finish when player quits without ROUNDFINISHED message: small refactoring, not tested at all
unc0rr
parents:
6756
diff
changeset
|
369 |
when (isJust gi && 0 == teamsInGameNumber (fromJust gi)) $ |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
370 |
processAction FinishGame |
6753
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
371 |
where |
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6733
diff
changeset
|
372 |
rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
373 |
|
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
374 |
|
5184 | 375 |
processAction (RemoveTeam teamName) = do |
376 |
rnc <- gets roomsClients |
|
377 |
ri <- clientRoomA |
|
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5426
diff
changeset
|
378 |
inGame <- io $ room'sM rnc (isJust . gameInfo) ri |
5184 | 379 |
chans <- othersChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
380 |
mapM_ processAction $ |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
381 |
ModifyRoom (\r -> r{ |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
382 |
teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
383 |
, gameInfo = liftM (\g -> g{leftTeams = teamName : leftTeams g}) $ gameInfo r |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
384 |
}) |
7124 | 385 |
: AnswerClients chans ["REMOVE_TEAM", teamName] |
386 |
: [SendTeamRemovalMessage teamName | inGame] |
|
5184 | 387 |
|
388 |
||
389 |
processAction (RemoveClientTeams clId) = do |
|
390 |
rnc <- gets roomsClients |
|
391 |
||
392 |
removeTeamActions <- io $ do |
|
393 |
clNick <- client'sM rnc nick clId |
|
394 |
rId <- clientRoomM rnc clId |
|
395 |
roomTeams <- room'sM rnc teams rId |
|
396 |
return . Prelude.map (RemoveTeam . teamname) . Prelude.filter (\t -> teamowner t == clNick) $ roomTeams |
|
397 |
||
398 |
mapM_ processAction removeTeamActions |
|
399 |
||
400 |
||
401 |
||
402 |
processAction CheckRegistered = do |
|
403 |
(Just ci) <- gets clientIndex |
|
404 |
n <- client's nick |
|
405 |
h <- client's host |
|
406 |
p <- client's clientProto |
|
407 |
uid <- client's clUID |
|
6191 | 408 |
haveSameNick <- liftM (not . null . tail . filter (\c -> caseInsensitiveCompare (nick c) n)) allClientsS |
5184 | 409 |
if haveSameNick then |
410 |
if p < 38 then |
|
411 |
mapM_ processAction [ByeClient "Nickname is already in use", removeNick] |
|
412 |
else |
|
413 |
mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick] |
|
414 |
else |
|
415 |
do |
|
416 |
db <- gets (dbQueries . serverInfo) |
|
417 |
io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
|
418 |
return () |
|
419 |
where |
|
420 |
removeNick = ModifyClient (\c -> c{nick = ""}) |
|
421 |
||
422 |
||
423 |
processAction ClearAccountsCache = do |
|
424 |
dbq <- gets (dbQueries . serverInfo) |
|
425 |
io $ writeChan dbq ClearCache |
|
426 |
return () |
|
427 |
||
428 |
||
429 |
processAction (ProcessAccountInfo info) = |
|
430 |
case info of |
|
431 |
HasAccount passwd isAdmin -> do |
|
432 |
chan <- client's sendChan |
|
433 |
mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})] |
|
434 |
Guest -> |
|
435 |
processAction JoinLobby |
|
436 |
Admin -> do |
|
437 |
mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby] |
|
438 |
chan <- client's sendChan |
|
439 |
processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
|
440 |
||
441 |
||
442 |
processAction JoinLobby = do |
|
443 |
chan <- client's sendChan |
|
444 |
clientNick <- client's nick |
|
7498
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
445 |
isAuthenticated <- liftM (not . B.null) $ client's webPassword |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
446 |
isAdmin <- client's isAdministrator |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
447 |
loggedInClients <- liftM (Prelude.filter logonPassed) $! allClientsS |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
448 |
let (lobbyNicks, clientsChans) = unzip . L.map (nick &&& sendChan) $ loggedInClients |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
449 |
let authenticatedNicks = L.map nick . L.filter (not . B.null . webPassword) $ loggedInClients |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
450 |
let adminsNicks = L.map nick . L.filter isAdministrator $ loggedInClients |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
451 |
let clFlags = B.concat . L.concat $ [["u" | isAuthenticated], ["a" | isAdmin]] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
452 |
mapM_ processAction . concat $ [ |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
453 |
[AnswerClients clientsChans ["LOBBY:JOINED", clientNick]] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
454 |
, [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
455 |
, [AnswerClients [chan] ("CLIENT_FLAGS" : "+u" : authenticatedNicks) | not $ null authenticatedNicks] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
456 |
, [AnswerClients [chan] ("CLIENT_FLAGS" : "+a" : adminsNicks) | not $ null adminsNicks] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
457 |
, [AnswerClients (chan : clientsChans) ["CLIENT_FLAGS", B.concat["+" , clFlags], clientNick] | not $ B.null clFlags] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
458 |
, [ModifyClient (\cl -> cl{logonPassed = True})] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
459 |
, [SendServerMessage] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
460 |
] |
5184 | 461 |
|
462 |
||
463 |
processAction (KickClient kickId) = do |
|
464 |
modify (\s -> s{clientIndex = Just kickId}) |
|
5214 | 465 |
clHost <- client's host |
466 |
currentTime <- io getCurrentTime |
|
467 |
mapM_ processAction [ |
|
468 |
AddIP2Bans clHost "60 seconds cooldown after kick" (addUTCTime 60 currentTime), |
|
469 |
ByeClient "Kicked" |
|
470 |
] |
|
5184 | 471 |
|
472 |
||
473 |
processAction (BanClient seconds reason banId) = do |
|
474 |
modify (\s -> s{clientIndex = Just banId}) |
|
475 |
clHost <- client's host |
|
476 |
currentTime <- io getCurrentTime |
|
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
477 |
let msg = B.concat ["Ban for ", B.pack . show $ seconds, " (", reason, ")"] |
5184 | 478 |
mapM_ processAction [ |
479 |
AddIP2Bans clHost msg (addUTCTime seconds currentTime) |
|
480 |
, KickClient banId |
|
481 |
] |
|
482 |
||
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
483 |
processAction (BanIP ip seconds reason) = do |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
484 |
currentTime <- io getCurrentTime |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
485 |
let msg = B.concat ["Ban for ", B.pack . show $ seconds, " (", reason, ")"] |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
486 |
processAction $ |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
487 |
AddIP2Bans ip msg (addUTCTime seconds currentTime) |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
488 |
|
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
489 |
processAction BanList = do |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
490 |
ch <- client's sendChan |
7766 | 491 |
b <- gets (B.pack . unlines . map show . bans . serverInfo) |
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
492 |
processAction $ |
7766 | 493 |
AnswerClients [ch] ["BANLIST", b] |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
494 |
|
7748 | 495 |
processAction (Unban entry) = do |
496 |
processAction $ ModifyServerInfo (\s -> s{bans = filter f $ bans s}) |
|
497 |
where |
|
498 |
f (BanByIP bip _ _) = bip == entry |
|
499 |
f (BanByNick bn _ _) = bn == entry |
|
5184 | 500 |
|
501 |
processAction (KickRoomClient kickId) = do |
|
502 |
modify (\s -> s{clientIndex = Just kickId}) |
|
503 |
ch <- client's sendChan |
|
504 |
mapM_ processAction [AnswerClients [ch] ["KICKED"], MoveToLobby "kicked"] |
|
505 |
||
506 |
||
507 |
processAction (AddClient cl) = do |
|
508 |
rnc <- gets roomsClients |
|
509 |
si <- gets serverInfo |
|
510 |
newClId <- io $ do |
|
511 |
ci <- addClient rnc cl |
|
512 |
_ <- Exception.mask (forkIO . clientRecvLoop (clientSocket cl) (coreChan si) (sendChan cl) ci) |
|
513 |
||
514 |
infoM "Clients" (show ci ++ ": New client. Time: " ++ show (connectTime cl)) |
|
515 |
||
516 |
return ci |
|
517 |
||
518 |
modify (\s -> s{clientIndex = Just newClId}) |
|
519 |
mapM_ processAction |
|
520 |
[ |
|
521 |
AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
|
522 |
, CheckBanned |
|
6809 | 523 |
, AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
5184 | 524 |
] |
525 |
||
526 |
||
527 |
processAction (AddNick2Bans n reason expiring) = do |
|
528 |
processAction $ ModifyServerInfo (\s -> s{bans = BanByNick n reason expiring : bans s}) |
|
529 |
||
530 |
processAction (AddIP2Bans ip reason expiring) = do |
|
531 |
(Just ci) <- gets clientIndex |
|
532 |
rc <- gets removedClients |
|
533 |
when (not $ ci `Set.member` rc) |
|
534 |
$ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
|
535 |
||
536 |
processAction CheckBanned = do |
|
537 |
clTime <- client's connectTime |
|
538 |
clNick <- client's nick |
|
539 |
clHost <- client's host |
|
540 |
si <- gets serverInfo |
|
541 |
let validBans = filter (checkNotExpired clTime) $ bans si |
|
542 |
let ban = L.find (checkBan clHost clNick) $ validBans |
|
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
543 |
mapM_ processAction $ |
5184 | 544 |
ModifyServerInfo (\s -> s{bans = validBans}) |
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
545 |
: [ByeClient (getBanReason $ fromJust ban) | isJust ban] |
5184 | 546 |
where |
547 |
checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
|
548 |
checkNotExpired testTime (BanByNick _ _ time) = testTime `diffUTCTime` time <= 0 |
|
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
549 |
checkBan ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
5184 | 550 |
checkBan _ n (BanByNick bn _ _) = bn == n |
551 |
getBanReason (BanByIP _ msg _) = msg |
|
552 |
getBanReason (BanByNick _ msg _) = msg |
|
553 |
||
554 |
processAction PingAll = do |
|
555 |
rnc <- gets roomsClients |
|
556 |
io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
|
557 |
cis <- io $ allClientsM rnc |
|
558 |
chans <- io $ mapM (client'sM rnc sendChan) cis |
|
559 |
io $ mapM_ (modifyClient rnc (\cl -> cl{pingsQueue = pingsQueue cl + 1})) cis |
|
560 |
processAction $ AnswerClients chans ["PING"] |
|
561 |
where |
|
562 |
kickTimeouted rnc ci = do |
|
563 |
pq <- io $ client'sM rnc pingsQueue ci |
|
7465
c2dcf97ca664
Okay, this is workaround over ping timeouts problem on the server. Could make server crash if recieve thread wakes up after second ping timeout event.
unc0rr
parents:
7351
diff
changeset
|
564 |
when (pq > 0) $ do |
5184 | 565 |
withStateT (\as -> as{clientIndex = Just ci}) $ |
566 |
processAction (ByeClient "Ping timeout") |
|
7600
31a177d2856c
Disable workaround, as it still makes server crash and hung clients are hidden from players anyway
unc0rr
parents:
7537
diff
changeset
|
567 |
-- when (pq > 1) $ |
31a177d2856c
Disable workaround, as it still makes server crash and hung clients are hidden from players anyway
unc0rr
parents:
7537
diff
changeset
|
568 |
-- processAction $ DeleteClient ci -- smth went wrong with client io threads, issue DeleteClient here |
5184 | 569 |
|
570 |
||
571 |
processAction StatsAction = do |
|
5211 | 572 |
si <- gets serverInfo |
573 |
when (not $ shutdownPending si) $ do |
|
5212
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
574 |
rnc <- gets roomsClients |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
575 |
(roomsNum, clientsNum) <- io $ withRoomsAndClients rnc st |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
576 |
io $ writeChan (dbQueries si) $ SendStats clientsNum (roomsNum - 1) |
5184 | 577 |
where |
578 |
st irnc = (length $ allRooms irnc, length $ allClients irnc) |
|
579 |
||
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
580 |
processAction RestartServer = do |
5212
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
581 |
sp <- gets (shutdownPending . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
582 |
when (not sp) $ do |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
583 |
sock <- gets (fromJust . serverSocket . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
584 |
args <- gets (runArgs . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
585 |
io $ do |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
586 |
noticeM "Core" "Closing listening socket" |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
587 |
sClose sock |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
588 |
noticeM "Core" "Spawning new server" |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
589 |
_ <- createProcess (proc "./hedgewars-server" args) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
590 |
return () |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
591 |
processAction $ ModifyServerInfo (\s -> s{shutdownPending = True}) |
5184 | 592 |
|
6012 | 593 |
#if defined(OFFICIAL_SERVER) |
5184 | 594 |
processAction SaveReplay = do |
595 |
ri <- clientRoomA |
|
596 |
rnc <- gets roomsClients |
|
597 |
io $ do |
|
598 |
r <- room'sM rnc id ri |
|
599 |
saveReplay r |
|
6012 | 600 |
#else |
601 |
processAction SaveReplay = return () |
|
602 |
#endif |