gameServer/stresstest2.hs
author alfadur
Wed, 14 Aug 2019 23:06:11 +0300
changeset 15315 90f9a0eac3ae
parent 11046 47a8c19ecb60
permissions -rw-r--r--
remove nopng from vcpkg build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10460
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
     1
{-
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10460
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
10460
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
     4
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
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: 4932
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: 4932
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
     8
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
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: 4932
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: 4932
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
    12
 * GNU General Public License for more details.
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
    13
 *
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
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: 4932
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: 4932
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: 4932
diff changeset
    17
 \-}
8dcea9087d75 Added copyrights to gameServer directory
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 4932
diff changeset
    18
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    19
{-# LANGUAGE CPP #-}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
module Main where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    22
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    23
import System.IO
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    24
import Control.Concurrent
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    25
import Network
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    26
import Control.OldException
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    27
import Control.Monad
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    28
import System.Random
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    29
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    30
#if !defined(mingw32_HOST_OS)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    31
import System.Posix
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
#endif
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    34
session1 nick room = ["NICK", nick, "", "PROTO", "32", ""]
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    35
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    36
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    37
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    38
testing = Control.OldException.handle print $ do
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    39
    putStrLn "Start"
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2352
diff changeset
    40
    sock <- connectTo "127.0.0.1" (PortNumber 46631)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    41
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    42
    num1 <- randomRIO (70000::Int, 70100)
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    43
    num2 <- randomRIO (0::Int, 2)
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    44
    num3 <- randomRIO (0::Int, 5)
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    45
    let nick1 = 'n' : show num1
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    46
    let room1 = 'r' : show num2
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    47
    mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (300::Int, 590) >>= threadDelay) $ session1 nick1 room1
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    48
    mapM_ (\x -> hPutStrLn sock x >> hFlush sock) $ concatMap (\x -> ["CHAT_MSG", show x, ""]) [1..]
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    49
    hClose sock
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    50
    putStrLn "Finish"
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    51
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    52
forks = testing
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    53
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    54
main = withSocketsDo $ do
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    55
#if !defined(mingw32_HOST_OS)
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2352
diff changeset
    56
    installHandler sigPIPE Ignore Nothing;
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    57
#endif
4905
7842d085acf4 Fix merge :D
unc0rr
parents: 4568
diff changeset
    58
    forks