From f1c95d03f81bd755982c6ac31b0d9757f466aeee Mon Sep 17 00:00:00 2001 From: Swann Martinez Date: Thu, 4 Jun 2020 18:38:03 +0200 Subject: [PATCH] feat: initial work to run a dedicated server --- multi_user/libs/replication | 2 +- multi_user/operators.py | 25 +++++++++++++------------ multi_user/preferences.py | 14 ++++++++++---- multi_user/ui.py | 15 +++++++++++---- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/multi_user/libs/replication b/multi_user/libs/replication index f8901d4..e380d73 160000 --- a/multi_user/libs/replication +++ b/multi_user/libs/replication @@ -1 +1 @@ -Subproject commit f8901d458c1051f362639a9c0248c22b4fb1861f +Subproject commit e380d73b03e0ba88aa57005c232961bb1ef5d382 diff --git a/multi_user/operators.py b/multi_user/operators.py index c758abb..f7e240e 100644 --- a/multi_user/operators.py +++ b/multi_user/operators.py @@ -115,32 +115,34 @@ class SessionStartOperator(bpy.types.Operator): default_strategy=settings.right_strategy) # Host a session - if self.host: + if self.host or runtime_settings.admin: # Scene setup if settings.start_empty: utils.clean_scene() + + for scene in bpy.data.scenes: + scene_uuid = client.add(scene) + client.commit(scene_uuid) + pwd = runtime_settings.password if runtime_settings.password else None + if self.host: try: - for scene in bpy.data.scenes: - scene_uuid = client.add(scene) - client.commit(scene_uuid) - client.host( id=settings.username, address=settings.ip, port=settings.port, ipc_port=settings.ipc_port, - timeout=settings.connection_timeout + timeout=settings.connection_timeout, + password=pwd ) except Exception as e: self.report({'ERROR'}, repr(e)) logging.error(f"Error: {e}") - finally: - runtime_settings.is_admin = True # Join a session else: - utils.clean_scene() + if pwd is None: + utils.clean_scene() try: client.connect( @@ -148,13 +150,12 @@ class SessionStartOperator(bpy.types.Operator): address=settings.ip, port=settings.port, ipc_port=settings.ipc_port, - timeout=settings.connection_timeout + timeout=settings.connection_timeout, + password=pwd ) except Exception as e: self.report({'ERROR'}, repr(e)) logging.error(f"Error: {e}") - finally: - runtime_settings.is_admin = False # Background client updates service #TODO: Refactoring diff --git a/multi_user/preferences.py b/multi_user/preferences.py index fea52eb..e42517c 100644 --- a/multi_user/preferences.py +++ b/multi_user/preferences.py @@ -340,10 +340,6 @@ class SessionUser(bpy.types.PropertyGroup): class SessionProps(bpy.types.PropertyGroup): - is_admin: bpy.props.BoolProperty( - name="is_admin", - default=False - ) session_mode: bpy.props.EnumProperty( name='session_mode', description='session mode', @@ -384,6 +380,16 @@ class SessionProps(bpy.types.PropertyGroup): description='Show only owned datablocks', default=True ) + admin: bpy.props.BoolProperty( + name="admin", + description='Connect as admin', + default=False + ) + password: bpy.props.StringProperty( + name="password", + description='Session password', + subtype='PASSWORD' + ) user_snap_running: bpy.props.BoolProperty( default=False ) diff --git a/multi_user/ui.py b/multi_user/ui.py index 802aa87..11e9c3d 100644 --- a/multi_user/ui.py +++ b/multi_user/ui.py @@ -180,14 +180,22 @@ class SESSION_PT_settings_network(bpy.types.Panel): row = box.row() row.label(text="Timeout (ms):") row.prop(settings, "connection_timeout", text="") - + row = box.row() if runtime_settings.session_mode == 'HOST': + row.label(text="Password:") + row.prop(runtime_settings, "password", text="") row = box.row() row.label(text="Start empty:") row.prop(settings, "start_empty", text="") row = box.row() row.operator("session.start", text="HOST").host = True else: + row.prop(runtime_settings, "admin", text='Connect as admin' ,icon='DISCLOSURE_TRI_DOWN' if runtime_settings.admin + else 'DISCLOSURE_TRI_RIGHT') + if runtime_settings.admin: + row = box.row() + row.label(text="Password:") + row.prop(runtime_settings, "password", text="") row = box.row() row.operator("session.start", text="CONNECT").host = False @@ -425,9 +433,8 @@ def draw_property(context, parent, property_uuid, level=0): # Operations - have_right_to_modify = runtime_settings.is_admin or \ - item.owner == settings.username or \ - item.owner == RP_COMMON + have_right_to_modify = item.owner == settings.username or \ + item.owner == RP_COMMON if have_right_to_modify: detail_item_box.operator(