Add a few helpful error messages from server when kicking failed
authorWuzzy <Wuzzy2@mail.ru>
Sat, 25 Aug 2018 20:52:33 +0200
changeset 13697 7f174e7285e5
parent 13696 d732ca5dcab9
child 13698 9b73f079e811
Add a few helpful error messages from server when kicking failed
gameServer/HWProtoInRoomState.hs
--- a/gameServer/HWProtoInRoomState.hs	Sat Aug 25 19:23:19 2018 +0200
+++ b/gameServer/HWProtoInRoomState.hs	Sat Aug 25 20:52:33 2018 +0200
@@ -335,21 +335,27 @@
 
 handleCmd_inRoom ["KICK", kickNick] = roomAdminOnly $ do
     (thisClientId, rnc) <- ask
-    maybeClientId <- clientByNick kickNick
+    maybeKickId <- clientByNick kickNick
     rm <- thisRoom
-    let kickId = fromJust maybeClientId
+    let kickId = fromJust maybeKickId
     let kickCl = rnc `client` kickId
     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
     let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2
-    return
-        [KickRoomClient kickId |
-            isJust maybeClientId
-            && (kickId /= thisClientId)
-            && sameRoom
-            && (not $ hasSuperPower kickCl)
-            && ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0)
-        ]
-
+    return $
+        -- Catch some error conditions
+        if (isNothing maybeKickId) then
+            [Warning $ loc "Player is not online."]
+        else if (kickId == thisClientId) then
+            [Warning $ loc "You can't kick yourself!"]
+        else if (not ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0)) then
+            [Warning $ loc "You can't kick the only other player!"]
+        else if (not sameRoom) then
+            [Warning $ loc "The player you tried to kick is not in your room."]
+        else if (hasSuperPower kickCl) then
+            [Warning $ loc "This player is protected from being kicked."]
+        else
+            -- Kick!
+            [KickRoomClient kickId]
 
 handleCmd_inRoom ["DELEGATE", newAdmin] = do
     (thisClientId, rnc) <- ask
@@ -441,7 +447,7 @@
     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
 
     if isJust $ masterID rm then
-        return []
+        return [AnswerClients [sendChan cl] ["CHAT", nickServer, loc "/callvote kick: This is only allowed in rooms without a room master."]]
         else
         if isJust maybeClientId && sameRoom then
             startVote $ VoteKick nickname