author | unc0rr |
Sat, 20 Oct 2012 18:54:03 +0400 | |
changeset 7769 | 1661680c6b59 |
parent 7766 | 98edc0724a28 |
child 7775 | 835ad028fb66 |
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 [ |
7682 | 264 |
ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName, isRestrictedJoins = False, isRestrictedTeams = False}) |
265 |
, ModifyClient2 newMasterId (\c -> c{isMaster = True}) |
|
266 |
, AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"] |
|
267 |
, AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster] |
|
268 |
, AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster] |
|
269 |
, AnswerClients thisRoomChans ["CLIENT_FLAGS", "+h", nick newMaster] |
|
5184 | 270 |
] |
271 |
||
7766 | 272 |
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
|
273 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
7766 | 274 |
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
|
275 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
276 |
|
5184 | 277 |
processAction (AddRoom roomName roomPassword) = do |
278 |
Just clId <- gets clientIndex |
|
279 |
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
|
280 |
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
|
281 |
n <- client's nick |
7682 | 282 |
chan <- client's sendChan |
5184 | 283 |
|
284 |
let rm = newRoom{ |
|
285 |
masterID = clId, |
|
286 |
name = roomName, |
|
287 |
password = roomPassword, |
|
288 |
roomProto = proto |
|
289 |
} |
|
290 |
||
291 |
rId <- io $ addRoom rnc rm |
|
292 |
||
293 |
processAction $ MoveToRoom rId |
|
294 |
||
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
|
295 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
5184 | 296 |
|
297 |
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
|
298 |
AnswerClients chans ("ROOM" : "ADD" : roomInfo n rm) |
7682 | 299 |
, AnswerClients [chan] ["CLIENT_FLAGS", "+h", n] |
5184 | 300 |
, ModifyClient (\cl -> cl{isMaster = True}) |
301 |
] |
|
302 |
||
303 |
||
304 |
processAction RemoveRoom = do |
|
305 |
Just clId <- gets clientIndex |
|
306 |
rnc <- gets roomsClients |
|
307 |
ri <- io $ clientRoomM rnc clId |
|
308 |
roomName <- io $ room'sM rnc name ri |
|
309 |
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
|
310 |
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
|
311 |
chans <- liftM (map sendChan) $! sameProtoClientsS proto |
5184 | 312 |
|
313 |
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
|
314 |
AnswerClients chans ["ROOM", "DEL", roomName], |
5184 | 315 |
AnswerClients others ["ROOMABANDONED", roomName] |
316 |
] |
|
317 |
||
318 |
io $ removeRoom rnc ri |
|
319 |
||
320 |
||
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
|
321 |
processAction UnreadyRoomClients = do |
5184 | 322 |
ri <- clientRoomA |
323 |
roomPlayers <- roomClientsS ri |
|
324 |
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
|
325 |
mapM_ processAction [ |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
326 |
AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers) |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
327 |
, ModifyRoomClients (\cl -> cl{isReady = False}) |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
328 |
, ModifyRoom (\r -> r{readyPlayers = 0}) |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7748
diff
changeset
|
329 |
] |
5184 | 330 |
where |
331 |
notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks |
|
332 |
||
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
333 |
|
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
|
334 |
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
|
335 |
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
|
336 |
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
|
337 |
thisRoomChans <- liftM (map sendChan) $ roomClientsS ri |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
338 |
answerRemovedTeams <- io $ |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
339 |
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
|
340 |
|
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
341 |
mapM_ processAction $ |
7124 | 342 |
SaveReplay |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
343 |
: 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
|
344 |
(\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
|
345 |
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
|
346 |
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
|
347 |
} |
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 |
) |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
349 |
: UnreadyRoomClients |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
350 |
: answerRemovedTeams |
5184 | 351 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
352 |
|
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
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
gameInfo = liftM (\g -> g{ |
7124 | 359 |
teamsInGameNumber = teamsInGameNumber g - 1 |
360 |
, 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
|
361 |
}) $ 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
|
362 |
}) |
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 |
] |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
364 |
|
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
|
365 |
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
|
366 |
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
|
367 |
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
|
368 |
when (isJust gi && 0 == teamsInGameNumber (fromJust gi)) $ |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
369 |
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
|
370 |
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
|
371 |
rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
372 |
|
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
373 |
|
5184 | 374 |
processAction (RemoveTeam teamName) = do |
375 |
rnc <- gets roomsClients |
|
376 |
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
|
377 |
inGame <- io $ room'sM rnc (isJust . gameInfo) ri |
5184 | 378 |
chans <- othersChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
379 |
mapM_ processAction $ |
7126
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
380 |
ModifyRoom (\r -> r{ |
8daa5c8e84c0
Bring leftTeams back (with a fix) as it is apparently needed for spectators.
unc0rr
parents:
7124
diff
changeset
|
381 |
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
|
382 |
, 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
|
383 |
}) |
7124 | 384 |
: AnswerClients chans ["REMOVE_TEAM", teamName] |
385 |
: [SendTeamRemovalMessage teamName | inGame] |
|
5184 | 386 |
|
387 |
||
388 |
processAction (RemoveClientTeams clId) = do |
|
389 |
rnc <- gets roomsClients |
|
390 |
||
391 |
removeTeamActions <- io $ do |
|
392 |
clNick <- client'sM rnc nick clId |
|
393 |
rId <- clientRoomM rnc clId |
|
394 |
roomTeams <- room'sM rnc teams rId |
|
395 |
return . Prelude.map (RemoveTeam . teamname) . Prelude.filter (\t -> teamowner t == clNick) $ roomTeams |
|
396 |
||
397 |
mapM_ processAction removeTeamActions |
|
398 |
||
399 |
||
400 |
||
401 |
processAction CheckRegistered = do |
|
402 |
(Just ci) <- gets clientIndex |
|
403 |
n <- client's nick |
|
404 |
h <- client's host |
|
405 |
p <- client's clientProto |
|
406 |
uid <- client's clUID |
|
6191 | 407 |
haveSameNick <- liftM (not . null . tail . filter (\c -> caseInsensitiveCompare (nick c) n)) allClientsS |
5184 | 408 |
if haveSameNick then |
409 |
if p < 38 then |
|
410 |
mapM_ processAction [ByeClient "Nickname is already in use", removeNick] |
|
411 |
else |
|
412 |
mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick] |
|
413 |
else |
|
414 |
do |
|
415 |
db <- gets (dbQueries . serverInfo) |
|
416 |
io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
|
417 |
return () |
|
418 |
where |
|
419 |
removeNick = ModifyClient (\c -> c{nick = ""}) |
|
420 |
||
421 |
||
422 |
processAction ClearAccountsCache = do |
|
423 |
dbq <- gets (dbQueries . serverInfo) |
|
424 |
io $ writeChan dbq ClearCache |
|
425 |
return () |
|
426 |
||
427 |
||
428 |
processAction (ProcessAccountInfo info) = |
|
429 |
case info of |
|
430 |
HasAccount passwd isAdmin -> do |
|
431 |
chan <- client's sendChan |
|
432 |
mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})] |
|
433 |
Guest -> |
|
434 |
processAction JoinLobby |
|
435 |
Admin -> do |
|
436 |
mapM_ processAction [ModifyClient (\cl -> cl{isAdministrator = True}), JoinLobby] |
|
437 |
chan <- client's sendChan |
|
438 |
processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
|
439 |
||
440 |
||
441 |
processAction JoinLobby = do |
|
442 |
chan <- client's sendChan |
|
443 |
clientNick <- client's nick |
|
7498
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
444 |
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
|
445 |
isAdmin <- client's isAdministrator |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
446 |
loggedInClients <- liftM (Prelude.filter logonPassed) $! allClientsS |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
mapM_ processAction . concat $ [ |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
452 |
[AnswerClients clientsChans ["LOBBY:JOINED", clientNick]] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
453 |
, [AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks)] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
454 |
, [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
|
455 |
, [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
|
456 |
, [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
|
457 |
, [ModifyClient (\cl -> cl{logonPassed = True})] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
458 |
, [SendServerMessage] |
86984f6fa1b9
Introduce 'a' and 'u' client flags to mark admins and authenticated users
unc0rr
parents:
7465
diff
changeset
|
459 |
] |
5184 | 460 |
|
461 |
||
462 |
processAction (KickClient kickId) = do |
|
463 |
modify (\s -> s{clientIndex = Just kickId}) |
|
5214 | 464 |
clHost <- client's host |
465 |
currentTime <- io getCurrentTime |
|
466 |
mapM_ processAction [ |
|
467 |
AddIP2Bans clHost "60 seconds cooldown after kick" (addUTCTime 60 currentTime), |
|
468 |
ByeClient "Kicked" |
|
469 |
] |
|
5184 | 470 |
|
471 |
||
472 |
processAction (BanClient seconds reason banId) = do |
|
473 |
modify (\s -> s{clientIndex = Just banId}) |
|
474 |
clHost <- client's host |
|
475 |
currentTime <- io getCurrentTime |
|
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
476 |
let msg = B.concat ["Ban for ", B.pack . show $ seconds, " (", reason, ")"] |
5184 | 477 |
mapM_ processAction [ |
478 |
AddIP2Bans clHost msg (addUTCTime seconds currentTime) |
|
479 |
, KickClient banId |
|
480 |
] |
|
481 |
||
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
482 |
processAction (BanIP ip seconds reason) = do |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
483 |
currentTime <- io getCurrentTime |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
484 |
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
|
485 |
processAction $ |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
486 |
AddIP2Bans ip msg (addUTCTime seconds currentTime) |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
487 |
|
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
488 |
processAction BanList = do |
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
489 |
ch <- client's sendChan |
7766 | 490 |
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
|
491 |
processAction $ |
7766 | 492 |
AnswerClients [ch] ["BANLIST", b] |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
493 |
|
7748 | 494 |
processAction (Unban entry) = do |
495 |
processAction $ ModifyServerInfo (\s -> s{bans = filter f $ bans s}) |
|
496 |
where |
|
497 |
f (BanByIP bip _ _) = bip == entry |
|
498 |
f (BanByNick bn _ _) = bn == entry |
|
5184 | 499 |
|
500 |
processAction (KickRoomClient kickId) = do |
|
501 |
modify (\s -> s{clientIndex = Just kickId}) |
|
502 |
ch <- client's sendChan |
|
503 |
mapM_ processAction [AnswerClients [ch] ["KICKED"], MoveToLobby "kicked"] |
|
504 |
||
505 |
||
506 |
processAction (AddClient cl) = do |
|
507 |
rnc <- gets roomsClients |
|
508 |
si <- gets serverInfo |
|
509 |
newClId <- io $ do |
|
510 |
ci <- addClient rnc cl |
|
511 |
_ <- Exception.mask (forkIO . clientRecvLoop (clientSocket cl) (coreChan si) (sendChan cl) ci) |
|
512 |
||
513 |
infoM "Clients" (show ci ++ ": New client. Time: " ++ show (connectTime cl)) |
|
514 |
||
515 |
return ci |
|
516 |
||
517 |
modify (\s -> s{clientIndex = Just newClId}) |
|
518 |
mapM_ processAction |
|
519 |
[ |
|
520 |
AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
|
521 |
, CheckBanned |
|
6809 | 522 |
, AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
5184 | 523 |
] |
524 |
||
525 |
||
526 |
processAction (AddNick2Bans n reason expiring) = do |
|
527 |
processAction $ ModifyServerInfo (\s -> s{bans = BanByNick n reason expiring : bans s}) |
|
528 |
||
529 |
processAction (AddIP2Bans ip reason expiring) = do |
|
530 |
(Just ci) <- gets clientIndex |
|
531 |
rc <- gets removedClients |
|
532 |
when (not $ ci `Set.member` rc) |
|
533 |
$ processAction $ ModifyServerInfo (\s -> s{bans = BanByIP ip reason expiring : bans s}) |
|
534 |
||
535 |
processAction CheckBanned = do |
|
536 |
clTime <- client's connectTime |
|
537 |
clNick <- client's nick |
|
538 |
clHost <- client's host |
|
539 |
si <- gets serverInfo |
|
540 |
let validBans = filter (checkNotExpired clTime) $ bans si |
|
541 |
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
|
542 |
mapM_ processAction $ |
5184 | 543 |
ModifyServerInfo (\s -> s{bans = validBans}) |
5426
109e9b5761c2
Implement command for banning by ip and a command for bans list
unc0rr
parents:
5214
diff
changeset
|
544 |
: [ByeClient (getBanReason $ fromJust ban) | isJust ban] |
5184 | 545 |
where |
546 |
checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
|
547 |
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
|
548 |
checkBan ip _ (BanByIP bip _ _) = bip `B.isPrefixOf` ip |
5184 | 549 |
checkBan _ n (BanByNick bn _ _) = bn == n |
550 |
getBanReason (BanByIP _ msg _) = msg |
|
551 |
getBanReason (BanByNick _ msg _) = msg |
|
552 |
||
553 |
processAction PingAll = do |
|
554 |
rnc <- gets roomsClients |
|
555 |
io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
|
556 |
cis <- io $ allClientsM rnc |
|
557 |
chans <- io $ mapM (client'sM rnc sendChan) cis |
|
558 |
io $ mapM_ (modifyClient rnc (\cl -> cl{pingsQueue = pingsQueue cl + 1})) cis |
|
559 |
processAction $ AnswerClients chans ["PING"] |
|
560 |
where |
|
561 |
kickTimeouted rnc ci = do |
|
562 |
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
|
563 |
when (pq > 0) $ do |
5184 | 564 |
withStateT (\as -> as{clientIndex = Just ci}) $ |
565 |
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
|
566 |
-- 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
|
567 |
-- processAction $ DeleteClient ci -- smth went wrong with client io threads, issue DeleteClient here |
5184 | 568 |
|
569 |
||
570 |
processAction StatsAction = do |
|
5211 | 571 |
si <- gets serverInfo |
572 |
when (not $ shutdownPending si) $ do |
|
5212
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
573 |
rnc <- gets roomsClients |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
574 |
(roomsNum, clientsNum) <- io $ withRoomsAndClients rnc st |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
575 |
io $ writeChan (dbQueries si) $ SendStats clientsNum (roomsNum - 1) |
5184 | 576 |
where |
577 |
st irnc = (length $ allRooms irnc, length $ allClients irnc) |
|
578 |
||
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7126
diff
changeset
|
579 |
processAction RestartServer = do |
5212
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
580 |
sp <- gets (shutdownPending . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
581 |
when (not sp) $ do |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
582 |
sock <- gets (fromJust . serverSocket . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
583 |
args <- gets (runArgs . serverInfo) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
584 |
io $ do |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
585 |
noticeM "Core" "Closing listening socket" |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
586 |
sClose sock |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
587 |
noticeM "Core" "Spawning new server" |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
588 |
_ <- createProcess (proc "./hedgewars-server" args) |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
589 |
return () |
eaffb02f0053
Don't perform RestartServer action when already did it once
unc0rr
parents:
5211
diff
changeset
|
590 |
processAction $ ModifyServerInfo (\s -> s{shutdownPending = True}) |
5184 | 591 |
|
6012 | 592 |
#if defined(OFFICIAL_SERVER) |
5184 | 593 |
processAction SaveReplay = do |
594 |
ri <- clientRoomA |
|
595 |
rnc <- gets roomsClients |
|
596 |
io $ do |
|
597 |
r <- room'sM rnc id ri |
|
598 |
saveReplay r |
|
6012 | 599 |
#else |
600 |
processAction SaveReplay = return () |
|
601 |
#endif |