Skip to content

Commit

Permalink
Revert to v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Qirky committed Jul 25, 2017
1 parent c50c1dc commit 2993a56
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 125 deletions.
7 changes: 3 additions & 4 deletions src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Client:

version = '0.2'
version = '0.3'

def __init__(self, hostname="188.166.144.124", port=57890, name=None, lang=FOXDOT):

Expand All @@ -34,15 +34,14 @@ def __init__(self, hostname="188.166.144.124", port=57890, name=None, lang=FOXDO

else:

self.id = self.send.conn_id # we get our id from the server
self.id = self.send.conn_id

print("Password accepted")

except ConnectionError as e:

sys.exit(e)


if self.id is None:

print("No ID number assigned by server")
Expand All @@ -68,7 +67,7 @@ def __init__(self, hostname="188.166.144.124", port=57890, name=None, lang=FOXDO

self.ui = Interface("Troop - {}@{}:{}".format(self.name, self.send.hostname, self.send.port), self.lang)

# If there's an error connecting, the method below runs but does not create a valid marker...
# If there was an error connecting then this method does not create a local marker

self.ui.createLocalMarker(self.id, self.name)

Expand Down
19 changes: 5 additions & 14 deletions src/interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def convert(index):
return tuple(int(value) for value in str(index).split("."))

def createLocalMarker(self, id_num, name):
""" Creates the "peer" for the client on the local machine """
""" """
self.text.local_peer = id_num
self.text.marker=Peer(id_num, self.text)
self.text.marker.name.set(name)
Expand Down Expand Up @@ -252,7 +252,7 @@ def write(self, msg):

sender_id = msg['src_id']

if sender_id not in self.text.peers:
if sender_id not in self.text.peers and sender_id != -1:

# Get peer's current location & name

Expand Down Expand Up @@ -446,13 +446,7 @@ def KeyPress(self, event):
wait_for_reply = False

if event.keysym == "Delete":

end_row, _ = self.convert(self.text.index(END))

# Leave a buffer line

# if row + 2 < end_row:


messages.append( MSG_DELETE(self.text.marker.id, row, col) )

elif event.keysym == "BackSpace":
Expand Down Expand Up @@ -664,11 +658,7 @@ def SelectHome(self, event):

def SelectAll(self, event=None):
start = "1.0"

end_row, _ = self.convert(self.text.index(END))
end_row = end_row - 2

end = self.text.index("{}.end".format(end_row))
end = self.text.index(END)

messages = [ MSG_SELECT(self.text.marker.id, start, end),
MSG_SET_MARK(self.text.marker.id, 1, 0) ]
Expand All @@ -679,6 +669,7 @@ def SelectAll(self, event=None):

def Selection(self, event=None):
""" Handles selected areas """
# stdout("hello")
return "break"

""" Update colour / formatting """
Expand Down
33 changes: 23 additions & 10 deletions src/interface/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,32 @@ def update_me(self):

if 'src_id' in msg:

this_peer = self.peers[msg['src_id']]
# this_peer = self.peers[msg['src_id']]
if msg['src_id'] == -1:

this_peer = None # Server message

else:

this_peer = self.peers[msg['src_id']]

# When a user connects

if isinstance(msg, MSG_CONNECT):

if self.marker.id != msg['src_id']:

print("Peer '{}' has joined the session".format(msg['name']))

# If the server responds with a console message

elif isinstance(msg, MSG_RESPONSE):

self.root.console.write(msg['string'])

# Handles selection changes

if isinstance(msg, MSG_SELECT):
elif isinstance(msg, MSG_SELECT):

sel1 = str(msg['start'])
sel2 = str(msg['end'])
Expand Down Expand Up @@ -127,14 +148,6 @@ def update_me(self):

index = "{}.{}".format(row, col)

# If the mark has been put onto the last line, add a buffer line to the end

last_row = self.root.convert(self.index(END))[0] - 1

## if row == last_row:
##
## self.insert(END, "\n")

self.mark_set(this_peer.mark, index)

this_peer.move(row, col) ## this wasn't here before
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self):
self.re = compile_regex(self.keywords)

def kill(self):
self.clock.stop()
self.execute("Clock.stop()")

def stop_sound(self):
return "Clock.clear()"
Expand Down
54 changes: 27 additions & 27 deletions src/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,43 @@ def handle(self):

except Exception as e:

self.ui.console.write(str(e))
print(e)

break

for msg in network_msg:

# Store information about a newly connected client

if type(msg) == MSG_CONNECT:
if isinstance(msg, MSG_CONNECT):

self.nodes[msg['src_id']] = Node(*msg)

self.update_text(msg)

# Notify user of newly connected users

if self.ui.text.marker.id != msg['src_id']:

print("Peer '{}' has joined the session".format(msg['name']))

# Code feedback from the server

elif type(msg) == MSG_RESPONSE:

self.ui.console.write(msg['string'])

# Ignore "set time" messages from oneself

elif type(msg) == MSG_SET_TIME and msg['src_id'] == self.ui.text.marker.id:

pass

# Write the data to the IDE

else:

self.update_text(msg)
#### self.update_text(msg)
####
#### # Notify user of newly connected users
####
#### if self.ui.text.marker.id != msg['src_id']:
####
#### print("Peer '{}' has joined the session".format(msg['name']))
##
## # Code feedback from the server
##
## elif type(msg) == MSG_RESPONSE:
##
## self.ui.console.write(msg['string'])
##
## # Ignore "set time" messages from oneself
##
## elif type(msg) == MSG_SET_TIME and msg['src_id'] == self.ui.text.marker.id:
##
## pass
##
## # Write the data to the IDE
##
## else:

self.update_text(msg)

return

Expand Down
86 changes: 17 additions & 69 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(self, hostname=socket.gethostname(), port=57890, local=True, log=Fa

# Reference to the thread that is listening for new connections
self.server_thread = Thread(target=self.server.serve_forever)
self.server_thread.daemon = True

# Clients (hostname, ip)
self.clients = []
Expand All @@ -88,19 +87,6 @@ def __init__(self, hostname=socket.gethostname(), port=57890, local=True, log=Fa
# Set up a char queue
self.char_queue = Queue.Queue()
self.char_queue_thread = Thread(target=self.update_send)
self.char_queue_thread.daemon = True

# This executes code
## if local is True:
##
## self.is_evaluating_local = True
## self.lang = Interpreter()
## sys.stdout = self
##
## else:
##
## self.is_evaluating_local = False
## self.lang = Clock()

# Set up log for logging a performance

Expand Down Expand Up @@ -145,27 +131,13 @@ def start(self):

except KeyboardInterrupt:

stdout("\nStopping...\n")

self.kill()

break
return

## def ping_clients(self):
## ''' Sends a clock-time message to clients '''
## if self.is_evaluating_local is False:
## t = self.lang.now()
## for i, client in enumerate(self.clients):
## try:
## # Get the clock time from the master
## if i == 0:
## client.send(MSG_GET_TIME())
## #else:
## # client.send(MSG_PING())
## except DeadClientError as err:
## self.remove_client(client.address)
## stdout(err, "- Client has been removed")
## return t

def get_next_id(self):
self.last_id += 1
return self.last_id
Expand Down Expand Up @@ -280,10 +252,19 @@ def remove_client(self, client_address):
def kill(self):
""" Properly terminates the server """
if self.log_file is not None: self.log_file.close()

outgoing = MSG_RESPONSE(-1, "Warning: Server manually killed by keyboard interrupt. Please close the application")

for client in self.clients:

client.send(outgoing)

sleep(1)

self.running = False
self.server.shutdown()
self.server.server_close()
# self.lang.kill()

return

def write(self, string):
Expand Down Expand Up @@ -335,13 +316,13 @@ def handle(self):

# If success, enter loop

while True:
while self.master.running:

try:

network_msg = NetworkMessage(self.request.recv(2048))

except:
except Exception as e:

# Handle the loss of a client

Expand All @@ -353,7 +334,7 @@ def handle(self):

for msg in network_msg:

# 1. If we have a new client connecting, add to the address book
# If we have a new client connecting, add to the address book

if isinstance(msg, MSG_CONNECT) and self.client_address not in self.master.clients:

Expand Down Expand Up @@ -393,19 +374,9 @@ def handle(self):

self.master.clients[0].send(MSG_GET_ALL(self.client_id(), new_client.id))

# Only get clock time (if necessary) from the first connected client

# self.master.clients[0].send(MSG_GET_TIME(self.client_id(), new_client.id))

else:

# If this is the first client to connect, set clock to 0

# self.master.lang.reset() ### TODO is this a good idea?

# Set a blank canvas if this is the first to connect

self.master.clients[0].send(MSG_SET_ALL(self.master.clients[0].id, "\n\n\n", 0))
self.master.clients[0].send(MSG_SET_ALL(self.master.clients[0].id, "", 0))

elif isinstance(msg, MSG_SET_ALL):

Expand All @@ -419,30 +390,6 @@ def handle(self):

client.send( MSG_SET_ALL(self.client_id(), msg['string'], new_client_id) )

## elif isinstance(msg, MSG_SET_TIME):
##
## new_client_id = msg['client_id']
##
## for client in self.master.clients:
##
## if client.id == new_client_id:
##
## client.send( MSG_SET_TIME(self.client_id(), msg['time'], msg['timestamp'], new_client_id) )

# If we have an execute message, evaluate

# -- may want to have a designated server for making audio?

#elif isinstance(msg, MSG_EVALUATE_):
# if self.master.is_evaluating_local:
# # Evaluate on server
# try:
# response = self.master.lang.evaluate(msg['string'])
# except Exception as e:
# stdout(e)
# else:
# self.master.char_queue.put((self.client_address, msg))

else:

# Add any other messages to the send queue
Expand Down Expand Up @@ -476,6 +423,7 @@ def __repr__(self):
def send(self, string):
try:
self.source.send(str(string))
#self.source.sendall(str(string)) # possible issue
except:
raise DeadClientError(self.hostname)
return
Expand Down

0 comments on commit 2993a56

Please sign in to comment.