summaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-23 17:01:39 +0200
committertroido <troido@protonmail.com>2020-04-23 17:01:39 +0200
commitd577a3f874a3fc2cb71708f400482ca817abc33e (patch)
tree1e3d89253e906bc6e5781c631b0e8341303889e9 /client.py
parent4d1cbdf2fc0d79b99589327eb378306c557d346a (diff)
added option to join the server without joining the game (just for the chat)
Diffstat (limited to 'client.py')
-rwxr-xr-xclient.py19
1 files changed, 13 insertions, 6 deletions
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"))