author | unC0Rr |
Wed, 18 Sep 2024 13:42:26 +0200 | |
branch | transitional_engine |
changeset 16064 | 0caa3dfb3ba2 |
parent 16012 | 2c92499daa67 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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:
10351
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:
10351
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:
10351
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10351
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 HWProtoLobbyState where |
21 |
||
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
|
22 |
import Data.Maybe |
1804 | 23 |
import Data.List |
16012 | 24 |
import Control.Monad |
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
|
25 |
import Control.Monad.Reader |
9303 | 26 |
import qualified Data.ByteString.Char8 as B |
1804 | 27 |
-------------------------------------- |
28 |
import CoreTypes |
|
29 |
import Utils |
|
13702 | 30 |
import Consts |
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 |
13515
9ba5e4594322
Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
13514
diff
changeset
|
34 |
import CommandHelp |
1804 | 35 |
|
4932 | 36 |
|
4989 | 37 |
handleCmd_lobby :: CmdHandler |
1804 | 38 |
|
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
|
39 |
|
11464 | 40 |
handleCmd_lobby ["LIST"] = do |
41 |
(ci, irnc) <- ask |
|
42 |
let cl = irnc `client` ci |
|
43 |
rooms <- allRoomInfos |
|
15900
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
14402
diff
changeset
|
44 |
let roomsInfoList = concatMap (\r -> roomInfo (clientProto cl) (maybeNick . liftM (client irnc) $ masterID r) r) . filter ((/=) 0 . roomProto) |
11464 | 45 |
return $ if hasAskedList cl then [] else |
46 |
[ ModifyClient (\c -> c{hasAskedList = True}) |
|
47 |
, AnswerClients [sendChan cl] ("ROOMS" : roomsInfoList rooms)] |
|
3501 | 48 |
|
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
|
49 |
handleCmd_lobby ["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
|
50 |
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
|
51 |
s <- roomOthersChans |
10092 | 52 |
return [AnswerClients s ["CHAT", n, msg], RegisterEvent LobbyChatMessage] |
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
|
53 |
|
4932 | 54 |
handleCmd_lobby ["CREATE_ROOM", rName, roomPassword] |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
55 |
| illegalName rName = return [Warning $ loc "Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}"] |
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
|
56 |
| 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
|
57 |
rs <- allRoomInfos |
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
|
58 |
cl <- thisClient |
4932 | 59 |
return $ if isJust $ find (\r -> rName == name r) rs then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
60 |
[Warning $ loc "A room with the same name already exists."] |
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 |
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
|
62 |
[ |
7775 | 63 |
AddRoom rName roomPassword |
64 |
, AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+hr", nick cl] |
|
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9035
diff
changeset
|
65 |
, ModifyClient (\c -> c{isMaster = True, isReady = True, isJoinedMidGame = False}) |
7775 | 66 |
, ModifyRoom (\r -> r{readyPlayers = 1}) |
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
|
67 |
] |
1804 | 68 |
|
3536 | 69 |
|
4932 | 70 |
handleCmd_lobby ["CREATE_ROOM", rName] = |
71 |
handleCmd_lobby ["CREATE_ROOM", rName, ""] |
|
3536 | 72 |
|
1862 | 73 |
|
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
|
74 |
handleCmd_lobby ["JOIN_ROOM", roomName, roomPassword] = do |
4932 | 75 |
(_, irnc) <- ask |
10342
16122539d2ea
Fix build, and also make protocol a bit more consistent and flexible (only in docs though, to be implemented)
unc0rr
parents:
10338
diff
changeset
|
76 |
|
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
|
77 |
let ris = allRooms irnc |
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
|
78 |
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
|
79 |
let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris |
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
|
80 |
let jRI = fromJust maybeRI |
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 |
let jRoom = irnc `room` jRI |
5931 | 82 |
let sameProto = clientProto cl == roomProto jRoom |
4597
31e042ab870c
Finally a solution for excess lazyness when working with unsafeThaw'ed arrays
unc0rr
parents:
4595
diff
changeset
|
83 |
let jRoomClients = map (client irnc) $ roomClients irnc jRI |
31e042ab870c
Finally a solution for excess lazyness when working with unsafeThaw'ed arrays
unc0rr
parents:
4595
diff
changeset
|
84 |
let nicks = map nick jRoomClients |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9729
diff
changeset
|
85 |
let owner = find isMaster jRoomClients |
4597
31e042ab870c
Finally a solution for excess lazyness when working with unsafeThaw'ed arrays
unc0rr
parents:
4595
diff
changeset
|
86 |
let chans = map sendChan (cl : jRoomClients) |
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
|
87 |
let isBanned = host cl `elem` roomBansList jRoom |
10342
16122539d2ea
Fix build, and also make protocol a bit more consistent and flexible (only in docs though, to be implemented)
unc0rr
parents:
10338
diff
changeset
|
88 |
let clTeams = |
12114
cdadc1d487f1
Only registered players regain their teams on rejoin
unc0rr
parents:
11467
diff
changeset
|
89 |
if (clientProto cl >= 48) && (isJust $ gameInfo jRoom) && isRegistered cl then |
11056
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
90 |
filter (\t -> teamowner t == nick cl) . teamsAtStart . fromJust $ gameInfo jRoom |
10342
16122539d2ea
Fix build, and also make protocol a bit more consistent and flexible (only in docs though, to be implemented)
unc0rr
parents:
10338
diff
changeset
|
91 |
else |
16122539d2ea
Fix build, and also make protocol a bit more consistent and flexible (only in docs though, to be implemented)
unc0rr
parents:
10338
diff
changeset
|
92 |
[] |
11056
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
93 |
let clTeamsNames = map teamname clTeams |
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
|
94 |
return $ |
15900
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
14402
diff
changeset
|
95 |
if isNothing maybeRI && clientProto cl < 60 && B.isPrefixOf "[v" roomName then |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
14402
diff
changeset
|
96 |
[Warning $ loc "Room version incompatible to your Hedgewars version!"] |
fc3cb23fd26f
Allow to see rooms of incompatible versions in the lobby
S.D.
parents:
14402
diff
changeset
|
97 |
else if isNothing maybeRI then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
98 |
[Warning $ loc "No such room."] |
10337
05a5762ab12c
Allow server admins to join room of another protocol version
unc0rr
parents:
10212
diff
changeset
|
99 |
else if (not sameProto) && (not $ isAdministrator cl) then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
100 |
[Warning $ loc "Room version incompatible to your Hedgewars version!"] |
11467
f2c36df8c7b1
Allow server admins to join passworded/restricted rooms when it is really needed
unc0rr
parents:
11464
diff
changeset
|
101 |
else if isRestrictedJoins jRoom && not (hasSuperPower cl) then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
102 |
[Warning $ loc "Access denied. This room currently doesn't allow joining."] |
12114
cdadc1d487f1
Only registered players regain their teams on rejoin
unc0rr
parents:
11467
diff
changeset
|
103 |
else if isRegisteredOnly jRoom && (not $ isRegistered cl) && not (isAdministrator cl) then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
104 |
[Warning $ loc "Access denied. This room is for registered users only."] |
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
|
105 |
else if isBanned then |
13079
81c154fd4380
More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents:
12114
diff
changeset
|
106 |
[Warning $ loc "You are banned from this room."] |
11467
f2c36df8c7b1
Allow server admins to join passworded/restricted rooms when it is really needed
unc0rr
parents:
11464
diff
changeset
|
107 |
else if roomPassword /= password jRoom && not (hasSuperPower cl) then |
6912
831416764d2d
Allow LIST command while in room to not annoy old frontends (0.9.17 or less) with warnings
unc0rr
parents:
6541
diff
changeset
|
108 |
[NoticeMessage WrongPassword] |
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
|
109 |
else |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9729
diff
changeset
|
110 |
( |
7682 | 111 |
MoveToRoom jRI |
11056
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
112 |
: ModifyClient (\c -> c{isJoinedMidGame = isJust $ gameInfo jRoom |
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
113 |
, teamsInGame = fromIntegral $ length clTeams |
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
114 |
, clientClan = teamcolor `fmap` listToMaybe clTeams}) |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9729
diff
changeset
|
115 |
: AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl] |
9787 | 116 |
: [(AnswerClients [sendChan cl] $ "JOINED" : nicks) | not $ null nicks] |
9753
9579596cf471
- Special rooms which stay even when last player quits. Not useful for now, and can't be removed at all.
unc0rr
parents:
9729
diff
changeset
|
117 |
) |
11056
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
118 |
++ [ModifyRoom (\r -> let (t', g') = moveTeams clTeamsNames . fromJust $ gameInfo r in r{gameInfo = Just g', teams = t'}) | not $ null clTeams] |
9787 | 119 |
++ [AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+h", nick $ fromJust owner] | isJust owner] |
120 |
++ [sendStateFlags cl jRoomClients | not $ null jRoomClients] |
|
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9035
diff
changeset
|
121 |
++ answerFullConfig cl jRoom |
8897
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8519
diff
changeset
|
122 |
++ answerTeams cl jRoom |
d6c310c65c91
- Revert server workaround over desync from r98e2dbdda8c0
unc0rr
parents:
8519
diff
changeset
|
123 |
++ watchRound cl jRoom chans |
13702 | 124 |
++ [AnswerClients [sendChan cl] ["CHAT", nickGreeting, greeting jRoom] | greeting jRoom /= ""] |
11056
62cc7f67105f
Restore player clan on rejoin (issue 934, not tested)
unc0rr
parents:
11055
diff
changeset
|
125 |
++ map (\t -> AnswerClients chans ["EM", toEngineMsg $ 'G' `B.cons` t]) clTeamsNames |
11055
c1c3f86af19e
Fix inverse paused state for spectators joining paused game (not tested)
unc0rr
parents:
11046
diff
changeset
|
126 |
++ [AnswerClients [sendChan cl] ["EM", toEngineMsg "I"] | isPaused `fmap` gameInfo jRoom == Just True] |
1804 | 127 |
|
4587 | 128 |
where |
10351
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10349
diff
changeset
|
129 |
moveTeams :: [B.ByteString] -> GameInfo -> ([TeamInfo], GameInfo) |
0eff41e9f63f
Restore teams in teams list on rejoin, should fix issues with second rejoin.
unc0rr
parents:
10349
diff
changeset
|
130 |
moveTeams cts g = (deleteFirstsBy2 (\a b -> teamname a == b) (teamsAtStart g) (leftTeams g \\ cts) |
10814
810ac1d21fd0
This should help with second rejoin bug. (reverting previous workaround over frontend bug and making a new one)
unc0rr
parents:
10734
diff
changeset
|
131 |
, g{leftTeams = leftTeams g \\ cts, rejoinedTeams = rejoinedTeams g ++ cts, teamsInGameNumber = teamsInGameNumber g + length cts}) |
8235 | 132 |
sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $ |
133 |
[f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby] |
|
134 |
where |
|
135 |
(ready, unready) = partition isReady clients |
|
136 |
(ingame, inroomlobby) = partition isInGame clients |
|
137 |
f fl lst = ["CLIENT_FLAGS" : fl : map nick lst | not $ null lst] |
|
3536 | 138 |
|
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9035
diff
changeset
|
139 |
-- get config from gameInfo if possible, otherwise from room |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9035
diff
changeset
|
140 |
answerFullConfig cl jRoom = let f r g = (if isJust $ gameInfo jRoom then g . fromJust . gameInfo else r) jRoom |
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
9035
diff
changeset
|
141 |
in answerFullConfigParams cl (f mapParams giMapParams) (f params giParams) |
4587 | 142 |
|
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
|
143 |
answerTeams cl jRoom = let f = if isJust $ gameInfo jRoom then teamsAtStart . fromJust . gameInfo else teams in answerAllTeams cl $ f jRoom |
4591 | 144 |
|
8237 | 145 |
watchRound cl jRoom chans = if isNothing $ gameInfo jRoom then |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2408
diff
changeset
|
146 |
[] |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2408
diff
changeset
|
147 |
else |
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:
9303
diff
changeset
|
148 |
AnswerClients [sendChan cl] ["RUN_GAME"] |
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:
9303
diff
changeset
|
149 |
: AnswerClients chans ["CLIENT_FLAGS", "+g", nick cl] |
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:
9303
diff
changeset
|
150 |
: ModifyClient (\c -> c{isInGame = True}) |
9381 | 151 |
: [AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : (reverse . roundMsgs . fromJust . gameInfo $ jRoom)] |
1813 | 152 |
|
3536 | 153 |
|
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 |
handleCmd_lobby ["JOIN_ROOM", roomName] = |
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 |
handleCmd_lobby ["JOIN_ROOM", roomName, ""] |
4568 | 156 |
|
1804 | 157 |
|
4616 | 158 |
handleCmd_lobby ["FOLLOW", asknick] = do |
159 |
(_, rnc) <- ask |
|
8486
9a65baafd7d7
Send JOINING message in response to FOLLOW. Actual join may still fail due to room restrictions. Not tested.
unc0rr
parents:
8403
diff
changeset
|
160 |
clChan <- liftM sendChan thisClient |
4616 | 161 |
ci <- clientByNick asknick |
162 |
let ri = clientRoom rnc $ fromJust ci |
|
8486
9a65baafd7d7
Send JOINING message in response to FOLLOW. Actual join may still fail due to room restrictions. Not tested.
unc0rr
parents:
8403
diff
changeset
|
163 |
let roomName = name $ room rnc ri |
5931 | 164 |
if isNothing ci || ri == lobbyId then |
4616 | 165 |
return [] |
166 |
else |
|
8486
9a65baafd7d7
Send JOINING message in response to FOLLOW. Actual join may still fail due to room restrictions. Not tested.
unc0rr
parents:
8403
diff
changeset
|
167 |
liftM ((:) (AnswerClients [clChan] ["JOINING", roomName])) $ handleCmd_lobby ["JOIN_ROOM", roomName] |
1862 | 168 |
|
9035
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
169 |
|
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
170 |
handleCmd_lobby ("RND":rs) = do |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
171 |
c <- liftM sendChan thisClient |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
172 |
return [Random [c] rs] |
e84d42a4311c
'/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents:
8897
diff
changeset
|
173 |
|
13514
da59012fbd7a
Add /help command for lobby and rooms too
Wuzzy <Wuzzy2@mail.ru>
parents:
13079
diff
changeset
|
174 |
handleCmd_lobby ["HELP"] = do |
da59012fbd7a
Add /help command for lobby and rooms too
Wuzzy <Wuzzy2@mail.ru>
parents:
13079
diff
changeset
|
175 |
cl <- thisClient |
13515
9ba5e4594322
Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
13514
diff
changeset
|
176 |
if isAdministrator cl then |
9ba5e4594322
Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
13514
diff
changeset
|
177 |
return (cmdHelpActionList [sendChan cl] cmdHelpLobbyAdmin) |
9ba5e4594322
Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
13514
diff
changeset
|
178 |
else |
9ba5e4594322
Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
13514
diff
changeset
|
179 |
return (cmdHelpActionList [sendChan cl] cmdHelpLobbyPlayer) |
13514
da59012fbd7a
Add /help command for lobby and rooms too
Wuzzy <Wuzzy2@mail.ru>
parents:
13079
diff
changeset
|
180 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2408
diff
changeset
|
181 |
--------------------------- |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2408
diff
changeset
|
182 |
-- Administrator's stuff -- |
1862 | 183 |
|
11032 | 184 |
handleCmd_lobby ["KICK", kickNick] = serverAdminOnly $ do |
4618 | 185 |
(ci, _) <- ask |
186 |
kickId <- clientByNick kickNick |
|
11032 | 187 |
return [KickClient $ fromJust kickId | isJust kickId && fromJust kickId /= ci] |
1866 | 188 |
|
4909 | 189 |
|
11032 | 190 |
handleCmd_lobby ["BAN", banNick, reason, duration] = serverAdminOnly $ do |
4909 | 191 |
(ci, _) <- ask |
192 |
banId <- clientByNick banNick |
|
11032 | 193 |
return [BanClient (readInt_ duration) reason (fromJust banId) | isJust banId && fromJust banId /= ci] |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
6912
diff
changeset
|
194 |
|
11032 | 195 |
handleCmd_lobby ["BANIP", ip, reason, duration] = serverAdminOnly $ |
196 |
return [BanIP ip (readInt_ duration) reason] |
|
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
6912
diff
changeset
|
197 |
|
11032 | 198 |
handleCmd_lobby ["BANNICK", n, reason, duration] = serverAdminOnly $ |
199 |
return [BanNick n (readInt_ duration) reason] |
|
8154 | 200 |
|
11032 | 201 |
handleCmd_lobby ["BANLIST"] = serverAdminOnly $ |
202 |
return [BanList] |
|
1804 | 203 |
|
3283 | 204 |
|
11032 | 205 |
handleCmd_lobby ["UNBAN", entry] = serverAdminOnly $ |
206 |
return [Unban entry] |
|
7748 | 207 |
|
208 |
||
11032 | 209 |
handleCmd_lobby ["SET_SERVER_VAR", "MOTD_NEW", newMessage] = serverAdminOnly $ |
210 |
return [ModifyServerInfo (\si -> si{serverMessage = newMessage})] |
|
1925 | 211 |
|
11032 | 212 |
handleCmd_lobby ["SET_SERVER_VAR", "MOTD_OLD", newMessage] = serverAdminOnly $ |
213 |
return [ModifyServerInfo (\si -> si{serverMessageForOldVersions = newMessage})] |
|
3260
b44b88908758
Allow to set motd for old client versions (not used yet, as server needs some refactoring)
unc0rr
parents:
2961
diff
changeset
|
214 |
|
11032 | 215 |
handleCmd_lobby ["SET_SERVER_VAR", "LATEST_PROTO", protoNum] = serverAdminOnly $ |
216 |
return [ModifyServerInfo (\si -> si{latestReleaseVersion = readNum}) | readNum > 0] |
|
3260
b44b88908758
Allow to set motd for old client versions (not used yet, as server needs some refactoring)
unc0rr
parents:
2961
diff
changeset
|
217 |
where |
5030
42746c5d4a80
Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents:
4989
diff
changeset
|
218 |
readNum = readInt_ protoNum |
7321
57bd4f201401
- Try sending remove message in 'finally' as a last resort
unc0rr
parents:
6912
diff
changeset
|
219 |
|
11032 | 220 |
handleCmd_lobby ["GET_SERVER_VAR"] = serverAdminOnly $ |
221 |
return [SendServerVars] |
|
3283 | 222 |
|
11032 | 223 |
handleCmd_lobby ["CLEAR_ACCOUNTS_CACHE"] = serverAdminOnly $ |
224 |
return [ClearAccountsCache] |
|
3283 | 225 |
|
14402
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
226 |
handleCmd_lobby ["RESTART_SERVER", "YES"] = serverAdminOnly $ |
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
227 |
return [RestartServer] |
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
228 |
|
11032 | 229 |
handleCmd_lobby ["RESTART_SERVER"] = serverAdminOnly $ |
14402
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
230 |
return [Warning $ loc "Please confirm server restart with '/restart_server yes'."] |
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
231 |
|
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
232 |
handleCmd_lobby ["RESTART_SERVER", _] = handleCmd_lobby ["RESTART_SERVER"] |
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
233 |
|
4914 | 234 |
|
11032 | 235 |
handleCmd_lobby ["STATS"] = serverAdminOnly $ |
236 |
return [Stats] |
|
3283 | 237 |
|
13849
07b3dacd00f8
gameServer: Always report command name if getting an incorrect command
Wuzzy <Wuzzy2@mail.ru>
parents:
13702
diff
changeset
|
238 |
handleCmd_lobby (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in lobby)"] |
13855 | 239 |
|
14402
32e8c81ca35c
Add reminder to call /restart_server with "yes"
Wuzzy <Wuzzy2@mail.ru>
parents:
13855
diff
changeset
|
240 |
handleCmd_lobby [] = return [ProtocolError "Empty command (state: in lobby)"] |