2020-01-27 23:37:28 +01:00
|
|
|
|
using Common;
|
|
|
|
|
using Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebInterface.Services
|
|
|
|
|
{
|
|
|
|
|
public class PrivateServerService : IPrivateServerService
|
|
|
|
|
{
|
|
|
|
|
private static readonly Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
|
|
|
|
private static readonly IPEndPoint webApiListenerEndPoint = new IPEndPoint(IPAddress.Loopback, 11028);
|
|
|
|
|
|
2020-01-29 16:32:23 +01:00
|
|
|
|
public SpawnedServerInfo SpawnNewPrivateServer(int players, string modName, string tempFolderName = "")
|
2020-01-27 23:37:28 +01:00
|
|
|
|
{
|
|
|
|
|
players = Math.Min(8, Math.Max(3, players));
|
|
|
|
|
|
2020-01-29 16:32:23 +01:00
|
|
|
|
SpawnedServerInfo serverProcess = ProcessSpawner.SpawnServer(players, modName, tempFolderName);
|
2020-01-27 23:37:28 +01:00
|
|
|
|
byte[] payload = Encoding.ASCII.GetBytes($"B{serverProcess.Port}\t{serverProcess.Process.Id}\0");
|
|
|
|
|
socket.SendTo(payload, webApiListenerEndPoint);
|
|
|
|
|
|
|
|
|
|
return serverProcess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|