65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using Articulate_Network;
|
|
using Articulate_Network.Managers;
|
|
using MIT_Builder_Client.Handlers;
|
|
using MIT_Packets;
|
|
using MIT_Packets.Enums;
|
|
using MIT_Packets.Transfer;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MIT_Builder_Client
|
|
{
|
|
class Program
|
|
{
|
|
static Client client;
|
|
public static ClientStatus status = ClientStatus.Waiting;
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
AnnouncePacket.Register();
|
|
|
|
client = new Client();
|
|
|
|
client.Connect("10.136.5.59", 50).ContinueWith(t =>
|
|
{
|
|
if (t.Result.Connected)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("Successfully connected to master server.");
|
|
|
|
AnnounceClient();
|
|
}
|
|
});
|
|
|
|
client.DataReceived += Client_DataReceived;
|
|
|
|
Console.ReadLine();
|
|
}
|
|
|
|
static void AnnounceClient()
|
|
{
|
|
string macAddress = NetworkInterface.GetAllNetworkInterfaces().Where(nic => nic.OperationalStatus == OperationalStatus.Up).Select(nic => nic.GetPhysicalAddress().ToString()).FirstOrDefault();
|
|
|
|
client.SendPacket(new AnnouncePacket()
|
|
{
|
|
Type = 1,
|
|
RequestConfig = true,
|
|
MacAddress = macAddress
|
|
});
|
|
}
|
|
|
|
private static void Client_DataReceived(object sender, Articulate_Network.Events.DataReceivedEventArgs e)
|
|
{
|
|
//Console.WriteLine($"Received Packet: {e.Packet.GetType().Name}");
|
|
|
|
if (e.Packet is StartFileTransferPacket || e.Packet is SendFileChunkPacket || e.Packet is EndFileTransferPacket)
|
|
FileTransferHandler.HandleTransfer(e.Packet);
|
|
}
|
|
}
|
|
}
|