Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoGomesNegri committed Oct 31, 2021
1 parent 388458e commit b56d1c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# tf2-web-server-manager
A Team Fortress 2 server manager that runs inside your browser.

To run, start the program and visit "localhost:3000" on your browser. There, you can log in to your server and run any command as if you were on the server window
23 changes: 13 additions & 10 deletions app/Rcon.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Rcon where
import Network.Simple.TCP
import Data.ByteString as B
import Data.ByteString.Lazy as BL
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.UTF8 as UTF8
import Data.Int as Int
import Data.Binary
Expand All @@ -15,8 +15,8 @@ import TransHelpers
import Control.Monad (join)


individualWait = 100000
numberWait = 6
individualWait = 10000
numberWait = 50

type Port = Int

Expand Down Expand Up @@ -100,17 +100,17 @@ authenticateConn Connection { port = port, adress = adress, password = pwd} sock
Nothing -> return False

getAndWait :: Socket -> Int -> MaybeT IO B.ByteString
getAndWait socket s = MaybeT $ go 0 B.empty s where
go :: Int -> B.ByteString -> Int -> IO (Maybe B.ByteString)
go count total size = do
getAndWait socket size = MaybeT $ go 0 B.empty where
go :: Int -> B.ByteString -> IO (Maybe B.ByteString)
go count total = do
stuff <- recv socket size
case stuff of
Just x -> do
let newTotal = B.concat [total,x]
if B.length x < size && count < numberWait then threadDelay individualWait >> go (count + 1) newTotal size else
if B.length x < size && count < numberWait then threadDelay individualWait >> go (count + 1) newTotal else
return $ return newTotal
Nothing ->
if count < numberWait then threadDelay individualWait >> go (count + 1) total size else return Nothing
if count < numberWait then threadDelay individualWait >> go (count + 1) total else return Nothing

getServerPacket :: Socket -> Maybe Int32 -> MaybeT IO Packet
getServerPacket socket idM = do
Expand Down Expand Up @@ -146,7 +146,10 @@ createPackage command idInt reqType =
null = UTF8.fromString "\0\0"

sendCmd :: String -> Connection -> IO (Maybe String)
sendCmd s c = runMaybeT $ sendCmdInternal s c
sendCmd s c = runMaybeT $ unlines . safeInit . lines <$> sendCmdInternal s c

safeInit [] = []
safeInit xs = init xs

sendCmdInternal :: String -> Connection -> MaybeT IO String
sendCmdInternal body conn =
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Server.elm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ update msg model =
TokenWrong -> wrapModel {model | error = TokenWrongErr}
ChangePage req -> (model, (Browser.Navigation.load (reqToString req)))
ChangeUrl u -> (model, (Browser.Navigation.pushUrl model.key (Url.toString u)))
CmdGood str -> wrapModel {model | commandResponse = str, waiting = False}
CmdGood str -> wrapModel {model | commandResponse = str, waiting = False, error = None}
CmdBad -> wrapModel {model | error = NoCmd, waiting = False}


Expand Down Expand Up @@ -111,7 +111,7 @@ view model =
,nl,
text (case model.error of
None -> ""
NoCmd -> "It was not possible to run your command."
NoCmd -> "The server took a while to respond. The command may not have ran."
TokenWrongErr -> "The token was incorrect. Please log in again"
)
]}
Expand Down

0 comments on commit b56d1c5

Please sign in to comment.