forked from NiclasOlofsson/MiNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiNetService.cs
More file actions
86 lines (77 loc) · 2.08 KB
/
Copy pathMiNetService.cs
File metadata and controls
86 lines (77 loc) · 2.08 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Diagnostics;
using log4net;
using log4net.Config;
using Topshelf;
// Configure log4net using the .config file
[assembly: XmlConfigurator(Watch = true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
namespace MiNET.Service
{
public class MiNetService
{
private static readonly ILog Log = LogManager.GetLogger(typeof (MiNetServer));
private MiNetServer _server;
/// <summary>
/// Starts this instance.
/// </summary>
private void Start()
{
Log.Info("Starting MiNET as user " + Environment.UserName);
_server = new MiNetServer();
//_server.LevelManager = new SpreadLevelManager(Environment.ProcessorCount * 4);
_server.StartServer();
}
/// <summary>
/// Stops this instance.
/// </summary>
private void Stop()
{
Log.Info("Stopping MiNET");
_server.StopServer();
}
/// <summary>
/// The programs entry point.
/// </summary>
/// <param name="args">The arguments.</param>
private static void Main(string[] args)
{
//Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
if (IsRunningOnMono())
{
var service = new MiNetService();
service.Start();
Console.WriteLine("MiNET running. Press <enter> to stop service.");
Console.ReadLine();
service.Stop();
}
else
{
HostFactory.Run(host =>
{
host.Service<MiNetService>(s =>
{
s.ConstructUsing(construct => new MiNetService());
s.WhenStarted(service => service.Start());
s.WhenStopped(service => service.Stop());
});
host.RunAsLocalService();
host.SetDisplayName("MiNET Service");
host.SetDescription("MiNET Minecraft Pocket Edition server.");
host.SetServiceName("MiNET");
});
}
}
/// <summary>
/// Determines whether is running on mono.
/// </summary>
/// <returns></returns>
public static bool IsRunningOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}
}
}