Skip to content

Commit

Permalink
Add echo-console
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Jan 31, 2011
1 parent 20a891f commit de42c34
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 20 additions & 1 deletion Proxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ makeListenerThread serverAI proxyAI = do
bindSocketToAddrInfo l proxyAI
listen l 5

putStrLn "Ready to accept connections"
putStr $ "Ready to accept connections on " ++ show (addrAddress proxyAI) ++ "\n"

forever $ do (clientSock, clientAddr) <- accept l
_ <- forkIO (handleClient serverAI clientSock clientAddr)
Expand Down Expand Up @@ -204,6 +204,9 @@ processCommand ::
String {- ^ chat command -} ->
IO ()

processCommand clientChan _ "console-echo"
= makePipeListener clientChan

processCommand clientChan _ "help"
= traverse_ (tellPlayer clientChan) helpMessage

Expand Down Expand Up @@ -584,3 +587,19 @@ getOptions = do
_ -> do hPutStrLn stderr "Required server-host and server-port missing\n"
hPutStrLn stderr $ usageInfo usageText options
exitFailure

-- External command echo support

makePipeListener clientChan =
do forkIO $ do
xs <- lines <$> readFile "console"
tellPlayer clientChan "Console opened"
traverse_ process xs
tellPlayer clientChan "Console closed"
`Control.Exception.catch` \ (SomeException e) ->
tellPlayer clientChan $ "Console failed: " ++ show e
return ()
where
process x = case reads x of
[(y,_)] -> sendMessages clientChan [y]
_ -> hPutStrLn stderr $ "Failed to parse: " ++ show x
12 changes: 10 additions & 2 deletions minecraft-proxy.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ Executable minecraft-proxy
Main-is: Proxy.hs

-- Packages needed in order to build this package.
Build-depends: binary, data-binary-ieee754, utf8-string, containers, base == 4.2.*,
network-bytestring, network, bytestring, zlib == 0.5.3.*, array
Build-depends:
array,
base == 4.2.*,
binary,
bytestring,
containers,
data-binary-ieee754,
network == 2.3.*,
utf8-string,
zlib == 0.5.3.*

-- Modules not exported by this package.
-- Other-modules:
Expand Down

0 comments on commit de42c34

Please sign in to comment.