gameServer/NetRoutines.hs
changeset 10076 b235e520ea21
parent 9528 9351e96990ae
child 10078 8572d1f8b2f0
--- a/gameServer/NetRoutines.hs	Sun Jan 26 00:09:50 2014 +0400
+++ b/gameServer/NetRoutines.hs	Sun Jan 26 02:17:04 2014 +0400
@@ -6,13 +6,20 @@
 import Data.Time
 import Control.Monad
 import Data.Unique
+import qualified Codec.Binary.Base64 as Base64
+import qualified Data.ByteString as BW
+import qualified Data.ByteString.Char8 as B
+import qualified Control.Exception as E
+import System.Entropy
 -----------------------------
 import CoreTypes
 import Utils
-import RoomsAndClients
+
 
 acceptLoop :: Socket -> Chan CoreMessage -> IO ()
-acceptLoop servSock chan = forever $
+acceptLoop servSock chan = E.bracket openHandle closeHandle f
+    where
+    f ch = forever $
         do
         (sock, sockAddr) <- Network.Socket.accept servSock
 
@@ -23,6 +30,7 @@
         sendChan' <- newChan
 
         uid <- newUnique
+        salt <- liftM (B.pack . Base64.encode . BW.unpack) $ hGetEntropy ch 16
 
         let newClient =
                 (ClientInfo
@@ -33,6 +41,7 @@
                     currentTime
                     ""
                     ""
+                    salt
                     False
                     False
                     0