From 9a2896bed272a1db54520a5179d7c8872c5eb6e0 Mon Sep 17 00:00:00 2001 From: pavetok Date: Fri, 25 Apr 2014 23:00:41 +0400 Subject: [PATCH 1/4] added "update_client_protocol" method --- src/Rammbock/core.py | 5 +++++ src/Rammbock/networking.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/Rammbock/core.py b/src/Rammbock/core.py index a1edf4c..83fd116 100644 --- a/src/Rammbock/core.py +++ b/src/Rammbock/core.py @@ -206,6 +206,11 @@ def get_client_protocol(self, name=None): """ return self._clients.get(name).protocol_name or '' + def update_client_protocol(self, client, protocol): + protocol = self._get_protocol(protocol) + client = self._clients.get(client) + client.set_protocol(protocol) + def accept_connection(self, name=None, alias=None): """Accepts a connection to server identified by `name` or the latest server if `name` is empty. diff --git a/src/Rammbock/networking.py b/src/Rammbock/networking.py index 2fe28e3..b4d35c8 100644 --- a/src/Rammbock/networking.py +++ b/src/Rammbock/networking.py @@ -306,6 +306,9 @@ def connect_to(self, server_ip, server_port): self._is_connected = True return self + def set_protocol(self, protocol): + self._protocol = protocol + class UDPClient(_Client, _UDPNode): pass From 890b7cab956164997950d3b02491d91076350958 Mon Sep 17 00:00:00 2001 From: "Pavel.Vetokhin" Date: Mon, 28 Apr 2014 15:53:19 +0400 Subject: [PATCH 2/4] fixed "update_client_protocol" method --- src/Rammbock/core.py | 10 +++++++++- src/Rammbock/networking.py | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Rammbock/core.py b/src/Rammbock/core.py index 83fd116..f34b6bd 100644 --- a/src/Rammbock/core.py +++ b/src/Rammbock/core.py @@ -206,10 +206,18 @@ def get_client_protocol(self, name=None): """ return self._clients.get(name).protocol_name or '' - def update_client_protocol(self, client, protocol): + def update_client_protocol(self, protocol, client=None): + """Updates client protocol. If client is not + given then update the latest client. + + Examples: + | Update client protocol | protocol_name | + | Update client protocol | protocol_name | client_name | + """ protocol = self._get_protocol(protocol) client = self._clients.get(client) client.set_protocol(protocol) + client.update_message_stream() def accept_connection(self, name=None, alias=None): """Accepts a connection to server identified by `name` or the latest diff --git a/src/Rammbock/networking.py b/src/Rammbock/networking.py index b4d35c8..53d5740 100644 --- a/src/Rammbock/networking.py +++ b/src/Rammbock/networking.py @@ -309,6 +309,9 @@ def connect_to(self, server_ip, server_port): def set_protocol(self, protocol): self._protocol = protocol + def update_message_stream(self): + self._message_stream = self._get_message_stream() + class UDPClient(_Client, _UDPNode): pass From 0620ec424ce5cd8dd76b05a1f1302534343cdcf1 Mon Sep 17 00:00:00 2001 From: "Pavel.Vetokhin" Date: Wed, 4 Jun 2014 11:49:27 +0400 Subject: [PATCH 3/4] sending messages with null values --- src/Rammbock/templates/primitives.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Rammbock/templates/primitives.py b/src/Rammbock/templates/primitives.py index b7c2e1a..5a6351c 100644 --- a/src/Rammbock/templates/primitives.py +++ b/src/Rammbock/templates/primitives.py @@ -137,7 +137,7 @@ def __init__(self, length, name, default_value=None, align=None): self.length = Length(length, align) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) length, aligned_length = self.length.decode_lengths(message) binary = to_bin_of_length(length, value) binary = binary[::-1] if little_endian else binary @@ -162,7 +162,7 @@ def _get_int_value(self, message, value): return to_twos_comp(value, bin_len) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) value = self._get_int_value(message, value) return UInt._encode_value(self, value, message, little_endian) @@ -202,7 +202,7 @@ def __init__(self, length, name, default_value=None): raise AssertionError('Binary field length must be static. Length: %s' % length) def _encode_value(self, value, message, little_endian=False): - self._raise_error_if_no_value(value, message) + # self._raise_error_if_no_value(value, message) minimum_binary = to_bin(value) length, aligned = self.length.decode_lengths(message, len(minimum_binary)) binary = to_bin_of_length(self._byte_length(length), value) From 136e2fc0fa1e2b65cdb03c1bf89fa96f554b16e2 Mon Sep 17 00:00:00 2001 From: "Pavel.Vetokhin" Date: Thu, 5 Jun 2014 09:49:31 +0400 Subject: [PATCH 4/4] added is_client method --- src/Rammbock/core.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Rammbock/core.py b/src/Rammbock/core.py index f34b6bd..4a79e82 100644 --- a/src/Rammbock/core.py +++ b/src/Rammbock/core.py @@ -193,6 +193,14 @@ def _start_client(self, client_class, ip=None, port=None, name=None, timeout=Non client.set_own_ip_and_port(ip=ip, port=port) return self._clients.add(client, name) + def _is_client(self, client_name): + client_exist = True + try: + self._clients.get_with_name(client_name) + except KeyError: + client_exist = False + return client_exist + def _get_protocol(self, protocol): try: protocol = self._protocols[protocol] if protocol else None