author | unc0rr |
Thu, 27 Mar 2014 23:25:31 +0400 | |
changeset 10215 | 26fc5502ba22 |
parent 10212 | 5fb3bb2de9d2 |
child 10217 | 1a1da2342c5b |
permissions | -rw-r--r-- |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
1 |
{-# LANGUAGE OverloadedStrings #-} |
1804 | 2 |
module HWProtoInRoomState where |
3 |
||
4 |
import qualified Data.Map as Map |
|
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
5 |
import Data.List as L |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
6 |
import Data.Maybe |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
7 |
import qualified Data.ByteString.Char8 as B |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
8 |
import Control.Monad |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
9 |
import Control.Monad.Reader |
1804 | 10 |
-------------------------------------- |
11 |
import CoreTypes |
|
12 |
import Utils |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
13 |
import HandlerUtils |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
14 |
import RoomsAndClients |
6068 | 15 |
import EngineInteraction |
10039 | 16 |
import Votes |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
17 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
18 |
startGame :: Reader (ClientIndex, IRnC) [Action] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
19 |
startGame = do |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
20 |
(ci, rnc) <- ask |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
21 |
cl <- thisClient |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
22 |
rm <- thisRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
23 |
chans <- roomClientsChans |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
24 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
25 |
let nicks = map (nick . client rnc) . roomClients rnc $ clientRoom rnc ci |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
26 |
let allPlayersRegistered = all ((<) 0 . B.length . webPassword . client rnc . teamownerId) $ teams rm |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
27 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
28 |
if (playersIn rm == readyPlayers rm || clientProto cl > 43) && not (isJust $ gameInfo rm) then |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
29 |
if enoughClans rm then |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
30 |
return [ |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
31 |
ModifyRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
32 |
(\r -> r{ |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
33 |
gameInfo = Just $ newGameInfo (teams rm) (length $ teams rm) allPlayersRegistered (mapParams rm) (params rm) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
34 |
} |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
35 |
) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
36 |
, AnswerClients chans ["RUN_GAME"] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
37 |
, SendUpdateOnThisRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
38 |
, AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
39 |
, ModifyRoomClients (\c -> c{isInGame = True}) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
40 |
] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
41 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
42 |
return [Warning $ loc "Less than two clans!"] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
43 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
44 |
return [] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
45 |
where |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
46 |
enoughClans = not . null . drop 1 . group . map teamcolor . teams |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
47 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
48 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
49 |
|
4989 | 50 |
handleCmd_inRoom :: CmdHandler |
1804 | 51 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
52 |
handleCmd_inRoom ["CHAT", msg] = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
53 |
n <- clientNick |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
54 |
s <- roomOthersChans |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
55 |
return [AnswerClients s ["CHAT", n, msg]] |
1804 | 56 |
|
10095 | 57 |
handleCmd_inRoom ["PART"] = return [MoveToLobby "part"] |
58 |
handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg] |
|
3531 | 59 |
|
1811 | 60 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
61 |
handleCmd_inRoom ("CFG" : paramName : paramStrs) |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
62 |
| null paramStrs = return [ProtocolError $ loc "Empty config entry"] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
63 |
| otherwise = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
64 |
chans <- roomOthersChans |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
65 |
cl <- thisClient |
9770 | 66 |
rm <- thisRoom |
67 |
||
68 |
if isSpecial rm then |
|
69 |
return [Warning $ loc "Restricted"] |
|
70 |
else if isMaster cl then |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
71 |
return [ |
4941 | 72 |
ModifyRoom f, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
73 |
AnswerClients chans ("CFG" : paramName : paramStrs)] |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
74 |
else |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
75 |
return [ProtocolError $ loc "Not room master"] |
4941 | 76 |
where |
77 |
f r = if paramName `Map.member` (mapParams r) then |
|
78 |
r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)} |
|
79 |
else |
|
80 |
r{params = Map.insert paramName paramStrs (params r)} |
|
1804 | 81 |
|
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
82 |
|
4932 | 83 |
handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo) |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
84 |
| length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info"] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
85 |
| otherwise = do |
4932 | 86 |
(ci, _) <- ask |
87 |
rm <- thisRoom |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
88 |
clNick <- clientNick |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
89 |
clChan <- thisClientChans |
4932 | 90 |
othChans <- roomOthersChans |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
91 |
roomChans <- roomClientsChans |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
92 |
cl <- thisClient |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
93 |
teamColor <- |
8924 | 94 |
if clientProto cl < 42 then |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
95 |
return color |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
96 |
else |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
97 |
liftM (head . (L.\\) (map B.singleton ['0'..]) . map teamcolor . teams) thisRoom |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
98 |
let roomTeams = teams rm |
8897
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8757
diff
changeset
|
99 |
let hhNum = let p = if not $ null roomTeams then minimum [hhnum $ head roomTeams, canAddNumber roomTeams] else 4 in newTeamHHNum roomTeams p |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
100 |
let newTeam = clNick `seq` TeamInfo ci clNick tName teamColor grave fort voicepack flag dif hhNum (hhsList hhsInfo) |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
101 |
return $ |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
102 |
if not . null . drop (maxTeams rm - 1) $ roomTeams then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
103 |
[Warning $ loc "too many teams"] |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
104 |
else if canAddNumber roomTeams <= 0 then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
105 |
[Warning $ loc "too many hedgehogs"] |
4932 | 106 |
else if isJust $ findTeam rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
107 |
[Warning $ loc "There's already a team with same name in the list"] |
5996
2c72fe81dd37
Convert boolean variable + a bunch of fields which make sense only while game is going on into Maybe + structure
unc0rr
parents:
5931
diff
changeset
|
108 |
else if isJust $ gameInfo rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
109 |
[Warning $ loc "round in progress"] |
4932 | 110 |
else if isRestrictedTeams rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
111 |
[Warning $ loc "restricted"] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
112 |
else |
7986
53b1da5ee7f4
Maybe this caused server crashes? Add more strictness on team owner record field
unc0rr
parents:
7947
diff
changeset
|
113 |
[ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}), |
7921
6b074de32bea
Send ROOM UPD message when team is added/deleted from room, and when game starts or finishes
unc0rr
parents:
7862
diff
changeset
|
114 |
SendUpdateOnThisRoom, |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
115 |
ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}), |
4932 | 116 |
AnswerClients clChan ["TEAM_ACCEPTED", tName], |
8550
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
117 |
AnswerClients othChans $ teamToNet $ newTeam, |
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
118 |
AnswerClients roomChans ["TEAM_COLOR", tName, teamColor], |
8899 | 119 |
AnswerClients roomChans ["HH_NUM", tName, showB $ hhnum newTeam] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
120 |
] |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
121 |
where |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
122 |
canAddNumber rt = (48::Int) - (sum $ map hhnum rt) |
4932 | 123 |
findTeam = find (\t -> tName == teamname t) . teams |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4989
diff
changeset
|
124 |
dif = readInt_ difStr |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
125 |
hhsList [] = [] |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
126 |
hhsList [_] = error "Hedgehogs list with odd elements number" |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
127 |
hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
128 |
newTeamHHNum rt p = min p (canAddNumber rt) |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
129 |
maxTeams r |
5931 | 130 |
| roomProto r < 38 = 6 |
131 |
| otherwise = 8 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
132 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
133 |
|
4932 | 134 |
handleCmd_inRoom ["REMOVE_TEAM", tName] = do |
135 |
(ci, _) <- ask |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
136 |
r <- thisRoom |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
137 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
138 |
let maybeTeam = findTeam r |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
139 |
let team = fromJust maybeTeam |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
140 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
141 |
return $ |
8428 | 142 |
if isNothing $ maybeTeam then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
143 |
[Warning $ loc "REMOVE_TEAM: no such team"] |
8431 | 144 |
else if ci /= teamownerId team then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
145 |
[ProtocolError $ loc "Not team owner!"] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
146 |
else |
4932 | 147 |
[RemoveTeam tName, |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
148 |
ModifyClient |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
149 |
(\c -> c{ |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
150 |
teamsInGame = teamsInGame c - 1, |
8433 | 151 |
clientClan = if teamsInGame c == 1 then Nothing else Just $ anotherTeamClan ci team r |
4989 | 152 |
}) |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
153 |
] |
4568 | 154 |
where |
8433 | 155 |
anotherTeamClan ci team = teamcolor . fromMaybe (error "CHECKPOINT 011") . find (\t -> (teamownerId t == ci) && (t /= team)) . teams |
4932 | 156 |
findTeam = find (\t -> tName == teamname t) . teams |
3561 | 157 |
|
3568 | 158 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
159 |
handleCmd_inRoom ["HH_NUM", teamName, numberStr] = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
160 |
cl <- thisClient |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
161 |
r <- thisRoom |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
162 |
clChan <- thisClientChans |
8477
330b0b8846cf
Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents:
8433
diff
changeset
|
163 |
others <- roomOthersChans |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
164 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
165 |
let maybeTeam = findTeam r |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
166 |
let team = fromJust maybeTeam |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
167 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
168 |
return $ |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
169 |
if not $ isMaster cl then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
170 |
[ProtocolError $ loc "Not room master"] |
8429 | 171 |
else if isNothing maybeTeam then |
172 |
[] |
|
8428 | 173 |
else if hhNumber < 1 || hhNumber > 8 || hhNumber > canAddNumber r + hhnum team then |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
174 |
[AnswerClients clChan ["HH_NUM", teamName, showB $ hhnum team]] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
175 |
else |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
176 |
[ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
8477
330b0b8846cf
Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents:
8433
diff
changeset
|
177 |
AnswerClients others ["HH_NUM", teamName, showB hhNumber]] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
178 |
where |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4989
diff
changeset
|
179 |
hhNumber = readInt_ numberStr |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
180 |
findTeam = find (\t -> teamName == teamname t) . teams |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
181 |
canAddNumber = (-) 48 . sum . map hhnum . teams |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
182 |
|
1804 | 183 |
|
3568 | 184 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
185 |
handleCmd_inRoom ["TEAM_COLOR", teamName, newColor] = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
186 |
cl <- thisClient |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
187 |
others <- roomOthersChans |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
188 |
r <- thisRoom |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
189 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
190 |
let maybeTeam = findTeam r |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
191 |
let team = fromJust maybeTeam |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
192 |
|
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
193 |
return $ |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
194 |
if not $ isMaster cl then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
195 |
[ProtocolError $ loc "Not room master"] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
196 |
else if isNothing maybeTeam then |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
197 |
[] |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
198 |
else |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
199 |
[ModifyRoom $ modifyTeam team{teamcolor = newColor}, |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
200 |
AnswerClients others ["TEAM_COLOR", teamName, newColor], |
4986
33fe91b2bcbf
Use Maybe for storing client's clan, allows less error-prone spectator checks
unc0rr
parents:
4975
diff
changeset
|
201 |
ModifyClient2 (teamownerId team) (\c -> c{clientClan = Just newColor})] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
202 |
where |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
203 |
findTeam = find (\t -> teamName == teamname t) . teams |
3568 | 204 |
|
1804 | 205 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
206 |
handleCmd_inRoom ["TOGGLE_READY"] = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
207 |
cl <- thisClient |
4932 | 208 |
rm <- thisRoom |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
209 |
chans <- roomClientsChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
210 |
|
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
211 |
(ci, rnc) <- ask |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
212 |
let ri = clientRoom rnc ci |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
213 |
let unreadyClients = filter (not . isReady) . map (client rnc) $ roomClients rnc ri |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
214 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
215 |
gs <- if (not $ isReady cl) && (isSpecial rm) && (unreadyClients == [cl]) then startGame else return [] |
3577 | 216 |
|
10017 | 217 |
return $ |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
218 |
ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
219 |
: ModifyClient (\c -> c{isReady = not $ isReady cl}) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
220 |
: (AnswerClients chans $ if clientProto cl < 38 then |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
221 |
[if isReady cl then "NOT_READY" else "READY", nick cl] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
222 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
223 |
["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
224 |
: gs |
1804 | 225 |
|
226 |
||
10194 | 227 |
handleCmd_inRoom ["START_GAME"] = roomAdminOnly startGame |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
228 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
229 |
handleCmd_inRoom ["EM", msg] = do |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
230 |
cl <- thisClient |
4932 | 231 |
rm <- thisRoom |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
232 |
chans <- roomOthersChans |
4931
da43c36a6e92
Don't accept EM message when the game isn't started
unc0rr
parents:
4917
diff
changeset
|
233 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
234 |
if teamsInGame cl > 0 && (isJust $ gameInfo rm) && (not $ B.null legalMsgs) then |
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
235 |
return $ AnswerClients chans ["EM", legalMsgs] |
10017 | 236 |
: [ModifyRoom (\r -> r{gameInfo = liftM |
9304
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9035
diff
changeset
|
237 |
(\g -> g{ |
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9035
diff
changeset
|
238 |
roundMsgs = if B.null nonEmptyMsgs then roundMsgs g else nonEmptyMsgs : roundMsgs g |
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9035
diff
changeset
|
239 |
, lastFilteredTimedMsg = fromMaybe (lastFilteredTimedMsg g) lastFTMsg}) |
10092 | 240 |
$ gameInfo r}), RegisterEvent EngineMessage] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
241 |
else |
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
242 |
return [] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
243 |
where |
9304
3f4c3fc146c2
Fix spectator desync in rare conditions (there was team which left during its turn, and last command with timestamp from it was '+')
unc0rr
parents:
9035
diff
changeset
|
244 |
(legalMsgs, nonEmptyMsgs, lastFTMsg) = checkNetCmd msg |
1804 | 245 |
|
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
246 |
|
8550
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
247 |
handleCmd_inRoom ["ROUNDFINISHED", _] = do |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
248 |
cl <- thisClient |
4932 | 249 |
rm <- thisRoom |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
250 |
chans <- roomClientsChans |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
251 |
|
6753
e95b1f62d0de
Don't remove client's teams from teams list on "ROUNDFINISHED 0", just send team removal message to others.
unc0rr
parents:
6738
diff
changeset
|
252 |
let clTeams = map teamname . filter (\t -> teamowner t == nick cl) . teams $ rm |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
253 |
let unsetInGameState = [AnswerClients chans ["CLIENT_FLAGS", "-g", nick cl], ModifyClient (\c -> c{isInGame = False})] |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
254 |
|
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
255 |
if isInGame cl then |
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
256 |
if isJust $ gameInfo rm then |
8422 | 257 |
return $ unsetInGameState ++ map SendTeamRemovalMessage clTeams |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
258 |
else |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
259 |
return unsetInGameState |
4295
1f5604cd99be
This revision should, in theory, correctly merge 0.9.14 and tip, so that future merges of 0.9.14 should work properly
nemo
parents:
4242
diff
changeset
|
260 |
else |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
261 |
return [] -- don't accept this message twice |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
262 |
where |
8550
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
263 |
-- isCorrect = correctly == "1" |
1811 | 264 |
|
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:
4941
diff
changeset
|
265 |
-- compatibility with clients with protocol < 38 |
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:
4941
diff
changeset
|
266 |
handleCmd_inRoom ["ROUNDFINISHED"] = |
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:
4941
diff
changeset
|
267 |
handleCmd_inRoom ["ROUNDFINISHED", "1"] |
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:
4941
diff
changeset
|
268 |
|
10194 | 269 |
handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = roomAdminOnly $ |
270 |
return [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})] |
|
4568 | 271 |
|
1831 | 272 |
|
10194 | 273 |
handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = roomAdminOnly $ |
274 |
return [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})] |
|
1879 | 275 |
|
1831 | 276 |
|
10194 | 277 |
handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = roomAdminOnly $ |
278 |
return [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r})] |
|
8232 | 279 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
280 |
|
10194 | 281 |
handleCmd_inRoom ["ROOM_NAME", newName] = roomAdminOnly $ do |
5098 | 282 |
cl <- thisClient |
283 |
rs <- allRoomInfos |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6403
diff
changeset
|
284 |
rm <- thisRoom |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6403
diff
changeset
|
285 |
chans <- sameProtoChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
286 |
|
5098 | 287 |
return $ |
10017 | 288 |
if illegalName newName then |
9454 | 289 |
[Warning $ loc "Illegal room name"] |
290 |
else |
|
9770 | 291 |
if isSpecial rm then |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
292 |
[Warning $ loc "Restricted"] |
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
293 |
else |
5098 | 294 |
if isJust $ find (\r -> newName == name r) rs then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
295 |
[Warning $ loc "Room with such name already exists"] |
5098 | 296 |
else |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6403
diff
changeset
|
297 |
[ModifyRoom roomUpdate, |
9702 | 298 |
AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))] |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6403
diff
changeset
|
299 |
where |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
6403
diff
changeset
|
300 |
roomUpdate r = r{name = newName} |
5098 | 301 |
|
302 |
||
10194 | 303 |
handleCmd_inRoom ["KICK", kickNick] = roomAdminOnly $ do |
4614 | 304 |
(thisClientId, rnc) <- ask |
305 |
maybeClientId <- clientByNick kickNick |
|
8513 | 306 |
rm <- thisRoom |
4614 | 307 |
let kickId = fromJust maybeClientId |
8513 | 308 |
let kickCl = rnc `client` kickId |
4932 | 309 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId |
8627
ea2d32a03ac9
Eh, two players condition seems to make more sense than two clans here
unc0rr
parents:
8550
diff
changeset
|
310 |
let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2 |
4614 | 311 |
return |
8513 | 312 |
[KickRoomClient kickId | |
10194 | 313 |
isJust maybeClientId |
8513 | 314 |
&& (kickId /= thisClientId) |
315 |
&& sameRoom |
|
8627
ea2d32a03ac9
Eh, two players condition seems to make more sense than two clans here
unc0rr
parents:
8550
diff
changeset
|
316 |
&& ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0) |
8513 | 317 |
] |
1879 | 318 |
|
1831 | 319 |
|
8247 | 320 |
handleCmd_inRoom ["DELEGATE", newAdmin] = do |
321 |
(thisClientId, rnc) <- ask |
|
322 |
maybeClientId <- clientByNick newAdmin |
|
323 |
master <- liftM isMaster thisClient |
|
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
324 |
serverAdmin <- liftM isAdministrator thisClient |
9715 | 325 |
thisRoomMasterId <- liftM masterID thisRoom |
8247 | 326 |
let newAdminId = fromJust maybeClientId |
327 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId |
|
328 |
return |
|
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
329 |
[ChangeMaster (Just newAdminId) | |
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
330 |
(master || serverAdmin) |
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
331 |
&& isJust maybeClientId |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
332 |
&& (Just newAdminId /= thisRoomMasterId) |
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
333 |
&& sameRoom] |
8247 | 334 |
|
335 |
||
4614 | 336 |
handleCmd_inRoom ["TEAMCHAT", msg] = do |
337 |
cl <- thisClient |
|
338 |
chans <- roomSameClanChans |
|
339 |
return [AnswerClients chans ["EM", engineMsg cl]] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
340 |
where |
8757 | 341 |
engineMsg cl = toEngineMsg $ B.concat ["b", nick cl, " (team): ", msg, "\x20\x20"] |
4568 | 342 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
343 |
|
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
344 |
handleCmd_inRoom ["BAN", banNick] = do |
8002 | 345 |
(thisClientId, rnc) <- ask |
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
346 |
maybeClientId <- clientByNick banNick |
8002 | 347 |
master <- liftM isMaster thisClient |
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
348 |
let banId = fromJust maybeClientId |
8002 | 349 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc banId |
350 |
if master && isJust maybeClientId && (banId /= thisClientId) && sameRoom then |
|
351 |
return [ |
|
8189 | 352 |
-- ModifyRoom (\r -> r{roomBansList = let h = host $ rnc `client` banId in h `deepseq` h : roomBansList r}) |
353 |
KickRoomClient banId |
|
8002 | 354 |
] |
355 |
else |
|
356 |
return [] |
|
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
357 |
|
9035
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
358 |
handleCmd_inRoom ("RND":rs) = do |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
359 |
n <- clientNick |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
360 |
s <- roomClientsChans |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
361 |
return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs] |
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
7321
diff
changeset
|
362 |
|
10194 | 363 |
handleCmd_inRoom ["FIX"] = serverAdminOnly $ |
364 |
return [ModifyRoom (\r -> r{isSpecial = True})] |
|
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
365 |
|
10194 | 366 |
handleCmd_inRoom ["UNFIX"] = serverAdminOnly $ |
367 |
return [ModifyRoom (\r -> r{isSpecial = False})] |
|
9770 | 368 |
|
9787 | 369 |
handleCmd_inRoom ["GREETING", msg] = do |
370 |
cl <- thisClient |
|
371 |
rm <- thisRoom |
|
372 |
return [ModifyRoom (\r -> r{greeting = msg}) | isAdministrator cl || (isMaster cl && (not $ isSpecial rm))] |
|
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9715
diff
changeset
|
373 |
|
10039 | 374 |
|
375 |
handleCmd_inRoom ["CALLVOTE"] = do |
|
376 |
cl <- thisClient |
|
10195 | 377 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "Available callvote commands: kick <nickname>, map <name>"]] |
10039 | 378 |
|
379 |
handleCmd_inRoom ["CALLVOTE", "KICK"] = do |
|
380 |
cl <- thisClient |
|
381 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: specify nickname"]] |
|
382 |
||
383 |
handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do |
|
384 |
(thisClientId, rnc) <- ask |
|
385 |
cl <- thisClient |
|
10058 | 386 |
rm <- thisRoom |
10039 | 387 |
maybeClientId <- clientByNick nickname |
388 |
let kickId = fromJust maybeClientId |
|
389 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId |
|
390 |
||
10058 | 391 |
if isNothing $ masterID rm then |
392 |
return [] |
|
10039 | 393 |
else |
10058 | 394 |
if isJust maybeClientId && sameRoom then |
395 |
startVote $ VoteKick nickname |
|
396 |
else |
|
397 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: no such user"]] |
|
10039 | 398 |
|
10195 | 399 |
|
10212 | 400 |
handleCmd_inRoom ["CALLVOTE", "MAP"] = do |
401 |
cl <- thisClient |
|
402 |
s <- liftM (Map.keys . roomSaves) thisRoom |
|
403 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", B.concat ["callvote map: ", B.intercalate ", " s]]] |
|
404 |
||
405 |
||
10195 | 406 |
handleCmd_inRoom ["CALLVOTE", "MAP", roomSave] = do |
407 |
cl <- thisClient |
|
408 |
rm <- thisRoom |
|
409 |
||
410 |
if Map.member roomSave $ roomSaves rm then |
|
411 |
startVote $ VoteMap roomSave |
|
412 |
else |
|
413 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote map: no such map"]] |
|
414 |
||
415 |
||
10039 | 416 |
handleCmd_inRoom ["VOTE", m] = do |
417 |
cl <- thisClient |
|
418 |
let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing |
|
419 |
if isJust b then |
|
10081 | 420 |
voted (fromJust b) |
10039 | 421 |
else |
422 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]] |
|
423 |
||
10194 | 424 |
|
425 |
handleCmd_inRoom ["SAVE", stateName] = serverAdminOnly $ do |
|
426 |
return [ModifyRoom $ \r -> r{roomSaves = Map.insert stateName (mapParams r, params r) (roomSaves r)}] |
|
427 |
||
428 |
handleCmd_inRoom ["DELETE", stateName] = serverAdminOnly $ do |
|
429 |
return [ModifyRoom $ \r -> r{roomSaves = Map.delete stateName (roomSaves r)}] |
|
430 |
||
10195 | 431 |
handleCmd_inRoom ["SAVEROOM", fileName] = serverAdminOnly $ do |
432 |
return [SaveRoom fileName] |
|
10194 | 433 |
|
10195 | 434 |
handleCmd_inRoom ["LOADROOM", fileName] = serverAdminOnly $ do |
435 |
return [LoadRoom fileName] |
|
436 |
||
6912
831416764d2d
Allow LIST command while in room to not annoy old frontends (0.9.17 or less) with warnings
unc0rr
parents:
6815
diff
changeset
|
437 |
handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17) |
831416764d2d
Allow LIST command while in room to not annoy old frontends (0.9.17 or less) with warnings
unc0rr
parents:
6815
diff
changeset
|
438 |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6690
diff
changeset
|
439 |
handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"] |
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6690
diff
changeset
|
440 |
|
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6690
diff
changeset
|
441 |
handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"] |