From d577a3f874a3fc2cb71708f400482ca817abc33e Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 23 Apr 2020 17:01:39 +0200 Subject: added option to join the server without joining the game (just for the chat) --- client.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'client.py') diff --git a/client.py b/client.py index 2e4a4c4..bf908d6 100755 --- a/client.py +++ b/client.py @@ -6,6 +6,8 @@ import threading import json import getpass +# A simple asciifarm client that can only join the chat. + def send(sock, msg): length = len(msg) @@ -14,7 +16,7 @@ def send(sock, msg): sock.sendall(totalmsg) def receive(sock): - header = recvall(sock, 4) #sock.recv(4) + header = recvall(sock, 4) length = int.from_bytes(header, byteorder="big") return recvall(sock, length) @@ -30,10 +32,15 @@ def recvall(sock, length): bytes_recd = bytes_recd + len(chunk) return b''.join(chunks) +inet = "inet" in sys.argv +join = "join" in sys.argv - -sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -sock.connect("\0rustifarm")#("localhost", 1234)) +if inet: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect(("localhost", 9021)) +else: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect("\0rustifarm") def listen(): while True: @@ -48,10 +55,10 @@ threading.Thread(target=listen, daemon=True).start() if len(sys.argv) >= 2: name = sys.argv[1] else: - name = "~" + getpass.getuser() + name = getpass.getuser() print(name) -send(sock, bytes(json.dumps(["name", name]), "utf-8")) +send(sock, bytes(json.dumps(["auth", {"name": name, "join": join, "type": "guest"}]), "utf-8")) for line in sys.stdin: send(sock, bytes(json.dumps(["chat", line.strip()]), "utf-8")) -- cgit