More user-friendly server messages
authorWuzzy <Wuzzy2@mail.ru>
Mon, 05 Mar 2018 19:05:10 +0100
changeset 13079 81c154fd4380
parent 13078 dd904dd9c587
child 13080 23a498a2b5b8
More user-friendly server messages
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
gameServer/HWProtoNEState.hs
gameServer/Utils.hs
gameServer/Votes.hs
--- a/gameServer/HWProtoInRoomState.hs	Mon Mar 05 16:16:32 2018 +0100
+++ b/gameServer/HWProtoInRoomState.hs	Mon Mar 05 19:05:10 2018 +0100
@@ -57,7 +57,7 @@
                 , ModifyRoomClients (\c -> c{isInGame = True, teamIndexes = map snd . filter (\(t, _) -> teamowner t == nick c) $ zip (teams rm) [0..]})
                 ]
             else
-            return [Warning $ loc "Less than two clans!"]
+            return [Warning $ loc "The game can't be started with less than two clans!"]
         else
         return []
     where
@@ -77,20 +77,20 @@
 
 
 handleCmd_inRoom ("CFG" : paramName : paramStrs)
-    | null paramStrs = return [ProtocolError $ loc "Empty config entry"]
+    | null paramStrs = return [ProtocolError $ loc "Empty config entry."]
     | otherwise = do
         chans <- roomOthersChans
         cl <- thisClient
         rm <- thisRoom
 
         if isSpecial rm then
-            return [Warning $ loc "Restricted"]
+            return [Warning $ loc "Access denied."]
         else if isMaster cl then
            return [
                 ModifyRoom $ f (clientProto cl),
                 AnswerClients chans ("CFG" : paramName : paramStrs)]
             else
-            return [ProtocolError $ loc "Not room master"]
+            return [ProtocolError $ loc "You're not the room master!"]
     where
         f clproto r = if paramName `Map.member` (mapParams r) then
                 r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
@@ -103,7 +103,7 @@
 
 
 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
-    | length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info"]
+    | length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info!"]
     | otherwise = do
         rm <- thisRoom
         cl <- thisClient
@@ -125,15 +125,15 @@
         let newTeam = clNick `seq` TeamInfo clNick tName teamColor grave fort voicepack flag (isRegistered cl) dif hhNum (hhsList hhsInfo)
         return $
             if not . null . drop (teamsNumberLimit rm - 1) $ roomTeams then
-                [Warning $ loc "too many teams"]
+                [Warning $ loc "Too many teams!"]
             else if canAddNumber roomTeams <= 0 then
-                [Warning $ loc "too many hedgehogs"]
+                [Warning $ loc "Too many hedgehogs!"]
             else if isJust $ findTeam rm then
-                [Warning $ loc "There's already a team with same name in the list"]
+                [Warning $ loc "There's already a team with same name in the list."]
             else if isJust $ gameInfo rm then
-                [Warning $ loc "round in progress"]
+                [Warning $ loc "Joining not possible: Round is in progress."]
             else if isRestrictedTeams rm then
-                [Warning $ loc "restricted"]
+                [Warning $ loc "This room currently does not allow adding new teams."]
             else
                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
                 SendUpdateOnThisRoom,
@@ -166,9 +166,9 @@
 
         return $
             if isNothing $ maybeTeam then
-                [Warning $ loc "REMOVE_TEAM: no such team"]
+                [Warning $ loc "Error: The team you tried to remove does not exist."]
             else if clNick /= teamowner team then
-                [ProtocolError $ loc "Not team owner!"]
+                [ProtocolError $ loc "You can't remove a team you don't own."]
             else
                 [RemoveTeam tName,
                 ModifyClient
@@ -193,7 +193,7 @@
 
     return $
         if not $ isMaster cl then
-            [ProtocolError $ loc "Not room master"]
+            [ProtocolError $ loc "You're not the room master!"]
         else if isNothing maybeTeam then
             []
         else if hhNumber < 1 || hhNumber > 8 || hhNumber > canAddNumber r + hhnum team then
@@ -220,7 +220,7 @@
 
     return $
         if not $ isMaster cl then
-            [ProtocolError $ loc "Not room master"]
+            [ProtocolError $ loc "You're not the room master!"]
         else if isNothing maybeTeam || isNothing maybeClientId then
             []
         else
@@ -314,13 +314,13 @@
 
     return $
         if illegalName newName then
-            [Warning $ loc "Illegal room name"]
+            [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: $()*+?[]^{|}"]
         else
         if isSpecial rm then
-            [Warning $ loc "Restricted"]
+            [Warning $ loc "Access denied."]
         else
         if isJust $ find (\r -> newName == name r) rs then
-            [Warning $ loc "Room with such name already exists"]
+            [Warning $ loc "A room with the same name already exists."]
         else
             [ModifyRoom roomUpdate,
             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))]
@@ -418,7 +418,7 @@
 
 handleCmd_inRoom ["CALLVOTE", "KICK"] = do
     cl <- thisClient
-    return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "callvote kick: specify nickname"]]
+    return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote kick: You need to specify a nickname."]]
 
 handleCmd_inRoom ["CALLVOTE", "KICK", nickname] = do
     (thisClientId, rnc) <- ask
@@ -434,7 +434,7 @@
         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", "[server]", loc "/callvote kick: No such user!"]]
 
 
 handleCmd_inRoom ["CALLVOTE", "MAP"] = do
@@ -450,7 +450,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", "[server]", loc "/callvote map: No such map!"]]
 
 
 handleCmd_inRoom ["CALLVOTE", "PAUSE"] = do
@@ -460,7 +460,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", "[server]", loc "/callvote pause: No game in progress!"]]
 
 
 handleCmd_inRoom ["CALLVOTE", "NEWSEED"] = do
@@ -469,7 +469,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", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
 
 
 handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS", hhs] = do
@@ -479,7 +479,7 @@
     if h > 0 && h <= 8 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", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]]
 
 
 handleCmd_inRoom ("VOTE" : m : p) = do
@@ -488,7 +488,7 @@
     if isJust b then
         voted (p == ["FORCE"]) (fromJust b)
         else
-        return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]]
+        return [AnswerClients [sendChan cl] ["CHAT", "[server]", "/vote: Please use 'yes' or 'no'."]]
 
 
 handleCmd_inRoom ["SAVE", stateName, location] = serverAdminOnly $ do
--- a/gameServer/HWProtoLobbyState.hs	Mon Mar 05 16:16:32 2018 +0100
+++ b/gameServer/HWProtoLobbyState.hs	Mon Mar 05 19:05:10 2018 +0100
@@ -49,12 +49,12 @@
     return [AnswerClients s ["CHAT", n, msg], RegisterEvent LobbyChatMessage]
 
 handleCmd_lobby ["CREATE_ROOM", rName, roomPassword]
-    | illegalName rName = return [Warning $ loc "Illegal room name"]
+    | illegalName rName = return [Warning $ loc "Illegal room name! A room name must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}"]
     | otherwise = do
         rs <- allRoomInfos
         cl <- thisClient
         return $ if isJust $ find (\r -> rName == name r) rs then
-            [Warning "Room exists"]
+            [Warning $ loc "A room with the same name already exists."]
             else
             [
                 AddRoom rName roomPassword
@@ -90,15 +90,15 @@
     let clTeamsNames = map teamname clTeams
     return $
         if isNothing maybeRI then
-            [Warning $ loc "No such room"]
+            [Warning $ loc "No such room."]
             else if (not sameProto) && (not $ isAdministrator cl) then
-            [Warning $ loc "Room version incompatible to your hedgewars version"]
+            [Warning $ loc "Room version incompatible to your Hedgewars version!"]
             else if isRestrictedJoins jRoom && not (hasSuperPower cl) then
-            [Warning $ loc "Joining restricted"]
+            [Warning $ loc "Access denied. This room currently doesn't allow joining."]
             else if isRegisteredOnly jRoom && (not $ isRegistered cl) && not (isAdministrator cl) then
-            [Warning $ loc "Registered users only"]
+            [Warning $ loc "Access denied. This room is for registered users only."]
             else if isBanned then
-            [Warning $ loc "You are banned in this room"]
+            [Warning $ loc "You are banned from this room."]
             else if roomPassword /= password jRoom  && not (hasSuperPower cl) then
             [NoticeMessage WrongPassword]
             else
--- a/gameServer/HWProtoNEState.hs	Mon Mar 05 16:16:32 2018 +0100
+++ b/gameServer/HWProtoNEState.hs	Mon Mar 05 19:05:10 2018 +0100
@@ -34,9 +34,9 @@
 handleCmd_NotEntered ["NICK", newNick] = do
     (ci, irnc) <- ask
     let cl = irnc `client` ci
-    if not . B.null $ nick cl then return [ProtocolError $ loc "Nickname already chosen"]
+    if not . B.null $ nick cl then return [ProtocolError $ loc "Nickname already taken."]
         else
-        if illegalName newNick then return [ByeClient $ loc "Illegal nickname"]
+        if illegalName newNick then return [ByeClient $ loc "Illegal nickname! Nicknames must be between 1-40 characters long, must not have a trailing or leading space and must not have any of these characters: $()*+?[]^{|}"]
             else
             return $
                 ModifyClient (\c -> c{nick = newNick}) :
@@ -46,9 +46,9 @@
 handleCmd_NotEntered ["PROTO", protoNum] = do
     (ci, irnc) <- ask
     let cl = irnc `client` ci
-    if clientProto cl > 0 then return [ProtocolError $ loc "Protocol already known"]
+    if clientProto cl > 0 then return [ProtocolError $ loc "Protocol already known."]
         else
-        if parsedProto == 0 then return [ProtocolError $ loc "Bad number"]
+        if parsedProto == 0 then return [ProtocolError $ loc "Bad number."]
             else
             return $
                 ModifyClient (\c -> c{clientProto = parsedProto}) :
@@ -90,7 +90,7 @@
     (ci, irnc) <- ask
     let cl = irnc `client` ci
 
-    if parsedProto == 0 then return [ProtocolError $ loc "Bad number"]
+    if parsedProto == 0 then return [ProtocolError $ loc "Bad number."]
         else
         return $ [
             ModifyClient (\c -> c{clientProto = parsedProto, nick = newNick, webPassword = password, isChecker = True})
--- a/gameServer/Utils.hs	Mon Mar 05 16:16:32 2018 +0100
+++ b/gameServer/Utils.hs	Mon Mar 05 19:05:10 2018 +0100
@@ -72,6 +72,7 @@
         else
             t : replaceTeam tm ts
 
+-- NOTE: Don't forget to update the error messages when you change the naming rules!
 illegalName :: B.ByteString -> Bool
 illegalName b = B.null b || length s > 40 || all isSpace s || isSpace (head s) || isSpace (last s) || any isIllegalChar s
     where
--- a/gameServer/Votes.hs	Mon Mar 05 16:16:32 2018 +0100
+++ b/gameServer/Votes.hs	Mon Mar 05 19:05:10 2018 +0100
@@ -42,16 +42,16 @@
 
     case voting rm of
         Nothing -> 
-            return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "There's no voting going on"]]
+            return [AnswerClients [sendChan cl] ["CHAT", "[server]", 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", "[server]", loc "You already have voted."]]
             else if forced && (not $ isAdministrator cl) then
                 return []
             else
-                ((:) (AnswerClients [sendChan cl] ["CHAT", "[server]", loc "Your vote counted"]))
+                ((:) (AnswerClients [sendChan cl] ["CHAT", "[server]", loc "Your vote has been counted."]))
                 <$> (actOnVoting $ voting{votes = (uid, vote):votes voting})
 
     where
@@ -73,7 +73,7 @@
     closeVoting = do
         chans <- roomClientsChans
         return [
-            AnswerClients chans ["CHAT", "[server]", loc "Voting closed"]
+            AnswerClients chans ["CHAT", "[server]", loc "Voting closed."]
             , ModifyRoom (\r -> r{voting = Nothing})
             ]
 
@@ -108,7 +108,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", "[server]", loc "Pause toggled."],
                 AnswerClients chans ["EM", toEngineMsg "I"]]
     act (VoteNewSeed) =
         return [SetRandomSeed]
@@ -162,7 +162,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", "[server]", loc "Voting expired."]]
                         else
                         return []
                  Nothing -> return []
@@ -173,4 +173,4 @@
 voteInfo (VoteMap n) = B.concat [loc "map", " ", n]
 voteInfo (VotePause) = B.concat [loc "pause"]
 voteInfo (VoteNewSeed) = B.concat [loc "new seed"]
-voteInfo (VoteHedgehogsPerTeam i) = B.concat [loc "number of hedgehogs in team", " ", showB i]
+voteInfo (VoteHedgehogsPerTeam i) = B.concat [loc "hedgehogs per team: ", " ", showB i]