Skip to content

Commit 08ec7b2

Browse files
Wait for admin to restart
1 parent e836fd8 commit 08ec7b2

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lelonmo/socket_client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ def _wait_for_status(key, host): # Wait for a specific status in order to conti
3434
wait(persist_data.DATA["online"]["update_speed"])
3535

3636

37-
def join_game(ip="localhost"): # Initiate the connexion between client and server
37+
def join_game(wb, ip="localhost"): # Initiate the connexion between client and server
3838
player_id = _send_data("join%" + persist_data.DATA["online"]["name"], ip)
3939
if player_id == b"started":
4040
print("The game you tried to join already started")
4141
exit()
42+
elif player_id == b"wait%":
43+
wb.add("Waiting for admin to restart the game ...")
44+
while player_id == b"wait%":
45+
wait(persist_data.DATA["online"]["update_speed"])
46+
player_id = _send_data("join%" + persist_data.DATA["online"]["name"], ip)
47+
return int(player_id)
48+
elif player_id == b"":
49+
print("Error while joining, try again later")
4250
else:
4351
return int(player_id)
4452

@@ -113,7 +121,7 @@ def main(host="localhost"):
113121
wb.add("You are logged in as", persist_data.DATA["online"]["name"])
114122

115123
wb.add(f"Joining the game hosted at {host}")
116-
player_id = join_game(host)
124+
player_id = join_game(host, wb)
117125
wb.add("Joined successfully")
118126
admin = False
119127
if player_id == 0: # Player id =

server/socket_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import threading
55
import socket
66

7-
from . import letter_generator
8-
from . import word_check
7+
from server import letter_generator
8+
from server import word_check
99

1010

1111
class Game():
@@ -121,7 +121,7 @@ def handle_data(self, data: str, client_socket, client_thread):
121121
self._reset()
122122
self.handle_data(data, client_socket, client_thread)
123123
elif msg.startswith("join%"):
124-
self._answer("started", client_socket)
124+
self._answer("wait%", client_socket)
125125

126126

127127
class ClientThread(threading.Thread):

0 commit comments

Comments
 (0)