equal
deleted
inserted
replaced
17 #endif |
17 #endif |
18 |
18 |
19 type SState = Handle |
19 type SState = Handle |
20 io = liftIO |
20 io = liftIO |
21 |
21 |
22 |
|
23 readPacket :: StateT SState IO [String] |
22 readPacket :: StateT SState IO [String] |
24 readPacket = do |
23 readPacket = do |
25 h <- get |
24 h <- get |
26 p <- io $ hGetPacket h [] |
25 p <- io $ hGetPacket h [] |
27 return p |
26 return p |
43 hPutStrLn h "" |
42 hPutStrLn h "" |
44 hFlush h |
43 hFlush h |
45 |
44 |
46 emulateSession :: StateT SState IO () |
45 emulateSession :: StateT SState IO () |
47 emulateSession = do |
46 emulateSession = do |
|
47 n <- io $ randomRIO (100000::Int, 100000) |
48 waitPacket "CONNECTED" |
48 waitPacket "CONNECTED" |
49 sendPacket ["NICK", "test"] |
49 sendPacket ["NICK", "test" ++ (show n)] |
50 waitPacket "NICK" |
50 waitPacket "NICK" |
51 sendPacket ["PROTO", "31"] |
51 sendPacket ["PROTO", "31"] |
52 waitPacket "PROTO" |
52 waitPacket "PROTO" |
53 b <- waitPacket "LOBBY:JOINED" |
53 b <- waitPacket "LOBBY:JOINED" |
54 io $ print b |
54 --io $ print b |
|
55 return () |
55 |
56 |
56 testing = Control.OldException.handle print $ do |
57 testing = Control.OldException.handle print $ do |
57 putStrLn "Start" |
58 putStr "+" |
58 sock <- connectTo "127.0.0.1" (PortNumber 46631) |
59 sock <- connectTo "127.0.0.1" (PortNumber 46631) |
59 evalStateT emulateSession sock |
60 evalStateT emulateSession sock |
60 putStrLn "Finish" |
61 --hClose sock |
|
62 putStr "-" |
|
63 hFlush stdout |
61 |
64 |
62 forks = forever $ do |
65 forks = forever $ do |
63 delay <- randomRIO (400000::Int, 600000) |
66 delay <- randomRIO (20000::Int, 40000) |
64 threadDelay delay |
67 threadDelay delay |
65 forkIO testing |
68 forkIO testing |
66 |
69 |
67 main = withSocketsDo $ do |
70 main = withSocketsDo $ do |
68 #if !defined(mingw32_HOST_OS) |
71 #if !defined(mingw32_HOST_OS) |