gameServer/CommandHelp.hs
author Wuzzy <Wuzzy2@mail.ru>
Sat, 25 Aug 2018 19:07:17 +0200
changeset 13695 e529a34872f9
parent 13692 70c8feb81d35
child 13696 d732ca5dcab9
permissions -rw-r--r--
Fix some formatting problems with /me
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13515
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     1
{-
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     4
 *
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     8
 *
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    13
 *
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    17
 \-}
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    18
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    19
{-# LANGUAGE OverloadedStrings #-}
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    20
module CommandHelp where
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    21
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    22
import qualified Data.ByteString.Char8 as B
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    23
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    24
import CoreTypes
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    25
import Utils
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    26
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    27
-- List and documentation of chat commands
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    28
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    29
cmdHelpSharedPlayer :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    30
cmdHelpSharedPlayer = [
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    31
    loc "/info <player>: Show info about player",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    32
    loc "/me <message>: Chat action, e.g. '/me eats pizza' becomes '* Player eats pizza'",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    33
    loc "/rnd: Flip a virtual coin and reply with 'heads' or 'tails'",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    34
    loc "/rnd [A] [B] [C] [...]: Reply with a random word from the given list",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    35
    loc "/watch <id>: Watch a demo stored on the server with the given ID",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    36
    loc "/help: Show chat command help"
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    37
    ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    38
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    39
cmdHelpRoomOnlyPlayer :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    40
cmdHelpRoomOnlyPlayer = [
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    41
    -- For everyone
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    42
    loc "/callvote [arguments]: Start a vote",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    43
    loc "/vote <yes/no>: Vote 'yes' or 'no' for active vote",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    44
    -- For room master only
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    45
    loc "/greeting <message>: Set greeting message to be shown to players who join the room",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    46
    loc "/delegate <player>: Surrender room control to player",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    47
    loc "/maxteams <N>: Limit maximum number of teams to N"
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    48
    ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    49
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    50
cmdHelpSharedAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    51
cmdHelpSharedAdmin = [
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    52
    loc "/global <message>: Send global chat message which can be seen by everyone on the server",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    53
    loc "/registered_only: Toggle 'registered only' state. If enabled, only registered players can join server",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    54
    loc "/super_power: Activate your super power. With it you can enter any room and are protected from kicking. Expires when you leave server",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    55
    -- TODO: Add help for /save
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    56
    loc "/save <parameter>"
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    57
    -- TODO: Add /restart_server? This command seems broken at the moment
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    58
    ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    59
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    60
cmdHelpLobbyOnlyAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    61
cmdHelpLobbyOnlyAdmin = [
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    62
    loc "/stats: Query server stats"
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    63
    ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    64
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    65
cmdHelpRoomOnlyAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    66
cmdHelpRoomOnlyAdmin = [
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    67
    loc "/force <yes/no>: Force vote result for active vote",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    68
    loc "/fix: Force this room to stay open when it is empty",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    69
    loc "/unfix: Undo the /fix command",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    70
    loc "/saveroom <file name>: Save room configuration into a file",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    71
    loc "/loadroom <file name>: Load room configuration from a file",
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    72
    -- TODO: Add help for /delete
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    73
    loc "/delete <parameter>"
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    74
    ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    75
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    76
cmdHelpHeaderLobby :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    77
cmdHelpHeaderLobby = [ loc "List of lobby chat commands:" ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    78
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    79
cmdHelpHeaderRoom :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    80
cmdHelpHeaderRoom = [ loc "List of room chat commands:" ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    81
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    82
cmdHelpHeaderAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    83
cmdHelpHeaderAdmin = [ loc "Commands for server admins only:" ]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    84
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    85
-- Put it all together
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    86
-- Lobby commands
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    87
cmdHelpLobbyPlayer :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    88
cmdHelpLobbyPlayer = cmdHelpHeaderLobby ++ cmdHelpSharedPlayer
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    89
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    90
cmdHelpLobbyAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    91
cmdHelpLobbyAdmin = cmdHelpLobbyPlayer ++ cmdHelpHeaderAdmin ++ cmdHelpLobbyOnlyAdmin ++ cmdHelpSharedAdmin
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    92
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    93
-- Room commands
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    94
cmdHelpRoomPlayer :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    95
cmdHelpRoomPlayer = cmdHelpHeaderRoom ++ cmdHelpRoomOnlyPlayer ++ cmdHelpSharedPlayer
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    96
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    97
cmdHelpRoomAdmin :: [B.ByteString]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    98
cmdHelpRoomAdmin = cmdHelpRoomPlayer ++ cmdHelpHeaderAdmin ++ cmdHelpRoomOnlyAdmin ++ cmdHelpSharedAdmin
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
    99
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   100
-- Helper functions for chat command handler
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   101
cmdHelpActionEntry :: [ClientChan] -> B.ByteString -> Action
13692
70c8feb81d35 Make frontend translate server messages properly
Wuzzy <Wuzzy2@mail.ru>
parents: 13515
diff changeset
   102
cmdHelpActionEntry chan msg = AnswerClients chan [ "CHAT", "[server]", msg ]
13515
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   103
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   104
cmdHelpActionList :: [ClientChan] -> [B.ByteString] -> [Action]
9ba5e4594322 Refactor server chat command help, also add admin commands to help
Wuzzy <Wuzzy2@mail.ru>
parents:
diff changeset
   105
cmdHelpActionList chan list = map (cmdHelpActionEntry chan) list