2020-11-17 20:58:28 -08:00
|
|
|
/*************************************************************************
|
|
|
|
|
* ModernUO *
|
2023-08-09 09:09:26 -07:00
|
|
|
* Copyright 2019-2023 - ModernUO Development Team *
|
2020-11-17 20:58:28 -08:00
|
|
|
* Email: hi@modernuo.com *
|
|
|
|
|
* File: OutgoingMapPackets.cs *
|
|
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System.Buffers;
|
2021-01-04 23:47:20 -08:00
|
|
|
using System.Runtime.CompilerServices;
|
2020-11-17 20:58:28 -08:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
namespace Server.Network;
|
|
|
|
|
|
|
|
|
|
public static class OutgoingMapPackets
|
2020-11-17 20:58:28 -08:00
|
|
|
{
|
2022-02-27 00:13:49 -08:00
|
|
|
private static byte[] _mapPatchesPacket = new byte[41];
|
|
|
|
|
|
|
|
|
|
public static void SendMapPatches(this NetState ns)
|
2020-11-17 20:58:28 -08:00
|
|
|
{
|
2022-02-27 00:13:49 -08:00
|
|
|
if (ns.CannotSendPackets())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-22 23:35:18 -07:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
if (_mapPatchesPacket[0] == 0)
|
2020-11-17 20:58:28 -08:00
|
|
|
{
|
2022-02-27 00:13:49 -08:00
|
|
|
var writer = new SpanWriter(_mapPatchesPacket);
|
|
|
|
|
writer.Write((byte)0xBF); // Packet ID
|
|
|
|
|
writer.Write((ushort)41); // Length
|
|
|
|
|
writer.Write((ushort)0x18); // Subpacket
|
|
|
|
|
writer.Write(4);
|
2020-11-17 20:58:28 -08:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
for (int i = 0; i < 4; i++)
|
2021-02-14 16:06:49 -08:00
|
|
|
{
|
2022-02-27 00:13:49 -08:00
|
|
|
var map = Map.Maps[i];
|
2020-11-17 20:58:28 -08:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
writer.Write(map?.Tiles.Patch.StaticBlocks ?? 0);
|
|
|
|
|
writer.Write(map?.Tiles.Patch.LandBlocks ?? 0);
|
2021-02-14 16:06:49 -08:00
|
|
|
}
|
2020-11-17 20:58:28 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
ns.Send(_mapPatchesPacket);
|
|
|
|
|
}
|
2020-11-17 20:58:28 -08:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static void SendInvalidMap(this NetState ns) => ns?.Send(stackalloc byte[] { 0xC6 });
|
2020-11-17 20:58:28 -08:00
|
|
|
|
2022-02-27 00:13:49 -08:00
|
|
|
public static void SendMapChange(this NetState ns, Map map)
|
|
|
|
|
{
|
|
|
|
|
if (map == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2020-11-17 20:58:28 -08:00
|
|
|
}
|
2022-02-27 00:13:49 -08:00
|
|
|
|
|
|
|
|
ns?.Send(stackalloc byte[] { 0xBF, 0x00, 0x06, 0x00, 0x08, (byte)map.MapID });
|
2020-11-17 20:58:28 -08:00
|
|
|
}
|
|
|
|
|
}
|