예제 #1
0
        private void _UpdateSetProperty(long entity_id, int property, byte[] buffer)
        {
            IGhost ghost = _FindGhost(entity_id);

            if (ghost == null)
            {
                return;
            }

            MemberMap    map  = _Protocol.GetMemberMap();
            PropertyInfo info = map.GetProperty(property);

            object    value    = _Serializer.Deserialize(buffer);
            object    instance = ghost.GetInstance();
            Type      type     = _InterfaceProvider.Find(info.DeclaringType);
            FieldInfo field    = type.GetField("_" + info.Name, BindingFlags.Instance | BindingFlags.Public);

            if (field != null)
            {
                object      filedValue = field.GetValue(instance);
                IAccessable updateable = filedValue as IAccessable;
                updateable.Set(value);


                PackageSetPropertyDone pkg = new PackageSetPropertyDone();
                pkg.EntityId = entity_id;
                pkg.Property = property;
                _Requester.Request(ClientToServerOpCode.UpdateProperty, pkg.ToBuffer(_Serializer));
            }
        }
예제 #2
0
        internal void AddSupply(PropertyInfo info, PassageCallback passage)
        {
            long passageId = _NotifierPassage.RegisterSupply(passage);

            PackageNotifierEvent package = new PackageNotifierEvent();

            package.Entity   = _Ghost.GetID();
            package.Property = _Protocol.GetMemberMap().GetProperty(info);
            package.Passage  = passageId;
            _Requester.Request(ClientToServerOpCode.AddNotifierSupply, package.ToBuffer(_Protocol.GetSerialize()));
        }
예제 #3
0
        internal void Add(System.Reflection.EventInfo info, long handler)
        {
            MemberMap map = _Protocol.GetMemberMap();

            Serialization.ISerializer serialize = _Protocol.GetSerialize();

            PackageAddEvent package = new PackageAddEvent();

            package.Entity  = _Ghost.GetID();
            package.Event   = map.GetEvent(info);
            package.Handler = handler;
            _Requester.Request(ClientToServerOpCode.AddEvent, package.ToBuffer(serialize));
        }
예제 #4
0
        public void Update()
        {
            var ids = (from e in _Exists
                       where e.Value.IsAlive == false
                       select e.Key).ToList();

            foreach (var id in ids)
            {
                /*var args = new Dictionary<byte, byte[]>();
                 *              args[0] = id.ToByteArray();*/
                _Exists.Remove(id);

                if (_Requester == null)
                {
                    continue;
                }

                var data = new PackageRelease
                {
                    EntityId = id
                };

                // TODO:
                _Requester.Request(ClientToServerOpCode.Release, null);
            }
        }
예제 #5
0
        public void Update()
        {
            var ids = new List <Guid>();

            foreach (var e in _Exists)
            {
                if (e.Value.IsAlive == false)
                {
                    ids.Add(e.Key);
                }
            }

            foreach (var id in ids)
            {
                /*var args = new Dictionary<byte, byte[]>();
                 * args[0] = id.ToByteArray();*/


                _Exists.Remove(id);


                if (_Requester != null)
                {
                    var data = new PackageRelease();
                    data.EntityId = id;
                    _Requester.Request(ClientToServerOpCode.Release, data.ToBuffer(_Serializer));
                }
            }
        }
예제 #6
0
        public void Update()
        {
            List <long> ids = new List <long>();

            foreach (KeyValuePair <long, WeakReference <IGhost> > e in _Exists)
            {
                IGhost target = null;


                if (!e.Value.TryGetTarget(out target))
                {
                    ids.Add(e.Key);
                }
            }

            foreach (long id in ids)
            {
                _Exists.Remove(id);


                if (_Requester != null)
                {
                    PackageRelease data = new PackageRelease();
                    data.EntityId = id;
                    _Requester.Request(ClientToServerOpCode.Release, data.ToBuffer(_Serializer));
                }
            }
        }
예제 #7
0
        private void _PingTimerElapsed(object sender, ElapsedEventArgs e)
        {
            lock (_Sync)
            {
                if (_PingTimer != null)
                {
                    _PingTimeCounter = new TimeCounter();
                    _Requester.Request(ClientToServerOpCode.Ping, new byte[0]);
                }
            }

            _EndPing();
        }
예제 #8
0
        public void Run(MethodInfo info, object[] args, IValue return_value)
        {
            var map       = _Protocol.GetMemberMap();
            var serialize = _Protocol.GetSerialize();
            var method    = map.GetMethod(info);

            var package = new PackageCallMethod();

            package.EntityId     = _Ghost.GetID();
            package.MethodId     = method;
            package.MethodParams = args.Select(arg => serialize.Serialize(arg)).ToArray();

            if (return_value != null)
            {
                package.ReturnId = _ReturnValueQueue.PushReturnValue(return_value);
            }

            _Requester.Request(ClientToServerOpCode.CallMethod, package.ToBuffer(serialize));
        }