Fix component for mp models
This commit is contained in:
@ -182,7 +182,7 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
Ticked++;
|
Ticked++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (MainChat.Focused)
|
if (MainChat.Focused)
|
||||||
|
@ -84,7 +84,6 @@ namespace RageCoop.Client
|
|||||||
{
|
{
|
||||||
if (IsPlayer)
|
if (IsPlayer)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Username=="N/A")
|
if (Username=="N/A")
|
||||||
{
|
{
|
||||||
var p = PlayerList.GetPlayer(ID);
|
var p = PlayerList.GetPlayer(ID);
|
||||||
@ -290,9 +289,9 @@ namespace RageCoop.Client
|
|||||||
|
|
||||||
private void SetClothes()
|
private void SetClothes()
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < 11; i++)
|
for (byte i = 0; i < 12; i++)
|
||||||
{
|
{
|
||||||
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, i, (int)Clothes[i], (int)Clothes[i+11], (int)Clothes[i+22]);
|
Function.Call(Hash.SET_PED_COMPONENT_VARIATION, MainPed.Handle, i, (int)Clothes[i], (int)Clothes[i+12], (int)Clothes[i+24]);
|
||||||
}
|
}
|
||||||
_lastClothes = Clothes;
|
_lastClothes = Clothes;
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ namespace RageCoop.Client
|
|||||||
// Not sure whether component will always be lesser than 255, whatever...
|
// Not sure whether component will always be lesser than 255, whatever...
|
||||||
public static byte[] GetPedClothes(this Ped ped)
|
public static byte[] GetPedClothes(this Ped ped)
|
||||||
{
|
{
|
||||||
var result = new byte[33];
|
var result = new byte[36];
|
||||||
for (byte i = 0; i < 11; i++)
|
for (byte i = 0; i < 12; i++)
|
||||||
{
|
{
|
||||||
result[i]=(byte)Function.Call<short>(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
|
result[i]=(byte)Function.Call<short>(Hash.GET_PED_DRAWABLE_VARIATION, ped.Handle, i);
|
||||||
result[i+11]=(byte)Function.Call<short>(Hash.GET_PED_TEXTURE_VARIATION, ped.Handle, i);
|
result[i+12]=(byte)Function.Call<short>(Hash.GET_PED_TEXTURE_VARIATION, ped.Handle, i);
|
||||||
result[i+22]=(byte)Function.Call<short>(Hash.GET_PED_PALETTE_VARIATION, ped.Handle, i);
|
result[i+24]=(byte)Function.Call<short>(Hash.GET_PED_PALETTE_VARIATION, ped.Handle, i);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,13 @@ namespace RageCoop.Core
|
|||||||
CurrentIndex += index;
|
CurrentIndex += index;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
public string ReadString()
|
||||||
|
{
|
||||||
|
var len = ReadInt();
|
||||||
|
string value = Encoding.UTF8.GetString(ResultArray.Skip(CurrentIndex).Take(len).ToArray());
|
||||||
|
CurrentIndex += len;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3 ReadVector3()
|
public Vector3 ReadVector3()
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
namespace RageCoop.Core
|
namespace RageCoop.Core
|
||||||
{
|
{
|
||||||
@ -32,6 +33,8 @@ namespace RageCoop.Core
|
|||||||
return (0x08, BitConverter.GetBytes((float)obj));
|
return (0x08, BitConverter.GetBytes((float)obj));
|
||||||
case bool _:
|
case bool _:
|
||||||
return (0x09, BitConverter.GetBytes((bool)obj));
|
return (0x09, BitConverter.GetBytes((bool)obj));
|
||||||
|
case string _:
|
||||||
|
return (0x10, (obj as string).GetBytesWithLength());
|
||||||
default:
|
default:
|
||||||
return (0x0, null);
|
return (0x0, null);
|
||||||
}
|
}
|
||||||
@ -73,11 +76,31 @@ namespace RageCoop.Core
|
|||||||
{
|
{
|
||||||
bytes.AddRange(BitConverter.GetBytes(i));
|
bytes.AddRange(BitConverter.GetBytes(i));
|
||||||
}
|
}
|
||||||
|
public static void AddString(this List<byte> bytes, string s)
|
||||||
|
{
|
||||||
|
var sb = Encoding.UTF8.GetBytes(s);
|
||||||
|
bytes.AddInt(sb.Length);
|
||||||
|
bytes.AddRange(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetHash(string s)
|
||||||
|
{
|
||||||
|
MD5 md5Hasher = MD5.Create();
|
||||||
|
var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(s));
|
||||||
|
return BitConverter.ToInt32(hashed, 0);
|
||||||
|
}
|
||||||
public static byte[] GetBytes(this string s)
|
public static byte[] GetBytes(this string s)
|
||||||
{
|
{
|
||||||
return Encoding.UTF8.GetBytes(s);
|
return Encoding.UTF8.GetBytes(s);
|
||||||
}
|
}
|
||||||
|
public static byte[] GetBytesWithLength(this string s)
|
||||||
|
{
|
||||||
|
var data = new List<byte>(100);
|
||||||
|
var sb = Encoding.UTF8.GetBytes(s);
|
||||||
|
data.AddInt(sb.Length);
|
||||||
|
data.AddRange(sb);
|
||||||
|
return data.ToArray();
|
||||||
|
}
|
||||||
public static string GetString(this byte[] data)
|
public static string GetString(this byte[] data)
|
||||||
{
|
{
|
||||||
return Encoding.UTF8.GetString(data);
|
return Encoding.UTF8.GetString(data);
|
||||||
|
@ -24,9 +24,16 @@ namespace RageCoop.Core.Logging
|
|||||||
|
|
||||||
public Logger(bool overwrite=true)
|
public Logger(bool overwrite=true)
|
||||||
{
|
{
|
||||||
if (File.Exists(LogPath)&&overwrite) { File.Delete(LogPath); }
|
|
||||||
LoggerThread=new Thread(() =>
|
LoggerThread=new Thread(() =>
|
||||||
{
|
{
|
||||||
|
if (!UseConsole)
|
||||||
|
{
|
||||||
|
while (LogPath==default)
|
||||||
|
{
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
if (File.Exists(LogPath)&&overwrite) { File.Delete(LogPath); }
|
||||||
|
}
|
||||||
while (!Stopping)
|
while (!Stopping)
|
||||||
{
|
{
|
||||||
Flush();
|
Flush();
|
||||||
|
84
RageCoop.Core/Packets/CustomEvent.cs
Normal file
84
RageCoop.Core/Packets/CustomEvent.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Lidgren.Network;
|
||||||
|
namespace RageCoop.Core
|
||||||
|
{
|
||||||
|
public partial class Packets
|
||||||
|
{
|
||||||
|
|
||||||
|
public class CustomEvent : Packet
|
||||||
|
{
|
||||||
|
public int Hash { get; set; }
|
||||||
|
public List<object> Args { get; set; }
|
||||||
|
|
||||||
|
public override void Pack(NetOutgoingMessage message)
|
||||||
|
{
|
||||||
|
message.Write((byte)PacketTypes.CustomEvent);
|
||||||
|
|
||||||
|
List<byte> result = new List<byte>();
|
||||||
|
result.AddInt(Hash);
|
||||||
|
result.AddInt(Args.Count);
|
||||||
|
(byte, byte[]) tup;
|
||||||
|
foreach (var arg in Args)
|
||||||
|
{
|
||||||
|
tup=CoreUtils.GetBytesFromObject(arg);
|
||||||
|
if (tup.Item2==null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Object of type {arg.GetType()} is not supported");
|
||||||
|
}
|
||||||
|
result.Add(tup.Item1);
|
||||||
|
result.AddRange(tup.Item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
message.Write(result.Count);
|
||||||
|
message.Write(result.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Unpack(byte[] array)
|
||||||
|
{
|
||||||
|
BitReader reader = new BitReader(array);
|
||||||
|
|
||||||
|
Hash = reader.ReadInt();
|
||||||
|
var len=reader.ReadInt();
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
byte argType = reader.ReadByte();
|
||||||
|
switch (argType)
|
||||||
|
{
|
||||||
|
case 0x01:
|
||||||
|
Args.Add(reader.ReadByte());
|
||||||
|
break;
|
||||||
|
case 0x02:
|
||||||
|
Args.Add(reader.ReadShort());
|
||||||
|
break;
|
||||||
|
case 0x03:
|
||||||
|
Args.Add(reader.ReadUShort());
|
||||||
|
break;
|
||||||
|
case 0x04:
|
||||||
|
Args.Add(reader.ReadInt());
|
||||||
|
break;
|
||||||
|
case 0x05:
|
||||||
|
Args.Add(reader.ReadUInt());
|
||||||
|
break;
|
||||||
|
case 0x06:
|
||||||
|
Args.Add(reader.ReadLong());
|
||||||
|
break;
|
||||||
|
case 0x07:
|
||||||
|
Args.Add(reader.ReadULong());
|
||||||
|
break;
|
||||||
|
case 0x08:
|
||||||
|
Args.Add(reader.ReadFloat());
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
Args.Add(reader.ReadBool());
|
||||||
|
break;
|
||||||
|
case 0x10:
|
||||||
|
Args.Add(reader.ReadString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,112 +7,6 @@ using GTA.Math;
|
|||||||
|
|
||||||
namespace RageCoop.Core
|
namespace RageCoop.Core
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public struct LVector3
|
|
||||||
{
|
|
||||||
#region CLIENT-ONLY
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public Vector3 ToVector()
|
|
||||||
{
|
|
||||||
return new Vector3(X, Y, Z);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
#region SERVER-ONLY
|
|
||||||
public float Length() => (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
|
|
||||||
public static LVector3 Subtract(LVector3 pos1, LVector3 pos2) { return new LVector3(pos1.X - pos2.X, pos1.Y - pos2.Y, pos1.Z - pos2.Z); }
|
|
||||||
public static bool Equals(LVector3 value1, LVector3 value2) => value1.X == value2.X && value1.Y == value2.Y && value1.Z == value2.Z;
|
|
||||||
public static LVector3 operator /(LVector3 value1, float value2)
|
|
||||||
{
|
|
||||||
float num = 1f / value2;
|
|
||||||
return new LVector3(value1.X * num, value1.Y * num, value1.Z * num);
|
|
||||||
}
|
|
||||||
public static LVector3 operator -(LVector3 left, LVector3 right)
|
|
||||||
{
|
|
||||||
return new LVector3(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
|
||||||
}
|
|
||||||
public static LVector3 operator -(LVector3 value)
|
|
||||||
{
|
|
||||||
return default(LVector3) - value;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public LVector3(float X, float Y, float Z)
|
|
||||||
{
|
|
||||||
this.X = X;
|
|
||||||
this.Y = Y;
|
|
||||||
this.Z = Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float X { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float Y { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float Z { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public struct LQuaternion
|
|
||||||
{
|
|
||||||
#region CLIENT-ONLY
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public Quaternion ToQuaternion()
|
|
||||||
{
|
|
||||||
return new Quaternion(X, Y, Z, W);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public LQuaternion(float X, float Y, float Z, float W)
|
|
||||||
{
|
|
||||||
this.X = X;
|
|
||||||
this.Y = Y;
|
|
||||||
this.Z = Z;
|
|
||||||
this.W = W;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float X { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float Y { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float Z { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public float W { get; set; }
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public enum PacketTypes:byte
|
public enum PacketTypes:byte
|
||||||
{
|
{
|
||||||
Handshake=0,
|
Handshake=0,
|
||||||
@ -131,7 +25,6 @@ namespace RageCoop.Core
|
|||||||
FileTransferComplete=17,
|
FileTransferComplete=17,
|
||||||
|
|
||||||
CustomEvent = 18,
|
CustomEvent = 18,
|
||||||
InvokeCustomEvent=19,
|
|
||||||
#region Sync
|
#region Sync
|
||||||
|
|
||||||
#region INTERVAL
|
#region INTERVAL
|
||||||
@ -290,86 +183,6 @@ namespace RageCoop.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomEvent : Packet
|
|
||||||
{
|
|
||||||
public int Hash { get; set; }
|
|
||||||
public byte[] Data { get; set; }
|
|
||||||
|
|
||||||
public override void Pack(NetOutgoingMessage message)
|
|
||||||
{
|
|
||||||
message.Write((byte)PacketTypes.CustomEvent);
|
|
||||||
|
|
||||||
List<byte> byteArray = new List<byte>();
|
|
||||||
|
|
||||||
|
|
||||||
// Write hash
|
|
||||||
byteArray.AddInt(Hash);
|
|
||||||
|
|
||||||
// Write data
|
|
||||||
byteArray.AddRange(Data);
|
|
||||||
|
|
||||||
byte[] result = byteArray.ToArray();
|
|
||||||
|
|
||||||
message.Write(result.Length);
|
|
||||||
message.Write(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Unpack(byte[] array)
|
|
||||||
{
|
|
||||||
BitReader reader = new BitReader(array);
|
|
||||||
|
|
||||||
Hash = reader.ReadInt();
|
|
||||||
|
|
||||||
Data=reader.ReadByteArray(array.Length-4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class InvokeCustomEvent : Packet
|
|
||||||
{
|
|
||||||
public int Hash { get; set; }
|
|
||||||
public int[] Targets { get; set; }
|
|
||||||
public byte[] Data { get; set; }
|
|
||||||
|
|
||||||
public override void Pack(NetOutgoingMessage message)
|
|
||||||
{
|
|
||||||
message.Write((byte)PacketTypes.InvokeCustomEvent);
|
|
||||||
|
|
||||||
List<byte> byteArray = new List<byte>();
|
|
||||||
|
|
||||||
|
|
||||||
// Write hash
|
|
||||||
byteArray.AddInt(Hash);
|
|
||||||
|
|
||||||
// Write targets
|
|
||||||
byteArray.AddInt(Targets.Length);
|
|
||||||
foreach (var target in Targets)
|
|
||||||
{
|
|
||||||
byteArray.AddInt(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write data
|
|
||||||
byteArray.AddRange(Data);
|
|
||||||
|
|
||||||
byte[] result = byteArray.ToArray();
|
|
||||||
|
|
||||||
message.Write(result.Length);
|
|
||||||
message.Write(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Unpack(byte[] array)
|
|
||||||
{
|
|
||||||
BitReader reader = new BitReader(array);
|
|
||||||
|
|
||||||
Hash = reader.ReadInt();
|
|
||||||
|
|
||||||
Targets = new int[reader.ReadInt()];
|
|
||||||
for(int i = 0; i < Targets.Length; i++)
|
|
||||||
{
|
|
||||||
Targets[i]=reader.ReadInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
Data=reader.ReadByteArray(array.Length-4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#region ===== NATIVECALL =====
|
#region ===== NATIVECALL =====
|
||||||
public class NativeCall : Packet
|
public class NativeCall : Packet
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ namespace RageCoop.Core
|
|||||||
ModelHash = reader.ReadInt();
|
ModelHash = reader.ReadInt();
|
||||||
|
|
||||||
// Read player clothes
|
// Read player clothes
|
||||||
Clothes =reader.ReadByteArray(33);
|
Clothes =reader.ReadByteArray(36);
|
||||||
|
|
||||||
// Read ped OwnerID
|
// Read ped OwnerID
|
||||||
OwnerID= reader.ReadInt();
|
OwnerID= reader.ReadInt();
|
||||||
|
@ -30,4 +30,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Scripting\Events\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace RageCoop.Core.Scripting.Events
|
|
||||||
{
|
|
||||||
public class OnVehicleSpawned:CustomEvent
|
|
||||||
{
|
|
||||||
public int VehicleID { get; set; }
|
|
||||||
public override int EventID { get; set; } = Hasher.Hash("RageCoop.OnVehicleSpawned");
|
|
||||||
|
|
||||||
public override byte[] Serialize()
|
|
||||||
{
|
|
||||||
return BitConverter.GetBytes(VehicleID);
|
|
||||||
}
|
|
||||||
public override void Deserialize(byte[] data)
|
|
||||||
{
|
|
||||||
VehicleID= BitConverter.ToInt32(data, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
|
|
||||||
namespace RageCoop.Core.Scripting.Events
|
|
||||||
{
|
|
||||||
public interface ICustomEvent
|
|
||||||
{
|
|
||||||
int EventID { get; set; }
|
|
||||||
byte[] Serialize();
|
|
||||||
void Deserialize(byte[] data);
|
|
||||||
}
|
|
||||||
public abstract class CustomEvent:ICustomEvent
|
|
||||||
{
|
|
||||||
public abstract int EventID { get; set; }
|
|
||||||
public abstract byte[] Serialize();
|
|
||||||
public abstract void Deserialize(byte[] data);
|
|
||||||
}
|
|
||||||
public static class Hasher
|
|
||||||
{
|
|
||||||
public static int Hash(string s)
|
|
||||||
{
|
|
||||||
MD5 md5Hasher = MD5.Create();
|
|
||||||
var hashed = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(s));
|
|
||||||
return BitConverter.ToInt32(hashed, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using RageCoop.Core;
|
using RageCoop.Core;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
using GTA.Math;
|
using GTA.Math;
|
||||||
using RageCoop.Core.Scripting.Events;
|
using RageCoop.Core.Scripting;
|
||||||
|
|
||||||
namespace RageCoop.Server
|
namespace RageCoop.Server
|
||||||
{
|
{
|
||||||
@ -186,7 +186,7 @@ namespace RageCoop.Server
|
|||||||
Server.MainNetServer.SendMessage(outgoingMessage, userConnection, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Default);
|
Server.MainNetServer.SendMessage(outgoingMessage, userConnection, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendCustomEvent(int id,byte[] data)
|
public void SendCustomEvent(int id,List<object> args)
|
||||||
{
|
{
|
||||||
if (!IsReady)
|
if (!IsReady)
|
||||||
{
|
{
|
||||||
@ -201,7 +201,7 @@ namespace RageCoop.Server
|
|||||||
new Packets.CustomEvent()
|
new Packets.CustomEvent()
|
||||||
{
|
{
|
||||||
Hash=id,
|
Hash=id,
|
||||||
Data=data
|
Args=args
|
||||||
}.Pack(outgoingMessage);
|
}.Pack(outgoingMessage);
|
||||||
Server.MainNetServer.SendMessage(outgoingMessage, Connection, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Event);
|
Server.MainNetServer.SendMessage(outgoingMessage, Connection, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.Event);
|
||||||
|
|
||||||
|
@ -5,13 +5,18 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
using RageCoop.Core;
|
using RageCoop.Core;
|
||||||
using RageCoop.Core.Scripting.Events;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace RageCoop.Server.Scripting
|
namespace RageCoop.Server.Scripting
|
||||||
{
|
{
|
||||||
public static class API
|
public static class API
|
||||||
{
|
{
|
||||||
|
#region INTERNAL
|
||||||
|
internal static void InvokeCustomEvent(int hash,List<object> args)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
public static class Events
|
public static class Events
|
||||||
{
|
{
|
||||||
#region DELEGATES
|
#region DELEGATES
|
||||||
@ -194,26 +199,17 @@ namespace RageCoop.Server.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void SendCustomEvent(int eventID, byte[] data, IEnumerable<Client> recepients)
|
public static void TriggerCustomEvent(int eventHash,List<object> args,List<Client> targets=null)
|
||||||
{
|
{
|
||||||
foreach(var c in recepients)
|
targets ??= new(Server.Clients.Values);
|
||||||
|
var p = new Packets.CustomEvent()
|
||||||
{
|
{
|
||||||
c.SendCustomEvent(eventID,data);
|
Args=args,
|
||||||
}
|
Hash=eventHash
|
||||||
}
|
};
|
||||||
public static void SendCustomEvent(CustomEvent e, Client[] recepients)
|
foreach(var c in targets)
|
||||||
{
|
|
||||||
SendCustomEvent(e.EventID, e.Serialize(), recepients);
|
|
||||||
}
|
|
||||||
public static void SendCustomEvent(int eventID, byte[] data, int[] recepients)
|
|
||||||
{
|
|
||||||
if (recepients.Length==0)
|
|
||||||
{
|
{
|
||||||
SendCustomEvent(eventID,data,Server.Clients.Values);
|
Server.Send(p,c,ConnectionChannel.Event,NetDeliveryMethod.ReliableOrdered);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SendCustomEvent(eventID,data, Server.Clients.Values.Where(x => recepients.Contains(x.Player.PedID)).ToArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -328,13 +328,6 @@ namespace RageCoop.Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PacketTypes.InvokeCustomEvent:
|
|
||||||
{
|
|
||||||
var p = new Packets.InvokeCustomEvent();
|
|
||||||
p.Unpack(data);
|
|
||||||
API.SendCustomEvent(p.Hash,p.Data,p.Targets);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PacketTypes.FileTransferComplete:
|
case PacketTypes.FileTransferComplete:
|
||||||
{
|
{
|
||||||
Packets.FileTransferComplete packet = new Packets.FileTransferComplete();
|
Packets.FileTransferComplete packet = new Packets.FileTransferComplete();
|
||||||
|
Reference in New Issue
Block a user