# HG changeset patch # User unc0rr # Date 1299608864 -10800 # Node ID 90d1fb9fc2e1c1dca6619042c0321dd72009b3a9 # Parent 4b5d62ac01f77e2fc2450ed5aeced6f482e390be Fix check for duplicated nickname diff -r 4b5d62ac01f7 -r 90d1fb9fc2e1 gameServer/Actions.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 diff -r 4b5d62ac01f7 -r 90d1fb9fc2e1 gameServer/HWProtoNEState.hs --- 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 diff -r 4b5d62ac01f7 -r 90d1fb9fc2e1 gameServer/hedgewars-server.hs --- 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