Skip to content

Commit

Permalink
2.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCommCraft committed Jul 27, 2024
1 parent ec208fb commit ab225a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scratchcommunication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module for communicating with scratch projects.
"""

__version_number__ = '2.14.3'
__version_number__ = '2.14.4'

from .session import *
from .cloud import *
Expand Down
20 changes: 10 additions & 10 deletions scratchcommunication/cloud_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ def on_packet(event : Event):
assert event.name == "FROM_CLIENT"
salt = 0
value = event.value.replace("-", "")
msg_data = value.split(".", 1)[0]
msg_data = value.split(".", 1)[0][1:]
msg_type = int(value[0])

# Key fragment

if msg_type == 0:
key_part_id = msg_data[1:6]
key_part_id = msg_data[:5]
assert not key_part_id in self.key_parts
key_part = msg_data[6:]
key_part = msg_data[5:]
self.key_parts[key_part_id] = key_part
if len(self.key_parts) >= 100:
for key_part_id in list(self.key_parts.keys())[:-100]:
Expand All @@ -223,7 +223,7 @@ def on_packet(event : Event):

client = value.split(".", 1)[1][:5]

if not (self._decode(msg_data[1:29]).startswith("_connect") or self._decode(msg_data[1:29]).startswith("_safe_connect:")) and client in self.clients and not self.clients[client].secure:
if not (self._decode(msg_data[:28]).startswith("_connect") or self._decode(msg_data[:28]).startswith("_safe_connect:")) and client in self.clients and not self.clients[client].secure:
event.emit("non_secure_message_part", client=self.clients[client], decoded=self._decode(msg_data), raw=msg_data)
self.clients[client].current_msg.add(msg_data)
self.clients[client].event = event
Expand All @@ -237,14 +237,14 @@ def on_packet(event : Event):

# Secure message part

if not (self._decode(msg_data[1:29]).startswith("_connect") or self._decode(msg_data[1:29]).startswith("_safe_connect:")) and client in self.clients and self.clients[client].secure:
if not (self._decode(msg_data[:28]).startswith("_connect") or self._decode(msg_data[:28]).startswith("_safe_connect:")) and client in self.clients and self.clients[client].secure:
salt = int(msg_data[-15:]) / 100
assert salt > self.last_timestamp, "Invalid salt(too little)"
assert salt < time.time() + 30, "Invalid salt(too big)"
self.last_timestamp = salt
self.clients[client].current_msg.add(" "+self.clients[client].encrypter.decrypt(self._decode(msg_data[1:-15]), msg_data[-15:]))
self.clients[client].current_msg.add(self.clients[client].encrypter.decrypt(self._decode(msg_data[:-15]), msg_data[-15:]))
self.clients[client].event = event
event.emit("secure_message_part", client=self.clients[client], decoded=self.clients[client].encrypter.decrypt(self._decode(msg_data[1:-15]), msg_data[-15:]), raw=msg_data)
event.emit("secure_message_part", client=self.clients[client], decoded=self.clients[client].encrypter.decrypt(self._decode(msg_data[:-15]), msg_data[-15:]), raw=msg_data)
assert not "-" in event.value
self.clients[client].current_msg.finalize(decode=False)
event.emit("secure_message", client=self.clients[client], content=self.clients[client].current_msg.message)
Expand All @@ -256,13 +256,13 @@ def on_packet(event : Event):
# New secure user

key = None
if self._decode(msg_data[1:29]).startswith("_safe_connect:"):
if self._decode(msg_data[:28]).startswith("_safe_connect:"):
assert self.security
salt = int(msg_data[-15:]) / 100
assert salt > self.last_timestamp, "Invalid salt(too little)"
assert salt < time.time() + 30, "Invalid salt(too big)"
self.last_timestamp = salt
key_parts = [self.key_parts.get("".join(key_part)) for key_part in batched(msg_data[29:-15], 5)]
key_parts = [self.key_parts.get("".join(key_part)) for key_part in batched(msg_data[28:-15], 5)]
assert not None in key_parts
c_key = "".join(key_parts)
key = self._decrypt_key(c_key)
Expand Down Expand Up @@ -487,7 +487,7 @@ def __init__(self, message : str = "", complete : bool = False):
self.complete = complete

def add(self, data):
self.message += data[1:]
self.message += data

def finalize(self, decode : bool = True):
if decode:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with open("README.md", encoding="utf-8") as f:
long_description = f.read()

VERSION = '2.14.3'
VERSION = '2.14.4'

setup(
name='scratchcommunication',
Expand Down

0 comments on commit ab225a1

Please sign in to comment.