author | nemo |
Fri, 05 Jan 2018 16:12:19 -0500 | |
changeset 12879 | 286e170f4f6b |
parent 11046 | 47a8c19ecb60 |
permissions | -rw-r--r-- |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
1 |
{- |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
10460
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
4 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
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:
6805
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:
6805
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
8 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
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:
6805
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:
6805
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
12 |
* GNU General Public License for more details. |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
13 |
* |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
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:
6805
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:
6805
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:
6805
diff
changeset
|
17 |
\-} |
8dcea9087d75
Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
6805
diff
changeset
|
18 |
|
1804 | 19 |
{-# LANGUAGE CPP #-} |
20 |
||
21 |
module Main where |
|
22 |
||
23 |
import System.IO |
|
4932 | 24 |
import System.IO.Error |
1804 | 25 |
import Control.Concurrent |
26 |
import Network |
|
4905 | 27 |
import Control.OldException |
1804 | 28 |
import Control.Monad |
29 |
import System.Random |
|
30 |
||
31 |
#if !defined(mingw32_HOST_OS) |
|
32 |
import System.Posix |
|
33 |
#endif |
|
34 |
||
6805
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
35 |
session 0 nick room = ["NICK", nick, "", "PROTO", "42", "", "PING", "", "CHAT", "lobby 1", "", "PONG", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
36 |
session 1 nick room = ["NICK", nick, "", "PROTO", "42", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
37 |
session 2 nick room = ["NICK", nick, "", "PROTO", "42", "", "LIST", "", "JOIN_ROOM", room, "", "PONG", "", "CHAT", "room 2", "", "QUIT", "quit", ""] |
097289be7200
Add more strictness in hope it will help with space leak
unc0rr
parents:
5119
diff
changeset
|
38 |
session 3 nick room = ["NICK", nick, "", "PROTO", "42", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "", "PONG", "CHAT", "room 1", "", "PART", "creator", "", "QUIT", "part-quit", ""] |
1804 | 39 |
|
40 |
emulateSession sock s = do |
|
5119 | 41 |
mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (100000::Int, 600000) >>= threadDelay) s |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
42 |
hFlush sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
43 |
threadDelay 225000 |
1804 | 44 |
|
4905 | 45 |
testing = Control.OldException.handle print $ do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
46 |
putStrLn "Start" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
47 |
sock <- connectTo "127.0.0.1" (PortNumber 46631) |
1804 | 48 |
|
5119 | 49 |
num1 <- randomRIO (100000::Int, 101000) |
50 |
num2 <- randomRIO (0::Int, 3) |
|
51 |
num3 <- randomRIO (0::Int, 1000) |
|
4905 | 52 |
let nick1 = 'n' : show num1 |
5119 | 53 |
let room1 = 'r' : show num3 |
54 |
emulateSession sock $ session num2 nick1 room1 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
55 |
hClose sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
56 |
putStrLn "Finish" |
1804 | 57 |
|
58 |
forks = forever $ do |
|
5119 | 59 |
delays <- randomRIO (0::Int, 2) |
60 |
replicateM 200 $ |
|
61 |
do |
|
62 |
delay <- randomRIO (delays * 20000::Int, delays * 20000 + 50000) |
|
63 |
threadDelay delay |
|
64 |
forkIO testing |
|
1804 | 65 |
|
66 |
main = withSocketsDo $ do |
|
67 |
#if !defined(mingw32_HOST_OS) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
68 |
installHandler sigPIPE Ignore Nothing; |
1804 | 69 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
70 |
forks |