-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathProgram.cs
59 lines (52 loc) · 1.8 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using WebSocketSharp.Server;
namespace r2warsTorneo
{
static public class r2warsStatic
{
static public r2wars r2w = new r2wars();
static public Torneo torneo = new Torneo();
}
class Program
{
static void Main(string[] args)
{
string httpUrl = "http://0.0.0.0:9664";
string websocketUrl = "ws://0.0.0.0:9966";
if (OperatingSystem.IsWindows())
{
httpUrl = "http://127.0.0.1:9664";
websocketUrl = "ws://127.0.0.1:9966";
}
var tokenSource = new CancellationTokenSource();
CancellationToken ct = tokenSource.Token;
if (args.Length > 0) {
r2warsStatic.torneo.SetWarriorsDirectory(args[0]);
}
var taskA = new Task(() =>
{
var nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri(httpUrl), new CustomBootstrapper());
nancyHost.Start();
Console.WriteLine("Web server running at " + httpUrl);
Process.Start(httpUrl);
while (!ct.IsCancellationRequested) { Thread.Sleep(1000); }
nancyHost.Stop();
}, tokenSource.Token);
var taskB = new Task(() =>
{
var wssv = new WebSocketServer(websocketUrl);
wssv.AddWebSocketService<r2warsWebSocket>("/r2wars");
wssv.Start();
while (!ct.IsCancellationRequested) { Thread.Sleep(1000); }
wssv.Stop();
}, tokenSource.Token);
taskA.Start();
taskB.Start();
Console.ReadKey();
tokenSource.Cancel();
}
}
}