feat: initial work to run a dedicated server

This commit is contained in:
Swann Martinez
2020-06-04 18:38:03 +02:00
parent b55faf2d1c
commit f1c95d03f8
4 changed files with 35 additions and 21 deletions

View File

@ -115,32 +115,34 @@ class SessionStartOperator(bpy.types.Operator):
default_strategy=settings.right_strategy) default_strategy=settings.right_strategy)
# Host a session # Host a session
if self.host: if self.host or runtime_settings.admin:
# Scene setup # Scene setup
if settings.start_empty: if settings.start_empty:
utils.clean_scene() utils.clean_scene()
try: for scene in bpy.data.scenes:
for scene in bpy.data.scenes: scene_uuid = client.add(scene)
scene_uuid = client.add(scene) client.commit(scene_uuid)
client.commit(scene_uuid)
pwd = runtime_settings.password if runtime_settings.password else None
if self.host:
try:
client.host( client.host(
id=settings.username, id=settings.username,
address=settings.ip, address=settings.ip,
port=settings.port, port=settings.port,
ipc_port=settings.ipc_port, ipc_port=settings.ipc_port,
timeout=settings.connection_timeout timeout=settings.connection_timeout,
password=pwd
) )
except Exception as e: except Exception as e:
self.report({'ERROR'}, repr(e)) self.report({'ERROR'}, repr(e))
logging.error(f"Error: {e}") logging.error(f"Error: {e}")
finally:
runtime_settings.is_admin = True
# Join a session # Join a session
else: else:
utils.clean_scene() if pwd is None:
utils.clean_scene()
try: try:
client.connect( client.connect(
@ -148,13 +150,12 @@ class SessionStartOperator(bpy.types.Operator):
address=settings.ip, address=settings.ip,
port=settings.port, port=settings.port,
ipc_port=settings.ipc_port, ipc_port=settings.ipc_port,
timeout=settings.connection_timeout timeout=settings.connection_timeout,
password=pwd
) )
except Exception as e: except Exception as e:
self.report({'ERROR'}, repr(e)) self.report({'ERROR'}, repr(e))
logging.error(f"Error: {e}") logging.error(f"Error: {e}")
finally:
runtime_settings.is_admin = False
# Background client updates service # Background client updates service
#TODO: Refactoring #TODO: Refactoring

View File

@ -340,10 +340,6 @@ class SessionUser(bpy.types.PropertyGroup):
class SessionProps(bpy.types.PropertyGroup): class SessionProps(bpy.types.PropertyGroup):
is_admin: bpy.props.BoolProperty(
name="is_admin",
default=False
)
session_mode: bpy.props.EnumProperty( session_mode: bpy.props.EnumProperty(
name='session_mode', name='session_mode',
description='session mode', description='session mode',
@ -384,6 +380,16 @@ class SessionProps(bpy.types.PropertyGroup):
description='Show only owned datablocks', description='Show only owned datablocks',
default=True 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( user_snap_running: bpy.props.BoolProperty(
default=False default=False
) )

View File

@ -180,14 +180,22 @@ class SESSION_PT_settings_network(bpy.types.Panel):
row = box.row() row = box.row()
row.label(text="Timeout (ms):") row.label(text="Timeout (ms):")
row.prop(settings, "connection_timeout", text="") row.prop(settings, "connection_timeout", text="")
row = box.row()
if runtime_settings.session_mode == 'HOST': if runtime_settings.session_mode == 'HOST':
row.label(text="Password:")
row.prop(runtime_settings, "password", text="")
row = box.row() row = box.row()
row.label(text="Start empty:") row.label(text="Start empty:")
row.prop(settings, "start_empty", text="") row.prop(settings, "start_empty", text="")
row = box.row() row = box.row()
row.operator("session.start", text="HOST").host = True row.operator("session.start", text="HOST").host = True
else: 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 = box.row()
row.operator("session.start", text="CONNECT").host = False row.operator("session.start", text="CONNECT").host = False
@ -425,9 +433,8 @@ def draw_property(context, parent, property_uuid, level=0):
# Operations # Operations
have_right_to_modify = runtime_settings.is_admin or \ have_right_to_modify = item.owner == settings.username or \
item.owner == settings.username or \ item.owner == RP_COMMON
item.owner == RP_COMMON
if have_right_to_modify: if have_right_to_modify:
detail_item_box.operator( detail_item_box.operator(