More bug fixes and changes for DownloadManager
This commit is contained in:
@ -9,6 +9,7 @@ namespace CoopClient
|
||||
private static readonly List<DownloadFile> _downloadFiles = new List<DownloadFile>();
|
||||
private static readonly Dictionary<byte, FileStream> _streams = new Dictionary<byte, FileStream>();
|
||||
private static readonly List<byte> _filesFinished = new List<byte>();
|
||||
public static bool DownloadComplete = false;
|
||||
|
||||
public static void AddFile(byte id, Packets.DataFileType type, string name, long length)
|
||||
{
|
||||
@ -143,6 +144,8 @@ namespace CoopClient
|
||||
_downloadFiles.Clear();
|
||||
_filesFinished.Clear();
|
||||
}
|
||||
|
||||
DownloadComplete = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ namespace CoopClient
|
||||
public class JavascriptHook : Script
|
||||
{
|
||||
private static readonly List<V8ScriptEngine> ScriptEngines = new List<V8ScriptEngine>();
|
||||
internal static bool JavascriptLoaded { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Don't use this!
|
||||
@ -88,15 +89,23 @@ namespace CoopClient
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JavascriptLoaded = true;
|
||||
}
|
||||
|
||||
internal static void StopAll()
|
||||
{
|
||||
lock (ScriptEngines)
|
||||
{
|
||||
ScriptEngines.ForEach(engine => engine.Script.API.InvokeStop());
|
||||
ScriptEngines.ForEach(engine =>
|
||||
{
|
||||
engine.Script.API.InvokeStop();
|
||||
engine.Dispose();
|
||||
});
|
||||
ScriptEngines.Clear();
|
||||
}
|
||||
|
||||
JavascriptLoaded = false;
|
||||
}
|
||||
|
||||
internal static void InvokePlayerConnect(string username, long nethandle)
|
||||
|
@ -110,6 +110,11 @@ namespace CoopClient
|
||||
|
||||
MainNetworking.ReceiveMessages();
|
||||
|
||||
if (!JavascriptHook.JavascriptLoaded && DownloadManager.DownloadComplete)
|
||||
{
|
||||
JavascriptHook.LoadAll();
|
||||
}
|
||||
|
||||
if (IsGoingToCar && Game.Player.Character.IsInVehicle())
|
||||
{
|
||||
IsGoingToCar = false;
|
||||
|
@ -129,7 +129,6 @@ namespace CoopClient
|
||||
COOPAPI.Connected();
|
||||
GTA.UI.Notification.Show("~g~Connected!");
|
||||
|
||||
JavascriptHook.LoadAll();
|
||||
Logger.Write(">> Connected <<", Logger.LogLevel.Server);
|
||||
}
|
||||
break;
|
||||
@ -453,6 +452,27 @@ namespace CoopClient
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (byte)PacketTypes.FileTransferTick:
|
||||
{
|
||||
try
|
||||
{
|
||||
int len = message.ReadInt32();
|
||||
byte[] data = message.ReadBytes(len);
|
||||
Packets.FileTransferTick packet = new Packets.FileTransferTick();
|
||||
packet.NetIncomingMessageToPacket(data);
|
||||
|
||||
DownloadManager.Write(packet.ID, packet.FileChunk);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
||||
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
||||
Logger.Write($"[{packetType}] {ex.Source}", Logger.LogLevel.Server);
|
||||
Logger.Write($"[{packetType}] {ex.StackTrace}", Logger.LogLevel.Server);
|
||||
Client.Disconnect($"Packet Error [{packetType}]");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (byte)PacketTypes.FileTransferRequest:
|
||||
{
|
||||
try
|
||||
@ -472,23 +492,21 @@ namespace CoopClient
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (byte)PacketTypes.FileTransferTick:
|
||||
case (byte)PacketTypes.FileTransferComplete:
|
||||
{
|
||||
try
|
||||
{
|
||||
int len = message.ReadInt32();
|
||||
byte[] data = message.ReadBytes(len);
|
||||
Packets.FileTransferTick packet = new Packets.FileTransferTick();
|
||||
Packets.FileTransferComplete packet = new Packets.FileTransferComplete();
|
||||
packet.NetIncomingMessageToPacket(data);
|
||||
|
||||
DownloadManager.Write(packet.ID, packet.FileChunk);
|
||||
DownloadManager.DownloadComplete = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GTA.UI.Notification.Show("~r~~h~Packet Error");
|
||||
Logger.Write($"[{packetType}] {ex.Message}", Logger.LogLevel.Server);
|
||||
Logger.Write($"[{packetType}] {ex.Source}", Logger.LogLevel.Server);
|
||||
Logger.Write($"[{packetType}] {ex.StackTrace}", Logger.LogLevel.Server);
|
||||
Client.Disconnect($"Packet Error [{packetType}]");
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<AssemblyVersion>1.47.0.0001</AssemblyVersion>
|
||||
<AssemblyVersion>1.47.2.0001</AssemblyVersion>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
<RepositoryUrl>https://github.com/GTACOOP-R/GTACoop-R</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
@ -8,7 +8,7 @@ namespace CoopServer
|
||||
{
|
||||
internal static class DownloadManager
|
||||
{
|
||||
public static readonly List<long> ClientsToDelete = new();
|
||||
private static readonly List<long> ClientsToDelete = new();
|
||||
private static List<DownloadClient> _clients = new();
|
||||
private static readonly List<DownloadFile> _files = new();
|
||||
public static bool AnyFileExists = false;
|
||||
@ -20,8 +20,11 @@ namespace CoopServer
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_clients)
|
||||
{
|
||||
_clients.Add(new DownloadClient(nethandle, new(_files)));
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckForDirectoryAndFiles()
|
||||
{
|
||||
@ -79,6 +82,8 @@ namespace CoopServer
|
||||
}
|
||||
|
||||
public static void Tick()
|
||||
{
|
||||
lock (_clients)
|
||||
{
|
||||
lock (ClientsToDelete)
|
||||
{
|
||||
@ -95,7 +100,7 @@ namespace CoopServer
|
||||
|
||||
_clients.ForEach(client =>
|
||||
{
|
||||
if (!client.SendFiles())
|
||||
if (client.SendFiles())
|
||||
{
|
||||
lock (Server.Clients)
|
||||
{
|
||||
@ -105,10 +110,11 @@ namespace CoopServer
|
||||
x.FilesReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
AddClientToRemove(client.NetHandle);
|
||||
}
|
||||
});
|
||||
|
||||
Logging.Debug($"Clients [{_clients.Count}]");
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveClient(long nethandle)
|
||||
@ -126,6 +132,8 @@ namespace CoopServer
|
||||
/// <param name="nethandle"></param>
|
||||
/// <param name="id"></param>
|
||||
public static void TryToRemoveClient(long nethandle, int id)
|
||||
{
|
||||
lock (_clients)
|
||||
{
|
||||
DownloadClient client = _clients.FirstOrDefault(x => x.NetHandle == nethandle);
|
||||
if (client == null)
|
||||
@ -142,6 +150,15 @@ namespace CoopServer
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddClientToRemove(long nethandle)
|
||||
{
|
||||
lock (ClientsToDelete)
|
||||
{
|
||||
ClientsToDelete.Add(nethandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class DownloadClient
|
||||
{
|
||||
public long NetHandle = 0;
|
||||
@ -157,10 +174,7 @@ namespace CoopServer
|
||||
NetConnection conn = Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == NetHandle);
|
||||
if (conn == null)
|
||||
{
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
DownloadManager.ClientsToDelete.Add(NetHandle);
|
||||
}
|
||||
DownloadManager.AddClientToRemove(NetHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -201,14 +215,9 @@ namespace CoopServer
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>true if files should be sent otherwise false</returns>
|
||||
/// <returns>true if we are done otherwise false</returns>
|
||||
public bool SendFiles()
|
||||
{
|
||||
if (DownloadComplete())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DownloadFile file = _files[FilePosition];
|
||||
|
||||
Send(NetHandle, file);
|
||||
@ -217,11 +226,9 @@ namespace CoopServer
|
||||
{
|
||||
FilePosition++;
|
||||
_fileDataPosition = 0;
|
||||
|
||||
return DownloadComplete();
|
||||
}
|
||||
|
||||
return true;
|
||||
return DownloadComplete();
|
||||
}
|
||||
|
||||
private void Send(long nethandle, DownloadFile file)
|
||||
@ -229,10 +236,7 @@ namespace CoopServer
|
||||
NetConnection conn = Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == nethandle);
|
||||
if (conn == null)
|
||||
{
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
DownloadManager.ClientsToDelete.Add(NetHandle);
|
||||
}
|
||||
DownloadManager.AddClientToRemove(NetHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -271,10 +271,7 @@ namespace CoopServer
|
||||
{
|
||||
long nethandle = message.SenderConnection.RemoteUniqueIdentifier;
|
||||
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
DownloadManager.ClientsToDelete.Add(nethandle);
|
||||
}
|
||||
DownloadManager.AddClientToRemove(nethandle);
|
||||
|
||||
SendPlayerDisconnectPacket(nethandle);
|
||||
}
|
||||
|
Reference in New Issue
Block a user