author | sheepluva |
Thu, 06 Feb 2014 22:03:53 +0100 | |
changeset 10116 | dd27562b6f21 |
parent 10093 | ada172d33988 |
child 10460 | 8dcea9087d75 |
permissions | -rw-r--r-- |
4905 | 1 |
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-} |
1804 | 2 |
module NetRoutines where |
3 |
||
4 |
import Network.Socket |
|
5 |
import Control.Concurrent.Chan |
|
6 |
import Data.Time |
|
4905 | 7 |
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
|
8 |
import Data.Unique |
10076 | 9 |
import qualified Codec.Binary.Base64 as Base64 |
10 |
import qualified Data.ByteString as BW |
|
11 |
import qualified Data.ByteString.Char8 as B |
|
12 |
import qualified Control.Exception as E |
|
13 |
import System.Entropy |
|
1804 | 14 |
----------------------------- |
15 |
import CoreTypes |
|
1917 | 16 |
import Utils |
10076 | 17 |
|
1804 | 18 |
|
4905 | 19 |
acceptLoop :: Socket -> Chan CoreMessage -> IO () |
10076 | 20 |
acceptLoop servSock chan = E.bracket openHandle closeHandle f |
21 |
where |
|
22 |
f ch = forever $ |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
23 |
do |
4905 | 24 |
(sock, sockAddr) <- Network.Socket.accept servSock |
1804 | 25 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
26 |
clientHost <- sockAddr2String sockAddr |
1804 | 27 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
28 |
currentTime <- getCurrentTime |
4905 | 29 |
|
30 |
sendChan' <- newChan |
|
1804 | 31 |
|
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
|
32 |
uid <- newUnique |
10078 | 33 |
salt <- liftM (B.pack . Base64.encode . BW.unpack) $ hGetEntropy ch 18 |
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
|
34 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
35 |
let newClient = |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
36 |
(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
|
37 |
uid |
4905 | 38 |
sendChan' |
39 |
sock |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
40 |
clientHost |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
41 |
currentTime |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
42 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
43 |
"" |
10076 | 44 |
salt |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
45 |
False |
8372
3c193ec03e09
Logon procedure for checkers, introduce invisible clients
unc0rr
parents:
8371
diff
changeset
|
46 |
False |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
47 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
48 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
49 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
50 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
51 |
False |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
5209
diff
changeset
|
52 |
False |
8245 | 53 |
False |
8371 | 54 |
False |
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
8897
diff
changeset
|
55 |
False |
9435 | 56 |
False |
4986
33fe91b2bcbf
Use Maybe for storing client's clan, allows less error-prone spectator checks
unc0rr
parents:
4932
diff
changeset
|
57 |
Nothing |
8507 | 58 |
Nothing |
10093 | 59 |
newEventsInfo |
60 |
newEventsInfo |
|
61 |
newEventsInfo |
|
4987
cf9470964dba
Use 'undefined' less (replace with default values and 'error')
unc0rr
parents:
4986
diff
changeset
|
62 |
0 |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
63 |
) |
1804 | 64 |
|
4905 | 65 |
writeChan chan $ Accept newClient |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
66 |
return () |