author | unc0rr |
Sun, 06 Mar 2011 21:54:37 +0300 | |
changeset 4989 | 4771fed9272e |
parent 4975 | 31da8979e5b1 |
child 4991 | 90d1fb9fc2e1 |
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 |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
7 |
import System.Log.Logger |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
8 |
import Control.Monad |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
9 |
import Data.Time |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
10 |
import Data.Maybe |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
11 |
import Control.Monad.Reader |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
12 |
import Control.Monad.State.Strict |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
13 |
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
|
14 |
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
|
15 |
import Data.Unique |
4932 | 16 |
import Control.Arrow |
4959 | 17 |
import Control.Exception |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
18 |
----------------------------- |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
19 |
import CoreTypes |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
20 |
import Utils |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
21 |
import ClientIO |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
22 |
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
|
23 |
import Consts |
4989 | 24 |
import ConfigFile |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
25 |
|
4989 | 26 |
data Action = |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
27 |
AnswerClients ![ClientChan] ![B.ByteString] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
28 |
| SendServerMessage |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
29 |
| SendServerVars |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
30 |
| MoveToRoom RoomIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
31 |
| MoveToLobby B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
32 |
| RemoveTeam B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
33 |
| RemoveRoom |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
34 |
| UnreadyRoomClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
35 |
| JoinLobby |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
36 |
| ProtocolError B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
37 |
| Warning B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
38 |
| NoticeMessage Notice |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
39 |
| ByeClient B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
40 |
| KickClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
41 |
| KickRoomClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
42 |
| BanClient NominalDiffTime B.ByteString ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
43 |
| ChangeMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
44 |
| RemoveClientTeams ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
45 |
| ModifyClient (ClientInfo -> ClientInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
46 |
| ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
47 |
| ModifyRoom (RoomInfo -> RoomInfo) |
4989 | 48 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
49 |
| AddRoom B.ByteString B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
50 |
| CheckRegistered |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
51 |
| ClearAccountsCache |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
52 |
| ProcessAccountInfo AccountInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
53 |
| AddClient ClientInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
54 |
| DeleteClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
55 |
| PingAll |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
56 |
| StatsAction |
4914 | 57 |
| RestartServer Bool |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
58 |
|
4955 | 59 |
|
4989 | 60 |
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
|
61 |
|
4989 | 62 |
instance NFData Action where |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
63 |
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
|
64 |
rnf a = a `seq` () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
65 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
66 |
instance NFData B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
67 |
instance NFData (Chan a) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
68 |
|
4932 | 69 |
|
4989 | 70 |
othersChans :: StateT ServerState IO [ClientChan] |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
71 |
othersChans = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
72 |
cl <- client's id |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
73 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
74 |
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
|
75 |
|
4989 | 76 |
processAction :: Action -> StateT ServerState IO () |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
77 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
78 |
|
4932 | 79 |
processAction (AnswerClients chans msg) = |
80 |
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
|
81 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
82 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
83 |
processAction SendServerMessage = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
84 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
85 |
protonum <- client's clientProto |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
86 |
si <- liftM serverInfo get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
87 |
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
|
88 |
serverMessageForOldVersions si |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
89 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
90 |
serverMessage si |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
91 |
processAction $ AnswerClients [chan] ["SERVER_MESSAGE", message] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
92 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
93 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
94 |
processAction SendServerVars = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
95 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
96 |
si <- gets serverInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
97 |
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
|
98 |
where |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
99 |
vars si = [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
100 |
"MOTD_NEW", serverMessage si, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
101 |
"MOTD_OLD", serverMessageForOldVersions si, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
102 |
"LATEST_PROTO", B.pack . show $ latestReleaseVersion si |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
103 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
104 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
105 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
106 |
processAction (ProtocolError msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
107 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
108 |
processAction $ AnswerClients [chan] ["ERROR", msg] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
109 |
|
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 |
processAction (Warning msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
112 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
113 |
processAction $ AnswerClients [chan] ["WARNING", msg] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
114 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
115 |
processAction (NoticeMessage n) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
116 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
117 |
processAction $ AnswerClients [chan] ["NOTICE", B.pack . show . fromEnum $ n] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
118 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
119 |
processAction (ByeClient msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
120 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
121 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
122 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
123 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
124 |
clNick <- client's nick |
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 |
when (ri /= lobbyId) $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
127 |
processAction $ MoveToLobby ("quit: " `B.append` msg) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
128 |
return () |
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 |
clientsChans <- liftM (Prelude.map sendChan . Prelude.filter logonPassed) $! allClientsS |
4932 | 131 |
io $ |
132 |
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
|
133 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
134 |
processAction $ AnswerClients [chan] ["BYE", msg] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
135 |
processAction $ AnswerClients clientsChans ["LOBBY:LEFT", clNick, msg] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
136 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
137 |
s <- get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
138 |
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
|
139 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
140 |
processAction (DeleteClient ci) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
141 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
142 |
io $ removeClient rnc ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
143 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
144 |
s <- get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
145 |
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
|
146 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
147 |
processAction (ModifyClient f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
148 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
149 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
150 |
io $ modifyClient rnc f ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
151 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
152 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
153 |
processAction (ModifyClient2 ci f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
154 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
155 |
io $ modifyClient rnc f ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
156 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
157 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
158 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
159 |
processAction (ModifyRoom f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
160 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
161 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
162 |
io $ modifyRoom rnc f ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
163 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
164 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
165 |
|
4989 | 166 |
processAction (ModifyServerInfo f) = do |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
167 |
modify (\s -> s{serverInfo = f $ serverInfo s}) |
4989 | 168 |
si <- gets serverInfo |
169 |
io $ writeServerConfig si |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
170 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
171 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
172 |
processAction (MoveToRoom ri) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
173 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
174 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
175 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
176 |
io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
177 |
modifyClient rnc (\cl -> cl{teamsInGame = 0, isReady = False, isMaster = False}) ci |
4932 | 178 |
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
|
179 |
moveClientToRoom rnc ri ci |
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 |
chans <- liftM (map sendChan) $ roomClientsS ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
182 |
clNick <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
183 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
184 |
processAction $ AnswerClients chans ["JOINED", clNick] |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
187 |
processAction (MoveToLobby msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
188 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
189 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
190 |
rnc <- gets roomsClients |
4932 | 191 |
(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
|
192 |
ready <- client's isReady |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
193 |
master <- client's isMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
194 |
-- client <- client's id |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
195 |
clNick <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
196 |
chans <- othersChans |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
197 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
198 |
if master then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
199 |
if gameProgress && playersNum > 1 then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
200 |
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
|
201 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
202 |
processAction RemoveRoom |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
203 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
204 |
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
|
205 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
206 |
io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
207 |
modifyRoom rnc (\r -> r{ |
4932 | 208 |
playersIn = playersIn r - 1, |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
209 |
readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
210 |
}) ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
211 |
moveClientToLobby rnc ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
212 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
213 |
processAction ChangeMaster = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
214 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
215 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
216 |
newMasterId <- liftM head . io $ roomClientsIndicesM rnc ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
217 |
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
|
218 |
let newRoomName = nick newMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
219 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
220 |
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
|
221 |
ModifyClient2 newMasterId (\c -> c{isMaster = True}), |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
222 |
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
|
223 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
224 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
225 |
processAction (AddRoom roomName roomPassword) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
226 |
Just clId <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
227 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
228 |
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
|
229 |
|
4932 | 230 |
let rm = newRoom{ |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
231 |
masterID = clId, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
232 |
name = roomName, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
233 |
password = roomPassword, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
234 |
roomProto = proto |
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 |
|
4932 | 237 |
rId <- io $ addRoom rnc rm |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
238 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
239 |
processAction $ MoveToRoom rId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
240 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
241 |
chans <- liftM (map sendChan) $! roomClientsS lobbyId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
242 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
243 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
244 |
AnswerClients chans ["ROOM", "ADD", roomName] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
245 |
, ModifyClient (\cl -> cl{isMaster = True}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
246 |
] |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
249 |
processAction RemoveRoom = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
250 |
Just clId <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
251 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
252 |
ri <- io $ clientRoomM rnc clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
253 |
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
|
254 |
others <- othersChans |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
255 |
lobbyChans <- liftM (map sendChan) $! roomClientsS lobbyId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
256 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
257 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
258 |
AnswerClients lobbyChans ["ROOM", "DEL", roomName], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
259 |
AnswerClients others ["ROOMABANDONED", roomName] |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
262 |
io $ removeRoom rnc ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
263 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
264 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
265 |
processAction (UnreadyRoomClients) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
266 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
267 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
268 |
roomPlayers <- roomClientsS ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
277 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
278 |
processAction (RemoveTeam teamName) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
279 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
280 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
281 |
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
|
282 |
chans <- othersChans |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
283 |
if inGame then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
284 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
285 |
AnswerClients chans ["REMOVE_TEAM", teamName], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
286 |
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
|
287 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
288 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
289 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
290 |
AnswerClients chans ["EM", rmTeamMsg], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
291 |
ModifyRoom (\r -> r{ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
292 |
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
|
293 |
leftTeams = teamName : leftTeams r, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
294 |
roundMsgs = roundMsgs r Seq.|> rmTeamMsg |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
295 |
}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
296 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
297 |
where |
4932 | 298 |
rmTeamMsg = toEngineMsg $ B.singleton 'F' `B.append` teamName |
4907
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
301 |
processAction (RemoveClientTeams clId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
302 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
303 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
304 |
removeTeamActions <- io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
305 |
clNick <- client'sM rnc nick clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
306 |
rId <- clientRoomM rnc clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
307 |
roomTeams <- room'sM rnc teams rId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
308 |
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
|
309 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
310 |
mapM_ processAction removeTeamActions |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
314 |
processAction CheckRegistered = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
315 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
316 |
n <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
317 |
h <- client's host |
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
|
318 |
uid <- client's clUID |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
319 |
db <- gets (dbQueries . serverInfo) |
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
|
320 |
io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
321 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
322 |
|
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 |
processAction ClearAccountsCache = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
325 |
dbq <- gets (dbQueries . serverInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
326 |
io $ writeChan dbq ClearCache |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
327 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
328 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
329 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
330 |
processAction (ProcessAccountInfo info) = |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
331 |
case info of |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
332 |
HasAccount passwd isAdmin -> do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
333 |
chan <- client's sendChan |
4923 | 334 |
mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})] |
4932 | 335 |
Guest -> |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
336 |
processAction JoinLobby |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
337 |
Admin -> do |
4932 | 338 |
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
|
339 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
340 |
processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
341 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
342 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
343 |
processAction JoinLobby = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
344 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
345 |
clientNick <- client's nick |
4932 | 346 |
(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
|
347 |
mapM_ processAction $ |
4932 | 348 |
AnswerClients clientsChans ["LOBBY:JOINED", clientNick] |
349 |
: AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks) |
|
350 |
: [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
|
351 |
|
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
|
352 |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
353 |
processAction (KickClient kickId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
354 |
modify (\s -> s{clientIndex = Just kickId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
355 |
processAction $ ByeClient "Kicked" |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
356 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
357 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
358 |
processAction (BanClient seconds reason banId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
359 |
modify (\s -> s{clientIndex = Just banId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
360 |
clHost <- client's host |
4932 | 361 |
currentTime <- io getCurrentTime |
362 |
let msg = "Ban for " `B.append` (B.pack . show $ seconds) `B.append` "seconds (" `B.append` reason ` B.append` ")" |
|
4909 | 363 |
mapM_ processAction [ |
4932 | 364 |
ModifyServerInfo (\s -> s{lastLogins = (clHost, (addUTCTime seconds currentTime, msg)) : lastLogins s}) |
4909 | 365 |
, KickClient banId |
366 |
] |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
367 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
368 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
369 |
processAction (KickRoomClient kickId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
370 |
modify (\s -> s{clientIndex = Just kickId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
371 |
ch <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
372 |
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
|
373 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
374 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
375 |
processAction (AddClient cl) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
376 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
377 |
si <- gets serverInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
378 |
newClId <- io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
379 |
ci <- addClient rnc cl |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
380 |
t <- forkIO $ clientRecvLoop (clientSocket cl) (coreChan si) ci |
4932 | 381 |
_ <- forkIO $ clientSendLoop (clientSocket cl) t (coreChan si) (sendChan cl) ci |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
382 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
383 |
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
|
384 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
385 |
return ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
386 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
387 |
modify (\s -> s{clientIndex = Just newClId}) |
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
|
388 |
processAction $ AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
389 |
|
4932 | 390 |
let newLogins = takeWhile (\(_ , (time, _)) -> connectTime cl `diffUTCTime` time <= 0) $ lastLogins si |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
391 |
let info = host cl `Prelude.lookup` newLogins |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
392 |
if isJust info then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
393 |
mapM_ processAction [ModifyServerInfo (\s -> s{lastLogins = newLogins}), ByeClient (snd . fromJust $ info)] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
394 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
395 |
processAction $ ModifyServerInfo (\s -> s{lastLogins = (host cl, (addUTCTime 10 $ connectTime cl, "Reconnected too fast")) : newLogins}) |
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 PingAll = 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 |
io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
401 |
cis <- io $ allClientsM rnc |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
processAction $ AnswerClients chans ["PING"] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
405 |
where |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
406 |
kickTimeouted rnc ci = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
407 |
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
|
408 |
when (pq > 0) $ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
409 |
withStateT (\as -> as{clientIndex = Just ci}) $ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
410 |
processAction (ByeClient "Ping timeout") |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
411 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
412 |
|
4914 | 413 |
processAction StatsAction = do |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
414 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
415 |
si <- gets serverInfo |
4932 | 416 |
(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
|
417 |
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
|
418 |
where |
4932 | 419 |
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
|
420 |
|
4955 | 421 |
processAction (RestartServer force) = do |
422 |
if force then do |
|
4962 | 423 |
throw RestartException |
4955 | 424 |
else |
425 |
processAction $ ModifyServerInfo (\s -> s{restartPending=True}) |