author | nemo |
Wed, 24 Dec 2014 11:08:26 -0500 | |
changeset 10709 | 3fdd5e73530b |
parent 10460 | 8dcea9087d75 |
child 10912 | 5b8d8ecef5a8 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
10093
diff
changeset
|
18 |
|
4905 | 19 |
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-} |
1804 | 20 |
module NetRoutines where |
21 |
||
22 |
import Network.Socket |
|
23 |
import Control.Concurrent.Chan |
|
24 |
import Data.Time |
|
4905 | 25 |
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
|
26 |
import Data.Unique |
10076 | 27 |
import qualified Codec.Binary.Base64 as Base64 |
28 |
import qualified Data.ByteString as BW |
|
29 |
import qualified Data.ByteString.Char8 as B |
|
30 |
import qualified Control.Exception as E |
|
31 |
import System.Entropy |
|
1804 | 32 |
----------------------------- |
33 |
import CoreTypes |
|
1917 | 34 |
import Utils |
10076 | 35 |
|
1804 | 36 |
|
4905 | 37 |
acceptLoop :: Socket -> Chan CoreMessage -> IO () |
10076 | 38 |
acceptLoop servSock chan = E.bracket openHandle closeHandle f |
39 |
where |
|
40 |
f ch = forever $ |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
41 |
do |
4905 | 42 |
(sock, sockAddr) <- Network.Socket.accept servSock |
1804 | 43 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
44 |
clientHost <- sockAddr2String sockAddr |
1804 | 45 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
46 |
currentTime <- getCurrentTime |
4905 | 47 |
|
48 |
sendChan' <- newChan |
|
1804 | 49 |
|
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
|
50 |
uid <- newUnique |
10078 | 51 |
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
|
52 |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
53 |
let newClient = |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
54 |
(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
|
55 |
uid |
4905 | 56 |
sendChan' |
57 |
sock |
|
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
58 |
clientHost |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
59 |
currentTime |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
60 |
"" |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
61 |
"" |
10076 | 62 |
salt |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
63 |
False |
8372
3c193ec03e09
Logon procedure for checkers, introduce invisible clients
unc0rr
parents:
8371
diff
changeset
|
64 |
False |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
65 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
66 |
0 |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
67 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
68 |
False |
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
69 |
False |
7757
c20e6c80e249
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
unc0rr
parents:
5209
diff
changeset
|
70 |
False |
8245 | 71 |
False |
8371 | 72 |
False |
9109
878f06e9c484
- Fix issue 521 by resending FULLMAPCONFIG on game finish to those who joined mid-game. Semitested.
unc0rr
parents:
8897
diff
changeset
|
73 |
False |
9435 | 74 |
False |
4986
33fe91b2bcbf
Use Maybe for storing client's clan, allows less error-prone spectator checks
unc0rr
parents:
4932
diff
changeset
|
75 |
Nothing |
8507 | 76 |
Nothing |
10093 | 77 |
newEventsInfo |
78 |
newEventsInfo |
|
79 |
newEventsInfo |
|
4987
cf9470964dba
Use 'undefined' less (replace with default values and 'error')
unc0rr
parents:
4986
diff
changeset
|
80 |
0 |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
81 |
) |
1804 | 82 |
|
4905 | 83 |
writeChan chan $ Accept newClient |
2867
9be6693c78cb
- Unbreak support for client versions prior to 0.9.13-dev
unc0rr
parents:
2403
diff
changeset
|
84 |
return () |