From 69162ab2761bcd6ca393b57b39bd6c4c905c44b4 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 8 May 2016 21:28:41 +0200 Subject: [PATCH] Handle hello-event and ping-event --- yaboli/room.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/yaboli/room.py b/yaboli/room.py index 35e8ac1..533c6b8 100644 --- a/yaboli/room.py +++ b/yaboli/room.py @@ -1,5 +1,8 @@ +import time + from . import connection from . import messages +from . import session from . import sessions class Room(): @@ -17,15 +20,28 @@ class Room(): """ self.room = room - self.nick = nick + self.room_is_private = None self.password = password + + self.nick = nick + self.session = None + + self.account_name = None self.account_email = account_email self.account_password = account_password + self.ping_last = 0 + self.ping_next = 0 + self.ping_offset = 0 # difference between server and local time + self.messages = messages.Messages() self.sessions = sessions.Sessions() + self.callbacks = callbacks.Callbacks() self.con = connection.Connection(self.room) + + self.con.add_callback("hello-event", self._handle_hello_event) + self.con.add_callback("ping-event", self._handle_ping_event) def launch(self): """ @@ -35,3 +51,28 @@ class Room(): """ return self.con.launch() + + def _handle_hello_event(self, data): + """ + TODO + """ + + self.session = session.Session.from_data(data["session"]) + self.sessions.add(self.session) + + self.room_is_private = data["room_is_private"] + + if "account" in data: # in case you log in in another room + self.account_name = data["account"]["name"] + self.account_email = data["account"]["email"] + + def _handle_ping_event(self, data): + """ + TODO + """ + + self.ping_last = data["time"] + self.ping_next = data["next"] + self.ping_offset = self.ping_last - time.gmtime() + + self.con.send_packet("ping-reply", time=self.ping_last)