author | unc0rr |
Fri, 27 Mar 2009 14:02:27 +0000 | |
changeset 1924 | 8f8fe856ce9d |
parent 1917 | c94045b70142 |
child 1926 | cb46fbdcaa41 |
permissions | -rw-r--r-- |
1804 | 1 |
{-# LANGUAGE PatternSignatures #-} |
2 |
module NetRoutines where |
|
3 |
||
4 |
import Network |
|
5 |
import Network.Socket |
|
6 |
import System.IO |
|
7 |
import Control.Concurrent |
|
8 |
import Control.Concurrent.Chan |
|
9 |
import Control.Concurrent.STM |
|
10 |
import Control.Exception |
|
11 |
import Data.Time |
|
12 |
----------------------------- |
|
13 |
import CoreTypes |
|
14 |
import ClientIO |
|
1917 | 15 |
import Utils |
1804 | 16 |
|
17 |
acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO () |
|
18 |
acceptLoop servSock coreChan clientCounter = do |
|
19 |
Control.Exception.handle |
|
20 |
(\(_ :: Exception) -> putStrLn "exception on connect") $ |
|
21 |
do |
|
22 |
(socket, sockAddr) <- Network.Socket.accept servSock |
|
23 |
||
24 |
cHandle <- socketToHandle socket ReadWriteMode |
|
25 |
hSetBuffering cHandle LineBuffering |
|
26 |
clientHost <- sockAddr2String sockAddr |
|
27 |
||
28 |
currentTime <- getCurrentTime |
|
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1804
diff
changeset
|
29 |
--putStrLn $ (show currentTime) ++ " new client id: " ++ (show nextID) |
1804 | 30 |
|
31 |
sendChan <- newChan |
|
32 |
||
33 |
let newClient = |
|
34 |
(ClientInfo |
|
35 |
nextID |
|
36 |
sendChan |
|
37 |
cHandle |
|
38 |
clientHost |
|
39 |
--currentTime |
|
40 |
"" |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
41 |
"" |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
42 |
False |
1804 | 43 |
0 |
44 |
0 |
|
45 |
False |
|
46 |
False |
|
47 |
False |
|
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
48 |
False |
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
49 |
False |
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
50 |
) |
1804 | 51 |
|
52 |
writeChan coreChan $ Accept newClient |
|
53 |
||
54 |
forkIO $ clientRecvLoop cHandle coreChan nextID |
|
55 |
forkIO $ clientSendLoop cHandle coreChan sendChan nextID |
|
56 |
return () |
|
57 |
||
58 |
acceptLoop servSock coreChan nextID |
|
59 |
where |
|
60 |
nextID = clientCounter + 1 |