gameServer/NetRoutines.hs
author unc0rr
Mon, 30 Jun 2014 00:07:03 +0400
changeset 10345 2b264d67fac3
parent 10093 ada172d33988
child 10460 8dcea9087d75
permissions -rw-r--r--
Make team disappear after 3 turns in 'gone' state
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
     1
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
module NetRoutines where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     3
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     4
import Network.Socket
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
import Control.Concurrent.Chan
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
import Data.Time
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
     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
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
     9
import qualified Codec.Binary.Base64 as Base64
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    10
import qualified Data.ByteString as BW
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    11
import qualified Data.ByteString.Char8 as B
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    12
import qualified Control.Exception as E
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    13
import System.Entropy
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    14
-----------------------------
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
import CoreTypes
1917
c94045b70142 - Better ip2string implementation
unc0rr
parents: 1847
diff changeset
    16
import Utils
10076
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    17
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    18
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    19
acceptLoop :: Socket -> Chan CoreMessage -> IO ()
10076
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    20
acceptLoop servSock chan = E.bracket openHandle closeHandle f
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    21
    where
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    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
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    24
        (sock, sockAddr) <- Network.Socket.accept servSock
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    25
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2403
diff changeset
    26
        clientHost <- sockAddr2String sockAddr
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    27
2867
9be6693c78cb - Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents: 2403
diff changeset
    28
        currentTime <- getCurrentTime
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    29
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    30
        sendChan' <- newChan
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    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
8572d1f8b2f0 Some love to pas2c
unc0rr
parents: 10076
diff changeset
    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
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    38
                    sendChan'
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    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
b235e520ea21 Mutual authentication: server side
unc0rr
parents: 9528
diff changeset
    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
d1a830c304c7 Change room name if room admin is kicked
unc0rr
parents: 7766
diff changeset
    53
                    False
8371
0551b5c3de9a - Start work on checker
unc0rr
parents: 8245
diff changeset
    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
59eec19cb31a 'c' flag for contributors
unc0rr
parents: 9109
diff changeset
    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
f4475782cf45 Some more work on checker
unc0rr
parents: 8372
diff changeset
    58
                    Nothing
10093
ada172d33988 More work on flood detector
unc0rr
parents: 10078
diff changeset
    59
                    newEventsInfo
ada172d33988 More work on flood detector
unc0rr
parents: 10078
diff changeset
    60
                    newEventsInfo
ada172d33988 More work on flood detector
unc0rr
parents: 10078
diff changeset
    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
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    64
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    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 ()