--- a/gameServer/NetRoutines.hs Wed Feb 02 11:28:38 2011 +0300
+++ b/gameServer/NetRoutines.hs Wed Feb 02 21:23:12 2011 +0300
@@ -1,46 +1,41 @@
-{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
module NetRoutines where
-import Network
import Network.Socket
import System.IO
-import Control.Concurrent
import Control.Concurrent.Chan
-import Control.Concurrent.STM
import qualified Control.Exception as Exception
import Data.Time
+import Control.Monad
-----------------------------
import CoreTypes
-import ClientIO
import Utils
+import RoomsAndClients
-acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO ()
-acceptLoop servSock coreChan clientCounter = do
+acceptLoop :: Socket -> Chan CoreMessage -> IO ()
+acceptLoop servSock chan = forever $ do
Exception.handle
(\(_ :: Exception.IOException) -> putStrLn "exception on connect") $
do
- (socket, sockAddr) <- Network.Socket.accept servSock
+ (sock, sockAddr) <- Network.Socket.accept servSock
- cHandle <- socketToHandle socket ReadWriteMode
- hSetBuffering cHandle LineBuffering
clientHost <- sockAddr2String sockAddr
currentTime <- getCurrentTime
-
- sendChan <- newChan
+
+ sendChan' <- newChan
let newClient =
(ClientInfo
- nextID
- sendChan
- cHandle
+ sendChan'
+ sock
clientHost
currentTime
""
""
False
0
- 0
+ lobbyId
0
False
False
@@ -49,12 +44,5 @@
undefined
)
- writeChan coreChan $ Accept newClient
-
- forkIO $ clientRecvLoop cHandle coreChan nextID
- forkIO $ clientSendLoop cHandle coreChan sendChan nextID
+ writeChan chan $ Accept newClient
return ()
-
- acceptLoop servSock coreChan nextID
- where
- nextID = clientCounter + 1