author | koda |
Sat, 18 Feb 2012 19:33:04 +0100 | |
changeset 6713 | 3a02e9c25ac5 |
parent 5209 | f7a610e2ef5f |
child 7757 | c20e6c80e249 |
permissions | -rw-r--r-- |
4905 | 1 |
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-} |
1804 | 2 |
module NetRoutines where |
3 |
||
4 |
import Network.Socket |
|
5 |
import Control.Concurrent.Chan |
|
2296
19f2f76dc346
Patch for compiling with 6.10 (define NEW_EXCEPTIONS to do that)
unc0rr
parents:
2245
diff
changeset
|
6 |
import qualified Control.Exception as Exception |
1804 | 7 |
import Data.Time |
4905 | 8 |
import Control.Monad |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4905
diff
changeset
|
9 |
import Data.Unique |
1804 | 10 |
----------------------------- |
11 |
import CoreTypes |
|
1917 | 12 |
import Utils |
4905 | 13 |
import RoomsAndClients |
1804 | 14 |
|
4905 | 15 |
acceptLoop :: Socket -> Chan CoreMessage -> IO () |
4932 | 16 |
acceptLoop servSock chan = forever $ |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
17 |
do |
4905 | 18 |
(sock, sockAddr) <- Network.Socket.accept servSock |
1804 | 19 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
20 |
clientHost <- sockAddr2String sockAddr |
1804 | 21 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
22 |
currentTime <- getCurrentTime |
4905 | 23 |
|
24 |
sendChan' <- newChan |
|
1804 | 25 |
|
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4905
diff
changeset
|
26 |
uid <- newUnique |
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4905
diff
changeset
|
27 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
28 |
let newClient = |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
29 |
(ClientInfo |
4918
c6d3aec73f93
Add Unique field to Client structure, and use it to check for matching recieved account status with client
unc0rr
parents:
4905
diff
changeset
|
30 |
uid |
4905 | 31 |
sendChan' |
32 |
sock |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
33 |
clientHost |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
34 |
currentTime |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
35 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
36 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
37 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
38 |
0 |
4905 | 39 |
lobbyId |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
40 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
41 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
42 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
43 |
False |
4986
33fe91b2bcbf
Use Maybe for storing client's clan, allows less error-prone spectator checks
unc0rr
parents:
4932
diff
changeset
|
44 |
Nothing |
4987
cf9470964dba
Use 'undefined' less (replace with default values and 'error')
unc0rr
parents:
4986
diff
changeset
|
45 |
0 |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
46 |
) |
1804 | 47 |
|
4905 | 48 |
writeChan chan $ Accept newClient |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
49 |
return () |