Browse Source

Initial commit.

master
William Davis 2 months ago
commit
3a724f36d3
  1. 5
      client.py
  2. 34
      connection_handler.py
  3. 6
      launch.sh

5
client.py

@ -0,0 +1,5 @@
c = ''
while c != 'quit':
c = input('$ ')
with open('commands.history', 'a') as f:
f.write(c + '\n')

34
connection_handler.py

@ -0,0 +1,34 @@
from telnetlib import Telnet
from time import sleep
IN = 'commands.history'
OUT = 'gamelog.typescript'
STATUS = "RUNNING"
host = localhost
port = 23
tn = Telnet(host, port)
print('Starting in 4 seconds...')
sleep(4)
with open(OUT, 'a') as outfile, open(IN, 'r') as infile:
while STATUS != "EXIT":
try:
buf = tn.read_until(b'this should not match anything', 0)
if buf != b'':
outfile.write(buf.decode('latin_1'))
outfile.flush()
except EOFError:
STATUS = "EXIT"
print("Telnet session closed.")
#print(tn)
command = infile.readline()
if not command:
pass
else:
if command == '\n':
command = '\r'
tn.write(command.strip("\n").encode('latin_1'))
print("Connection handler exiting.")

6
launch.sh

@ -0,0 +1,6 @@
#!/usr/bin/env bash
rm commands.history
touch commands.history
python3 connection_handler.py &
python3 client.py
Loading…
Cancel
Save