custom packets callbacks fix

This commit is contained in:
ingvar1995 2016-10-15 19:03:33 +03:00
parent 5367764fdc
commit ecf045182a
2 changed files with 9 additions and 6 deletions

View File

@ -274,16 +274,18 @@ def lossless_packet(tox, friend_number, data, length, user_data):
"""
Incoming lossless packet
"""
data = data[:length]
plugin = PluginLoader.get_instance()
invoke_in_main_thread(plugin.callback_lossless, friend_number, data, length)
invoke_in_main_thread(plugin.callback_lossless, friend_number, data)
def lossy_packet(tox, friend_number, data, length, user_data):
"""
Incoming lossy packet
"""
data = data[:length]
plugin = PluginLoader.get_instance()
invoke_in_main_thread(plugin.callback_lossy, friend_number, data, length)
invoke_in_main_thread(plugin.callback_lossy, friend_number, data)
# -----------------------------------------------------------------------------------------------------------------

View File

@ -64,23 +64,24 @@ class PluginLoader(util.Singleton):
self._plugins[inst.get_short_name()] = [inst, autostart] # (inst, is active)
break
def callback_lossless(self, friend_number, data, length):
def callback_lossless(self, friend_number, data):
"""
New incoming custom lossless packet (callback)
"""
print('Custom', data)
l = data[0] - pl.LOSSLESS_FIRST_BYTE
name = ''.join(chr(x) for x in data[1:l + 1])
if name in self._plugins and self._plugins[name][1]:
self._plugins[name][0].lossless_packet(''.join(chr(x) for x in data[l + 1:length]), friend_number)
self._plugins[name][0].lossless_packet(''.join(chr(x) for x in data[l + 1:]), friend_number)
def callback_lossy(self, friend_number, data, length):
def callback_lossy(self, friend_number, data):
"""
New incoming custom lossy packet (callback)
"""
l = data[0] - pl.LOSSY_FIRST_BYTE
name = ''.join(chr(x) for x in data[1:l + 1])
if name in self._plugins and self._plugins[name][1]:
self._plugins[name][0].lossy_packet(''.join(chr(x) for x in data[l + 1:length]), friend_number)
self._plugins[name][0].lossy_packet(''.join(chr(x) for x in data[l + 1:]), friend_number)
def friend_online(self, friend_number):
"""