Ejemplo n.º 1
0
        public static void Process(ulong sender, params object[] args)
        {
            //Debug.Log("On Rec Connect Req Response");
            //Core.net.OnConnectRequestResponse(sender, (int)args[0], (int)args[1]);
            int prefabId   = (int)args[0];
            int networkId  = (int)args[1];
            int owner      = (int)args[2];
            int controller = (int)args[3];

            NetworkEntity e = Core.net.GetEntity(owner, networkId);

            //we send this event to an enity from client->entity controller if the client hasn't seen an update in a *while*
            //essentially the client is asking "what's going on" because they need to either take control, destroy the entity, or do something else.
            int scopeStatus = 0;

            if (e == null)
            {
                //this client is no longer has this entity.  It was probably destroyed because out of scope.
                scopeStatus = 2; //But since B sent this message, B still cares about the entity, so B should take control of this immediately
            }
            else
            {
                //float p = e.Priority(sender, e.transform.position.x, e.transform.position.y, e.transform.position.z);
                float p = e.PriorityCaller(sender, true);
                if (p <= 0f)
                {
                    //the sender is no longer getting updates because they are outside of priority (fell out of scope)
                    //they should destroy locally on B, because B shouldn't care about it anymore
                    scopeStatus = 1;
                }
                else
                {
                    //the sender is still in scope, but isn't getting updates. Must mean there is just no data to be sent (static, non-moving entity?)
                    //B should do nothing.  Keep their entity around because it's still *important* and in scope.
                    scopeStatus = 0;
                }
            }

            //the only other thing that can happen is if the receiver of this event is already disconnected.  in which case this
            //event will never get processed.  So the sender of this event needs to keep a timer (or listen for disconnects)
            //If the event never comes through B should take control of this entity because they obviously still care about it.

            Core.net.QueueMessage(sender, Core.net.GetMessageCode("EntityScopeResponse"), prefabId, networkId, owner, controller, scopeStatus);
        }