Ejemplo n.º 1
0
 public Task BroadcastAsync <T>(T packet, IBroadcastRule rule) where T : IPacket
 {
     lock (_locker)
     {
         return(Task.WhenAll(_players.Select(s => Task.Run(() => rule != null && rule.Match(s) ? s.SendPacketAsync(packet) : Task.CompletedTask))));
     }
 }
Ejemplo n.º 2
0
 public Task BroadcastAsync(IEnumerable <IPacket> packets, IBroadcastRule rule)
 {
     lock (_locker)
     {
         return(Task.WhenAll(_players.Select(s => Task.Run(() => rule != null && rule.Match(s) ? s.SendPacketsAsync(packets) : Task.CompletedTask))));
     }
 }
Ejemplo n.º 3
0
 private List <Task> BroadcastAsyncHere(IEnumerable <IPacket> packets, IBroadcastRule rule)
 {
     return(PlayerEntities.Select(s =>
                                  Task.Run(() =>
                                           rule == null || rule.Match(s.Value)
                 ? s.Value.Session.SendPacketsAsync(packets)
                 : Task.CompletedTask)).ToList());
 }
Ejemplo n.º 4
0
        public Task BroadcastAsync(IEnumerable <IPacket> packets, IBroadcastRule rule, Grid fromHere, byte chunkDistance = 0)
        {
            //var tempTaskList = BroadcastAsyncHere(packets, rule);

            if (chunkDistance == 0)
            {
                return(Task.WhenAll(BroadcastAsyncHere(packets, rule)));
            }

            List <Task> tempTaskList = new List <Task>();

            foreach (var grid in GridHelper.GetNonEqualGridsByDistanceOriginAndDestination(chunkDistance, fromHere, Id))
            {
                if (Map.Chunks.TryGetValue(grid, out var chunk))
                {
                    tempTaskList.Add(chunk.BroadcastAsync(packets, rule));
                }
            }

            return(Task.WhenAll(tempTaskList));
        }
Ejemplo n.º 5
0
        public Task BroadcastAsync <T>(IEnumerable <T> packets, IBroadcastRule rule, byte chunkDistance = 0) where T : IPacket
        {
            //var tempTaskList = BroadcastAsyncHere(packets, rule);

            if (chunkDistance == 0)
            {
                return(Task.WhenAll(BroadcastAsyncHere(packets, rule)));
            }

            List <Task> tempTaskList = new List <Task>();

            foreach (var grid in GridHelper.GetGridsByDistanceAndOrigin(chunkDistance, Id))
            {
                if (Map.Chunks.TryGetValue(grid, out var chunk))
                {
                    tempTaskList.Add(chunk.BroadcastAsync(packets, rule));
                }
            }

            return(Task.WhenAll(tempTaskList));
        }
Ejemplo n.º 6
0
 private static List <Task> BroadcastAsyncHere <T>(IEnumerable <T> packets, IBroadcastRule rule) where T : IPacket
 {
     return(BroadcastAsyncHere(packets, rule));
 }
Ejemplo n.º 7
0
 public Task BroadcastAsync(IEnumerable <IPacket> packets, IBroadcastRule rule)
 {
     return(Task.WhenAll(PlayerEntities.Select(s =>
                                               Task.Run(() => rule == null || rule.Match(s.Value) ? s.Value.Session.SendPacketsAsync(packets) : Task.CompletedTask))));
 }
Ejemplo n.º 8
0
 public Task BroadcastAsync <T>(T packet, IBroadcastRule rule) where T : IPacket
 {
     return(Task.WhenAll(PlayerEntities.Select(s =>
                                               Task.Run(() => rule == null || rule.Match(s.Value) ? s.Value.Session.SendPacketAsync(packet) : Task.CompletedTask))));
 }