better
This commit is contained in:
@ -32,7 +32,7 @@ namespace CoopClient.Entities
|
|||||||
{
|
{
|
||||||
long key = localNpcs.ElementAt(i).Key;
|
long key = localNpcs.ElementAt(i).Key;
|
||||||
|
|
||||||
if ((tickCount - localNpcs[key].LastUpdateReceived) > 3500)
|
if ((tickCount - localNpcs[key].LastUpdateReceived) > 3000)
|
||||||
{
|
{
|
||||||
if (localNpcs[key].Character != null && localNpcs[key].Character.Exists() && localNpcs[key].Health > 0)
|
if (localNpcs[key].Character != null && localNpcs[key].Character.Exists() && localNpcs[key].Health > 0)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ namespace CoopClient
|
|||||||
|
|
||||||
Tick += OnTick;
|
Tick += OnTick;
|
||||||
KeyDown += OnKeyDown;
|
KeyDown += OnKeyDown;
|
||||||
Aborted += OnAbort;
|
Aborted += (object sender, EventArgs e) => CleanUp();
|
||||||
|
|
||||||
Util.NativeMemory();
|
Util.NativeMemory();
|
||||||
}
|
}
|
||||||
@ -100,13 +100,15 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((Environment.TickCount - LastDataSend) >= (1000 / 60))
|
if ((Environment.TickCount - LastDataSend) < (1000 / 60))
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MainNetworking.SendPlayerData();
|
MainNetworking.SendPlayerData();
|
||||||
|
|
||||||
LastDataSend = Environment.TickCount;
|
LastDataSend = Environment.TickCount;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
@ -168,11 +170,6 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAbort(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CleanUp()
|
public static void CleanUp()
|
||||||
{
|
{
|
||||||
MainChat.Clear();
|
MainChat.Clear();
|
||||||
@ -201,7 +198,7 @@ namespace CoopClient
|
|||||||
entity.Delete();
|
entity.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Vehicle veh in World.GetAllVehicles().Where(v => v.Handle != Game.Player.Character.Handle))
|
foreach (Vehicle veh in World.GetAllVehicles().Where(v => v.Handle != Game.Player.Character.CurrentVehicle?.Handle))
|
||||||
{
|
{
|
||||||
veh.Delete();
|
veh.Delete();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using CoopClient.Entities;
|
using CoopClient.Entities;
|
||||||
|
|
||||||
@ -6,7 +7,6 @@ using Lidgren.Network;
|
|||||||
|
|
||||||
using GTA;
|
using GTA;
|
||||||
using GTA.Native;
|
using GTA.Native;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace CoopClient
|
namespace CoopClient
|
||||||
{
|
{
|
||||||
@ -270,39 +270,6 @@ namespace CoopClient
|
|||||||
|
|
||||||
Main.Players.Remove(packet.Player);
|
Main.Players.Remove(packet.Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!Main.NpcsAllowed)
|
|
||||||
//{
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//lock (Main.Npcs)
|
|
||||||
//{
|
|
||||||
// for (int i = 0; i < Main.Npcs.Count; i++)
|
|
||||||
// {
|
|
||||||
// long key = Main.Npcs.ElementAt(i).Key;
|
|
||||||
//
|
|
||||||
// if (!key.ToString().StartsWith(packet.Player.ToString()))
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// EntitiesNpc npcData = Main.Npcs[key];
|
|
||||||
//
|
|
||||||
// if (npcData.Character != null && npcData.Character.Exists() && npcData.Health > 0)
|
|
||||||
// {
|
|
||||||
// npcData.Character.Kill();
|
|
||||||
// npcData.Character.Delete();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (npcData.MainVehicle != null && npcData.MainVehicle.Exists() && npcData.MainVehicle.PassengerCount == 0)
|
|
||||||
// {
|
|
||||||
// npcData.MainVehicle.Delete();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Main.Npcs.Remove(key);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FullSyncPlayer(FullSyncPlayerPacket packet)
|
private void FullSyncPlayer(FullSyncPlayerPacket packet)
|
||||||
@ -444,6 +411,10 @@ namespace CoopClient
|
|||||||
{
|
{
|
||||||
arguments.Add(((FloatArgument)arg).Data);
|
arguments.Add(((FloatArgument)arg).Data);
|
||||||
}
|
}
|
||||||
|
else if (typeOf == typeof(StringArgument))
|
||||||
|
{
|
||||||
|
arguments.Add(((StringArgument)arg).Data);
|
||||||
|
}
|
||||||
else if (typeOf == typeof(LVector3Argument))
|
else if (typeOf == typeof(LVector3Argument))
|
||||||
{
|
{
|
||||||
arguments.Add(((LVector3Argument)arg).Data.X);
|
arguments.Add(((LVector3Argument)arg).Data.X);
|
||||||
|
@ -623,7 +623,8 @@ namespace CoopClient
|
|||||||
[ProtoInclude(1, typeof(IntArgument))]
|
[ProtoInclude(1, typeof(IntArgument))]
|
||||||
[ProtoInclude(2, typeof(BoolArgument))]
|
[ProtoInclude(2, typeof(BoolArgument))]
|
||||||
[ProtoInclude(3, typeof(FloatArgument))]
|
[ProtoInclude(3, typeof(FloatArgument))]
|
||||||
[ProtoInclude(4, typeof(LVector3Argument))]
|
[ProtoInclude(4, typeof(StringArgument))]
|
||||||
|
[ProtoInclude(5, typeof(LVector3Argument))]
|
||||||
class NativeArgument { }
|
class NativeArgument { }
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
@ -647,6 +648,13 @@ namespace CoopClient
|
|||||||
public float Data { get; set; }
|
public float Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ProtoContract]
|
||||||
|
class StringArgument : NativeArgument
|
||||||
|
{
|
||||||
|
[ProtoMember(1)]
|
||||||
|
public string Data { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
class LVector3Argument : NativeArgument
|
class LVector3Argument : NativeArgument
|
||||||
{
|
{
|
||||||
|
@ -556,7 +556,8 @@ namespace CoopServer
|
|||||||
[ProtoInclude(1, typeof(IntArgument))]
|
[ProtoInclude(1, typeof(IntArgument))]
|
||||||
[ProtoInclude(2, typeof(BoolArgument))]
|
[ProtoInclude(2, typeof(BoolArgument))]
|
||||||
[ProtoInclude(3, typeof(FloatArgument))]
|
[ProtoInclude(3, typeof(FloatArgument))]
|
||||||
[ProtoInclude(4, typeof(LVector3Argument))]
|
[ProtoInclude(4, typeof(StringArgument))]
|
||||||
|
[ProtoInclude(5, typeof(LVector3Argument))]
|
||||||
class NativeArgument { }
|
class NativeArgument { }
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
@ -580,6 +581,13 @@ namespace CoopServer
|
|||||||
public float Data { get; set; }
|
public float Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ProtoContract]
|
||||||
|
class StringArgument : NativeArgument
|
||||||
|
{
|
||||||
|
[ProtoMember(1)]
|
||||||
|
public string Data { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
class LVector3Argument : NativeArgument
|
class LVector3Argument : NativeArgument
|
||||||
{
|
{
|
||||||
|
@ -425,19 +425,16 @@ namespace CoopServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (KeyValuePair<long, EntitiesPlayer> player in Players)
|
if (Players.Any(x => x.Value.SocialClubName == packet.SocialClubName))
|
||||||
{
|
|
||||||
if (player.Value.SocialClubName == packet.SocialClubName)
|
|
||||||
{
|
{
|
||||||
local.Deny("The name of the Social Club is already taken!");
|
local.Deny("The name of the Social Club is already taken!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (player.Value.Username == packet.Username)
|
else if (Players.Any(x => x.Value.Username == packet.Username))
|
||||||
{
|
{
|
||||||
local.Deny("Username is already taken!");
|
local.Deny("Username is already taken!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
long localPlayerID = local.RemoteUniqueIdentifier;
|
long localPlayerID = local.RemoteUniqueIdentifier;
|
||||||
|
|
||||||
@ -645,7 +642,7 @@ namespace CoopServer
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetConnection userConnection = Util.GetConnectionByUsername(packet.Username);
|
NetConnection userConnection = Util.GetConnectionByUsername(packet.Username);
|
||||||
if (userConnection == null)
|
if (userConnection == default)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -62,34 +62,11 @@ namespace CoopServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NativeArgument> arguments = new();
|
List<NativeArgument> arguments = Util.ParseNativeArguments(args);
|
||||||
|
if (arguments == null)
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
NativeCallPacket packet = new()
|
NativeCallPacket packet = new()
|
||||||
{
|
{
|
||||||
@ -105,40 +82,17 @@ namespace CoopServer
|
|||||||
public static void SendNativeCallToPlayer(string username, ulong hash, params object[] args)
|
public static void SendNativeCallToPlayer(string username, ulong hash, params object[] args)
|
||||||
{
|
{
|
||||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||||
if (userConnection == null)
|
if (userConnection == default)
|
||||||
{
|
{
|
||||||
Logging.Warning("[ServerScript->SendNativeCallToPlayer(\"" + username + "\", \"" + hash + "\", params object[] args)]: User not found!");
|
Logging.Warning("[ServerScript->SendNativeCallToPlayer(\"" + username + "\", \"" + hash + "\", params object[] args)]: User not found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NativeArgument> arguments = new();
|
List<NativeArgument> arguments = Util.ParseNativeArguments(args);
|
||||||
|
if (arguments == null)
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
NativeCallPacket packet = new()
|
NativeCallPacket packet = new()
|
||||||
{
|
{
|
||||||
@ -173,7 +127,7 @@ namespace CoopServer
|
|||||||
public static void KickPlayerByUsername(string username, string[] reason)
|
public static void KickPlayerByUsername(string username, string[] reason)
|
||||||
{
|
{
|
||||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||||
if (userConnection == null)
|
if (userConnection == default)
|
||||||
{
|
{
|
||||||
Logging.Warning("[ServerScript->KickPlayerByUsername(\"" + username + "\", \"" + string.Join(" ", reason) + "\")]: User not found!");
|
Logging.Warning("[ServerScript->KickPlayerByUsername(\"" + username + "\", \"" + string.Join(" ", reason) + "\")]: User not found!");
|
||||||
return;
|
return;
|
||||||
@ -204,7 +158,7 @@ namespace CoopServer
|
|||||||
public static void SendChatMessageToPlayer(string username, string message, string from = "Server")
|
public static void SendChatMessageToPlayer(string username, string message, string from = "Server")
|
||||||
{
|
{
|
||||||
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
NetConnection userConnection = Util.GetConnectionByUsername(username);
|
||||||
if (userConnection == null)
|
if (userConnection == default)
|
||||||
{
|
{
|
||||||
Logging.Warning("[ServerScript->SendChatMessageToPlayer(\"" + username + "\", \"" + message + "\", \"" + from + "\")]: User not found!");
|
Logging.Warning("[ServerScript->SendChatMessageToPlayer(\"" + username + "\", \"" + message + "\", \"" + from + "\")]: User not found!");
|
||||||
return;
|
return;
|
||||||
|
@ -10,20 +10,53 @@ namespace CoopServer
|
|||||||
{
|
{
|
||||||
class Util
|
class Util
|
||||||
{
|
{
|
||||||
|
public static List<NativeArgument> ParseNativeArguments(params object[] args)
|
||||||
|
{
|
||||||
|
List<NativeArgument> result = new();
|
||||||
|
|
||||||
|
foreach (object arg in args)
|
||||||
|
{
|
||||||
|
Type typeOf = arg.GetType();
|
||||||
|
|
||||||
|
if (typeOf == typeof(int))
|
||||||
|
{
|
||||||
|
result.Add(new IntArgument() { Data = (int)arg });
|
||||||
|
}
|
||||||
|
else if (typeOf == typeof(bool))
|
||||||
|
{
|
||||||
|
result.Add(new BoolArgument() { Data = (bool)arg });
|
||||||
|
}
|
||||||
|
else if (typeOf == typeof(float))
|
||||||
|
{
|
||||||
|
result.Add(new FloatArgument() { Data = (float)arg });
|
||||||
|
}
|
||||||
|
else if (typeOf == typeof(string))
|
||||||
|
{
|
||||||
|
result.Add(new StringArgument() { Data = (string)arg });
|
||||||
|
}
|
||||||
|
else if (typeOf == typeof(LVector3))
|
||||||
|
{
|
||||||
|
result.Add(new LVector3Argument() { Data = (LVector3)arg });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logging.Error("[Util->ParseNativeArguments(params object[] args)]: Type of argument not found!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static NetConnection GetConnectionByUsername(string username)
|
public static NetConnection GetConnectionByUsername(string username)
|
||||||
{
|
{
|
||||||
long? userID = GetIdByUsername(username);
|
long? userID = Server.Players.FirstOrDefault(x => x.Value.Username == username).Key;
|
||||||
if (userID == null || !Server.MainNetServer.Connections.Any(x => x.RemoteUniqueIdentifier == userID))
|
if (userID == default || !Server.MainNetServer.Connections.Any(x => x.RemoteUniqueIdentifier == userID))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Server.MainNetServer.Connections.First(x => x.RemoteUniqueIdentifier == userID);
|
return Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == userID);
|
||||||
}
|
|
||||||
|
|
||||||
public static long? GetIdByUsername(string username)
|
|
||||||
{
|
|
||||||
return Server.Players.Any(x => x.Value.Username == username) ? Server.Players.First(x => x.Value.Username == username).Key : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a list of all connections but not the local connection
|
// Return a list of all connections but not the local connection
|
||||||
|
Reference in New Issue
Block a user