Skip to content
Snippets Groups Projects
Commit 3b6f98c4 authored by penguin0001's avatar penguin0001
Browse files

weird message handling etc

parent db54c16a
No related branches found
No related tags found
No related merge requests found
......@@ -23,13 +23,13 @@ def send(msg):
connect = True
print("You may use BYE to close the connection at any time.")
user_input = input("Enter username: ")
print("[you may use BYE to close the connection at any time]")
while connect:
server_msg = send(user_input)
print(server_msg)
user_input = input()
if user_input.upper() == "BYE" or server_msg == "ERR":
if user_input.upper() == "BYE" or server_msg == "ERR" or server_msg == "DONE" or server_msg == "END":
connect = False
......
......@@ -23,7 +23,7 @@ orders = {}
chef_present = True
global user
global state # one of: LOGIN, CUSTOMER, NEW, STARTER, MAIN, SIDE, OLD
global state # one of: LOGIN, CUSTOMER, NEW, STARTER, MAIN, SIDE, OLD, DONE
def handle_message(msg):
......@@ -35,7 +35,7 @@ def handle_message(msg):
state = "CUSTOMER"
return "NEW or OLD customer?"
else:
return "Username invalid."
return "Enter username: "
if state == 'CUSTOMER':
if msg.upper() == "NEW":
......@@ -45,7 +45,7 @@ def handle_message(msg):
state = 'OLD'
return 'PKUP?'
else:
return "ERR\nNEW or OLD?"
return "NEW or OLD?"
if state == "NEW":
if msg.upper() == "MENU":
......@@ -54,7 +54,7 @@ def handle_message(msg):
state = "STARTER"
return "Select starter: "
else:
return "ERR\nMENU or ORDR?"
return "MENU or ORDR?"
if state == "STARTER":
if is_starter(msg.lower()):
......@@ -63,7 +63,7 @@ def handle_message(msg):
state = "MAIN"
return "Select main: "
else:
return "ERR\nSelect starter: "
return "Select starter: "
if state == "MAIN":
if is_main(msg.lower()):
......@@ -71,23 +71,27 @@ def handle_message(msg):
state = "SIDE"
return "Select side: "
else:
return "ERR\nSelect main: "
return "Select main: "
if state == "SIDE":
if is_side(msg.lower()):
orders[user].append(msg.lower())
state = "DONE"
return "DONE"
else:
return "ERR\nSelect side: "
return "Select side: "
if state == "DONE":
return "DONE"
if state == "OLD":
if msg.upper() == "PKUP":
if user in orders:
return orders_to_string(user)
return orders_to_string(user) + "\nOrder picked up, you may close the connection."
else:
return "You don't have any orders to pick up. Please close the connection."
else:
return "ERR\nPKUP?"
return "PKUP?"
else:
return 'ERR'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment