author | unc0rr |
Sun, 15 May 2011 18:16:13 +0400 | |
changeset 5210 | a5329e52a71b |
parent 5209 | f7a610e2ef5f |
child 5211 | 8ebf92014447 |
permissions | -rw-r--r-- |
5184 | 1 |
{-# LANGUAGE OverloadedStrings #-} |
2 |
module Actions where |
|
3 |
||
4 |
import Control.Concurrent |
|
5 |
import qualified Data.Set as Set |
|
6 |
import qualified Data.Sequence as Seq |
|
7 |
import qualified Data.List as L |
|
8 |
import qualified Control.Exception as Exception |
|
9 |
import System.Log.Logger |
|
10 |
import Control.Monad |
|
11 |
import Data.Time |
|
12 |
import Data.Maybe |
|
13 |
import Control.Monad.Reader |
|
14 |
import Control.Monad.State.Strict |
|
15 |
import qualified Data.ByteString.Char8 as B |
|
16 |
import Control.DeepSeq |
|
17 |
import Data.Unique |
|
18 |
import Control.Arrow |
|
19 |
import Control.Exception |
|
20 |
import OfficialServer.GameReplayStore |
|
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 |
----------------------------- |
24 |
import CoreTypes |
|
25 |
import Utils |
|
26 |
import ClientIO |
|
27 |
import ServerState |
|
28 |
import Consts |
|
29 |
import ConfigFile |
|
30 |
||
31 |
data Action = |
|
32 |
AnswerClients ![ClientChan] ![B.ByteString] |
|
33 |
| SendServerMessage |
|
34 |
| SendServerVars |
|
35 |
| MoveToRoom RoomIndex |
|
36 |
| MoveToLobby B.ByteString |
|
37 |
| RemoveTeam B.ByteString |
|
38 |
| RemoveRoom |
|
39 |
| UnreadyRoomClients |
|
40 |
| JoinLobby |
|
41 |
| ProtocolError B.ByteString |
|
42 |
| Warning B.ByteString |
|
43 |
| NoticeMessage Notice |
|
44 |
| ByeClient B.ByteString |
|
45 |
| KickClient ClientIndex |
|
46 |
| KickRoomClient ClientIndex |
|
47 |
| BanClient NominalDiffTime B.ByteString ClientIndex |
|
48 |
| ChangeMaster |
|
49 |
| RemoveClientTeams ClientIndex |
|
50 |
| ModifyClient (ClientInfo -> ClientInfo) |
|
51 |
| ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
|
52 |
| ModifyRoom (RoomInfo -> RoomInfo) |
|
53 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
|
54 |
| AddRoom B.ByteString B.ByteString |
|
55 |
| CheckRegistered |
|
56 |
| ClearAccountsCache |
|
57 |
| ProcessAccountInfo AccountInfo |
|
58 |
| AddClient ClientInfo |
|
59 |
| DeleteClient ClientIndex |
|
60 |
| PingAll |
|
61 |
| StatsAction |
|
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
62 |
| RestartServer |
5184 | 63 |
| AddNick2Bans B.ByteString B.ByteString UTCTime |
64 |
| AddIP2Bans B.ByteString B.ByteString UTCTime |
|
65 |
| CheckBanned |
|
66 |
| SaveReplay |
|
67 |
||
68 |
||
69 |
type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
|
70 |
||
71 |
instance NFData Action where |
|
72 |
rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` () |
|
73 |
rnf a = a `seq` () |
|
74 |
||
75 |
instance NFData B.ByteString |
|
76 |
instance NFData (Chan a) |
|
77 |
||
78 |
||
79 |
othersChans :: StateT ServerState IO [ClientChan] |
|
80 |
othersChans = do |
|
81 |
cl <- client's id |
|
82 |
ri <- clientRoomA |
|
83 |
liftM (map sendChan . filter (/= cl)) $ roomClientsS ri |
|
84 |
||
85 |
processAction :: Action -> StateT ServerState IO () |
|
86 |
||
87 |
||
88 |
processAction (AnswerClients chans msg) = |
|
89 |
io $ mapM_ (`writeChan` (msg `deepseq` msg)) (chans `deepseq` chans) |
|
90 |
||
91 |
||
92 |
processAction SendServerMessage = do |
|
93 |
chan <- client's sendChan |
|
94 |
protonum <- client's clientProto |
|
95 |
si <- liftM serverInfo get |
|
96 |
let message = if protonum < latestReleaseVersion si then |
|
97 |
serverMessageForOldVersions si |
|
98 |
else |
|
99 |
serverMessage si |
|
100 |
processAction $ AnswerClients [chan] ["SERVER_MESSAGE", message] |
|
101 |
||
102 |
||
103 |
processAction SendServerVars = do |
|
104 |
chan <- client's sendChan |
|
105 |
si <- gets serverInfo |
|
106 |
io $ writeChan chan ("SERVER_VARS" : vars si) |
|
107 |
where |
|
108 |
vars si = [ |
|
109 |
"MOTD_NEW", serverMessage si, |
|
110 |
"MOTD_OLD", serverMessageForOldVersions si, |
|
111 |
"LATEST_PROTO", showB $ latestReleaseVersion si |
|
112 |
] |
|
113 |
||
114 |
||
115 |
processAction (ProtocolError msg) = do |
|
116 |
chan <- client's sendChan |
|
117 |
processAction $ AnswerClients [chan] ["ERROR", msg] |
|
118 |
||
119 |
||
120 |
processAction (Warning msg) = do |
|
121 |
chan <- client's sendChan |
|
122 |
processAction $ AnswerClients [chan] ["WARNING", msg] |
|
123 |
||
124 |
processAction (NoticeMessage n) = do |
|
125 |
chan <- client's sendChan |
|
126 |
processAction $ AnswerClients [chan] ["NOTICE", showB . fromEnum $ n] |
|
127 |
||
128 |
processAction (ByeClient msg) = do |
|
129 |
(Just ci) <- gets clientIndex |
|
130 |
ri <- clientRoomA |
|
131 |
||
132 |
chan <- client's sendChan |
|
133 |
clNick <- client's nick |
|
134 |
loggedIn <- client's logonPassed |
|
135 |
||
136 |
when (ri /= lobbyId) $ do |
|
137 |
processAction $ MoveToLobby ("quit: " `B.append` msg) |
|
138 |
return () |
|
139 |
||
140 |
clientsChans <- liftM (Prelude.map sendChan . Prelude.filter logonPassed) $! allClientsS |
|
141 |
io $ |
|
142 |
infoM "Clients" (show ci ++ " quits: " ++ B.unpack msg) |
|
143 |
||
144 |
processAction $ AnswerClients [chan] ["BYE", msg] |
|
145 |
when loggedIn $ processAction $ AnswerClients clientsChans ["LOBBY:LEFT", clNick, msg] |
|
146 |
||
147 |
s <- get |
|
148 |
put $! s{removedClients = ci `Set.insert` removedClients s} |
|
149 |
||
150 |
processAction (DeleteClient ci) = do |
|
151 |
io $ debugM "Clients" $ "DeleteClient: " ++ show ci |
|
152 |
||
153 |
rnc <- gets roomsClients |
|
154 |
io $ removeClient rnc ci |
|
155 |
||
156 |
s <- get |
|
157 |
put $! s{removedClients = ci `Set.delete` removedClients s} |
|
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
158 |
|
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
159 |
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
|
160 |
cls <- allClientsS |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
161 |
io $ when (sp && null cls) $ throwIO ShutdownException |
5184 | 162 |
|
163 |
processAction (ModifyClient f) = do |
|
164 |
(Just ci) <- gets clientIndex |
|
165 |
rnc <- gets roomsClients |
|
166 |
io $ modifyClient rnc f ci |
|
167 |
return () |
|
168 |
||
169 |
processAction (ModifyClient2 ci f) = do |
|
170 |
rnc <- gets roomsClients |
|
171 |
io $ modifyClient rnc f ci |
|
172 |
return () |
|
173 |
||
174 |
||
175 |
processAction (ModifyRoom f) = do |
|
176 |
rnc <- gets roomsClients |
|
177 |
ri <- clientRoomA |
|
178 |
io $ modifyRoom rnc f ri |
|
179 |
return () |
|
180 |
||
181 |
||
182 |
processAction (ModifyServerInfo f) = do |
|
183 |
modify (\s -> s{serverInfo = f $ serverInfo s}) |
|
184 |
si <- gets serverInfo |
|
185 |
io $ writeServerConfig si |
|
186 |
||
187 |
||
188 |
processAction (MoveToRoom ri) = do |
|
189 |
(Just ci) <- gets clientIndex |
|
190 |
rnc <- gets roomsClients |
|
191 |
||
192 |
io $ do |
|
193 |
modifyClient rnc (\cl -> cl{teamsInGame = 0, isReady = False, isMaster = False}) ci |
|
194 |
modifyRoom rnc (\r -> r{playersIn = playersIn r + 1}) ri |
|
195 |
moveClientToRoom rnc ri ci |
|
196 |
||
197 |
chans <- liftM (map sendChan) $ roomClientsS ri |
|
198 |
clNick <- client's nick |
|
199 |
||
200 |
processAction $ AnswerClients chans ["JOINED", clNick] |
|
201 |
||
202 |
||
203 |
processAction (MoveToLobby msg) = do |
|
204 |
(Just ci) <- gets clientIndex |
|
205 |
ri <- clientRoomA |
|
206 |
rnc <- gets roomsClients |
|
207 |
(gameProgress, playersNum) <- io $ room'sM rnc (gameinprogress &&& playersIn) ri |
|
208 |
ready <- client's isReady |
|
209 |
master <- client's isMaster |
|
210 |
-- client <- client's id |
|
211 |
clNick <- client's nick |
|
212 |
chans <- othersChans |
|
213 |
||
214 |
if master then |
|
215 |
if gameProgress && playersNum > 1 then |
|
216 |
mapM_ processAction [ChangeMaster, AnswerClients chans ["LEFT", clNick, msg], NoticeMessage AdminLeft, RemoveClientTeams ci] |
|
217 |
else |
|
218 |
processAction RemoveRoom |
|
219 |
else |
|
220 |
mapM_ processAction [AnswerClients chans ["LEFT", clNick, msg], RemoveClientTeams ci] |
|
221 |
||
222 |
-- when not removing room |
|
223 |
when (not master || (gameProgress && playersNum > 1)) . io $ do |
|
224 |
modifyRoom rnc (\r -> r{ |
|
225 |
playersIn = playersIn r - 1, |
|
226 |
readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r |
|
227 |
}) ri |
|
228 |
moveClientToLobby rnc ci |
|
229 |
||
230 |
processAction ChangeMaster = do |
|
231 |
(Just ci) <- gets clientIndex |
|
232 |
ri <- clientRoomA |
|
233 |
rnc <- gets roomsClients |
|
234 |
newMasterId <- liftM (head . filter (/= ci)) . io $ roomClientsIndicesM rnc ri |
|
235 |
newMaster <- io $ client'sM rnc id newMasterId |
|
236 |
let newRoomName = nick newMaster |
|
237 |
mapM_ processAction [ |
|
238 |
ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName}), |
|
239 |
ModifyClient2 newMasterId (\c -> c{isMaster = True}), |
|
240 |
AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"] |
|
241 |
] |
|
242 |
||
243 |
processAction (AddRoom roomName roomPassword) = do |
|
244 |
Just clId <- gets clientIndex |
|
245 |
rnc <- gets roomsClients |
|
246 |
proto <- io $ client'sM rnc clientProto clId |
|
247 |
||
248 |
let rm = newRoom{ |
|
249 |
masterID = clId, |
|
250 |
name = roomName, |
|
251 |
password = roomPassword, |
|
252 |
roomProto = proto |
|
253 |
} |
|
254 |
||
255 |
rId <- io $ addRoom rnc rm |
|
256 |
||
257 |
processAction $ MoveToRoom rId |
|
258 |
||
259 |
chans <- liftM (map sendChan) $! roomClientsS lobbyId |
|
260 |
||
261 |
mapM_ processAction [ |
|
262 |
AnswerClients chans ["ROOM", "ADD", roomName] |
|
263 |
, ModifyClient (\cl -> cl{isMaster = True}) |
|
264 |
] |
|
265 |
||
266 |
||
267 |
processAction RemoveRoom = do |
|
268 |
Just clId <- gets clientIndex |
|
269 |
rnc <- gets roomsClients |
|
270 |
ri <- io $ clientRoomM rnc clId |
|
271 |
roomName <- io $ room'sM rnc name ri |
|
272 |
others <- othersChans |
|
273 |
lobbyChans <- liftM (map sendChan) $! roomClientsS lobbyId |
|
274 |
||
275 |
mapM_ processAction [ |
|
276 |
AnswerClients lobbyChans ["ROOM", "DEL", roomName], |
|
277 |
AnswerClients others ["ROOMABANDONED", roomName] |
|
278 |
] |
|
279 |
||
280 |
io $ removeRoom rnc ri |
|
281 |
||
282 |
||
283 |
processAction (UnreadyRoomClients) = do |
|
284 |
rnc <- gets roomsClients |
|
285 |
ri <- clientRoomA |
|
286 |
roomPlayers <- roomClientsS ri |
|
287 |
roomClIDs <- io $ roomClientsIndicesM rnc ri |
|
288 |
pr <- client's clientProto |
|
289 |
processAction $ AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers) |
|
290 |
io $ mapM_ (modifyClient rnc (\cl -> cl{isReady = False})) roomClIDs |
|
291 |
processAction $ ModifyRoom (\r -> r{readyPlayers = 0}) |
|
292 |
where |
|
293 |
notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks |
|
294 |
||
295 |
||
296 |
processAction (RemoveTeam teamName) = do |
|
297 |
rnc <- gets roomsClients |
|
298 |
ri <- clientRoomA |
|
299 |
inGame <- io $ room'sM rnc gameinprogress ri |
|
300 |
chans <- othersChans |
|
301 |
if not $ inGame then |
|
302 |
mapM_ processAction [ |
|
303 |
AnswerClients chans ["REMOVE_TEAM", teamName], |
|
304 |
ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r}) |
|
305 |
] |
|
306 |
else |
|
307 |
mapM_ processAction [ |
|
308 |
AnswerClients chans ["EM", rmTeamMsg], |
|
309 |
ModifyRoom (\r -> r{ |
|
310 |
teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r, |
|
311 |
leftTeams = teamName : leftTeams r, |
|
312 |
roundMsgs = roundMsgs r Seq.|> rmTeamMsg |
|
313 |
}) |
|
314 |
] |
|
315 |
where |
|
316 |
rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName |
|
317 |
||
318 |
||
319 |
processAction (RemoveClientTeams clId) = do |
|
320 |
rnc <- gets roomsClients |
|
321 |
||
322 |
removeTeamActions <- io $ do |
|
323 |
clNick <- client'sM rnc nick clId |
|
324 |
rId <- clientRoomM rnc clId |
|
325 |
roomTeams <- room'sM rnc teams rId |
|
326 |
return . Prelude.map (RemoveTeam . teamname) . Prelude.filter (\t -> teamowner t == clNick) $ roomTeams |
|
327 |
||
328 |
mapM_ processAction removeTeamActions |
|
329 |
||
330 |
||
331 |
||
332 |
processAction CheckRegistered = do |
|
333 |
(Just ci) <- gets clientIndex |
|
334 |
n <- client's nick |
|
335 |
h <- client's host |
|
336 |
p <- client's clientProto |
|
337 |
uid <- client's clUID |
|
338 |
haveSameNick <- liftM (not . null . tail . filter (\c -> nick c == n)) allClientsS |
|
339 |
if haveSameNick then |
|
340 |
if p < 38 then |
|
341 |
mapM_ processAction [ByeClient "Nickname is already in use", removeNick] |
|
342 |
else |
|
343 |
mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick] |
|
344 |
else |
|
345 |
do |
|
346 |
db <- gets (dbQueries . serverInfo) |
|
347 |
io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
|
348 |
return () |
|
349 |
where |
|
350 |
removeNick = ModifyClient (\c -> c{nick = ""}) |
|
351 |
||
352 |
||
353 |
processAction ClearAccountsCache = do |
|
354 |
dbq <- gets (dbQueries . serverInfo) |
|
355 |
io $ writeChan dbq ClearCache |
|
356 |
return () |
|
357 |
||
358 |
||
359 |
processAction (ProcessAccountInfo info) = |
|
360 |
case info of |
|
361 |
HasAccount passwd isAdmin -> do |
|
362 |
chan <- client's sendChan |
|
363 |
mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})] |
|
364 |
Guest -> |
|
365 |
processAction JoinLobby |
|
366 |
Admin -> do |
|
367 |
mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby] |
|
368 |
chan <- client's sendChan |
|
369 |
processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
|
370 |
||
371 |
||
372 |
processAction JoinLobby = do |
|
373 |
chan <- client's sendChan |
|
374 |
clientNick <- client's nick |
|
375 |
(lobbyNicks, clientsChans) <- liftM (unzip . Prelude.map (nick &&& sendChan) . Prelude.filter logonPassed) $! allClientsS |
|
376 |
mapM_ processAction $ |
|
377 |
AnswerClients clientsChans ["LOBBY:JOINED", clientNick] |
|
378 |
: AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks) |
|
379 |
: [ModifyClient (\cl -> cl{logonPassed = True}), SendServerMessage] |
|
380 |
||
381 |
||
382 |
processAction (KickClient kickId) = do |
|
383 |
modify (\s -> s{clientIndex = Just kickId}) |
|
384 |
processAction $ ByeClient "Kicked" |
|
385 |
||
386 |
||
387 |
processAction (BanClient seconds reason banId) = do |
|
388 |
modify (\s -> s{clientIndex = Just banId}) |
|
389 |
clHost <- client's host |
|
390 |
currentTime <- io getCurrentTime |
|
391 |
let msg = B.concat ["Ban for ", B.pack . show $ seconds, "seconds (", reason, ")"] |
|
392 |
mapM_ processAction [ |
|
393 |
AddIP2Bans clHost msg (addUTCTime seconds currentTime) |
|
394 |
, KickClient banId |
|
395 |
] |
|
396 |
||
397 |
||
398 |
processAction (KickRoomClient kickId) = do |
|
399 |
modify (\s -> s{clientIndex = Just kickId}) |
|
400 |
ch <- client's sendChan |
|
401 |
mapM_ processAction [AnswerClients [ch] ["KICKED"], MoveToLobby "kicked"] |
|
402 |
||
403 |
||
404 |
processAction (AddClient cl) = do |
|
405 |
rnc <- gets roomsClients |
|
406 |
si <- gets serverInfo |
|
407 |
newClId <- io $ do |
|
408 |
ci <- addClient rnc cl |
|
409 |
_ <- Exception.mask (forkIO . clientRecvLoop (clientSocket cl) (coreChan si) (sendChan cl) ci) |
|
410 |
||
411 |
infoM "Clients" (show ci ++ ": New client. Time: " ++ show (connectTime cl)) |
|
412 |
||
413 |
return ci |
|
414 |
||
415 |
modify (\s -> s{clientIndex = Just newClId}) |
|
416 |
mapM_ processAction |
|
417 |
[ |
|
418 |
AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
|
419 |
, CheckBanned |
|
420 |
, AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
|
421 |
] |
|
422 |
||
423 |
||
424 |
processAction (AddNick2Bans n reason expiring) = do |
|
425 |
processAction $ ModifyServerInfo (\s -> s{bans = BanByNick n reason expiring : bans s}) |
|
426 |
||
427 |
processAction (AddIP2Bans ip reason expiring) = do |
|
428 |
(Just ci) <- gets clientIndex |
|
429 |
rc <- gets removedClients |
|
430 |
when (not $ ci `Set.member` rc) |
|
431 |
$ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
|
432 |
||
433 |
processAction CheckBanned = do |
|
434 |
clTime <- client's connectTime |
|
435 |
clNick <- client's nick |
|
436 |
clHost <- client's host |
|
437 |
si <- gets serverInfo |
|
438 |
let validBans = filter (checkNotExpired clTime) $ bans si |
|
439 |
let ban = L.find (checkBan clHost clNick) $ validBans |
|
440 |
when (isJust ban) $ |
|
441 |
mapM_ processAction [ |
|
442 |
ModifyServerInfo (\s -> s{bans = validBans}) |
|
443 |
, ByeClient (getBanReason $ fromJust ban) |
|
444 |
] |
|
445 |
where |
|
446 |
checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
|
447 |
checkNotExpired testTime (BanByNick _ _ time) = testTime `diffUTCTime` time <= 0 |
|
448 |
checkBan ip _ (BanByIP bip _ _) = bip == ip |
|
449 |
checkBan _ n (BanByNick bn _ _) = bn == n |
|
450 |
getBanReason (BanByIP _ msg _) = msg |
|
451 |
getBanReason (BanByNick _ msg _) = msg |
|
452 |
||
453 |
processAction PingAll = do |
|
454 |
rnc <- gets roomsClients |
|
455 |
io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
|
456 |
cis <- io $ allClientsM rnc |
|
457 |
chans <- io $ mapM (client'sM rnc sendChan) cis |
|
458 |
io $ mapM_ (modifyClient rnc (\cl -> cl{pingsQueue = pingsQueue cl + 1})) cis |
|
459 |
processAction $ AnswerClients chans ["PING"] |
|
460 |
where |
|
461 |
kickTimeouted rnc ci = do |
|
462 |
pq <- io $ client'sM rnc pingsQueue ci |
|
463 |
when (pq > 0) $ |
|
464 |
withStateT (\as -> as{clientIndex = Just ci}) $ |
|
465 |
processAction (ByeClient "Ping timeout") |
|
466 |
||
467 |
||
468 |
processAction StatsAction = do |
|
469 |
rnc <- gets roomsClients |
|
470 |
si <- gets serverInfo |
|
471 |
(roomsNum, clientsNum) <- io $ withRoomsAndClients rnc st |
|
472 |
io $ writeChan (dbQueries si) $ SendStats clientsNum (roomsNum - 1) |
|
473 |
where |
|
474 |
st irnc = (length $ allRooms irnc, length $ allClients irnc) |
|
475 |
||
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
476 |
processAction RestartServer = do |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
477 |
sock <- gets (fromJust . serverSocket . serverInfo) |
5210 | 478 |
args <- gets (runArgs . serverInfo) |
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
479 |
io $ do |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
480 |
noticeM "Core" "Closing listening socket" |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
481 |
sClose sock |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
482 |
noticeM "Core" "Spawning new server" |
5210 | 483 |
_ <- createProcess (proc "./hedgewars-server" args) |
5209
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
484 |
return () |
f7a610e2ef5f
On restart command close server socket and spawn new server, keep running until last client quits
unc0rr
parents:
5184
diff
changeset
|
485 |
processAction $ ModifyServerInfo (\s -> s{shutdownPending=True}) |
5184 | 486 |
|
487 |
processAction SaveReplay = do |
|
488 |
ri <- clientRoomA |
|
489 |
rnc <- gets roomsClients |
|
490 |
io $ do |
|
491 |
r <- room'sM rnc id ri |
|
492 |
saveReplay r |