Add ServerBlip.Handle handle

This commit is contained in:
Sardelka
2022-07-04 09:54:43 +08:00
parent 8ac5cc40c1
commit 44f106fd0c
2 changed files with 31 additions and 15 deletions

View File

@ -10,6 +10,23 @@ namespace RageCoop.Client
{
internal static partial class Networking
{
private static Func<byte, BitReader, object> _resolveHandle = (t, reader) =>
{
switch (t)
{
case 50:
return EntityPool.ServerProps[reader.ReadInt()].MainProp?.Handle;
case 51:
return EntityPool.GetPedByID(reader.ReadInt())?.MainPed?.Handle;
case 52:
return EntityPool.GetVehicleByID(reader.ReadInt())?.MainVehicle?.Handle;
case 60:
return EntityPool.ServerBlips[reader.ReadInt()].Handle;
default:
throw new ArgumentException("Cannot resolve server side argument: "+t);
}
};
private static AutoResetEvent PublicKeyReceived=new AutoResetEvent(false);
private static Dictionary<int, Action<PacketType, byte[]>> PendingResponses = new Dictionary<int, Action<PacketType, byte[]>>();
@ -248,20 +265,7 @@ namespace RageCoop.Client
break;
case PacketType.CustomEvent:
{
Packets.CustomEvent packet = new Packets.CustomEvent((t, reader) =>
{
switch (t)
{
case 50:
return EntityPool.ServerProps[reader.ReadInt()].MainProp?.Handle;
case 51:
return EntityPool.GetPedByID(reader.ReadInt())?.MainPed?.Handle;
case 52:
return EntityPool.GetVehicleByID(reader.ReadInt())?.MainVehicle?.Handle;
default:
throw new ArgumentException("Cannot resolve server side argument: "+t);
}
});
Packets.CustomEvent packet = new Packets.CustomEvent(_resolveHandle);
packet.Unpack(data);
Scripting.API.Events.InvokeCustomEventReceived(packet);
}

View File

@ -126,7 +126,6 @@ namespace RageCoop.Server
internal ServerProp(Server server) : base(server) { }
/// <summary>
/// Delete this prop
/// </summary>
@ -219,6 +218,18 @@ namespace RageCoop.Server
Server = server;
}
/// <summary>
/// Pass this as an argument in CustomEvent or NativeCall to convert this object to handle at client side.
/// </summary>
public Tuple<byte, byte[]> Handle
{
get
{
return new(60, BitConverter.GetBytes(ID));
}
}
/// <summary>
/// Network ID (not handle!)
/// </summary>
@ -292,6 +303,7 @@ namespace RageCoop.Server
Server.Entities.RemoveServerBlip(ID);
}
private bool _bouncing=false;
internal void Update()
{