author | unc0rr |
Wed, 02 Sep 2009 08:53:46 +0000 | |
changeset 2344 | 63b3da03ce46 |
parent 2296 | 19f2f76dc346 |
child 2348 | b39d826e1ccd |
permissions | -rw-r--r-- |
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
1 |
{-# LANGUAGE CPP, PatternSignatures #-} |
1804 | 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 |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
10 |
#if defined(NEW_EXCEPTIONS) |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
11 |
import qualified Control.OldException as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
12 |
#else |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
13 |
import qualified Control.Exception as Exception |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
14 |
#endif |
1804 | 15 |
import Data.Time |
16 |
----------------------------- |
|
17 |
import CoreTypes |
|
18 |
import ClientIO |
|
1917 | 19 |
import Utils |
1804 | 20 |
|
21 |
acceptLoop :: Socket -> Chan CoreMessage -> Int -> IO () |
|
22 |
acceptLoop servSock coreChan clientCounter = do |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
23 |
Exception.handle |
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
24 |
(\(_ :: Exception.Exception) -> putStrLn "exception on connect") $ |
1804 | 25 |
do |
26 |
(socket, sockAddr) <- Network.Socket.accept servSock |
|
27 |
||
28 |
cHandle <- socketToHandle socket ReadWriteMode |
|
29 |
hSetBuffering cHandle LineBuffering |
|
30 |
clientHost <- sockAddr2String sockAddr |
|
31 |
||
32 |
currentTime <- getCurrentTime |
|
33 |
||
34 |
sendChan <- newChan |
|
35 |
||
36 |
let newClient = |
|
37 |
(ClientInfo |
|
38 |
nextID |
|
39 |
sendChan |
|
40 |
cHandle |
|
41 |
clientHost |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1924
diff
changeset
|
42 |
currentTime |
1804 | 43 |
"" |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
44 |
"" |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
45 |
False |
1804 | 46 |
0 |
47 |
0 |
|
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
48 |
0 |
1804 | 49 |
False |
50 |
False |
|
51 |
False |
|
2245
c011aecc95e5
unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents:
2004
diff
changeset
|
52 |
undefined |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
53 |
) |
1804 | 54 |
|
55 |
writeChan coreChan $ Accept newClient |
|
56 |
||
57 |
forkIO $ clientRecvLoop cHandle coreChan nextID |
|
58 |
forkIO $ clientSendLoop cHandle coreChan sendChan nextID |
|
59 |
return () |
|
60 |
||
61 |
acceptLoop servSock coreChan nextID |
|
62 |
where |
|
63 |
nextID = clientCounter + 1 |