Skip to content

Commit

Permalink
small reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoGomesNegri committed Oct 31, 2021
1 parent dd456de commit 388458e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,5 @@ serveFile f = do
randomString :: Int -> IO Token
randomString size =
let all = ['0'..'9'] ++ ['a'..'z'] ++ ['A'..'Z'] in
let randomChar = (!!) all <$> getStdRandom (randomR (0, 61)) in
let randomChar = (!!) all <$> getStdRandom (randomR (0, length all - 1)) in
(sequenceA . replicate size) randomChar
13 changes: 10 additions & 3 deletions app/Rcon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import System.Random(randomIO)
import TransHelpers
import Control.Monad (join)


individualWait = 100000
numberWait = 6

type Port = Int

data RequestType = Auth | Command | AuthResponse | CommandResponse deriving Show
Expand All @@ -36,10 +40,13 @@ data ConnErr = BadPassword | UnexpectedResponse | ConnError String deriving Show
errHandler :: SomeException -> IO (Either ConnErr Connection)
errHandler e = return $ Left $ ConnError (show e)

errHandlerMaybe :: SomeException -> IO (Maybe a)
errHandlerMaybe _ = return Nothing

withConn :: Connection -> (Socket -> IO a) -> MaybeT IO a
withConn conn@Connection {adress = adress, port = port, password = pwd} action = do
MaybeT $
handle errHandler $
handle errHandlerMaybe $
connect adress (show port) $ \(socket,_) -> do
authenticated <- authenticateConn conn socket
if authenticated then do
Expand Down Expand Up @@ -100,10 +107,10 @@ getAndWait socket s = MaybeT $ go 0 B.empty s where
case stuff of
Just x -> do
let newTotal = B.concat [total,x]
if B.length x < size && count < 6 then threadDelay 100000 >> go (count + 1) newTotal size else
if B.length x < size && count < numberWait then threadDelay individualWait >> go (count + 1) newTotal size else
return $ return newTotal
Nothing ->
if count < 6 then threadDelay 100000 >> go (count + 1) total size else return Nothing
if count < numberWait then threadDelay individualWait >> go (count + 1) total size else return Nothing

getServerPacket :: Socket -> Maybe Int32 -> MaybeT IO Packet
getServerPacket socket idM = do
Expand Down

0 comments on commit 388458e

Please sign in to comment.