Stuff
This commit is contained in:
@ -150,8 +150,8 @@ namespace CoopClient
|
||||
}
|
||||
else if (!Game.Player.Character.IsInVehicle())
|
||||
{
|
||||
Vehicle veh = World.GetNearbyVehicles(Game.Player.Character, 5f).First();
|
||||
if (veh != null)
|
||||
Vehicle veh = World.GetNearbyVehicles(Game.Player.Character, 5f).FirstOrDefault();
|
||||
if (veh != default)
|
||||
{
|
||||
for (int i = 0; i < veh.PassengerCapacity; i++)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using Lidgren.Network;
|
||||
|
||||
using GTA;
|
||||
using GTA.Native;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CoopClient
|
||||
{
|
||||
@ -217,6 +218,11 @@ namespace CoopClient
|
||||
ChatMessagePacket chatMessagePacket = (ChatMessagePacket)packet;
|
||||
Main.MainChat.AddMessage(chatMessagePacket.Username, chatMessagePacket.Message);
|
||||
break;
|
||||
case (byte)PacketTypes.NativeCallPacket:
|
||||
packet = new NativeCallPacket();
|
||||
packet.NetIncomingMessageToPacket(message);
|
||||
DecodeNativeCall((NativeCallPacket)packet);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NetIncomingMessageType.ConnectionLatencyUpdated:
|
||||
@ -417,6 +423,42 @@ namespace CoopClient
|
||||
player.VehicleDead = (packet.Flag.Value & (byte)VehicleDataFlags.IsDead) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void DecodeNativeCall(NativeCallPacket packet)
|
||||
{
|
||||
List<InputArgument> arguments = new List<InputArgument>();
|
||||
|
||||
packet.Args.ForEach(arg =>
|
||||
{
|
||||
Type typeOf = arg.GetType();
|
||||
|
||||
if (typeOf == typeof(IntArgument))
|
||||
{
|
||||
arguments.Add(((IntArgument)arg).Data);
|
||||
}
|
||||
else if (typeOf == typeof(BoolArgument))
|
||||
{
|
||||
arguments.Add(((BoolArgument)arg).Data);
|
||||
}
|
||||
else if (typeOf == typeof(FloatArgument))
|
||||
{
|
||||
arguments.Add(((FloatArgument)arg).Data);
|
||||
}
|
||||
else if (typeOf == typeof(LVector3Argument))
|
||||
{
|
||||
arguments.Add(((LVector3Argument)arg).Data.X);
|
||||
arguments.Add(((LVector3Argument)arg).Data.Y);
|
||||
arguments.Add(((LVector3Argument)arg).Data.Z);
|
||||
}
|
||||
else
|
||||
{
|
||||
GTA.UI.Notification.Show("[DecodeNativeCall][" + packet.Hash + "]: Type of argument not found!");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Function.Call((Hash)packet.Hash, arguments.ToArray());
|
||||
}
|
||||
#endregion // -- PLAYER --
|
||||
|
||||
#region -- NPC --
|
||||
|
@ -125,7 +125,8 @@ namespace CoopClient
|
||||
LightSyncPlayerVehPacket,
|
||||
FullSyncNpcPacket,
|
||||
FullSyncNpcVehPacket,
|
||||
ChatMessagePacket
|
||||
ChatMessagePacket,
|
||||
NativeCallPacket
|
||||
}
|
||||
|
||||
[Flags]
|
||||
@ -586,6 +587,73 @@ namespace CoopClient
|
||||
Message = data.Message;
|
||||
}
|
||||
}
|
||||
|
||||
#region ===== NATIVECALL =====
|
||||
[ProtoContract]
|
||||
class NativeCallPacket : Packet
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public ulong Hash { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public List<NativeArgument> Args { get; set; }
|
||||
|
||||
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
|
||||
{
|
||||
message.Write((byte)PacketTypes.NativeCallPacket);
|
||||
|
||||
byte[] result = CoopSerializer.Serialize(this);
|
||||
|
||||
message.Write(result.Length);
|
||||
message.Write(result);
|
||||
}
|
||||
|
||||
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
|
||||
{
|
||||
int len = message.ReadInt32();
|
||||
|
||||
NativeCallPacket data = CoopSerializer.Deserialize<NativeCallPacket>(message.ReadBytes(len));
|
||||
|
||||
Hash = data.Hash;
|
||||
Args = data.Args;
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
[ProtoInclude(1, typeof(IntArgument))]
|
||||
[ProtoInclude(2, typeof(BoolArgument))]
|
||||
[ProtoInclude(3, typeof(FloatArgument))]
|
||||
[ProtoInclude(4, typeof(LVector3Argument))]
|
||||
class NativeArgument { }
|
||||
|
||||
[ProtoContract]
|
||||
class IntArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public int Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class BoolArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public bool Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class FloatArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public float Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class LVector3Argument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public LVector3 Data { get; set; }
|
||||
}
|
||||
#endregion // ===== NATIVECALL =====
|
||||
#endregion
|
||||
|
||||
#region -- NPC --
|
||||
|
@ -15,7 +15,7 @@ namespace FirstGameMode
|
||||
[Command("inrange")]
|
||||
public static void InRangeCommand(CommandContext ctx)
|
||||
{
|
||||
if (ctx.Player.Ped.IsInRangeOf(new LVector3(0f, 0f, 75f), 7f))
|
||||
if (ctx.Player.IsInRangeOf(new LVector3(0f, 0f, 75f), 7f))
|
||||
{
|
||||
API.SendChatMessageToPlayer(ctx.Player.Username, "You are in range! :)");
|
||||
}
|
||||
@ -42,5 +42,30 @@ namespace FirstGameMode
|
||||
|
||||
API.KickPlayerByUsername(ctx.Args[0], ctx.Args.Skip(1).ToArray());
|
||||
}
|
||||
|
||||
[Command("setweather")]
|
||||
public static void SetWeatherCommand(CommandContext ctx)
|
||||
{
|
||||
int hours, minutes, seconds;
|
||||
|
||||
if (ctx.Args.Length < 3)
|
||||
{
|
||||
API.SendChatMessageToPlayer(ctx.Player.Username, "Please use \"/setweather <HOURS> <MINUTES> <SECONDS>\"");
|
||||
return;
|
||||
}
|
||||
else if (!int.TryParse(ctx.Args[0], out hours) || !int.TryParse(ctx.Args[1], out minutes) || !int.TryParse(ctx.Args[2], out seconds))
|
||||
{
|
||||
API.SendChatMessageToPlayer(ctx.Player.Username, "Please use \"/setweather <NUMBER> <NUMBER> <NUMBER>\"");
|
||||
return;
|
||||
}
|
||||
|
||||
API.SendNativeCallToPlayer(ctx.Player.Username, 0x47C3B5848C3E45D8, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
[Command("upp")]
|
||||
public static void UpdatePlayerPositionCommand(CommandContext ctx)
|
||||
{
|
||||
Main.ShowPlayerPosition = !Main.ShowPlayerPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="CoopServer">
|
||||
<HintPath>..\..\Server\bin\Release\net5.0\CoopServer.dll</HintPath>
|
||||
<HintPath>..\..\Server\bin\Debug\net5.0\CoopServer.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Timers;
|
||||
|
||||
using CoopServer;
|
||||
@ -10,6 +11,8 @@ namespace FirstGameMode
|
||||
{
|
||||
private static readonly Timer RunningSinceTimer = new() { Interval = 1000 };
|
||||
private static int RunningSince = 0;
|
||||
public static bool ShowPlayerPosition = false;
|
||||
private static List<string> SecretLocation = new List<string>();
|
||||
|
||||
public Main()
|
||||
{
|
||||
@ -19,6 +22,7 @@ namespace FirstGameMode
|
||||
API.OnPlayerConnected += OnPlayerConnected;
|
||||
API.OnPlayerDisconnected += OnPlayerDisconnected;
|
||||
API.OnChatMessage += OnChatMessage;
|
||||
API.OnPlayerPositionUpdate += OnPlayerPositionUpdate;
|
||||
|
||||
API.RegisterCommand("running", RunningCommand);
|
||||
API.RegisterCommands<Commands>();
|
||||
@ -51,5 +55,18 @@ namespace FirstGameMode
|
||||
|
||||
API.SendChatMessageToAll(message, username);
|
||||
}
|
||||
|
||||
public static void OnPlayerPositionUpdate(EntitiesPlayer player)
|
||||
{
|
||||
if (ShowPlayerPosition)
|
||||
{
|
||||
if (!SecretLocation.Contains(player.Username) && player.IsInRangeOf(new LVector3(0, 0, 75), 7f))
|
||||
{
|
||||
API.SendChatMessageToPlayer(player.Username, "Hey! you find this secret location!");
|
||||
SecretLocation.Add(player.Username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
namespace CoopServer.Entities
|
||||
{
|
||||
public struct EntitiesPed
|
||||
{
|
||||
public LVector3 Position { get; set; }
|
||||
|
||||
public bool IsInRangeOf(LVector3 position, float distance)
|
||||
{
|
||||
return LVector3.Subtract(Position, position).Length() < distance;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,30 @@
|
||||
public string SocialClubName { get; set; }
|
||||
public string Username { get; set; }
|
||||
public float Latency { get; set; }
|
||||
public EntitiesPed Ped = new();
|
||||
private LVector3 LastPosition = new();
|
||||
private LVector3 CurrentPosition = new();
|
||||
public LVector3 Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return CurrentPosition;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
LastPosition = CurrentPosition;
|
||||
CurrentPosition = value;
|
||||
|
||||
if (Server.GameMode != null && !LVector3.Equals(CurrentPosition, LastPosition))
|
||||
{
|
||||
Server.GameMode.API.InvokePlayerPositionUpdate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInRangeOf(LVector3 position, float distance)
|
||||
{
|
||||
return LVector3.Subtract(Position, position).Length() < distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ using System.IO;
|
||||
|
||||
namespace CoopServer
|
||||
{
|
||||
class Logging
|
||||
public class Logging
|
||||
{
|
||||
private static readonly object _lock = new();
|
||||
private static readonly object Lock = new();
|
||||
|
||||
public static void Info(string message)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (Lock)
|
||||
{
|
||||
string msg = string.Format("[{0}] [INFO] {1}", Date(), message);
|
||||
|
||||
@ -24,7 +24,7 @@ namespace CoopServer
|
||||
|
||||
public static void Warning(string message)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (Lock)
|
||||
{
|
||||
string msg = string.Format("[{0}] [WARNING] {1}", Date(), message);
|
||||
|
||||
@ -39,7 +39,7 @@ namespace CoopServer
|
||||
|
||||
public static void Error(string message)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (Lock)
|
||||
{
|
||||
string msg = string.Format("[{0}] [ERROR] {1}", Date(), message);
|
||||
|
||||
@ -59,7 +59,7 @@ namespace CoopServer
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
lock (Lock)
|
||||
{
|
||||
string msg = string.Format("[{0}] [DEBUG] {1}", Date(), message);
|
||||
|
||||
|
@ -29,6 +29,7 @@ namespace CoopServer
|
||||
#region SERVER-ONLY
|
||||
public float Length() => (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
|
||||
public static LVector3 Subtract(LVector3 pos1, LVector3 pos2) => new(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;
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -67,7 +68,8 @@ namespace CoopServer
|
||||
LightSyncPlayerVehPacket,
|
||||
FullSyncNpcPacket,
|
||||
FullSyncNpcVehPacket,
|
||||
ChatMessagePacket
|
||||
ChatMessagePacket,
|
||||
NativeCallPacket
|
||||
}
|
||||
|
||||
[Flags]
|
||||
@ -518,6 +520,73 @@ namespace CoopServer
|
||||
Message = data.Message;
|
||||
}
|
||||
}
|
||||
|
||||
#region ===== NATIVECALL =====
|
||||
[ProtoContract]
|
||||
class NativeCallPacket : Packet
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public ulong Hash { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public List<NativeArgument> Args { get; set; }
|
||||
|
||||
public override void PacketToNetOutGoingMessage(NetOutgoingMessage message)
|
||||
{
|
||||
message.Write((byte)PacketTypes.NativeCallPacket);
|
||||
|
||||
byte[] result = CoopSerializer.Serialize(this);
|
||||
|
||||
message.Write(result.Length);
|
||||
message.Write(result);
|
||||
}
|
||||
|
||||
public override void NetIncomingMessageToPacket(NetIncomingMessage message)
|
||||
{
|
||||
int len = message.ReadInt32();
|
||||
|
||||
NativeCallPacket data = CoopSerializer.Deserialize<NativeCallPacket>(message.ReadBytes(len));
|
||||
|
||||
Hash = data.Hash;
|
||||
Args = data.Args;
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
[ProtoInclude(1, typeof(IntArgument))]
|
||||
[ProtoInclude(2, typeof(BoolArgument))]
|
||||
[ProtoInclude(3, typeof(FloatArgument))]
|
||||
[ProtoInclude(4, typeof(LVector3Argument))]
|
||||
class NativeArgument { }
|
||||
|
||||
[ProtoContract]
|
||||
class IntArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public int Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class BoolArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public bool Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class FloatArgument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public float Data { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class LVector3Argument : NativeArgument
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public LVector3 Data { get; set; }
|
||||
}
|
||||
#endregion // ===== NATIVECALL =====
|
||||
#endregion
|
||||
|
||||
#region -- NPC --
|
||||
|
@ -31,7 +31,7 @@ namespace CoopServer
|
||||
|
||||
public static readonly Dictionary<long, EntitiesPlayer> Players = new();
|
||||
|
||||
private static ServerScript GameMode;
|
||||
public static ServerScript GameMode;
|
||||
public static readonly Dictionary<Command, Action<CommandContext>> Commands = new Dictionary<Command, Action<CommandContext>>();
|
||||
|
||||
public Server()
|
||||
@ -476,7 +476,7 @@ namespace CoopServer
|
||||
|
||||
if (GameMode != null)
|
||||
{
|
||||
GameMode.API.InvokePlayerConnect(Players[packet.Player]);
|
||||
GameMode.API.InvokePlayerConnected(Players[packet.Player]);
|
||||
}
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(local);
|
||||
@ -518,7 +518,7 @@ namespace CoopServer
|
||||
{
|
||||
if (GameMode != null)
|
||||
{
|
||||
GameMode.API.InvokePlayerDisconnect(Players[packet.Player], reason);
|
||||
GameMode.API.InvokePlayerDisconnected(Players[packet.Player]);
|
||||
}
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(packet.Player);
|
||||
@ -536,7 +536,7 @@ namespace CoopServer
|
||||
{
|
||||
EntitiesPlayer player = Players[packet.Extra.Player];
|
||||
|
||||
player.Ped.Position = packet.Extra.Position;
|
||||
player.Position = packet.Extra.Position;
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(packet.Extra.Player);
|
||||
if (playerList.Count == 0)
|
||||
@ -558,7 +558,7 @@ namespace CoopServer
|
||||
{
|
||||
EntitiesPlayer player = Players[packet.Extra.Player];
|
||||
|
||||
player.Ped.Position = packet.Extra.Position;
|
||||
player.Position = packet.Extra.Position;
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(packet.Extra.Player);
|
||||
if (playerList.Count == 0)
|
||||
@ -580,7 +580,7 @@ namespace CoopServer
|
||||
{
|
||||
EntitiesPlayer player = Players[packet.Extra.Player];
|
||||
|
||||
player.Ped.Position = packet.Extra.Position;
|
||||
player.Position = packet.Extra.Position;
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(packet.Extra.Player);
|
||||
if (playerList.Count == 0)
|
||||
@ -602,7 +602,7 @@ namespace CoopServer
|
||||
{
|
||||
EntitiesPlayer player = Players[packet.Extra.Player];
|
||||
|
||||
player.Ped.Position = packet.Extra.Position;
|
||||
player.Position = packet.Extra.Position;
|
||||
|
||||
List<NetConnection> playerList = Util.FilterAllLocal(packet.Extra.Player);
|
||||
if (playerList.Count == 0)
|
||||
|
@ -8,7 +8,7 @@ namespace CoopServer
|
||||
{
|
||||
public abstract class ServerScript
|
||||
{
|
||||
public API API = new();
|
||||
public API API { get; } = new();
|
||||
}
|
||||
|
||||
public class API
|
||||
@ -23,18 +23,19 @@ namespace CoopServer
|
||||
public event ChatEvent OnChatMessage;
|
||||
public event PlayerEvent OnPlayerConnected;
|
||||
public event PlayerEvent OnPlayerDisconnected;
|
||||
public event PlayerEvent OnPlayerPositionUpdate;
|
||||
|
||||
internal void InvokeStart()
|
||||
{
|
||||
OnStart?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void InvokePlayerConnect(Entities.EntitiesPlayer player)
|
||||
internal void InvokePlayerConnected(Entities.EntitiesPlayer player)
|
||||
{
|
||||
OnPlayerConnected?.Invoke(player);
|
||||
}
|
||||
|
||||
internal void InvokePlayerDisconnect(Entities.EntitiesPlayer player, string reason)
|
||||
internal void InvokePlayerDisconnected(Entities.EntitiesPlayer player)
|
||||
{
|
||||
OnPlayerDisconnected?.Invoke(player);
|
||||
}
|
||||
@ -45,40 +46,131 @@ namespace CoopServer
|
||||
OnChatMessage?.Invoke(username, message, args);
|
||||
return args.Cancel;
|
||||
}
|
||||
|
||||
internal void InvokePlayerPositionUpdate(Entities.EntitiesPlayer player)
|
||||
{
|
||||
OnPlayerPositionUpdate?.Invoke(player);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region FUNCTIONS
|
||||
public static void SendNativeCallToAll(ulong hash, params object[] args)
|
||||
{
|
||||
List<NetConnection> connections = Server.MainNetServer.Connections;
|
||||
if (connections.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<NativeArgument> arguments = new();
|
||||
|
||||
foreach (object arg in args)
|
||||
{
|
||||
Type typeOf = arg.GetType();
|
||||
|
||||
if (typeOf == typeof(int))
|
||||
{
|
||||
arguments.Add(new IntArgument() { Data = (int)arg });
|
||||
}
|
||||
else if (typeOf == typeof(bool))
|
||||
{
|
||||
arguments.Add(new BoolArgument() { Data = (bool)arg });
|
||||
}
|
||||
else if (typeOf == typeof(float))
|
||||
{
|
||||
arguments.Add(new FloatArgument() { Data = (float)arg });
|
||||
}
|
||||
else if (typeOf == typeof(LVector3))
|
||||
{
|
||||
arguments.Add(new LVector3Argument() { Data = (LVector3)arg });
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Error("[ServerScript->SendNativeCallToAll(" + hash + ", params object[] args)]: Type of argument not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NativeCallPacket packet = new()
|
||||
{
|
||||
Hash = hash,
|
||||
Args = arguments
|
||||
};
|
||||
|
||||
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
|
||||
packet.PacketToNetOutGoingMessage(outgoingMessage);
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, Server.MainNetServer.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
public static void SendNativeCallToPlayer(string username, ulong hash, params object[] args)
|
||||
{
|
||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||
if (userConnection == null)
|
||||
{
|
||||
Logging.Warning("[ServerScript->SendNativeCallToPlayer(\"" + username + "\", \"" + hash + "\", params object[] args)]: User not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<NativeArgument> arguments = new();
|
||||
|
||||
foreach (object arg in args)
|
||||
{
|
||||
Type typeOf = arg.GetType();
|
||||
|
||||
if (typeOf == typeof(int))
|
||||
{
|
||||
arguments.Add(new IntArgument() { Data = (int)arg });
|
||||
}
|
||||
else if (typeOf == typeof(bool))
|
||||
{
|
||||
arguments.Add(new BoolArgument() { Data = (bool)arg });
|
||||
}
|
||||
else if (typeOf == typeof(float))
|
||||
{
|
||||
arguments.Add(new FloatArgument() { Data = (float)arg });
|
||||
}
|
||||
else if (typeOf == typeof(LVector3))
|
||||
{
|
||||
arguments.Add(new LVector3Argument() { Data = (LVector3)arg });
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Error("[ServerScript->SendNativeCallToAll(" + hash + ", params object[] args)]: Type of argument not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NativeCallPacket packet = new()
|
||||
{
|
||||
Hash = hash,
|
||||
Args = arguments
|
||||
};
|
||||
|
||||
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
|
||||
packet.PacketToNetOutGoingMessage(outgoingMessage);
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, userConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
public static List<long> GetAllConnections()
|
||||
{
|
||||
List<long> result = new();
|
||||
|
||||
lock (Server.MainNetServer.Connections)
|
||||
{
|
||||
Server.MainNetServer.Connections.ForEach(x => result.Add(x.RemoteUniqueIdentifier));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int GetAllPlayersCount()
|
||||
{
|
||||
lock (Server.Players)
|
||||
{
|
||||
return Server.Players.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<long, Entities.EntitiesPlayer> GetAllPlayers()
|
||||
{
|
||||
lock (Server.Players)
|
||||
{
|
||||
return Server.Players;
|
||||
}
|
||||
}
|
||||
|
||||
public static void KickPlayerByUsername(string username, string[] reason)
|
||||
{
|
||||
lock (Server.MainNetServer.Connections)
|
||||
{
|
||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||
if (userConnection == null)
|
||||
@ -89,14 +181,15 @@ namespace CoopServer
|
||||
|
||||
userConnection.Disconnect(string.Join(" ", reason));
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendChatMessageToAll(string message, string username = "Server")
|
||||
{
|
||||
List<NetConnection> connections = Server.MainNetServer.Connections;
|
||||
|
||||
if (connections.Count != 0)
|
||||
if (connections.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ChatMessagePacket packet = new()
|
||||
{
|
||||
Username = username,
|
||||
@ -108,12 +201,7 @@ namespace CoopServer
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, Server.MainNetServer.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
Logging.Info(username + ": " + message);
|
||||
}
|
||||
|
||||
public static void SendChatMessageToPlayer(string username, string message, string from = "Server")
|
||||
{
|
||||
lock (Server.MainNetServer.Connections)
|
||||
{
|
||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||
if (userConnection == null)
|
||||
@ -133,9 +221,6 @@ namespace CoopServer
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, userConnection, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
Logging.Info(from + ": " + message);
|
||||
}
|
||||
|
||||
public static void RegisterCommand(string name, Action<CommandContext> callback)
|
||||
{
|
||||
Server.RegisterCommand(name, callback);
|
||||
|
@ -39,12 +39,12 @@ namespace CoopServer
|
||||
// Return a list of players within range of ...
|
||||
public static List<NetConnection> GetAllInRange(LVector3 position, float range)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.FindAll(e => Server.Players[e.RemoteUniqueIdentifier].Ped.IsInRangeOf(position, range)));
|
||||
return new(Server.MainNetServer.Connections.FindAll(e => Server.Players[e.RemoteUniqueIdentifier].IsInRangeOf(position, range)));
|
||||
}
|
||||
// Return a list of players within range of ... but not the local one
|
||||
public static List<NetConnection> GetAllInRange(LVector3 position, float range, NetConnection local)
|
||||
{
|
||||
return new(Server.MainNetServer.Connections.Where(e => e != local && Server.Players[e.RemoteUniqueIdentifier].Ped.IsInRangeOf(position, range)));
|
||||
return new(Server.MainNetServer.Connections.Where(e => e != local && Server.Players[e.RemoteUniqueIdentifier].IsInRangeOf(position, range)));
|
||||
}
|
||||
|
||||
public static T Read<T>(string file) where T : new()
|
||||
|
Reference in New Issue
Block a user