Add Unique field to Client structure, and use it to check for matching recieved account status with client
authorunc0rr
Sat, 05 Feb 2011 11:32:15 +0300
changeset 4918 c6d3aec73f93
parent 4917 8ff92bdc9f98
child 4919 2ba6a2315838
child 4920 bc3c077e15a2
Add Unique field to Client structure, and use it to check for matching recieved account status with client
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/NetRoutines.hs
gameServer/OfficialServer/DBInteraction.hs
gameServer/ServerCore.hs
--- a/gameServer/Actions.hs	Sat Feb 05 11:05:16 2011 +0300
+++ b/gameServer/Actions.hs	Sat Feb 05 11:32:15 2011 +0300
@@ -16,6 +16,7 @@
 import Control.DeepSeq
 import Data.Time
 import Text.Printf
+import Data.Unique
 -----------------------------
 import CoreTypes
 import Utils
@@ -308,8 +309,9 @@
     (Just ci) <- gets clientIndex
     n <- client's nick
     h <- client's host
+    uid <- client's clUID
     db <- gets (dbQueries . serverInfo)
-    io $ writeChan db $ CheckAccount ci n h
+    io $ writeChan db $ CheckAccount ci (hashUnique uid) n h
     return ()
 
 
--- a/gameServer/CoreTypes.hs	Sat Feb 05 11:05:16 2011 +0300
+++ b/gameServer/CoreTypes.hs	Sat Feb 05 11:32:15 2011 +0300
@@ -13,6 +13,7 @@
 import Network
 import Data.Function
 import Data.ByteString.Char8 as B
+import Data.Unique
 
 import RoomsAndClients
 
@@ -21,6 +22,7 @@
 data ClientInfo =
     ClientInfo
     {
+        clUID :: Unique,
         sendChan :: ClientChan,
         clientSocket :: Socket,
         host :: B.ByteString,
@@ -161,7 +163,7 @@
     deriving (Show, Read)
 
 data DBQuery =
-    CheckAccount ClientIndex B.ByteString B.ByteString
+    CheckAccount ClientIndex Int B.ByteString B.ByteString
     | ClearCache
     | SendStats Int Int
     deriving (Show, Read)
@@ -169,14 +171,14 @@
 data CoreMessage =
     Accept ClientInfo
     | ClientMessage (ClientIndex, [B.ByteString])
-    | ClientAccountInfo (ClientIndex, AccountInfo)
+    | ClientAccountInfo ClientIndex Int AccountInfo
     | TimerAction Int
     | Remove ClientIndex
 
 instance Show CoreMessage where
     show (Accept _) = "Accept"
     show (ClientMessage _) = "ClientMessage"
-    show (ClientAccountInfo _) = "ClientAccountInfo"
+    show (ClientAccountInfo {}) = "ClientAccountInfo"
     show (TimerAction _) = "TimerAction"
     show (Remove _) = "Remove"
 
--- a/gameServer/NetRoutines.hs	Sat Feb 05 11:05:16 2011 +0300
+++ b/gameServer/NetRoutines.hs	Sat Feb 05 11:32:15 2011 +0300
@@ -2,11 +2,11 @@
 module NetRoutines where
 
 import Network.Socket
-import System.IO
 import Control.Concurrent.Chan
 import qualified Control.Exception as Exception
 import Data.Time
 import Control.Monad
+import Data.Unique
 -----------------------------
 import CoreTypes
 import Utils
@@ -25,8 +25,11 @@
 
         sendChan' <- newChan
 
+        uid <- newUnique
+
         let newClient =
                 (ClientInfo
+                    uid
                     sendChan'
                     sock
                     clientHost
--- a/gameServer/OfficialServer/DBInteraction.hs	Sat Feb 05 11:05:16 2011 +0300
+++ b/gameServer/OfficialServer/DBInteraction.hs	Sat Feb 05 11:32:15 2011 +0300
@@ -23,9 +23,8 @@
 fakeDbConnection serverInfo = forever $ do
     q <- readChan $ dbQueries serverInfo
     case q of
-        CheckAccount clUid _ clHost -> do
-            writeChan (coreChan serverInfo) $ ClientAccountInfo (clUid,
-                if clHost `elem` localAddressList then Admin else Guest)
+        CheckAccount clId clUid _ clHost -> do
+            writeChan (coreChan serverInfo) $ ClientAccountInfo clId clUid (if clHost `elem` localAddressList then Admin else Guest)
         ClearCache -> return ()
         SendStats {} -> return ()
 
@@ -36,7 +35,7 @@
     do
     q <- readChan queries
     updatedCache <- case q of
-        CheckAccount clUid clNick _ -> do
+        CheckAccount clId clNick _ -> do
             let cacheEntry = clNick `Map.lookup` accountsCache
             currentTime <- getCurrentTime
             if (isNothing cacheEntry) || (currentTime `diffUTCTime` (fst . fromJust) cacheEntry > 2 * 24 * 60 * 60) then
@@ -44,16 +43,16 @@
                     hPutStrLn hIn $ show q
                     hFlush hIn
 
-                    (clId, accountInfo) <- hGetLine hOut >>= (maybeException . maybeRead)
+                    (clId', accountInfo) <- hGetLine hOut >>= (maybeException . maybeRead)
 
-                    writeChan coreChan $ ClientAccountInfo (clId, accountInfo)
+                    writeChan coreChan $ ClientAccountInfo (clId', accountInfo)
 
                     return $ Map.insert clNick (currentTime, accountInfo) accountsCache
                 `Exception.onException`
                     (unGetChan queries q)
                 else
                 do
-                    writeChan coreChan $ ClientAccountInfo (clUid, snd $ fromJust cacheEntry)
+                    writeChan coreChan $ ClientAccountInfo (clId, snd $ fromJust cacheEntry)
                     return accountsCache
 
         ClearCache -> return Map.empty
--- a/gameServer/ServerCore.hs	Sat Feb 05 11:05:16 2011 +0300
+++ b/gameServer/ServerCore.hs	Sat Feb 05 11:32:15 2011 +0300
@@ -9,6 +9,7 @@
 import Data.Set as Set
 import qualified Data.ByteString.Char8 as B
 import Control.DeepSeq
+import Data.Unique
 --------------------------------------
 import CoreTypes
 import NetRoutines
@@ -57,13 +58,14 @@
                 --debugM "Clients" "Message from dead client"
                 --return (serverInfo, rnc)
 
-        ClientAccountInfo (ci, info) -> do
+        ClientAccountInfo ci uid info -> do
             rnc <- gets roomsClients
             exists <- liftIO $ clientExists rnc ci
             when (exists) $ do
                 as <- get
                 put $! as{clientIndex = Just ci}
-                processAction (ProcessAccountInfo info)
+                uid' <- client's clUID
+                when (uid == (hashUnique uid')) $ processAction (ProcessAccountInfo info)
                 return ()
 
         TimerAction tick ->