Case-insensitive comparison of nicks
authorunc0rr
Sun, 23 Oct 2011 11:37:52 +0400
changeset 6191 190a8e5d9956
parent 6190 1db2486e45f4
child 6192 7c34bf4fbb54
Case-insensitive comparison of nicks
gameServer/Actions.hs
gameServer/HWProtoLobbyState.hs
gameServer/Utils.hs
gameServer/hedgewars-server.cabal
--- a/gameServer/Actions.hs	Sun Oct 23 09:01:53 2011 +0200
+++ b/gameServer/Actions.hs	Sun Oct 23 11:37:52 2011 +0400
@@ -340,7 +340,7 @@
     h <- client's host
     p <- client's clientProto
     uid <- client's clUID
-    haveSameNick <- liftM (not . null . tail . filter (\c -> nick c == n)) allClientsS
+    haveSameNick <- liftM (not . null . tail . filter (\c -> caseInsensitiveCompare (nick c) n)) allClientsS
     if haveSameNick then
         if p < 38 then
             mapM_ processAction [ByeClient "Nickname is already in use", removeNick]
--- a/gameServer/HWProtoLobbyState.hs	Sun Oct 23 09:01:53 2011 +0200
+++ b/gameServer/HWProtoLobbyState.hs	Sun Oct 23 11:37:52 2011 +0400
@@ -82,7 +82,7 @@
     let chans = map sendChan (cl : jRoomClients)
     return $
         if isNothing maybeRI || not sameProto then 
-            [Warning "No such rooms"]
+            [Warning "No such room"]
             else if isRestrictedJoins jRoom then
             [Warning "Joining restricted"]
             else if roomPassword /= password jRoom then
--- a/gameServer/Utils.hs	Sun Oct 23 09:01:53 2011 +0200
+++ b/gameServer/Utils.hs	Sun Oct 23 11:37:52 2011 +0400
@@ -5,6 +5,7 @@
 import Data.Word
 import qualified Data.Map as Map
 import qualified Data.Set as Set
+import qualified Data.Char as Char
 import Numeric
 import Network.Socket
 import System.IO
@@ -14,6 +15,7 @@
 import qualified Data.ByteString.Lazy as BL
 import qualified Text.Show.ByteString as BS
 import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString.UTF8 as UTF8
 import qualified Data.ByteString as BW
 -------------------------------------------------
 import CoreTypes
@@ -112,3 +114,8 @@
 
 cutHost :: B.ByteString -> B.ByteString
 cutHost = B.intercalate "." .  flip (++) ["*","*"] . List.take 2 . B.split '.'
+
+caseInsensitiveCompare :: B.ByteString -> B.ByteString -> Bool
+caseInsensitiveCompare a b = f a == f b
+    where
+        f = map Char.toUpper . UTF8.toString
--- a/gameServer/hedgewars-server.cabal	Sun Oct 23 09:01:53 2011 +0200
+++ b/gameServer/hedgewars-server.cabal	Sun Oct 23 11:37:52 2011 +0400
@@ -27,6 +27,7 @@
     dataenc,
     hslogger,
     process,
-    deepseq
+    deepseq,
+    utf8-string
 
   ghc-options: -O2