Handle hello-event and ping-event
This commit is contained in:
parent
dbdbc66737
commit
69162ab276
1 changed files with 42 additions and 1 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
|
import time
|
||||||
|
|
||||||
from . import connection
|
from . import connection
|
||||||
from . import messages
|
from . import messages
|
||||||
|
from . import session
|
||||||
from . import sessions
|
from . import sessions
|
||||||
|
|
||||||
class Room():
|
class Room():
|
||||||
|
|
@ -17,15 +20,28 @@ class Room():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.room = room
|
self.room = room
|
||||||
self.nick = nick
|
self.room_is_private = None
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
|
self.nick = nick
|
||||||
|
self.session = None
|
||||||
|
|
||||||
|
self.account_name = None
|
||||||
self.account_email = account_email
|
self.account_email = account_email
|
||||||
self.account_password = account_password
|
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.messages = messages.Messages()
|
||||||
self.sessions = sessions.Sessions()
|
self.sessions = sessions.Sessions()
|
||||||
|
self.callbacks = callbacks.Callbacks()
|
||||||
|
|
||||||
self.con = connection.Connection(self.room)
|
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):
|
def launch(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -35,3 +51,28 @@ class Room():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.con.launch()
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue