gameServer/HWProtoInRoomState.hs
author Wuzzy <Wuzzy2@mail.ru>
Tue, 17 Jul 2018 12:55:07 +0200
branch0.9.24
changeset 13591 9f05872969dc
parent 13079 81c154fd4380
child 13509 f747c385b5ba
permissions -rw-r--r--
Fix cursor teleporting to center after leaving game with video recording
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10884
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
10460
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
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
module HWProtoInRoomState where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    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
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    28
--------------------------------------
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    29
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    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
e18713ecf1e0 Introduce EngineInteraction module
unc0rr
parents: 6012
diff changeset
    33
import EngineInteraction
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
    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
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
    44
    let allPlayersRegistered = all isOwnerRegistered $ teams rm
9995
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
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
    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
11557
cf5d45444357 Oops, fix whose nick to compare to
unc0rr
parents: 11556
diff changeset
    57
                , ModifyRoomClients (\c -> c{isInGame = True, teamIndexes = map snd . filter (\(t, _) -> teamowner t == nick c) $ zip (teams rm) [0..]})
9995
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
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
    60
            return [Warning $ loc "The game can't be started with less than two clans!"]
9995
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
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4986
diff changeset
    68
handleCmd_inRoom :: CmdHandler
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    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
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    74
10095
003fc694c0c3 Actually do some actions when flood detected
unc0rr
parents: 10092
diff changeset
    75
handleCmd_inRoom ["PART"] = return [MoveToLobby "part"]
003fc694c0c3 Actually do some actions when flood detected
unc0rr
parents: 10092
diff changeset
    76
handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg]
3531
66c403badff6 Reimplement room creating
unC0Rr@gmail.com
parents: 3500
diff changeset
    77
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
    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)
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
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
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
    84
        rm <- thisRoom
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
    85
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
    86
        if isSpecial rm then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
    87
            return [Warning $ loc "Access denied."]
9770
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
    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 [
10730
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
    90
                ModifyRoom $ f (clientProto cl),
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
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
    93
            return [ProtocolError $ loc "You're not the room master!"]
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
    94
    where
10730
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
    95
        f clproto r = if paramName `Map.member` (mapParams r) then
4941
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
    96
                r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
90572c338e60 Fix for my last commit (which was all nonsense)
unc0rr
parents: 4932
diff changeset
    97
                else
10730
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
    98
                r{params = Map.insert paramName (fixedParamStr clproto) (params r)}
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
    99
        fixedParamStr clproto
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
   100
            | clproto /= 49 = paramStrs
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
   101
            | paramName /= "SCHEME" = paramStrs
eac6a4d53752 Server-side workaround for frontend's script parameter bug in .21
unc0rr
parents: 10511
diff changeset
   102
            | otherwise = L.init paramStrs ++ [B.replicate 50 'X' `B.append` L.last paramStrs]
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   103
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
   104
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   105
handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   106
    | 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
   107
    | otherwise = do
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   108
        rm <- thisRoom
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   109
        cl <- thisClient
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
   110
        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
   111
        clChan <- thisClientChans
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   112
        othChans <- roomOthersChans
7862
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7775
diff changeset
   113
        roomChans <- roomClientsChans
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7775
diff changeset
   114
        teamColor <-
8924
13ac59499066 update 0.9.19 with dev branch
koda
parents: 8899
diff changeset
   115
            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
   116
                return color
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7775
diff changeset
   117
                else
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7775
diff changeset
   118
                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
   119
        let roomTeams = teams rm
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   120
        let hhNum = newTeamHHNum roomTeams $
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   121
                if not $ null roomTeams then
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   122
                    minimum [hhnum $ head roomTeams, canAddNumber roomTeams]
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   123
                else
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   124
                    defaultHedgehogsNumber rm
12114
cdadc1d487f1 Only registered players regain their teams on rejoin
unc0rr
parents: 11575
diff changeset
   125
        let newTeam = clNick `seq` TeamInfo clNick tName teamColor grave fort voicepack flag (isRegistered cl) 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
   126
        return $
10884
7b76811fb689 Fix off-by-1 error
unC0Rr
parents: 10882
diff changeset
   127
            if not . null . drop (teamsNumberLimit rm - 1) $ roomTeams then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   128
                [Warning $ loc "Too many teams!"]
8421
fc39fe044a4f Make number of hedgehogs restriction actually work in network game
unc0rr
parents: 8418
diff changeset
   129
            else if canAddNumber roomTeams <= 0 then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   130
                [Warning $ loc "Too many hedgehogs!"]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   131
            else if isJust $ findTeam rm then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   132
                [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
   133
            else if isJust $ gameInfo rm then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   134
                [Warning $ loc "Joining not possible: Round is in progress."]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   135
            else if isRestrictedTeams rm then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   136
                [Warning $ loc "This room currently does not allow adding new teams."]
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
   137
            else
7986
53b1da5ee7f4 Maybe this caused server crashes? Add more strictness on team owner record field
unc0rr
parents: 7947
diff changeset
   138
                [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
   139
                SendUpdateOnThisRoom,
7862
bd76ca40db68 Choose first unused color for added team (addresses issue 431) + other small changes
unc0rr
parents: 7775
diff changeset
   140
                ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}),
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   141
                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
   142
                AnswerClients othChans $ teamToNet $ newTeam,
17378d33e62e This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents: 8541
diff changeset
   143
                AnswerClients roomChans ["TEAM_COLOR", tName, teamColor],
8899
7493dde4ef51 This isn't necessary anymore
unc0rr
parents: 8897
diff changeset
   144
                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
   145
                ]
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
        where
8421
fc39fe044a4f Make number of hedgehogs restriction actually work in network game
unc0rr
parents: 8418
diff changeset
   147
        canAddNumber rt = (48::Int) - (sum $ map hhnum rt)
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   148
        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
   149
        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
   150
        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
   151
        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
   152
        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
   153
        newTeamHHNum rt p = min p (canAddNumber rt)
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7266
diff changeset
   154
        maxTeams r
5931
184057074257 - Allow 8 teams in game on 0.9.16-dev
unc0rr
parents: 5143
diff changeset
   155
            | roomProto r < 38 = 6
184057074257 - Allow 8 teams in game on 0.9.16-dev
unc0rr
parents: 5143
diff changeset
   156
            | otherwise = 8
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7266
diff changeset
   157
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
   158
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   159
handleCmd_inRoom ["REMOVE_TEAM", tName] = do
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   160
        (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
   161
        r <- thisRoom
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   162
        clNick <- clientNick
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
   163
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
        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
   165
        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
   166
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
        return $
8428
73ab5a17ee55 Fix crashers
unc0rr
parents: 8422
diff changeset
   168
            if isNothing $ maybeTeam then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   169
                [Warning $ loc "Error: The team you tried to remove does not exist."]
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   170
            else if clNick /= teamowner team then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   171
                [ProtocolError $ loc "You can't remove a team you don't own."]
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
   172
            else
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   173
                [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
   174
                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
   175
                    (\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
   176
                        teamsInGame = teamsInGame c - 1,
11414
6f119783a1ad Remove CHECKPOINT 011 occurence, probably hiding some bug
unc0rr
parents: 11046
diff changeset
   177
                        clientClan = if teamsInGame c == 1 then Nothing else anotherTeamClan clNick team r
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4986
diff changeset
   178
                    })
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
   179
                ]
4568
f85243bf890e Ok. This should pull 0.9.14.1 server into default
nemo
parents: 4337
diff changeset
   180
    where
11414
6f119783a1ad Remove CHECKPOINT 011 occurence, probably hiding some bug
unc0rr
parents: 11046
diff changeset
   181
        anotherTeamClan clNick team = liftM teamcolor . find (\t -> (teamowner t == clNick) && (t /= team)) . teams
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   182
        findTeam = find (\t -> tName == teamname t) . teams
3561
7f8e07e4a4e3 Reimplement REMOVE_TEAM
unc0rr
parents: 3555
diff changeset
   183
3568
ae89cf0735dc A bunch of reimplemented commands
unc0rr
parents: 3566
diff changeset
   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 ["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
   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
    r <- thisRoom
8421
fc39fe044a4f Make number of hedgehogs restriction actually work in network game
unc0rr
parents: 8418
diff changeset
   188
    clChan <- thisClientChans
8477
330b0b8846cf Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents: 8433
diff changeset
   189
    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
   190
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 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
   192
    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
   193
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
    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
   195
        if not $ isMaster cl then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   196
            [ProtocolError $ loc "You're not the room master!"]
8429
f814a7c2a318 Oops, got too excited
unc0rr
parents: 8428
diff changeset
   197
        else if isNothing maybeTeam then
f814a7c2a318 Oops, got too excited
unc0rr
parents: 8428
diff changeset
   198
            []
8428
73ab5a17ee55 Fix crashers
unc0rr
parents: 8422
diff changeset
   199
        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
   200
            [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
   201
        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
   202
            [ModifyRoom $ modifyTeam team{hhnum = hhNumber},
8477
330b0b8846cf Don't confirm hogs number to room admin when no constraint hit
unc0rr
parents: 8433
diff changeset
   203
            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
   204
    where
5030
42746c5d4a80 Changed the standard show function to Text.Show.ByteString, and misc.
EJ <eivind.jahren@gmail.com>
parents: 4989
diff changeset
   205
        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
   206
        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
   207
        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
   208
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   209
3568
ae89cf0735dc A bunch of reimplemented commands
unc0rr
parents: 3566
diff changeset
   210
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
   211
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
   212
    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
   213
    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
   214
    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
   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
    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
   217
    let team = fromJust maybeTeam
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   218
    maybeClientId <- clientByNick $ teamowner team
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   219
    let teamOwnerId = fromJust maybeClientId
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
   220
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
    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
   222
        if not $ isMaster cl then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   223
            [ProtocolError $ loc "You're not the room master!"]
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   224
        else if isNothing maybeTeam || isNothing maybeClientId 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
   225
            []
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
   226
        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
   227
            [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
   228
            AnswerClients others ["TEAM_COLOR", teamName, newColor],
10732
7c4f9e5e447c Get rid of teamownerId since rejoin feature makes it virtually useless, as you cannot rely on it anymore. Should fix recently experienced server crashes.
unc0rr
parents: 10730
diff changeset
   229
            ModifyClient2 teamOwnerId (\c -> c{clientClan = Just newColor})]
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   230
    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
   231
        findTeam = find (\t -> teamName == teamname t) . teams
3568
ae89cf0735dc A bunch of reimplemented commands
unc0rr
parents: 3566
diff changeset
   232
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   233
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
   234
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
   235
    cl <- thisClient
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   236
    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
   237
    chans <- roomClientsChans
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7266
diff changeset
   238
9995
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   239
    (ci, rnc) <- ask
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   240
    let ri = clientRoom rnc ci
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   241
    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
   242
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   243
    gs <- if (not $ isReady cl) && (isSpecial rm) && (unreadyClients == [cl]) then startGame else return []
3577
0ef6f5182a75 START_GAME command
unc0rr
parents: 3568
diff changeset
   244
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   245
    return $
9995
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   246
        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
   247
        : ModifyClient (\c -> c{isReady = not $ isReady cl})
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   248
        : (AnswerClients chans $ if clientProto cl < 38 then
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   249
                [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
   250
                else
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   251
                ["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
   252
        : gs
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   253
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   254
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   255
handleCmd_inRoom ["START_GAME"] = roomAdminOnly startGame
9995
8bf092ddc536 In special rooms game starts when all players are ready
unc0rr
parents: 9787
diff changeset
   256
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
   257
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
   258
    cl <- thisClient
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   259
    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
   260
    chans <- roomOthersChans
4931
da43c36a6e92 Don't accept EM message when the game isn't started
unc0rr
parents: 4917
diff changeset
   261
11556
af9aa8d5863c Filter out hog speech messages with non-local team index (not tested)
unc0rr
parents: 11508
diff changeset
   262
    let (legalMsgs, nonEmptyMsgs, lastFTMsg) = checkNetCmd (teamIndexes cl) msg
af9aa8d5863c Filter out hog speech messages with non-local team index (not tested)
unc0rr
parents: 11508
diff changeset
   263
8484
99c14f14f788 New checker of engine messages which is aware of glued together messages
unc0rr
parents: 8477
diff changeset
   264
    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
   265
        return $ AnswerClients chans ["EM", legalMsgs]
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   266
            : [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
   267
                (\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
   268
                    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
   269
                    , lastFilteredTimedMsg = fromMaybe (lastFilteredTimedMsg g) lastFTMsg})
10092
a92a4ba39a79 Fix build
unc0rr
parents: 10081
diff changeset
   270
                $ 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
   271
        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
   272
        return []
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   273
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
   274
8550
17378d33e62e This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents: 8541
diff changeset
   275
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
   276
    cl <- thisClient
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   277
    rm <- thisRoom
7765
1e162c1d6dc7 'In game' client flag, both server and frontend support
unc0rr
parents: 7757
diff changeset
   278
    chans <- roomClientsChans
1e162c1d6dc7 'In game' client flag, both server and frontend support
unc0rr
parents: 7757
diff changeset
   279
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
   280
    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
   281
    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
   282
7757
c20e6c80e249 Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents: 7537
diff changeset
   283
    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
   284
        if isJust $ gameInfo rm then
8422
ec41194d4444 Okay, let's try not trust even room admin on this
unc0rr
parents: 8421
diff changeset
   285
            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
   286
            else
7765
1e162c1d6dc7 'In game' client flag, both server and frontend support
unc0rr
parents: 7757
diff changeset
   287
            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
   288
        else
7757
c20e6c80e249 Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents: 7537
diff changeset
   289
        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
   290
    where
8550
17378d33e62e This change from r0cd63b963330 caused more troubles than solved. Also fix some warnings.
unc0rr
parents: 8541
diff changeset
   291
--        isCorrect = correctly == "1"
1811
1b9e33623b7e Implement 'roundfinished' cmd on net server
unc0rr
parents: 1804
diff changeset
   292
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
   293
-- 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
   294
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
   295
    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
   296
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   297
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
   298
    return [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r}), SendUpdateOnThisRoom]
4568
f85243bf890e Ok. This should pull 0.9.14.1 server into default
nemo
parents: 4337
diff changeset
   299
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   300
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   301
handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = roomAdminOnly $
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   302
    return [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   303
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   304
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   305
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
   306
    return [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r}), SendUpdateOnThisRoom]
8232
fb5aa767a2a0 "Registered users only" room flag
unc0rr
parents: 8189
diff changeset
   307
8484
99c14f14f788 New checker of engine messages which is aware of glued together messages
unc0rr
parents: 8477
diff changeset
   308
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   309
handleCmd_inRoom ["ROOM_NAME", newName] = roomAdminOnly $ do
5098
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   310
    cl <- thisClient
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   311
    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
   312
    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
   313
    chans <- sameProtoChans
7321
57bd4f201401 - Try sending remove message in 'finally' as a last resort
unc0rr
parents: 7266
diff changeset
   314
5098
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   315
    return $
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 10015
diff changeset
   316
        if illegalName newName then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   317
            [Warning $ loc "Illegal room name! The 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: $()*+?[]^{|}"]
9454
ac1874d56057 Fix bug 703
unc0rr
parents: 9304
diff changeset
   318
        else
9770
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
   319
        if isSpecial rm then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   320
            [Warning $ loc "Access denied."]
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
   321
        else
5098
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   322
        if isJust $ find (\r -> newName == name r) rs then
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   323
            [Warning $ loc "A room with the same name already exists."]
5098
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   324
        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
   325
            [ModifyRoom roomUpdate,
9702
27006953d901 - Column for script in rooms list
unc0rr
parents: 9454
diff changeset
   326
            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
   327
    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
   328
        roomUpdate r = r{name = newName}
5098
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   329
cb9cf41a208c Allow to rename room
unc0rr
parents: 5030
diff changeset
   330
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   331
handleCmd_inRoom ["KICK", kickNick] = roomAdminOnly $ do
4614
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   332
    (thisClientId, rnc) <- ask
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   333
    maybeClientId <- clientByNick kickNick
8513
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   334
    rm <- thisRoom
4614
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   335
    let kickId = fromJust maybeClientId
8513
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   336
    let kickCl = rnc `client` kickId
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4931
diff changeset
   337
    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
   338
    let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2
4614
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   339
    return
8513
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   340
        [KickRoomClient kickId |
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   341
            isJust maybeClientId
8513
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   342
            && (kickId /= thisClientId)
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   343
            && sameRoom
11508
a4ad8a9e0f69 Don't allow to kick an admin with super power enabled
unc0rr
parents: 11414
diff changeset
   344
            && (not $ hasSuperPower kickCl)
8627
ea2d32a03ac9 Eh, two players condition seems to make more sense than two clans here
unc0rr
parents: 8550
diff changeset
   345
            && ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0)
8513
cd85ab23f38b Disallow kicking the opponent in duel
unc0rr
parents: 8484
diff changeset
   346
        ]
1879
bb114339eb4e Implement kick from room
unc0rr
parents: 1866
diff changeset
   347
1831
025348f05b9f Implement two more missing protocol commands
unc0rr
parents: 1818
diff changeset
   348
8247
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   349
handleCmd_inRoom ["DELEGATE", newAdmin] = do
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   350
    (thisClientId, rnc) <- ask
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   351
    maybeClientId <- clientByNick newAdmin
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   352
    master <- liftM isMaster thisClient
8403
fbc6e7602e05 - Allow server admins to use DELEGATE even when not room owner
unc0rr
parents: 8401
diff changeset
   353
    serverAdmin <- liftM isAdministrator thisClient
9715
30a303d226f9 Forbid /delegate to room admin
unc0rr
parents: 9702
diff changeset
   354
    thisRoomMasterId <- liftM masterID thisRoom
8247
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   355
    let newAdminId = fromJust maybeClientId
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   356
    let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   357
    return
8403
fbc6e7602e05 - Allow server admins to use DELEGATE even when not room owner
unc0rr
parents: 8401
diff changeset
   358
        [ChangeMaster (Just newAdminId) |
fbc6e7602e05 - Allow server admins to use DELEGATE even when not room owner
unc0rr
parents: 8401
diff changeset
   359
            (master || serverAdmin)
fbc6e7602e05 - Allow server admins to use DELEGATE even when not room owner
unc0rr
parents: 8401
diff changeset
   360
                && 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
   361
                && (Just newAdminId /= thisRoomMasterId)
8403
fbc6e7602e05 - Allow server admins to use DELEGATE even when not room owner
unc0rr
parents: 8401
diff changeset
   362
                && sameRoom]
8247
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   363
d7cf4a9ce685 Command to delegate room to other player
unc0rr
parents: 8232
diff changeset
   364
4614
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   365
handleCmd_inRoom ["TEAMCHAT", msg] = do
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   366
    cl <- thisClient
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   367
    chans <- roomSameClanChans
26661bf28dd5 Reimplement some more protocol commands
unc0rr
parents: 4337
diff changeset
   368
    return [AnswerClients chans ["EM", engineMsg cl]]
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2747
diff changeset
   369
    where
8757
266df6d5ed73 Add space for better visual performance
unc0rr
parents: 8627
diff changeset
   370
        engineMsg cl = toEngineMsg $ B.concat ["b", nick cl, " (team): ", msg, "\x20\x20"]
4568
f85243bf890e Ok. This should pull 0.9.14.1 server into default
nemo
parents: 4337
diff changeset
   371
8484
99c14f14f788 New checker of engine messages which is aware of glued together messages
unc0rr
parents: 8477
diff changeset
   372
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
   373
handleCmd_inRoom ["BAN", banNick] = do
8002
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   374
    (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
   375
    maybeClientId <- clientByNick banNick
8002
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   376
    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
   377
    let banId = fromJust maybeClientId
8002
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   378
    let sameRoom = clientRoom rnc thisClientId == clientRoom rnc banId
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   379
    if master && isJust maybeClientId && (banId /= thisClientId) && sameRoom then
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   380
        return [
8189
328f429c3ecc - Disable in-room bans
unc0rr
parents: 8002
diff changeset
   381
--                ModifyRoom (\r -> r{roomBansList = let h = host $ rnc `client` banId in h `deepseq` h : roomBansList r})
328f429c3ecc - Disable in-room bans
unc0rr
parents: 8002
diff changeset
   382
                KickRoomClient banId
8002
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   383
            ]
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   384
        else
8113afd3858f More strictness on room bans
unc0rr
parents: 7986
diff changeset
   385
        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
   386
9035
e84d42a4311c '/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents: 8983
diff changeset
   387
handleCmd_inRoom ("RND":rs) = do
e84d42a4311c '/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents: 8983
diff changeset
   388
    n <- clientNick
e84d42a4311c '/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents: 8983
diff changeset
   389
    s <- roomClientsChans
e84d42a4311c '/rnd' command. Pass it a (possibly empty) list of items.
unc0rr
parents: 8983
diff changeset
   390
    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
   391
10882
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   392
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   393
handleCmd_inRoom ["MAXTEAMS", n] = roomAdminOnly $ do
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   394
    cl <- thisClient
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   395
    let m = readInt_ n
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   396
    if m < 2 || m > 8 then
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   397
        return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/maxteams: specify number from 2 to 8"]]
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   398
    else
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   399
        return [ModifyRoom (\r -> r{teamsNumberLimit = m})]
ed7717f659ae - Fix ping timeouts after incorrect "/vote" commands (protocol violation)
unc0rr
parents: 10881
diff changeset
   400
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   401
handleCmd_inRoom ["FIX"] = serverAdminOnly $
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   402
    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
   403
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   404
handleCmd_inRoom ["UNFIX"] = serverAdminOnly $
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   405
    return [ModifyRoom (\r -> r{isSpecial = False})]
9770
5706b637bae2 - Restrict game config changes in special rooms
unc0rr
parents: 9753
diff changeset
   406
9787
0da6ba2f1f93 - /greeting command for room greeting message
unc0rr
parents: 9770
diff changeset
   407
handleCmd_inRoom ["GREETING", msg] = do
0da6ba2f1f93 - /greeting command for room greeting message
unc0rr
parents: 9770
diff changeset
   408
    cl <- thisClient
0da6ba2f1f93 - /greeting command for room greeting message
unc0rr
parents: 9770
diff changeset
   409
    rm <- thisRoom
0da6ba2f1f93 - /greeting command for room greeting message
unc0rr
parents: 9770
diff changeset
   410
    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
   411
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   412
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   413
handleCmd_inRoom ["CALLVOTE"] = do
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   414
    cl <- thisClient
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   415
    return [AnswerClients [sendChan cl]
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   416
        ["CHAT", "[server]", loc "Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs"]
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   417
        ]
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   418
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   419
handleCmd_inRoom ["CALLVOTE", "KICK"] = do
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   420
    cl <- thisClient
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   421
    return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote kick: You need to specify a nickname."]]
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   422
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   423
handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   424
    (thisClientId, rnc) <- ask
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   425
    cl <- thisClient
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10057
diff changeset
   426
    rm <- thisRoom
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   427
    maybeClientId <- clientByNick nickname
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   428
    let kickId = fromJust maybeClientId
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   429
    let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   430
10217
1a1da2342c5b Fix condition
unc0rr
parents: 10215
diff changeset
   431
    if isJust $ masterID rm then
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10057
diff changeset
   432
        return []
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   433
        else
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10057
diff changeset
   434
        if isJust maybeClientId && sameRoom then
4ed428389c4e - Implement /callvote
unc0rr
parents: 10057
diff changeset
   435
            startVote $ VoteKick nickname
4ed428389c4e - Implement /callvote
unc0rr
parents: 10057
diff changeset
   436
            else
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   437
            return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote kick: No such user!"]]
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   438
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   439
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   440
handleCmd_inRoom ["CALLVOTE", "MAP"] = do
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   441
    cl <- thisClient
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   442
    s <- liftM (Map.keys . roomSaves) thisRoom
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   443
    return [AnswerClients [sendChan cl] ["CHAT", "[server]", B.concat ["callvote map: ", B.intercalate ", " s]]]
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   444
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   445
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   446
handleCmd_inRoom ["CALLVOTE", "MAP", roomSave] = do
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   447
    cl <- thisClient
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   448
    rm <- thisRoom
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   449
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   450
    if Map.member roomSave $ roomSaves rm then
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   451
        startVote $ VoteMap roomSave
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   452
        else
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   453
        return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote map: No such map!"]]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   454
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   455
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   456
handleCmd_inRoom ["CALLVOTE", "PAUSE"] = do
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   457
    cl <- thisClient
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   458
    rm <- thisRoom
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   459
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   460
    if isJust $ gameInfo rm then
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   461
        startVote VotePause
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10217
diff changeset
   462
        else 
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   463
        return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote pause: No game in progress!"]]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   464
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   465
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   466
handleCmd_inRoom ["CALLVOTE", "NEWSEED"] = do
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   467
    startVote VoteNewSeed
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   468
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   469
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   470
handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS"] = do
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   471
    cl <- thisClient
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   472
    return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   473
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   474
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   475
handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS", hhs] = do
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   476
    cl <- thisClient
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   477
    let h = readInt_ hhs
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   478
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   479
    if h > 0 && h <= 8 then
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   480
        startVote $ VoteHedgehogsPerTeam h
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   481
        else
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   482
        return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10732
diff changeset
   483
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   484
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10786
diff changeset
   485
handleCmd_inRoom ("VOTE" : m : p) = do
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   486
    cl <- thisClient
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   487
    let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   488
    if isJust b then
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10786
diff changeset
   489
        voted (p == ["FORCE"]) (fromJust b)
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   490
        else
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 12114
diff changeset
   491
        return [AnswerClients [sendChan cl] ["CHAT", "[server]", "/vote: Please use 'yes' or 'no'."]]
10039
58cf89284115 Halfplement voting
unc0rr
parents: 9995
diff changeset
   492
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   493
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11557
diff changeset
   494
handleCmd_inRoom ["SAVE", stateName, location] = serverAdminOnly $ do
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11557
diff changeset
   495
    return [ModifyRoom $ \r -> r{roomSaves = Map.insert stateName (location, mapParams r, params r) (roomSaves r)}]
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   496
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   497
handleCmd_inRoom ["DELETE", stateName] = serverAdminOnly $ do
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   498
    return [ModifyRoom $ \r -> r{roomSaves = Map.delete stateName (roomSaves r)}]
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   499
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   500
handleCmd_inRoom ["SAVEROOM", fileName] = serverAdminOnly $ do
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   501
    return [SaveRoom fileName]
10194
7025bd3c3131 Allow to save and delete room config in room
unc0rr
parents: 10095
diff changeset
   502
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   503
handleCmd_inRoom ["LOADROOM", fileName] = serverAdminOnly $ do
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   504
    return [LoadRoom fileName]
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10194
diff changeset
   505
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
   506
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
   507
6721
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6690
diff changeset
   508
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
   509
7dbf8a0c1f5d - Register HWTeam metatype so HWTeam objects could be passed via queued connections
unc0rr
parents: 6690
diff changeset
   510
handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"]