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