Files
RAGECOOP-V/RageCoop.Core/Packets/FilePackets.cs

128 lines
3.0 KiB
C#
Raw Permalink Normal View History

2022-09-08 12:41:56 -07:00

2022-04-02 16:40:24 +02:00
using Lidgren.Network;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Core
2022-04-02 16:40:24 +02:00
{
2022-09-08 12:41:56 -07:00
internal enum FileResponse : byte
{
2022-09-08 12:41:56 -07:00
NeedToDownload = 0,
AlreadyExists = 1,
Completed = 2,
Loaded = 3,
LoadFailed = 4,
}
2022-07-01 14:39:43 +08:00
internal partial class Packets
2022-04-02 16:40:24 +02:00
{
2022-07-01 14:39:43 +08:00
internal class FileTransferRequest : Packet
2022-04-02 16:40:24 +02:00
{
2022-08-06 10:49:55 +08:00
public override PacketType Type => PacketType.FileTransferRequest;
public int ID { get; set; }
2022-04-02 16:40:24 +02:00
public string Name { get; set; }
2022-04-02 16:40:24 +02:00
2022-04-02 18:11:30 +02:00
public long FileLength { get; set; }
2022-04-02 16:40:24 +02:00
protected override void Serialize(NetOutgoingMessage m)
2022-04-02 16:40:24 +02:00
{
2022-04-02 16:40:24 +02:00
// The ID from the download
m.Write(ID);
2022-04-02 16:40:24 +02:00
// The name of the file
m.Write(Name);
2022-04-02 16:40:24 +02:00
// The length of the file
m.Write(FileLength);
2022-04-02 16:40:24 +02:00
}
public override void Deserialize(NetIncomingMessage m)
2022-04-02 16:40:24 +02:00
{
ID = m.ReadInt32();
Name = m.ReadString();
FileLength = m.ReadInt64();
2022-04-02 16:40:24 +02:00
}
}
2022-07-01 14:39:43 +08:00
internal class FileTransferResponse : Packet
2022-07-01 12:22:31 +08:00
{
2022-08-06 10:49:55 +08:00
public override PacketType Type => PacketType.FileTransferResponse;
2022-07-01 12:22:31 +08:00
public int ID { get; set; }
public FileResponse Response { get; set; }
protected override void Serialize(NetOutgoingMessage m)
2022-07-01 12:22:31 +08:00
{
// The ID from the download
m.Write(ID);
2022-07-01 12:22:31 +08:00
m.Write((byte)Response);
2022-07-01 12:22:31 +08:00
}
public override void Deserialize(NetIncomingMessage m)
2022-07-01 12:22:31 +08:00
{
ID = m.ReadInt32();
Response = (FileResponse)m.ReadByte();
2022-07-01 12:22:31 +08:00
}
}
2022-07-01 14:39:43 +08:00
internal class FileTransferChunk : Packet
2022-04-02 16:40:24 +02:00
{
2022-09-08 12:41:56 -07:00
public override PacketType Type => PacketType.FileTransferChunk;
public int ID { get; set; }
2022-04-02 16:40:24 +02:00
public byte[] FileChunk { get; set; }
protected override void Serialize(NetOutgoingMessage m)
2022-04-02 16:40:24 +02:00
{
// The ID from the download
m.Write(ID);
m.WriteByteArray(FileChunk);
2022-04-02 16:40:24 +02:00
}
public override void Deserialize(NetIncomingMessage m)
2022-04-02 16:40:24 +02:00
{
ID = m.ReadInt32();
FileChunk = m.ReadByteArray();
2022-04-02 16:40:24 +02:00
}
}
2022-07-01 14:39:43 +08:00
internal class FileTransferComplete : Packet
2022-04-02 16:40:24 +02:00
{
2022-09-08 12:41:56 -07:00
public override PacketType Type => PacketType.FileTransferComplete;
public int ID { get; set; }
2022-04-02 16:40:24 +02:00
protected override void Serialize(NetOutgoingMessage m)
2022-04-02 16:40:24 +02:00
{
// The ID for the download
m.Write(ID);
2022-04-02 16:40:24 +02:00
}
public override void Deserialize(NetIncomingMessage m)
2022-04-02 16:40:24 +02:00
{
ID = m.ReadInt32();
2022-04-02 16:40:24 +02:00
}
}
2022-07-01 14:39:43 +08:00
internal class AllResourcesSent : Packet
2022-07-01 12:22:31 +08:00
{
2022-09-08 12:41:56 -07:00
public override PacketType Type => PacketType.AllResourcesSent;
2022-07-01 12:22:31 +08:00
}
2022-04-02 16:40:24 +02:00
}
}