Small changes and stopping sending own disconnect packet
This commit is contained in:
@ -27,7 +27,7 @@ namespace CoopServer
|
||||
private long CallbacksCount = 0;
|
||||
internal readonly Dictionary<long, Action<object>> Callbacks = new();
|
||||
internal bool FilesReceived = false;
|
||||
public bool FilesSent = false;
|
||||
internal bool FilesSent = false;
|
||||
|
||||
#region CUSTOMDATA FUNCTIONS
|
||||
public void SetData<T>(string name, T data)
|
||||
|
@ -8,7 +8,8 @@ namespace CoopServer
|
||||
{
|
||||
internal static class DownloadManager
|
||||
{
|
||||
private static readonly List<DownloadClient> _clients = new();
|
||||
public static readonly List<long> ClientsToDelete = new();
|
||||
private static List<DownloadClient> _clients = new();
|
||||
private static readonly List<DownloadFile> _files = new();
|
||||
public static bool AnyFileExists = false;
|
||||
|
||||
@ -79,14 +80,30 @@ namespace CoopServer
|
||||
|
||||
public static void Tick()
|
||||
{
|
||||
lock (ClientsToDelete)
|
||||
{
|
||||
foreach (long nethandle in ClientsToDelete)
|
||||
{
|
||||
DownloadClient client = _clients.FirstOrDefault(x => x.NetHandle == nethandle);
|
||||
if (client != null)
|
||||
{
|
||||
_clients.Remove(client);
|
||||
}
|
||||
}
|
||||
ClientsToDelete.Clear();
|
||||
}
|
||||
|
||||
_clients.ForEach(client =>
|
||||
{
|
||||
if (!client.SendFiles())
|
||||
{
|
||||
Client x = Server.Clients.FirstOrDefault(x => x.NetHandle == client.NetHandle);
|
||||
if (x != null)
|
||||
lock (Server.Clients)
|
||||
{
|
||||
x.FilesReceived = true;
|
||||
Client x = Server.Clients.FirstOrDefault(x => x.NetHandle == client.NetHandle);
|
||||
if (x != null)
|
||||
{
|
||||
x.FilesReceived = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -136,23 +153,29 @@ namespace CoopServer
|
||||
_files = files;
|
||||
|
||||
NetConnection conn = Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == NetHandle);
|
||||
if (conn != null)
|
||||
if (conn == null)
|
||||
{
|
||||
_files.ForEach(file =>
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
|
||||
|
||||
new Packets.FileTransferRequest()
|
||||
{
|
||||
ID = file.FileID,
|
||||
FileType = (byte)Packets.DataFileType.Script,
|
||||
FileName = file.FileName,
|
||||
FileLength = file.FileLength
|
||||
}.PacketToNetOutGoingMessage(outgoingMessage);
|
||||
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, conn, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.File);
|
||||
});
|
||||
DownloadManager.ClientsToDelete.Add(NetHandle);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_files.ForEach(file =>
|
||||
{
|
||||
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
|
||||
|
||||
new Packets.FileTransferRequest()
|
||||
{
|
||||
ID = file.FileID,
|
||||
FileType = (byte)Packets.DataFileType.Script,
|
||||
FileName = file.FileName,
|
||||
FileLength = file.FileLength
|
||||
}.PacketToNetOutGoingMessage(outgoingMessage);
|
||||
|
||||
Server.MainNetServer.SendMessage(outgoingMessage, conn, NetDeliveryMethod.ReliableOrdered, (byte)ConnectionChannel.File);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -186,6 +209,10 @@ namespace CoopServer
|
||||
NetConnection conn = Server.MainNetServer.Connections.FirstOrDefault(x => x.RemoteUniqueIdentifier == nethandle);
|
||||
if (conn == null)
|
||||
{
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
DownloadManager.ClientsToDelete.Add(NetHandle);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,10 @@ namespace CoopServer
|
||||
{
|
||||
long nethandle = message.SenderConnection.RemoteUniqueIdentifier;
|
||||
|
||||
DownloadManager.RemoveClient(nethandle);
|
||||
lock (DownloadManager.ClientsToDelete)
|
||||
{
|
||||
DownloadManager.ClientsToDelete.Add(nethandle);
|
||||
}
|
||||
|
||||
SendPlayerDisconnectPacket(nethandle);
|
||||
}
|
||||
@ -736,20 +739,20 @@ namespace CoopServer
|
||||
}
|
||||
|
||||
// Send all players a message that someone has left the server
|
||||
private static void SendPlayerDisconnectPacket(long clientID)
|
||||
private static void SendPlayerDisconnectPacket(long nethandle)
|
||||
{
|
||||
List<NetConnection> clients = MainNetServer.Connections;
|
||||
List<NetConnection> clients = MainNetServer.Connections.FindAll(x => x.RemoteUniqueIdentifier != nethandle);
|
||||
if (clients.Count > 0)
|
||||
{
|
||||
NetOutgoingMessage outgoingMessage = MainNetServer.CreateMessage();
|
||||
new Packets.PlayerDisconnect()
|
||||
{
|
||||
NetHandle = clientID
|
||||
NetHandle = nethandle
|
||||
}.PacketToNetOutGoingMessage(outgoingMessage);
|
||||
MainNetServer.SendMessage(outgoingMessage, clients, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
Client localClient = Clients.Find(x => x.NetHandle == clientID);
|
||||
Client localClient = Clients.FirstOrDefault(x => x.NetHandle == nethandle);
|
||||
if (localClient == null)
|
||||
{
|
||||
return;
|
||||
|
Reference in New Issue
Block a user