author | unc0rr |
Sun, 03 Apr 2011 13:34:04 +0400 | |
changeset 5091 | 288dcbda3b77 |
parent 5090 | 2922455e606e |
child 5092 | 28e0a6d2d09a |
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 |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
20 |
----------------------------- |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
21 |
import CoreTypes |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
22 |
import Utils |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
23 |
import ClientIO |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
24 |
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
|
25 |
import Consts |
4989 | 26 |
import ConfigFile |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
27 |
|
4989 | 28 |
data Action = |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
29 |
AnswerClients ![ClientChan] ![B.ByteString] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
30 |
| SendServerMessage |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
31 |
| SendServerVars |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
32 |
| MoveToRoom RoomIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
33 |
| MoveToLobby B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
34 |
| RemoveTeam B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
35 |
| RemoveRoom |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
36 |
| UnreadyRoomClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
37 |
| JoinLobby |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
38 |
| ProtocolError B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
39 |
| Warning B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
40 |
| NoticeMessage Notice |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
41 |
| ByeClient B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
42 |
| KickClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
43 |
| KickRoomClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
44 |
| BanClient NominalDiffTime B.ByteString ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
45 |
| ChangeMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
46 |
| RemoveClientTeams ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
47 |
| ModifyClient (ClientInfo -> ClientInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
48 |
| ModifyClient2 ClientIndex (ClientInfo -> ClientInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
49 |
| ModifyRoom (RoomInfo -> RoomInfo) |
4989 | 50 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
51 |
| AddRoom B.ByteString B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
52 |
| CheckRegistered |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
53 |
| ClearAccountsCache |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
54 |
| ProcessAccountInfo AccountInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
55 |
| AddClient ClientInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
56 |
| DeleteClient ClientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
57 |
| PingAll |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
58 |
| StatsAction |
4914 | 59 |
| RestartServer Bool |
5007 | 60 |
| AddNick2Bans B.ByteString B.ByteString UTCTime |
61 |
| AddIP2Bans B.ByteString B.ByteString UTCTime |
|
62 |
| CheckBanned |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
63 |
|
4955 | 64 |
|
4989 | 65 |
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
|
66 |
|
4989 | 67 |
instance NFData Action where |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
68 |
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
|
69 |
rnf a = a `seq` () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
70 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
71 |
instance NFData B.ByteString |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
72 |
instance NFData (Chan a) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
73 |
|
4932 | 74 |
|
4989 | 75 |
othersChans :: StateT ServerState IO [ClientChan] |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
76 |
othersChans = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
77 |
cl <- client's id |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
78 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
79 |
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
|
80 |
|
4989 | 81 |
processAction :: Action -> StateT ServerState IO () |
4907
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 |
|
4932 | 84 |
processAction (AnswerClients chans msg) = |
85 |
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
|
86 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
87 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
88 |
processAction SendServerMessage = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
89 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
90 |
protonum <- client's clientProto |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
91 |
si <- liftM serverInfo get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
92 |
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
|
93 |
serverMessageForOldVersions si |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
94 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
95 |
serverMessage si |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
96 |
processAction $ AnswerClients [chan] ["SERVER_MESSAGE", message] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
97 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
98 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
99 |
processAction SendServerVars = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
100 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
101 |
si <- gets serverInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
102 |
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
|
103 |
where |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
104 |
vars si = [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
105 |
"MOTD_NEW", serverMessage si, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
106 |
"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
|
107 |
"LATEST_PROTO", showB $ latestReleaseVersion si |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
108 |
] |
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 (ProtocolError 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] ["ERROR", 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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
116 |
processAction (Warning msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
117 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
118 |
processAction $ AnswerClients [chan] ["WARNING", msg] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
119 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
120 |
processAction (NoticeMessage n) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
124 |
processAction (ByeClient msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
125 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
126 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
127 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
128 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
129 |
clNick <- client's nick |
5091 | 130 |
loggedIn <- client's logonPassed |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
131 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
132 |
when (ri /= lobbyId) $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
133 |
processAction $ MoveToLobby ("quit: " `B.append` msg) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
134 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
135 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
136 |
clientsChans <- liftM (Prelude.map sendChan . Prelude.filter logonPassed) $! allClientsS |
4932 | 137 |
io $ |
138 |
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
|
139 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
140 |
processAction $ AnswerClients [chan] ["BYE", msg] |
5091 | 141 |
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
|
142 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
143 |
s <- get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
144 |
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
|
145 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
|
4907
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 $ removeClient rnc ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
151 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
152 |
s <- get |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
153 |
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
|
154 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
155 |
processAction (ModifyClient f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
156 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
157 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
158 |
io $ modifyClient rnc f ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
159 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
160 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
161 |
processAction (ModifyClient2 ci f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
162 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
163 |
io $ modifyClient rnc f ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
164 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
165 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
166 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
167 |
processAction (ModifyRoom f) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
168 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
169 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
170 |
io $ modifyRoom rnc f ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
171 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
172 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
173 |
|
4989 | 174 |
processAction (ModifyServerInfo f) = do |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
175 |
modify (\s -> s{serverInfo = f $ serverInfo s}) |
4989 | 176 |
si <- gets serverInfo |
177 |
io $ writeServerConfig si |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
178 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
179 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
180 |
processAction (MoveToRoom ri) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
181 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
182 |
rnc <- gets roomsClients |
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 |
io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
185 |
modifyClient rnc (\cl -> cl{teamsInGame = 0, isReady = False, isMaster = False}) ci |
4932 | 186 |
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
|
187 |
moveClientToRoom rnc ri ci |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
188 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
189 |
chans <- liftM (map sendChan) $ roomClientsS ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
190 |
clNick <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
191 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
192 |
processAction $ AnswerClients chans ["JOINED", clNick] |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
195 |
processAction (MoveToLobby msg) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
196 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
197 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
198 |
rnc <- gets roomsClients |
4932 | 199 |
(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
|
200 |
ready <- client's isReady |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
201 |
master <- client's isMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
202 |
-- client <- client's id |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
203 |
clNick <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
204 |
chans <- othersChans |
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 |
if master then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
207 |
if gameProgress && playersNum > 1 then |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
208 |
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
|
209 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
210 |
processAction RemoveRoom |
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 |
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
|
213 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
214 |
io $ do |
4999 | 215 |
modifyRoom rnc (\r -> r{ |
216 |
playersIn = playersIn r - 1, |
|
217 |
readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r |
|
218 |
}) ri |
|
219 |
moveClientToLobby rnc ci |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
220 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
221 |
processAction ChangeMaster = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
222 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
223 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
let newRoomName = nick newMaster |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
227 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
228 |
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
|
229 |
ModifyClient2 newMasterId (\c -> c{isMaster = True}), |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
230 |
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
|
231 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
232 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
233 |
processAction (AddRoom roomName roomPassword) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
234 |
Just clId <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
235 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
236 |
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
|
237 |
|
4932 | 238 |
let rm = newRoom{ |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
239 |
masterID = clId, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
240 |
name = roomName, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
241 |
password = roomPassword, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
242 |
roomProto = proto |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
243 |
} |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
244 |
|
4932 | 245 |
rId <- io $ addRoom rnc rm |
4907
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 |
processAction $ MoveToRoom rId |
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 |
chans <- liftM (map sendChan) $! roomClientsS lobbyId |
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 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
252 |
AnswerClients chans ["ROOM", "ADD", roomName] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
253 |
, ModifyClient (\cl -> cl{isMaster = True}) |
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 |
|
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 |
processAction RemoveRoom = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
258 |
Just clId <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
259 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
260 |
ri <- io $ clientRoomM rnc clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
261 |
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
|
262 |
others <- othersChans |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
263 |
lobbyChans <- liftM (map sendChan) $! roomClientsS lobbyId |
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 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
266 |
AnswerClients lobbyChans ["ROOM", "DEL", roomName], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
267 |
AnswerClients others ["ROOMABANDONED", roomName] |
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
270 |
io $ removeRoom rnc ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
271 |
|
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 |
processAction (UnreadyRoomClients) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
274 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
275 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
276 |
roomPlayers <- roomClientsS ri |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
285 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
286 |
processAction (RemoveTeam teamName) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
287 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
288 |
ri <- clientRoomA |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
289 |
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
|
290 |
chans <- othersChans |
4999 | 291 |
if not $ inGame then |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
292 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
293 |
AnswerClients chans ["REMOVE_TEAM", teamName], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
294 |
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
|
295 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
296 |
else |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
297 |
mapM_ processAction [ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
298 |
AnswerClients chans ["EM", rmTeamMsg], |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
299 |
ModifyRoom (\r -> r{ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
300 |
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
|
301 |
leftTeams = teamName : leftTeams r, |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
302 |
roundMsgs = roundMsgs r Seq.|> rmTeamMsg |
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 |
] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
305 |
where |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
5008
diff
changeset
|
306 |
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
|
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 |
processAction (RemoveClientTeams clId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
310 |
rnc <- gets roomsClients |
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 |
removeTeamActions <- io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
313 |
clNick <- client'sM rnc nick clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
314 |
rId <- clientRoomM rnc clId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
315 |
roomTeams <- room'sM rnc teams rId |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
316 |
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
|
317 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
318 |
mapM_ processAction removeTeamActions |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
319 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
320 |
|
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 |
processAction CheckRegistered = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
323 |
(Just ci) <- gets clientIndex |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
324 |
n <- client's nick |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
325 |
h <- client's host |
4991 | 326 |
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
|
327 |
uid <- client's clUID |
4991 | 328 |
haveSameNick <- liftM (not . null . tail . filter (\c -> nick c == n)) allClientsS |
329 |
if haveSameNick then |
|
330 |
if p < 38 then |
|
331 |
mapM_ processAction [ByeClient "Nickname is already in use", removeNick] |
|
332 |
else |
|
333 |
mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick] |
|
334 |
else |
|
335 |
do |
|
336 |
db <- gets (dbQueries . serverInfo) |
|
337 |
io $ writeChan db $ CheckAccount ci (hashUnique uid) n h |
|
338 |
return () |
|
339 |
where |
|
340 |
removeNick = ModifyClient (\c -> c{nick = ""}) |
|
4907
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 ClearAccountsCache = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
344 |
dbq <- gets (dbQueries . serverInfo) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
345 |
io $ writeChan dbq ClearCache |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
346 |
return () |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
347 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
348 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
349 |
processAction (ProcessAccountInfo info) = |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
350 |
case info of |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
351 |
HasAccount passwd isAdmin -> do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
352 |
chan <- client's sendChan |
4923 | 353 |
mapM_ processAction [AnswerClients [chan] ["ASKPASSWORD"], ModifyClient (\c -> c{webPassword = passwd, isAdministrator = isAdmin})] |
4932 | 354 |
Guest -> |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
355 |
processAction JoinLobby |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
356 |
Admin -> do |
4932 | 357 |
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
|
358 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
359 |
processAction $ AnswerClients [chan] ["ADMIN_ACCESS"] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
360 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
361 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
362 |
processAction JoinLobby = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
363 |
chan <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
364 |
clientNick <- client's nick |
4932 | 365 |
(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
|
366 |
mapM_ processAction $ |
4932 | 367 |
AnswerClients clientsChans ["LOBBY:JOINED", clientNick] |
368 |
: AnswerClients [chan] ("LOBBY:JOINED" : clientNick : lobbyNicks) |
|
369 |
: [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
|
370 |
|
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
|
371 |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
372 |
processAction (KickClient kickId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
373 |
modify (\s -> s{clientIndex = Just kickId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
374 |
processAction $ ByeClient "Kicked" |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
375 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
376 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
377 |
processAction (BanClient seconds reason banId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
378 |
modify (\s -> s{clientIndex = Just banId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
379 |
clHost <- client's host |
4932 | 380 |
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
|
381 |
let msg = B.concat ["Ban for ", B.pack . show $ seconds, "seconds (", reason, ")"] |
4909 | 382 |
mapM_ processAction [ |
5007 | 383 |
AddIP2Bans clHost msg (addUTCTime seconds currentTime) |
4909 | 384 |
, KickClient banId |
385 |
] |
|
4907
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 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
388 |
processAction (KickRoomClient kickId) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
389 |
modify (\s -> s{clientIndex = Just kickId}) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
390 |
ch <- client's sendChan |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
391 |
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
|
392 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
393 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
394 |
processAction (AddClient cl) = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
395 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
396 |
si <- gets serverInfo |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
397 |
newClId <- io $ do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
398 |
ci <- addClient rnc cl |
5077 | 399 |
_ <- 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
|
400 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
401 |
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
|
402 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
403 |
return ci |
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 |
modify (\s -> s{clientIndex = Just newClId}) |
5007 | 406 |
mapM_ processAction |
407 |
[ |
|
408 |
AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion] |
|
409 |
, CheckBanned |
|
5090 | 410 |
, AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl) |
5007 | 411 |
] |
412 |
||
413 |
||
414 |
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
|
415 |
processAction $ ModifyServerInfo (\s -> s{bans = BanByNick n reason expiring : bans s}) |
5007 | 416 |
|
417 |
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
|
418 |
(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
|
419 |
rc <- gets removedClients |
af9e4a66111b
Don't add ip ban with new timestamp when user gets kicked due to ban
unc0rr
parents:
5007
diff
changeset
|
420 |
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
|
421 |
$ 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
|
422 |
|
5007 | 423 |
processAction CheckBanned = do |
424 |
clTime <- client's connectTime |
|
425 |
clNick <- client's nick |
|
426 |
clHost <- client's host |
|
427 |
si <- gets serverInfo |
|
428 |
let validBans = filter (checkNotExpired clTime) $ bans si |
|
429 |
let ban = L.find (checkBan clHost clNick) $ validBans |
|
430 |
when (isJust ban) $ |
|
431 |
mapM_ processAction [ |
|
432 |
ModifyServerInfo (\s -> s{bans = validBans}) |
|
433 |
, ByeClient (getBanReason $ fromJust ban) |
|
434 |
] |
|
435 |
where |
|
436 |
checkNotExpired testTime (BanByIP _ _ time) = testTime `diffUTCTime` time <= 0 |
|
437 |
checkNotExpired testTime (BanByNick _ _ time) = testTime `diffUTCTime` time <= 0 |
|
438 |
checkBan ip _ (BanByIP bip _ _) = bip == ip |
|
439 |
checkBan _ n (BanByNick bn _ _) = bn == n |
|
440 |
getBanReason (BanByIP _ msg _) = msg |
|
441 |
getBanReason (BanByNick _ msg _) = msg |
|
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
442 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
443 |
processAction PingAll = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
444 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
445 |
io (allClientsM rnc) >>= mapM_ (kickTimeouted rnc) |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
446 |
cis <- io $ allClientsM rnc |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
447 |
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
|
448 |
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
|
449 |
processAction $ AnswerClients chans ["PING"] |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
450 |
where |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
451 |
kickTimeouted rnc ci = do |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
452 |
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
|
453 |
when (pq > 0) $ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
454 |
withStateT (\as -> as{clientIndex = Just ci}) $ |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
455 |
processAction (ByeClient "Ping timeout") |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
456 |
|
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
457 |
|
4914 | 458 |
processAction StatsAction = do |
4907
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
459 |
rnc <- gets roomsClients |
8bf14795a528
KICK and BAN actions (ban has no protocol command for it yet)
unc0rr
parents:
4905
diff
changeset
|
460 |
si <- gets serverInfo |
4932 | 461 |
(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
|
462 |
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
|
463 |
where |
4932 | 464 |
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
|
465 |
|
4955 | 466 |
processAction (RestartServer force) = do |
467 |
if force then do |
|
4962 | 468 |
throw RestartException |
4955 | 469 |
else |
470 |
processAction $ ModifyServerInfo (\s -> s{restartPending=True}) |