Esempio n. 1
0
 protected override Task RunAsync(UdpResult result, UdpShared udpshared)
 {
     return(Task.Factory.StartNew(() =>
     {
         uint eid;
         if (udpshared.entities.TryGetValue(result.endPoint, out eid))
         {
             ushort func = result.byteStream.GetUShort();
             //DebugUtility.Log($"DealMsg::func::{func}");
             using (IPay paylodable = udpshared.msgMaper.TakeMsgClone(func))
             {
                 if (paylodable == null)
                 {
                     return;
                 }
                 //DebugUtility.Log($"DealMsg::func::{func}");
                 paylodable.GetFrom(result.byteStream);
                 ADealer dealer = udpshared.msgMaper.TakeDealer(func);
                 Entity entity;
                 if (udpshared.world.TryGetEntity(eid, out entity))
                 {
                     dealer?.Run(entity, paylodable);
                 }
             }
             //DebugUtility.Log($"DealMsg:: id::{entity.Id}");
         }
     }));
 }
Esempio n. 2
0
        private async void receve(Entity entity)
        {
            var websocket = entity.Get <NetworkData>().webSocket;

            while (true)
            {
                if (!world.HasEntity(entity.Id))
                {
                    return;
                }
                ByteStream stream = null;
                try
                {
                    byte[] rec = await websocket.ReceiveAsync().ConfigureAwait(false);

                    stream = ByteStream.Take();
                    stream.Set(rec);
                    ushort func = stream.GetUShort();
                    using (IPay paylodable = maper.TakeMsgClone(func))
                    {
                        if (paylodable == null)
                        {
                            return;
                        }
                        paylodable.GetFrom(stream);
                        ADealer dealer = maper.TakeDealer(func);
                        dealer?.Run(entity, paylodable);
                    }
                }
                catch (Exception e)
                {
                    DebugUtility.Error($"Error::{e}");
                }
                finally
                {
                    if (stream != null)
                    {
                        ByteStream.Return(stream);
                    }
                }
            }
        }