<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.soldat.pl/index.php?action=history&amp;feed=atom&amp;title=HRemote</id>
		<title>HRemote - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.soldat.pl/index.php?action=history&amp;feed=atom&amp;title=HRemote"/>
		<link rel="alternate" type="text/html" href="https://wiki.soldat.pl/index.php?title=HRemote&amp;action=history"/>
		<updated>2026-05-26T02:29:48Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://wiki.soldat.pl/index.php?title=HRemote&amp;diff=177&amp;oldid=prev</id>
		<title>Freeman: Created page with &quot;&lt;source lang=&quot;haskell&quot;&gt; import Network import System.IO import Data.Char import Data.List import Control.Concurrent (threadDelay)  -- config serverIP = &quot;localhost&quot; serverPort ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.soldat.pl/index.php?title=HRemote&amp;diff=177&amp;oldid=prev"/>
				<updated>2012-08-15T11:36:13Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;source lang=&amp;quot;haskell&amp;quot;&amp;gt; import Network import System.IO import Data.Char import Data.List import Control.Concurrent (threadDelay)  -- config serverIP = &amp;quot;localhost&amp;quot; serverPort ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;haskell&amp;quot;&amp;gt;&lt;br /&gt;
import Network&lt;br /&gt;
import System.IO&lt;br /&gt;
import Data.Char&lt;br /&gt;
import Data.List&lt;br /&gt;
import Control.Concurrent (threadDelay)&lt;br /&gt;
&lt;br /&gt;
-- config&lt;br /&gt;
serverIP = &amp;quot;localhost&amp;quot;&lt;br /&gt;
serverPort = 23073&lt;br /&gt;
adminPassword = &amp;quot;boob&amp;quot;&lt;br /&gt;
onConnect = &amp;quot;/say In-game commands now running&amp;quot;&lt;br /&gt;
unpauseInterval = 1000000&lt;br /&gt;
&lt;br /&gt;
-- function definitions&lt;br /&gt;
sleep = threadDelay&lt;br /&gt;
&lt;br /&gt;
-- trim gets rid of prefixing and suffixing whitespaces&lt;br /&gt;
trim = reverse . dropSpaces . reverse . dropSpaces&lt;br /&gt;
dropSpaces = dropWhile isSpace&lt;br /&gt;
&lt;br /&gt;
-- splits a string by a string&lt;br /&gt;
split :: String -&amp;gt; String -&amp;gt; [String]&lt;br /&gt;
split _ &amp;quot;&amp;quot; = []&lt;br /&gt;
split delim string = let (h,t) = chomp delim string in h : split delim t&lt;br /&gt;
&lt;br /&gt;
-- chomp chomp&lt;br /&gt;
chomp  :: String -&amp;gt; String -&amp;gt; (String,String)&lt;br /&gt;
chomp _ [] = ([],[])&lt;br /&gt;
chomp delim str@(x:xs) | delim `isPrefixOf` str = (&amp;quot;&amp;quot;, drop (length delim) str)&lt;br /&gt;
                       | otherwise = let (h,t) = (chomp delim xs) in (x:h, t)&lt;br /&gt;
&lt;br /&gt;
-- sends a line&lt;br /&gt;
send h str = do&lt;br /&gt;
    hPutStrLn h str&lt;br /&gt;
    -- logs to stdout whatever we send&lt;br /&gt;
    putStrLn $ &amp;quot;&amp;gt; &amp;quot; ++ str&lt;br /&gt;
&lt;br /&gt;
-- reads a line&lt;br /&gt;
recv = hGetLine&lt;br /&gt;
&lt;br /&gt;
-- forever&lt;br /&gt;
forever action = action &amp;gt;&amp;gt; forever action&lt;br /&gt;
&lt;br /&gt;
-- gets the said text (cleans nickname)&lt;br /&gt;
getCommand str = safe $ tail' $ split &amp;quot;] !&amp;quot; str&lt;br /&gt;
    where safe [] = &amp;quot;&amp;quot;; safe [x] = x;&lt;br /&gt;
          tail' [] = []; tail' l@(x:xs) = tail l&lt;br /&gt;
&lt;br /&gt;
-- main listening function&lt;br /&gt;
listen h = forever $ do&lt;br /&gt;
    buff &amp;lt;- (recv h &amp;gt;&amp;gt;= (\x -&amp;gt; (return . trim) x))&lt;br /&gt;
    --  give to parse&lt;br /&gt;
    --  print (getCommand buff)&lt;br /&gt;
    parse (getCommand buff) h&lt;br /&gt;
    putStrLn buff&lt;br /&gt;
&lt;br /&gt;
-- parser&lt;br /&gt;
parse cmd h | cmd == &amp;quot;pause&amp;quot; = pause h&lt;br /&gt;
            | cmd == &amp;quot;unpause&amp;quot; = unpause h&lt;br /&gt;
            | &amp;quot;map&amp;quot; `isPrefixOf` cmd = mapChange h (trim $ snd $ break (==' ') cmd)&lt;br /&gt;
            | cmd == &amp;quot;restart&amp;quot; = restart h&lt;br /&gt;
            | otherwise = return ()&lt;br /&gt;
&lt;br /&gt;
-- various commands&lt;br /&gt;
pause h = send h &amp;quot;/pause&amp;quot;&lt;br /&gt;
unpause h = do&lt;br /&gt;
    send h &amp;quot;/say 3&amp;quot;&lt;br /&gt;
    sleep unpauseInterval&lt;br /&gt;
    send h &amp;quot;/say 2&amp;quot;&lt;br /&gt;
    sleep unpauseInterval&lt;br /&gt;
    send h &amp;quot;/say 1&amp;quot;&lt;br /&gt;
    sleep unpauseInterval&lt;br /&gt;
    send h &amp;quot;/unpause&amp;quot;&lt;br /&gt;
mapChange h mapName = do&lt;br /&gt;
    send h (&amp;quot;/map &amp;quot;++mapName)&lt;br /&gt;
restart h = do&lt;br /&gt;
    send h &amp;quot;/restart&amp;quot;&lt;br /&gt;
&lt;br /&gt;
-- main entry&lt;br /&gt;
main = do&lt;br /&gt;
    putStrLn &amp;quot;Starting -&amp;quot;&lt;br /&gt;
    h &amp;lt;- connectTo serverIP (PortNumber (fromIntegral serverPort))&lt;br /&gt;
    hSetBuffering h NoBuffering&lt;br /&gt;
    send h adminPassword&lt;br /&gt;
    send h onConnect&lt;br /&gt;
    listen h&lt;br /&gt;
    putStrLn &amp;quot;Exit&amp;quot;&lt;br /&gt;
    hClose h&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Freeman</name></author>	</entry>

	</feed>