Fix check for duplicated nickname
authorunc0rr
Tue, 08 Mar 2011 21:27:44 +0300
changeset 4991 90d1fb9fc2e1
parent 4990 4b5d62ac01f7
child 4992 408301a9d2d6
Fix check for duplicated nickname
gameServer/Actions.hs
gameServer/HWProtoNEState.hs
gameServer/hedgewars-server.hs
--- a/gameServer/Actions.hs	Sun Mar 06 21:55:44 2011 +0300
+++ b/gameServer/Actions.hs	Tue Mar 08 21:27:44 2011 +0300
@@ -315,10 +315,21 @@
     (Just ci) <- gets clientIndex
     n <- client's nick
     h <- client's host
+    p <- client's clientProto
     uid <- client's clUID
-    db <- gets (dbQueries . serverInfo)
-    io $ writeChan db $ CheckAccount ci (hashUnique uid) n h
-    return ()
+    haveSameNick <- liftM (not . null . tail . filter (\c -> nick c == n)) allClientsS
+    if haveSameNick then
+        if p < 38 then
+            mapM_ processAction [ByeClient "Nickname is already in use", removeNick]
+            else
+            mapM_ processAction [NoticeMessage NickAlreadyInUse, removeNick]
+        else
+        do
+        db <- gets (dbQueries . serverInfo)
+        io $ writeChan db $ CheckAccount ci (hashUnique uid) n h
+        return ()
+   where
+       removeNick = ModifyClient (\c -> c{nick = ""})
 
 
 processAction ClearAccountsCache = do
--- a/gameServer/HWProtoNEState.hs	Sun Mar 06 21:55:44 2011 +0300
+++ b/gameServer/HWProtoNEState.hs	Tue Mar 08 21:27:44 2011 +0300
@@ -1,8 +1,6 @@
 {-# LANGUAGE OverloadedStrings #-}
 module HWProtoNEState where
 
-import Data.Maybe
-import Data.List
 import Control.Monad.Reader
 import qualified Data.ByteString.Char8 as B
 --------------------------------------
@@ -18,16 +16,12 @@
     let cl = irnc `client` ci
     if not . B.null $ nick cl then return [ProtocolError "Nickname already chosen"]
         else
-        if haveSameNick irnc then if clientProto cl < 38 then return [ByeClient "Nickname is already in use"] else return [NoticeMessage NickAlreadyInUse]
+        if illegalName newNick then return [ByeClient "Illegal nickname"]
             else
-            if illegalName newNick then return [ByeClient "Illegal nickname"]
-                else
-                return $
-                    ModifyClient (\c -> c{nick = newNick}) :
-                    AnswerClients [sendChan cl] ["NICK", newNick] :
-                    [CheckRegistered | clientProto cl /= 0]
-    where
-    haveSameNick irnc = isJust . find (== newNick) . map (nick . client irnc) $ allClients irnc
+            return $
+                ModifyClient (\c -> c{nick = newNick}) :
+                AnswerClients [sendChan cl] ["NICK", newNick] :
+                [CheckRegistered | clientProto cl /= 0]
 
 handleCmd_NotEntered ["PROTO", protoNum] = do
     (ci, irnc) <- ask
--- a/gameServer/hedgewars-server.hs	Sun Mar 06 21:55:44 2011 +0300
+++ b/gameServer/hedgewars-server.hs	Tue Mar 08 21:27:44 2011 +0300
@@ -12,7 +12,9 @@
 import Opts
 import CoreTypes
 import ServerCore
+#if defined(OFFICIAL_SERVER)
 import ConfigFile
+#endif
 
 #if !defined(mingw32_HOST_OS)
 import System.Posix