--- a/gameServer/Actions.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/Actions.hs Sat Aug 25 19:23:19 2018 +0200
@@ -733,7 +733,7 @@
processAction (Random chans items) = do
let i = if null items then ["heads", "tails"] else items
n <- io $ randomRIO (0, length i - 1)
- processAction $ AnswerClients chans ["CHAT", "[random]", i !! n]
+ processAction $ AnswerClients chans ["CHAT", nickRandom, i !! n]
processAction (LoadGhost location) = do
--- a/gameServer/CommandHelp.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/CommandHelp.hs Sat Aug 25 19:23:19 2018 +0200
@@ -23,6 +23,7 @@
import CoreTypes
import Utils
+import Consts
-- List and documentation of chat commands
@@ -99,7 +100,7 @@
-- Helper functions for chat command handler
cmdHelpActionEntry :: [ClientChan] -> B.ByteString -> Action
-cmdHelpActionEntry chan msg = AnswerClients chan [ "CHAT", "[server]", msg ]
+cmdHelpActionEntry chan msg = AnswerClients chan [ "CHAT", nickServer, msg ]
cmdHelpActionList :: [ClientChan] -> [B.ByteString] -> [Action]
cmdHelpActionList chan list = map (cmdHelpActionEntry chan) list
--- a/gameServer/Consts.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/Consts.hs Sat Aug 25 19:23:19 2018 +0200
@@ -24,11 +24,32 @@
serverVersion :: B.ByteString
serverVersion = "3"
+-- Maximum hedgehogs per team
cHogsPerTeam :: Int
cHogsPerTeam = 8
+-- Maximum teams count
cMaxTeams :: Int
cMaxTeams = 8
+-- Maximum total number of hedgehogs
cMaxHHs :: Int
cMaxHHs = cHogsPerTeam * cMaxTeams
+
+{- "Fake" nick names used for special server messages in chat.
+They are enclosed in brackets; these characters not allowed in real nick names.
+The brackets are required as they are parsed by the frontend.
+Names enclosed in square brackets send messages that are supposed to be translated by the frontend.
+Names enclosed in parenthesis send messages that are not supposed to be translated. -}
+
+-- For most server messages, usually response to a command
+nickServer :: B.ByteString
+nickServer = "[server]"
+
+-- For /rnd command
+nickRandom :: B.ByteString
+nickRandom = "[random]"
+
+-- For /global command
+nickGlobal :: B.ByteString
+nickGlobal = "(global notice)"
--- a/gameServer/HWProtoCore.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/HWProtoCore.hs Sat Aug 25 19:23:19 2018 +0200
@@ -31,6 +31,7 @@
import HandlerUtils
import RoomsAndClients
import Utils
+import Consts
handleCmd, handleCmd_loggedin :: CmdHandler
@@ -81,8 +82,7 @@
h "GLOBAL" p = serverAdminOnly $ do
rnc <- liftM snd ask
let chans = map (sendChan . client rnc) $ allClients rnc
- -- parenthesis instead of square brackets used to avoid accidental translation by frontend
- return [AnswerClients chans ["CHAT", "(global notice)", p]]
+ return [AnswerClients chans ["CHAT", nickGlobal, p]]
h "WATCH" f = return [QueryReplay f]
h "FIX" _ = handleCmd ["FIX"]
h "UNFIX" _ = handleCmd ["UNFIX"]
@@ -105,13 +105,13 @@
return
[ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s})
-- TODO: Say whether 'registered only' state is on or off
- , AnswerClients [sendChan cl] ["CHAT", "[server]", loc "'Registered only' state toggled."]
+ , AnswerClients [sendChan cl] ["CHAT", nickServer, loc "'Registered only' state toggled."]
]
h "SUPER_POWER" _ = serverAdminOnly $ do
cl <- thisClient
return
[ModifyClient (\c -> c{hasSuperPower = True})
- , AnswerClients [sendChan cl] ["CHAT", "[server]", loc "Super power activated."]
+ , AnswerClients [sendChan cl] ["CHAT", nickServer, loc "Super power activated."]
]
h _ _ = return [Warning $ loc "Unknown command or invalid parameters. Say '/help' in chat for a list of commands." ]
@@ -136,7 +136,7 @@
""
let hostStr = if isAdminAsking then host cl else B.empty
if noSuchClient then
- answerClient [ "CHAT", "[server]", loc "Player is not online." ]
+ answerClient [ "CHAT", nickServer, loc "Player is not online." ]
else
answerClient [
"INFO",
--- a/gameServer/HWProtoInRoomState.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/HWProtoInRoomState.hs Sat Aug 25 19:23:19 2018 +0200
@@ -399,7 +399,7 @@
cl <- thisClient
let m = readInt_ n
if m < 2 || m > cMaxTeams then
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/maxteams: specify number from 2 to 8"]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/maxteams: specify number from 2 to 8"]]
else
return [ModifyRoom (\r -> r{teamsNumberLimit = m})]
@@ -425,12 +425,12 @@
handleCmd_inRoom ["CALLVOTE"] = do
cl <- thisClient
return [AnswerClients [sendChan cl]
- ["CHAT", "[server]", loc "Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs"]
+ ["CHAT", nickServer, loc "Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs"]
]
handleCmd_inRoom ["CALLVOTE", "KICK"] = do
cl <- thisClient
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote kick: You need to specify a nickname."]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote kick: You need to specify a nickname."]]
handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do
(thisClientId, rnc) <- ask
@@ -446,13 +446,13 @@
if isJust maybeClientId && sameRoom then
startVote $ VoteKick nickname
else
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote kick: No such user!"]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote kick: No such user!"]]
handleCmd_inRoom ["CALLVOTE", "MAP"] = do
cl <- thisClient
s <- liftM (Map.keys . roomSaves) thisRoom
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", B.concat ["callvote map: ", B.intercalate ", " s]]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, B.concat ["callvote map: ", B.intercalate ", " s]]]
handleCmd_inRoom ["CALLVOTE", "MAP", roomSave] = do
@@ -462,7 +462,7 @@
if Map.member roomSave $ roomSaves rm then
startVote $ VoteMap roomSave
else
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote map: No such map!"]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote map: No such map!"]]
handleCmd_inRoom ["CALLVOTE", "PAUSE"] = do
@@ -472,7 +472,7 @@
if isJust $ gameInfo rm then
startVote VotePause
else
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote pause: No game in progress!"]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote pause: No game in progress!"]]
handleCmd_inRoom ["CALLVOTE", "NEWSEED"] = do
@@ -481,7 +481,7 @@
handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS"] = do
cl <- thisClient
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote hedgehogs: Specify number from 1 to 8."]]
handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS", hhs] = do
@@ -491,7 +491,7 @@
if h > 0 && h <= cHogsPerTeam then
startVote $ VoteHedgehogsPerTeam h
else
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote hedgehogs: Specify number from 1 to 8."]]
handleCmd_inRoom ("VOTE" : m : p) = do
@@ -500,7 +500,7 @@
if isJust b then
voted (p == ["FORCE"]) (fromJust b)
else
- return [AnswerClients [sendChan cl] ["CHAT", "[server]",
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer,
if (p == ["FORCE"]) then
loc "/force: Please use 'yes' or 'no'."
else
--- a/gameServer/Votes.hs Sat Aug 25 19:07:17 2018 +0200
+++ b/gameServer/Votes.hs Sat Aug 25 19:23:19 2018 +0200
@@ -43,16 +43,16 @@
case voting rm of
Nothing ->
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "There's no voting going on."]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "There's no voting going on."]]
Just voting ->
if (not forced) && (uid `L.notElem` entitledToVote voting) then
return []
else if (not forced) && (uid `L.elem` map fst (votes voting)) then
- return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "You already have voted."]]
+ return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "You already have voted."]]
else if forced && (not $ isAdministrator cl) then
return []
else
- ((:) (AnswerClients [sendChan cl] ["CHAT", "[server]", loc "Your vote has been counted."]))
+ ((:) (AnswerClients [sendChan cl] ["CHAT", nickServer, loc "Your vote has been counted."]))
<$> (actOnVoting $ voting{votes = (uid, vote):votes voting})
where
@@ -74,7 +74,7 @@
closeVoting = do
chans <- roomClientsChans
return [
- AnswerClients chans ["CHAT", "[server]", loc "Voting closed."]
+ AnswerClients chans ["CHAT", nickServer, loc "Voting closed."]
, ModifyRoom (\r -> r{voting = Nothing})
]
@@ -101,7 +101,7 @@
chans <- roomClientsChans
return $
[ModifyRoom $ \r -> r{params = p, mapParams = mp}
- , AnswerClients chans ["CHAT", "[server]", location]
+ , AnswerClients chans ["CHAT", nickServer, location]
, SendUpdateOnThisRoom
, LoadGhost location]
act (VotePause) = do
@@ -109,7 +109,7 @@
chans <- roomClientsChans
let modifyGameInfo f room = room{gameInfo = fmap f $ gameInfo room}
return [ModifyRoom (modifyGameInfo $ \g -> g{isPaused = not $ isPaused g}),
- AnswerClients chans ["CHAT", "[server]", loc "Pause toggled."],
+ AnswerClients chans ["CHAT", nickServer, loc "Pause toggled."],
AnswerClients chans ["EM", toEngineMsg "I"]]
act (VoteNewSeed) =
return [SetRandomSeed]
@@ -144,7 +144,7 @@
else
return [
ModifyRoom (\r -> r{voting = Just (newVoting vt){entitledToVote = uids}})
- , AnswerClients chans ["CHAT", "[server]", B.concat [loc "New voting started", ": ", voteInfo vt]]
+ , AnswerClients chans ["CHAT", nickServer, B.concat [loc "New voting started", ": ", voteInfo vt]]
, ReactCmd ["VOTE", "YES"]
]
@@ -163,7 +163,7 @@
modifyRoom rnc (\r -> r{voting = if voteTTL rv == 0 then Nothing else Just rv{voteTTL = voteTTL rv - 1}}) ri
if voteTTL rv == 0 then do
chans <- liftM (map sendChan) $ roomClientsM rnc ri
- return [AnswerClients chans ["CHAT", "[server]", loc "Voting expired."]]
+ return [AnswerClients chans ["CHAT", nickServer, loc "Voting expired."]]
else
return []
Nothing -> return []