equal
deleted
inserted
replaced
1 {-# LANGUAGE CPP #-} |
1 {-# LANGUAGE CPP #-} |
2 |
2 |
3 module Main where |
3 module Main where |
4 |
4 |
5 import IO |
|
6 import System.IO |
5 import System.IO |
|
6 import System.IO.Error |
7 import Control.Concurrent |
7 import Control.Concurrent |
8 import Network |
8 import Network |
9 import Control.OldException |
9 import Control.OldException |
10 import Control.Monad |
10 import Control.Monad |
11 import System.Random |
11 import System.Random |
20 io = liftIO |
20 io = liftIO |
21 |
21 |
22 readPacket :: StateT SState IO [String] |
22 readPacket :: StateT SState IO [String] |
23 readPacket = do |
23 readPacket = do |
24 h <- get |
24 h <- get |
25 p <- io $ hGetPacket h [] |
25 io $ hGetPacket h [] |
26 return p |
|
27 where |
26 where |
28 hGetPacket h buf = do |
27 hGetPacket h buf = do |
29 l <- hGetLine h |
28 l <- hGetLine h |
30 if (not $ null l) then hGetPacket h (buf ++ [l]) else return buf |
29 if not $ null l then hGetPacket h (buf ++ [l]) else return buf |
31 |
30 |
32 waitPacket :: String -> StateT SState IO Bool |
31 waitPacket :: String -> StateT SState IO Bool |
33 waitPacket s = do |
32 waitPacket s = do |
34 p <- readPacket |
33 p <- readPacket |
35 return $ head p == s |
34 return $ head p == s |
44 |
43 |
45 emulateSession :: StateT SState IO () |
44 emulateSession :: StateT SState IO () |
46 emulateSession = do |
45 emulateSession = do |
47 n <- io $ randomRIO (100000::Int, 100100) |
46 n <- io $ randomRIO (100000::Int, 100100) |
48 waitPacket "CONNECTED" |
47 waitPacket "CONNECTED" |
49 sendPacket ["NICK", "test" ++ (show n)] |
48 sendPacket ["NICK", "test" ++ show n] |
50 waitPacket "NICK" |
49 waitPacket "NICK" |
51 sendPacket ["PROTO", "31"] |
50 sendPacket ["PROTO", "31"] |
52 waitPacket "PROTO" |
51 waitPacket "PROTO" |
53 b <- waitPacket "LOBBY:JOINED" |
52 b <- waitPacket "LOBBY:JOINED" |
54 --io $ print b |
53 --io $ print b |