Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented CLIENT_OBJECT_SET_FIELD and STATESERVER_OBJECT_DELETE_RAM messages #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Artifacts
*.pyc
build/
dist/
astron.egg-info/
# Misc
.idea/
.project
.pydevproject
.gitignore
*.log*
*.db
9 changes: 6 additions & 3 deletions astron/distributed_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def init(self):
print("DO created without custom init(): %d (%s)" % (self.do_id, str(type(self))))

def delete(self):
"""Overwrite this to execute code just before a views deletion."""
"""Overwrite this to execute code just before a views' deletion."""
# FIXME: Redup in object_repository if the docstring is actually accurate.
print("DO deleted: %d" % (self.do_id, ))

def update_field(self, sender, field_id, dgi):
def update_field(self, field_id, dgi, sender=None):
"""Handles incoming SET_FIELD updates."""
decoded_args = []
field = self.dclass.get_field(self.field_id_to_dmethod_id[field_id])
Expand All @@ -80,7 +80,10 @@ def update_field(self, sender, field_id, dgi):
else:
decoded_args.append(self.type_unpacker[arg_type](dgi))
# print("Updating field %s in %d with args %s" % (field.name(), self.do_id, str(decoded_args)))
getattr(self, field.name())(sender, *decoded_args)
if sender:
getattr(self, field.name())(sender, *decoded_args)
return
getattr(self, field.name())(*decoded_args) # update field on client (CA doesn't send sender)

def send_update(self, field_name, *values):
"""Handles outgoing SET_FIELD updates."""
Expand Down
12 changes: 9 additions & 3 deletions astron/object_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def __init__(self, dcfilename=default_dcfilename, stateserver = 400000, dbss = 4
self.msg_type = MSG_TYPE_INTERNAL
self.handlers.update({
servermsg.STATESERVER_OBJECT_SET_FIELD : self.handle_STATESERVER_OBJECT_SET_FIELD,
servermsg.STATESERVER_OBJECT_DELETE_RAM : self.handle_STATESERVER_OBJECT_DELETE_RAM,
servermsg.STATESERVER_OBJECT_CHANGING_LOCATION : self.handle_STATESERVER_OBJECT_CHANGING_LOCATION,
servermsg.STATESERVER_OBJECT_GET_AI : self.handle_STATESERVER_OBJECT_GET_AI,
servermsg.STATESERVER_OBJECT_ENTER_LOCATION_WITH_REQUIRED: self.handle_STATESERVER_OBJECT_ENTER_LOCATION_WITH_REQUIRED,
Expand Down Expand Up @@ -379,7 +380,12 @@ def send_STATESERVER_OBJECT_GET_ZONE_OBJECTS(self, context, parent_id, zone_id):
def handle_STATESERVER_OBJECT_SET_FIELD(self, dgi, sender, recipients):
do_id = dgi.read_uint32()
field_id = dgi.read_uint16()
self.distributed_objects[do_id].update_field(sender, field_id, dgi)
self.distributed_objects[do_id].update_field(field_id, dgi, sender=sender)

def handle_STATESERVER_OBJECT_DELETE_RAM(self, dgi, sender, recipients):
do_id = dgi.read_uint32()
dist_obj = self.distributed_objects[do_id]
dist_obj.delete()

def handle_STATESERVER_OBJECT_CHANGING_LOCATION(self, dgi, sender, recipients):
print("handle_STATESERVER_OBJECT_CHANGING_LOCATION", sender, recipients)
Expand Down Expand Up @@ -627,8 +633,8 @@ def handle_CLIENT_DONE_INTEREST_RESP(self, dgi):
def handle_CLIENT_OBJECT_SET_FIELD(self, dgi):
do_id = dgi.read_uint32()
field_id = dgi.read_uint16()
# FIXME: There's still the value in the dgi
# FIXME: Implement
dist_obj = self.distributed_objects[do_id]
dist_obj.update_field(field_id, dgi)

def handle_CLIENT_OBJECT_SET_FIELDS(self, dgi):
do_id = dgi.read_uint32()
Expand Down