示例#1
0
        public static void Send(IEnumerable <int> Who, int IgnoreIndex,
                                int Size, int X, int Y, int TileChangeType = 0)
        {
            if (Who == null)
            {
                return;
            }

            List <RemoteClient> clients = new List <RemoteClient>();

            foreach (int i in Who)
            {
                if (i == IgnoreIndex)
                {
                    continue;
                }
                if ((i < 0) || (i >= Main.maxPlayers))
                {
                    throw new ArgumentOutOfRangeException(nameof(Who));
                }
                RemoteClient client = Netplay.Clients[i];
                if (NetMessage.buffer[i].broadcast && client.IsConnected() && client.SectionRange(Size, X, Y))
                {
                    clients.Add(client);
                }
            }
            if (clients.Count == 0)
            {
                return;
            }

            byte[] data;
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.BaseStream.Position = 2L;
                    bw.Write((byte)PacketTypes.TileSendSquare);
                    WriteTiles(bw, Size, X, Y, TileChangeType);
                    long position = bw.BaseStream.Position;
                    bw.BaseStream.Position = 0L;
                    bw.Write((short)position);
                    bw.BaseStream.Position = position;
                    data = ms.ToArray();
                }

            foreach (RemoteClient client in clients)
            {
                try
                {
                    if (FakeManager.NetSendBytes(client, data, 0, data.Length))
                    {
                        continue;
                    }

                    client.Socket.AsyncSend(data, 0, data.Length,
                                            new SocketSendCallback(client.ServerWriteCallBack), null);
                }
                catch (IOException) { }
            }