mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-27 14:18:00 +03:00
Fix color output on Linux and Mac OS X, log time stamps with packets, allow configuring local end point with command line parameter.
This commit is contained in:
parent
4e1f9b17a8
commit
db3a49539f
@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Syroot.Worms.Worms2.GameServer
|
||||
{
|
||||
@ -9,11 +10,22 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
{
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
private static void Main()
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
//Proxy.Run(); return;
|
||||
|
||||
Server server = new Server();
|
||||
server.Run(new IPEndPoint(IPAddress.Any, 17000));
|
||||
server.Run(ParseEndPoint(args.Length > 0 ? args[0] : null));
|
||||
}
|
||||
|
||||
private static IPEndPoint ParseEndPoint(string? s)
|
||||
{
|
||||
if (UInt16.TryParse(s, out ushort port))
|
||||
return new IPEndPoint(IPAddress.Any, port);
|
||||
else if (IPEndPoint.TryParse(s, out IPEndPoint endPoint))
|
||||
return endPoint;
|
||||
else
|
||||
return new IPEndPoint(IPAddress.Any, 17000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Syroot.Worms.Worms2.GameServer": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "127.0.0.1:17002"
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 17000);
|
||||
TcpListener listener = new TcpListener(localEndPoint);
|
||||
listener.Start();
|
||||
ColorConsole.WriteLine($"Proxy listening under {localEndPoint}...");
|
||||
ColorConsole.WriteLine(Color.Orange, $"Proxy listening under {localEndPoint}...");
|
||||
|
||||
TcpClient? client;
|
||||
while ((client = listener.AcceptTcpClient()) != null)
|
||||
|
@ -69,9 +69,9 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
private static void LogPacket(PacketConnection connection, Packet packet, bool fromClient)
|
||||
{
|
||||
if (fromClient)
|
||||
ColorConsole.WriteLine(Color.Cyan, $"{connection.RemoteEndPoint} >> {packet}");
|
||||
ColorConsole.WriteLine(Color.Cyan, $"{DateTime.Now:HH:mm:ss} {connection.RemoteEndPoint} >> {packet}");
|
||||
else
|
||||
ColorConsole.WriteLine(Color.Magenta, $"{connection.RemoteEndPoint} << {packet}");
|
||||
ColorConsole.WriteLine(Color.Magenta, $"{DateTime.Now:HH:mm:ss} {connection.RemoteEndPoint} << {packet}");
|
||||
}
|
||||
|
||||
private User? GetUser(PacketConnection connection)
|
||||
@ -93,7 +93,7 @@ namespace Syroot.Worms.Worms2.GameServer
|
||||
// Start a new listener for new incoming connections.
|
||||
TcpListener listener = new TcpListener(localEndPoint);
|
||||
listener.Start();
|
||||
Console.WriteLine($"Server listening under {listener.LocalEndpoint}...");
|
||||
ColorConsole.WriteLine(Color.Orange, $"Server listening under {listener.LocalEndpoint}...");
|
||||
|
||||
// Dispatch each connection into its own thread.
|
||||
TcpClient? client;
|
||||
|
@ -3,7 +3,7 @@
|
||||
<!-- Metadata -->
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>..\..\..\res\icon.ico</ApplicationIcon>
|
||||
<AssemblyName>Worms 2 Server</AssemblyName>
|
||||
<AssemblyName>w2server</AssemblyName>
|
||||
<Authors>Syroot</Authors>
|
||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||
<Description>Worms 2 Game Server</Description>
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
<!-- References -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Syroot.ColoredConsole" Version="1.0.0" />
|
||||
<PackageReference Include="Syroot.ColoredConsole" Version="1.0.1" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
|
||||
<ProjectReference Include="..\..\library\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
</ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user