mirror of
https://github.com/mm201/pkmn-classic-framework.git
synced 2026-04-22 16:47:32 -05:00
Made the GT server testable.
This commit is contained in:
parent
dd93326fe8
commit
664fe2d89e
|
|
@ -91,6 +91,14 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
}
|
||||
}
|
||||
|
||||
public override string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Generation IV Global Terminal";
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] m_pad;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
|||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Security;
|
||||
using System.Net;
|
||||
|
||||
namespace PkmnFoundations.GlobalTerminalService
|
||||
{
|
||||
|
|
@ -59,6 +60,8 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
{
|
||||
if (m_workers.Count > 0) return;
|
||||
|
||||
Console.WriteLine("{0} server running on port {1} with {2} threads.", Title, ((IPEndPoint)m_listener.LocalEndpoint).Port, Threads);
|
||||
|
||||
m_closing = false;
|
||||
m_listener.Start();
|
||||
for (int x = 0; x < Threads; x++)
|
||||
|
|
@ -84,6 +87,9 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
|
||||
private void MainLoop(object o)
|
||||
{
|
||||
int threadIndex = m_workers.IndexOf(Thread.CurrentThread);
|
||||
Console.WriteLine("Thread {0} begins.", threadIndex);
|
||||
|
||||
while (!m_closing)
|
||||
{
|
||||
if (!m_listener.Pending())
|
||||
|
|
@ -108,6 +114,8 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
byte[] response = ProcessRequest(data);
|
||||
s.Write(response, 0, response.Length);
|
||||
}
|
||||
|
||||
Console.WriteLine("Thread {0} ends.", threadIndex);
|
||||
m_workers.Remove(Thread.CurrentThread);
|
||||
}
|
||||
|
||||
|
|
@ -125,5 +133,7 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
}
|
||||
|
||||
protected abstract byte[] ProcessRequest(byte[] data);
|
||||
|
||||
public abstract String Title { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{7AB1A65F-3AD1-4356-94E7-F1A669BF4CE0}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PkmnFoundations.GlobalTerminalService</RootNamespace>
|
||||
<AssemblyName>GlobalTerminalService</AssemblyName>
|
||||
|
|
@ -34,6 +34,9 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
|
|||
|
|
@ -13,12 +13,18 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
/// </summary>
|
||||
static void Main()
|
||||
{
|
||||
#if DEBUG
|
||||
Service1 myService = new Service1();
|
||||
myService.Start();
|
||||
while (true) { }
|
||||
#else
|
||||
ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new ServiceBase[]
|
||||
{
|
||||
new Service1()
|
||||
};
|
||||
ServiceBase.Run(ServicesToRun);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,22 @@ namespace PkmnFoundations.GlobalTerminalService
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private GTServer4 m_server;
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
m_server = new GTServer4();
|
||||
m_server.BeginPolling();
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
if (m_server != null) m_server.EndPolling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user