author | unc0rr |
Thu, 06 May 2010 17:53:37 +0000 | |
changeset 3436 | 288fcbdb77b6 |
parent 3425 | ead2ed20dfd4 |
child 3947 | 709fdb89f76c |
permissions | -rw-r--r-- |
1804 | 1 |
{-# LANGUAGE CPP #-} |
2 |
||
3 |
module Main where |
|
4 |
||
5 |
import IO |
|
6 |
import System.IO |
|
7 |
import Control.Concurrent |
|
8 |
import Network |
|
3425 | 9 |
import Control.OldException |
1804 | 10 |
import Control.Monad |
11 |
import System.Random |
|
12 |
||
13 |
#if !defined(mingw32_HOST_OS) |
|
14 |
import System.Posix |
|
15 |
#endif |
|
16 |
||
3425 | 17 |
session1 nick room = ["NICK", nick, "", "PROTO", "32", "", "PING", "", "CHAT", "lobby 1", "", "CREATE_ROOM", room, "", "CHAT", "room 1", "", "QUIT", "creator", ""] |
18 |
session2 nick room = ["NICK", nick, "", "PROTO", "32", "", "LIST", "", "JOIN_ROOM", room, "", "CHAT", "room 2", "", "PART", "", "CHAT", "lobby after part", "", "QUIT", "part-quit", ""] |
|
19 |
session3 nick room = ["NICK", nick, "", "PROTO", "32", "", "LIST", "", "JOIN_ROON", room, "", "CHAT", "room 2", "", "QUIT", "quit", ""] |
|
1804 | 20 |
|
21 |
emulateSession sock s = do |
|
3425 | 22 |
mapM_ (\x -> hPutStrLn sock x >> hFlush sock >> randomRIO (300000::Int, 590000) >>= threadDelay) s |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
23 |
hFlush sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
24 |
threadDelay 225000 |
1804 | 25 |
|
3425 | 26 |
testing = Control.OldException.handle print $ do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
27 |
putStrLn "Start" |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
28 |
sock <- connectTo "127.0.0.1" (PortNumber 46631) |
1804 | 29 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
30 |
num1 <- randomRIO (70000::Int, 70100) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
31 |
num2 <- randomRIO (0::Int, 2) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
32 |
num3 <- randomRIO (0::Int, 5) |
3425 | 33 |
let nick1 = 'n' : show num1 |
34 |
let room1 = 'r' : show num2 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
35 |
case num2 of |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
36 |
0 -> emulateSession sock $ session1 nick1 room1 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
37 |
1 -> emulateSession sock $ session2 nick1 room1 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
38 |
2 -> emulateSession sock $ session3 nick1 room1 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
39 |
hClose sock |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
40 |
putStrLn "Finish" |
1804 | 41 |
|
42 |
forks = forever $ do |
|
3425 | 43 |
delay <- randomRIO (300000::Int, 590000) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
44 |
threadDelay delay |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
45 |
forkIO testing |
1804 | 46 |
|
47 |
main = withSocketsDo $ do |
|
48 |
#if !defined(mingw32_HOST_OS) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
49 |
installHandler sigPIPE Ignore Nothing; |
1804 | 50 |
#endif |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2352
diff
changeset
|
51 |
forks |