author | Gianfranco Costamagna <costamagnagianfranco@yahoo.it> |
Wed, 26 Nov 2014 13:10:09 +0100 | |
changeset 10559 | 44095e0a0c1a |
parent 10511 | c33b2f001730 |
child 10730 | eac6a4d53752 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10392
diff
changeset
|
18 |
|
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
|
19 |
{-# LANGUAGE OverloadedStrings #-} |
1804 | 20 |
module HWProtoInRoomState where |
21 |
||
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
import Control.Monad.Reader |
1804 | 28 |
-------------------------------------- |
29 |
import CoreTypes |
|
30 |
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
|
31 |
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
|
32 |
import RoomsAndClients |
6068 | 33 |
import EngineInteraction |
10039 | 34 |
import Votes |
9995
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 |
startGame :: Reader (ClientIndex, IRnC) [Action] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
37 |
startGame = do |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
38 |
(ci, rnc) <- ask |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
39 |
cl <- thisClient |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
40 |
rm <- thisRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
41 |
chans <- roomClientsChans |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
42 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
43 |
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
|
44 |
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
|
45 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
46 |
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
|
47 |
if enoughClans rm then |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
48 |
return [ |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
49 |
ModifyRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
50 |
(\r -> r{ |
10392 | 51 |
gameInfo = Just $ newGameInfo (teams rm) (length $ teams rm) allPlayersRegistered (mapParams rm) (params rm) False |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
52 |
} |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
53 |
) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
54 |
, AnswerClients chans ["RUN_GAME"] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
55 |
, SendUpdateOnThisRoom |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
56 |
, AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
57 |
, ModifyRoomClients (\c -> c{isInGame = True}) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
58 |
] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
59 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
60 |
return [Warning $ loc "Less than two clans!"] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
61 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
62 |
return [] |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
63 |
where |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
64 |
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
|
65 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
66 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
67 |
|
4989 | 68 |
handleCmd_inRoom :: CmdHandler |
1804 | 69 |
|
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
return [AnswerClients s ["CHAT", n, msg]] |
1804 | 74 |
|
10095 | 75 |
handleCmd_inRoom ["PART"] = return [MoveToLobby "part"] |
76 |
handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg] |
|
3531 | 77 |
|
1811 | 78 |
|
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
|
79 |
handleCmd_inRoom ("CFG" : paramName : paramStrs) |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
80 |
| 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
|
81 |
| 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
|
82 |
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
|
83 |
cl <- thisClient |
9770 | 84 |
rm <- thisRoom |
85 |
||
86 |
if isSpecial rm then |
|
87 |
return [Warning $ loc "Restricted"] |
|
88 |
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
|
89 |
return [ |
4941 | 90 |
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
|
91 |
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
|
92 |
else |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
93 |
return [ProtocolError $ loc "Not room master"] |
4941 | 94 |
where |
95 |
f r = if paramName `Map.member` (mapParams r) then |
|
96 |
r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)} |
|
97 |
else |
|
98 |
r{params = Map.insert paramName paramStrs (params r)} |
|
1804 | 99 |
|
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
|
100 |
|
4932 | 101 |
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
|
102 |
| 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
|
103 |
| otherwise = do |
4932 | 104 |
(ci, _) <- ask |
105 |
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
|
106 |
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
|
107 |
clChan <- thisClientChans |
4932 | 108 |
othChans <- roomOthersChans |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
109 |
roomChans <- roomClientsChans |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
110 |
cl <- thisClient |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
111 |
teamColor <- |
8924 | 112 |
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
|
113 |
return color |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
114 |
else |
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
115 |
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
|
116 |
let roomTeams = teams rm |
8897
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8757
diff
changeset
|
117 |
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
|
118 |
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
|
119 |
return $ |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
120 |
if not . null . drop (maxTeams rm - 1) $ roomTeams then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
121 |
[Warning $ loc "too many teams"] |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
122 |
else if canAddNumber roomTeams <= 0 then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
123 |
[Warning $ loc "too many hedgehogs"] |
4932 | 124 |
else if isJust $ findTeam rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
125 |
[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
|
126 |
else if isJust $ gameInfo rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
127 |
[Warning $ loc "round in progress"] |
4932 | 128 |
else if isRestrictedTeams rm then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
129 |
[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
|
130 |
else |
7986
53b1da5ee7f4
Maybe this caused server crashes? Add more strictness on team owner record field
unc0rr
parents:
7947
diff
changeset
|
131 |
[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
|
132 |
SendUpdateOnThisRoom, |
7862
bd76ca40db68
Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents:
7775
diff
changeset
|
133 |
ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}), |
4932 | 134 |
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
|
135 |
AnswerClients othChans $ teamToNet $ newTeam, |
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
136 |
AnswerClients roomChans ["TEAM_COLOR", tName, teamColor], |
8899 | 137 |
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
|
138 |
] |
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 |
where |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
140 |
canAddNumber rt = (48::Int) - (sum $ map hhnum rt) |
4932 | 141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
newTeamHHNum rt p = min p (canAddNumber rt) |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
147 |
maxTeams r |
5931 | 148 |
| roomProto r < 38 = 6 |
149 |
| otherwise = 8 |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
150 |
|
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
|
151 |
|
4932 | 152 |
handleCmd_inRoom ["REMOVE_TEAM", tName] = do |
153 |
(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
|
154 |
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
|
155 |
|
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
|
156 |
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
|
157 |
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
|
158 |
|
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 |
return $ |
8428 | 160 |
if isNothing $ maybeTeam then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
161 |
[Warning $ loc "REMOVE_TEAM: no such team"] |
8431 | 162 |
else if ci /= teamownerId team then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
163 |
[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
|
164 |
else |
4932 | 165 |
[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
|
166 |
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
|
167 |
(\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
|
168 |
teamsInGame = teamsInGame c - 1, |
8433 | 169 |
clientClan = if teamsInGame c == 1 then Nothing else Just $ anotherTeamClan ci team r |
4989 | 170 |
}) |
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
|
171 |
] |
4568 | 172 |
where |
8433 | 173 |
anotherTeamClan ci team = teamcolor . fromMaybe (error "CHECKPOINT 011") . find (\t -> (teamownerId t == ci) && (t /= team)) . teams |
4932 | 174 |
findTeam = find (\t -> tName == teamname t) . teams |
3561 | 175 |
|
3568 | 176 |
|
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
|
177 |
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
|
178 |
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
|
179 |
r <- thisRoom |
8421
fc39fe044a4f
Make number of hedgehogs restriction actually work in network game
unc0rr
parents:
8418
diff
changeset
|
180 |
clChan <- thisClientChans |
8477
330b0b8846cf
Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents:
8433
diff
changeset
|
181 |
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
|
182 |
|
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
|
183 |
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
|
184 |
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
|
185 |
|
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 |
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
|
187 |
if not $ isMaster cl then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
188 |
[ProtocolError $ loc "Not room master"] |
8429 | 189 |
else if isNothing maybeTeam then |
190 |
[] |
|
8428 | 191 |
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
|
192 |
[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
|
193 |
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
|
194 |
[ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
8477
330b0b8846cf
Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents:
8433
diff
changeset
|
195 |
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
|
196 |
where |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4989
diff
changeset
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
|
1804 | 201 |
|
3568 | 202 |
|
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 |
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
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
|
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
|
208 |
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
|
209 |
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
|
210 |
|
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
|
211 |
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
|
212 |
if not $ isMaster cl then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
213 |
[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
|
214 |
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
|
215 |
[] |
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
|
216 |
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
|
217 |
[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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
findTeam = find (\t -> teamName == teamname t) . teams |
3568 | 222 |
|
1804 | 223 |
|
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
|
224 |
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
|
225 |
cl <- thisClient |
4932 | 226 |
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
|
227 |
chans <- roomClientsChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
228 |
|
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
229 |
(ci, rnc) <- ask |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
230 |
let ri = clientRoom rnc ci |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
231 |
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
|
232 |
|
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
233 |
gs <- if (not $ isReady cl) && (isSpecial rm) && (unreadyClients == [cl]) then startGame else return [] |
3577 | 234 |
|
10017 | 235 |
return $ |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
236 |
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
|
237 |
: ModifyClient (\c -> c{isReady = not $ isReady cl}) |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
238 |
: (AnswerClients chans $ if clientProto cl < 38 then |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
239 |
[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
|
240 |
else |
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
241 |
["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
|
242 |
: gs |
1804 | 243 |
|
244 |
||
10194 | 245 |
handleCmd_inRoom ["START_GAME"] = roomAdminOnly startGame |
9995
8bf092ddc536
In special rooms game starts when all players are ready
unc0rr
parents:
9787
diff
changeset
|
246 |
|
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
|
247 |
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
|
248 |
cl <- thisClient |
4932 | 249 |
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
|
250 |
chans <- roomOthersChans |
4931
da43c36a6e92
Don't accept EM message when the game isn't started
unc0rr
parents:
4917
diff
changeset
|
251 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
252 |
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
|
253 |
return $ AnswerClients chans ["EM", legalMsgs] |
10017 | 254 |
: [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
|
255 |
(\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
|
256 |
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
|
257 |
, lastFilteredTimedMsg = fromMaybe (lastFilteredTimedMsg g) lastFTMsg}) |
10092 | 258 |
$ 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
|
259 |
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
|
260 |
return [] |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
261 |
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
|
262 |
(legalMsgs, nonEmptyMsgs, lastFTMsg) = checkNetCmd msg |
1804 | 263 |
|
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
|
264 |
|
8550
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
265 |
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
|
266 |
cl <- thisClient |
4932 | 267 |
rm <- thisRoom |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
268 |
chans <- roomClientsChans |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
269 |
|
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
|
270 |
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
|
271 |
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
|
272 |
|
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
273 |
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
|
274 |
if isJust $ gameInfo rm then |
8422 | 275 |
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
|
276 |
else |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7757
diff
changeset
|
277 |
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
|
278 |
else |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
7537
diff
changeset
|
279 |
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
|
280 |
where |
8550
17378d33e62e
This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents:
8541
diff
changeset
|
281 |
-- isCorrect = correctly == "1" |
1811 | 282 |
|
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
|
283 |
-- 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
|
284 |
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
|
285 |
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
|
286 |
|
10194 | 287 |
handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = roomAdminOnly $ |
10511
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
288 |
return [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r}), SendUpdateOnThisRoom] |
4568 | 289 |
|
1831 | 290 |
|
10194 | 291 |
handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = roomAdminOnly $ |
292 |
return [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})] |
|
1879 | 293 |
|
1831 | 294 |
|
10194 | 295 |
handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = roomAdminOnly $ |
10511
c33b2f001730
This should work, can't test: room flags passed in room info message instead of just 'in-game' state, including 'in-game', 'restricted joins', 'registered only' and 'passworded' flags
unc0rr
parents:
10460
diff
changeset
|
296 |
return [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r}), SendUpdateOnThisRoom] |
8232 | 297 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
298 |
|
10194 | 299 |
handleCmd_inRoom ["ROOM_NAME", newName] = roomAdminOnly $ do |
5098 | 300 |
cl <- thisClient |
301 |
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
|
302 |
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
|
303 |
chans <- sameProtoChans |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
7266
diff
changeset
|
304 |
|
5098 | 305 |
return $ |
10017 | 306 |
if illegalName newName then |
9454 | 307 |
[Warning $ loc "Illegal room name"] |
308 |
else |
|
9770 | 309 |
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
|
310 |
[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
|
311 |
else |
5098 | 312 |
if isJust $ find (\r -> newName == name r) rs then |
8401
87410ae372f6
Server messages localization using Qt's l10n subsystem:
unc0rr
parents:
8369
diff
changeset
|
313 |
[Warning $ loc "Room with such name already exists"] |
5098 | 314 |
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
|
315 |
[ModifyRoom roomUpdate, |
9702 | 316 |
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
|
317 |
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
|
318 |
roomUpdate r = r{name = newName} |
5098 | 319 |
|
320 |
||
10194 | 321 |
handleCmd_inRoom ["KICK", kickNick] = roomAdminOnly $ do |
4614 | 322 |
(thisClientId, rnc) <- ask |
323 |
maybeClientId <- clientByNick kickNick |
|
8513 | 324 |
rm <- thisRoom |
4614 | 325 |
let kickId = fromJust maybeClientId |
8513 | 326 |
let kickCl = rnc `client` kickId |
4932 | 327 |
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
|
328 |
let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2 |
4614 | 329 |
return |
8513 | 330 |
[KickRoomClient kickId | |
10194 | 331 |
isJust maybeClientId |
8513 | 332 |
&& (kickId /= thisClientId) |
333 |
&& sameRoom |
|
8627
ea2d32a03ac9
Eh, two players condition seems to make more sense than two clans here
unc0rr
parents:
8550
diff
changeset
|
334 |
&& ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0) |
8513 | 335 |
] |
1879 | 336 |
|
1831 | 337 |
|
8247 | 338 |
handleCmd_inRoom ["DELEGATE", newAdmin] = do |
339 |
(thisClientId, rnc) <- ask |
|
340 |
maybeClientId <- clientByNick newAdmin |
|
341 |
master <- liftM isMaster thisClient |
|
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
342 |
serverAdmin <- liftM isAdministrator thisClient |
9715 | 343 |
thisRoomMasterId <- liftM masterID thisRoom |
8247 | 344 |
let newAdminId = fromJust maybeClientId |
345 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId |
|
346 |
return |
|
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
347 |
[ChangeMaster (Just newAdminId) | |
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
348 |
(master || serverAdmin) |
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
349 |
&& 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
|
350 |
&& (Just newAdminId /= thisRoomMasterId) |
8403
fbc6e7602e05
- Allow server admins to use DELEGATE even when not room owner
unc0rr
parents:
8401
diff
changeset
|
351 |
&& sameRoom] |
8247 | 352 |
|
353 |
||
4614 | 354 |
handleCmd_inRoom ["TEAMCHAT", msg] = do |
355 |
cl <- thisClient |
|
356 |
chans <- roomSameClanChans |
|
357 |
return [AnswerClients chans ["EM", engineMsg cl]] |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2747
diff
changeset
|
358 |
where |
8757 | 359 |
engineMsg cl = toEngineMsg $ B.concat ["b", nick cl, " (team): ", msg, "\x20\x20"] |
4568 | 360 |
|
8484
99c14f14f788
New checker of engine messages which is aware of glued together messages
unc0rr
parents:
8477
diff
changeset
|
361 |
|
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 |
handleCmd_inRoom ["BAN", banNick] = do |
8002 | 363 |
(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
|
364 |
maybeClientId <- clientByNick banNick |
8002 | 365 |
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
|
366 |
let banId = fromJust maybeClientId |
8002 | 367 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc banId |
368 |
if master && isJust maybeClientId && (banId /= thisClientId) && sameRoom then |
|
369 |
return [ |
|
8189 | 370 |
-- ModifyRoom (\r -> r{roomBansList = let h = host $ rnc `client` banId in h `deepseq` h : roomBansList r}) |
371 |
KickRoomClient banId |
|
8002 | 372 |
] |
373 |
else |
|
374 |
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
|
375 |
|
9035
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
376 |
handleCmd_inRoom ("RND":rs) = do |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
377 |
n <- clientNick |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
378 |
s <- roomClientsChans |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8983
diff
changeset
|
379 |
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
|
380 |
|
10194 | 381 |
handleCmd_inRoom ["FIX"] = serverAdminOnly $ |
382 |
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
|
383 |
|
10194 | 384 |
handleCmd_inRoom ["UNFIX"] = serverAdminOnly $ |
385 |
return [ModifyRoom (\r -> r{isSpecial = False})] |
|
9770 | 386 |
|
9787 | 387 |
handleCmd_inRoom ["GREETING", msg] = do |
388 |
cl <- thisClient |
|
389 |
rm <- thisRoom |
|
390 |
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
|
391 |
|
10039 | 392 |
|
393 |
handleCmd_inRoom ["CALLVOTE"] = do |
|
394 |
cl <- thisClient |
|
10392 | 395 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "Available callvote commands: kick <nickname>, map <name>, pause"]] |
10039 | 396 |
|
397 |
handleCmd_inRoom ["CALLVOTE", "KICK"] = do |
|
398 |
cl <- thisClient |
|
399 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: specify nickname"]] |
|
400 |
||
401 |
handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do |
|
402 |
(thisClientId, rnc) <- ask |
|
403 |
cl <- thisClient |
|
10058 | 404 |
rm <- thisRoom |
10039 | 405 |
maybeClientId <- clientByNick nickname |
406 |
let kickId = fromJust maybeClientId |
|
407 |
let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId |
|
408 |
||
10217 | 409 |
if isJust $ masterID rm then |
10058 | 410 |
return [] |
10039 | 411 |
else |
10058 | 412 |
if isJust maybeClientId && sameRoom then |
413 |
startVote $ VoteKick nickname |
|
414 |
else |
|
415 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote kick: no such user"]] |
|
10039 | 416 |
|
10195 | 417 |
|
10212 | 418 |
handleCmd_inRoom ["CALLVOTE", "MAP"] = do |
419 |
cl <- thisClient |
|
420 |
s <- liftM (Map.keys . roomSaves) thisRoom |
|
421 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", B.concat ["callvote map: ", B.intercalate ", " s]]] |
|
422 |
||
423 |
||
10195 | 424 |
handleCmd_inRoom ["CALLVOTE", "MAP", roomSave] = do |
425 |
cl <- thisClient |
|
426 |
rm <- thisRoom |
|
427 |
||
428 |
if Map.member roomSave $ roomSaves rm then |
|
429 |
startVote $ VoteMap roomSave |
|
430 |
else |
|
431 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote map: no such map"]] |
|
432 |
||
10392 | 433 |
handleCmd_inRoom ["CALLVOTE", "PAUSE"] = do |
434 |
cl <- thisClient |
|
435 |
rm <- thisRoom |
|
436 |
||
437 |
if isJust $ gameInfo rm then |
|
438 |
startVote VotePause |
|
439 |
else |
|
440 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "callvote pause: no game in progress"]] |
|
10195 | 441 |
|
10039 | 442 |
handleCmd_inRoom ["VOTE", m] = do |
443 |
cl <- thisClient |
|
444 |
let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing |
|
445 |
if isJust b then |
|
10081 | 446 |
voted (fromJust b) |
10039 | 447 |
else |
448 |
return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]] |
|
449 |
||
10194 | 450 |
|
451 |
handleCmd_inRoom ["SAVE", stateName] = serverAdminOnly $ do |
|
452 |
return [ModifyRoom $ \r -> r{roomSaves = Map.insert stateName (mapParams r, params r) (roomSaves r)}] |
|
453 |
||
454 |
handleCmd_inRoom ["DELETE", stateName] = serverAdminOnly $ do |
|
455 |
return [ModifyRoom $ \r -> r{roomSaves = Map.delete stateName (roomSaves r)}] |
|
456 |
||
10195 | 457 |
handleCmd_inRoom ["SAVEROOM", fileName] = serverAdminOnly $ do |
458 |
return [SaveRoom fileName] |
|
10194 | 459 |
|
10195 | 460 |
handleCmd_inRoom ["LOADROOM", fileName] = serverAdminOnly $ do |
461 |
return [LoadRoom fileName] |
|
462 |
||
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
|
463 |
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
|
464 |
|
6721
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6690
diff
changeset
|
465 |
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
|
466 |
|
7dbf8a0c1f5d
- Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents:
6690
diff
changeset
|
467 |
handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"] |