diff --git a/src/Syroot.Worms.OnlineWorms.Server/Client.cs b/src/Syroot.Worms.OnlineWorms.Server/Client.cs
index 20a424b..f28e0a9 100644
--- a/src/Syroot.Worms.OnlineWorms.Server/Client.cs
+++ b/src/Syroot.Worms.OnlineWorms.Server/Client.cs
@@ -1,4 +1,6 @@
-using System.Net.Sockets;
+using System.Drawing;
+using System.Net;
+using System.Net.Sockets;
using Syroot.Worms.OnlineWorms.Server.Net;
namespace Syroot.Worms.OnlineWorms.Server
@@ -28,9 +30,9 @@ namespace Syroot.Worms.OnlineWorms.Server
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
- public void HandleConnect(ConnectQueryPacket inPacket)
+ public void HandleConnect(ConnectQuery packet)
{
- SendPacket(new ConnectReplyPacket
+ SendPacket(new ConnectReply
{
Unknown = _server.Name,
Unknown2 = _server.RegionName,
@@ -38,37 +40,82 @@ namespace Syroot.Worms.OnlineWorms.Server
});
}
- public void HandleLogin(LoginQueryPacket inPacket)
+ public void HandleLogin(LoginQuery packet)
{
- LoginPlayerInfo[] playerInfos = new LoginPlayerInfo[inPacket.Logins.Length];
- for (int i = 0; i < inPacket.Logins.Length; i++)
- {
- LoginCredentials credentials = inPacket.Logins[i];
- playerInfos[i] = new LoginPlayerInfo
- {
- ID = credentials.ID,
- Rank = 19
- };
- }
-
// Send login result.
- SendPacket(new LoginReplyPacket
+ // Create player infos from the given credentials. This would be the place to check for actual accounts.
+ LoginPlayerInfo[] playerInfos = new LoginPlayerInfo[packet.Logins.Length];
+ for (int i = 0; i < packet.Logins.Length; i++)
+ {
+ LoginCredentials credentials = packet.Logins[i];
+ playerInfos[i] = new LoginPlayerInfo { ID = credentials.ID, Rank = 19 };
+ }
+ SendPacket(new LoginReply
{
Unknown1 = 1,
LoginResult = LoginResult.Success,
PlayerInfos = playerInfos
});
+
// Send info text.
- SendPacket(new ServerInfoReplyPacket { Text = @"Welcome to the Online Worms Server.
-Encoding tests are following:
-Direct Sound Error로 게임 사운드가
-지원되지 않습니다.
-%s님을 목록에서 삭제 \t하시겠습니까?
-01234567890" });
+ SendPacket(new ServerInfoReply
+ {
+ Text = "Welcome to the Online Worms Server."
+ });
+
+ // Send channels.
+ SendPacket(new ChannelInfosReply
+ {
+ Channels = new[]
+ {
+ new ChannelInfo
+ {
+ Name = "Test Channel",
+ EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
+ Type = ChannelType.Normal,
+ Color = Color.LightGreen,
+ UserLoad = 5
+ },
+ new ChannelInfo
+ {
+ Name = "Real Channel",
+ EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
+ Type = ChannelType.Normal,
+ Color = Color.Yellow,
+ UserLoad = 1
+ },
+ new ChannelInfo
+ {
+ Name = "Nothing Goes",
+ EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
+ Type = ChannelType.Roping,
+ Color = Color.Orange,
+ Coins = 2,
+ UserLoad = 6
+ },
+ new ChannelInfo
+ {
+ Name = "Boredom Time",
+ EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
+ Type = ChannelType.Roping,
+ Color = Color.HotPink,
+ Coins = 1,
+ UserLoad = 3
+ },
+ new ChannelInfo
+ {
+ Name = "Unhelpful Channel",
+ EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
+ Type = ChannelType.Special,
+ Color = Color.White,
+ UserLoad = 1
+ }
+ }
+ });
}
#if DEBUG
- public void HandleRaw(RawQueryPacket inPacket) { }
+ public void HandleRaw(RawQuery packet) { }
#endif
// ---- METHODS (PROTECTED) ------------------------------------------------------------------------------------
diff --git a/src/Syroot.Worms.OnlineWorms.Server/Net/PacketFactory.cs b/src/Syroot.Worms.OnlineWorms.Server/Net/PacketFactory.cs
index bb6d3ce..cb69057 100644
--- a/src/Syroot.Worms.OnlineWorms.Server/Net/PacketFactory.cs
+++ b/src/Syroot.Worms.OnlineWorms.Server/Net/PacketFactory.cs
@@ -43,7 +43,7 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
#if DEBUG
return _packetTypes.TryGetValue(id, out Type type)
? (Packet)Activator.CreateInstance(type, true)
- : new RawQueryPacket(id);
+ : new RawQuery(id);
#else
return (Packet)Activator.CreateInstance(_packetTypes[id], true);
#endif
@@ -57,7 +57,7 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
internal static ushort GetID(Packet packet)
{
#if DEBUG
- if (packet is RawQueryPacket rawPacket)
+ if (packet is RawQuery rawPacket)
return rawPacket.ID;
else
#endif
diff --git a/src/Syroot.Worms.OnlineWorms.Server/Net/PacketStream.cs b/src/Syroot.Worms.OnlineWorms.Server/Net/PacketStream.cs
index 30c50e7..2ef13b6 100644
--- a/src/Syroot.Worms.OnlineWorms.Server/Net/PacketStream.cs
+++ b/src/Syroot.Worms.OnlineWorms.Server/Net/PacketStream.cs
@@ -1,4 +1,5 @@
-using System.IO;
+using System.Drawing;
+using System.IO;
using System.Text;
using Syroot.BinaryData;
@@ -99,11 +100,27 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
return _baseStream.ReadString(StringCoding.Int16CharCount, _win949Encoding);
}
+ ///
+ /// Reads the remaining bytes in the buffer.
+ ///
+ /// The remaining bytes.
internal byte[] ReadToEnd()
{
return _baseStream.ReadBytes((int)(Length - Position));
}
+ ///
+ /// Writes the given as an RGB0 integer value.
+ ///
+ /// The to write.
+ internal void WriteColor(Color color)
+ {
+ _baseStream.WriteByte(color.R);
+ _baseStream.WriteByte(color.G);
+ _baseStream.WriteByte(color.B);
+ _baseStream.WriteByte(0);
+ }
+
///
/// Writes a 2-byte length-prefixed, Windows-949 encoded string.
///
diff --git a/src/Syroot.Worms.OnlineWorms.Server/Net/Packets/ChannelInfosReply.cs b/src/Syroot.Worms.OnlineWorms.Server/Net/Packets/ChannelInfosReply.cs
new file mode 100644
index 0000000..bfabd60
--- /dev/null
+++ b/src/Syroot.Worms.OnlineWorms.Server/Net/Packets/ChannelInfosReply.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Net;
+using Syroot.BinaryData;
+
+namespace Syroot.Worms.OnlineWorms.Server.Net
+{
+ ///
+ /// Represents an additional server response to a , providing available server channels.
+ ///
+ [Packet(0x80C9)]
+ internal class ChannelInfosReply : Packet
+ {
+ // ---- PROPERTIES ---------------------------------------------------------------------------------------------
+
+ public IList Channels { get; set; }
+
+ // ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
+
+ internal override void Deserialize(PacketStream stream) => throw new NotImplementedException();
+
+ internal override void Serialize(PacketStream stream)
+ {
+ stream.WriteUInt16((ushort)Channels.Count);
+ foreach (ChannelInfo channel in Channels)
+ {
+ stream.WriteEnum(channel.Type);
+ stream.WriteByte(channel.Coins);
+ stream.WriteColor(channel.Color);
+ stream.WriteUInt16(1); // ?
+
+ stream.WriteString(channel.Name);
+ stream.WriteByte(0); // ?
+
+ stream.WriteBytes(channel.EndPoint.Address.GetAddressBytes());
+ stream.WriteUInt16((ushort)channel.EndPoint.Port);
+ stream.WriteByte(channel.UserLoad);
+ }
+ }
+ }
+
+ internal class ChannelInfo
+ {
+ ///
+ /// Gets or sets the name of the channel. Should not exceed 32 characters.
+ ///
+ internal string Name { get; set; }
+
+ ///
+ /// Gets or sets the under which the server hosting this channel can be reached.
+ ///
+ internal IPEndPoint EndPoint { get; set; }
+
+ ///
+ /// Gets or sets the type of the channel determining where it will be shown in the server screen.
+ ///
+ internal ChannelType Type { get; set; }
+
+ ///
+ /// Gets or sets an indicator of coins with unclear meaning. 0 is no indicator, 1 is few coins, 2 is many.
+ ///
+ internal byte Coins { get; set; }
+
+ ///
+ /// Gets or sets the text color of the channel.
+ ///
+ internal Color Color { get; set; }
+
+ ///
+ /// Gets or sets an indicator of the number of players in this channel. 0 hides the channel, and 6 represents a
+ /// full channel.
+ ///
+ internal byte UserLoad { get; set; }
+ }
+
+ internal enum ChannelType : byte
+ {
+ Normal = 0,
+ Roping = 1,
+ Special = 2
+ }
+}
diff --git a/src/Syroot.Worms.OnlineWorms.Server/Server.cs b/src/Syroot.Worms.OnlineWorms.Server/Server.cs
index 2cfaf81..180649a 100644
--- a/src/Syroot.Worms.OnlineWorms.Server/Server.cs
+++ b/src/Syroot.Worms.OnlineWorms.Server/Server.cs
@@ -21,6 +21,11 @@ namespace Syroot.Worms.OnlineWorms.Server
internal string RegionName => "Global";
internal ushort Version => 114;
+ ///
+ /// Gets the port under which the server listens for new connections.
+ ///
+ internal int Port { get; private set; }
+
internal Log Log { get; } = new Log();
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
@@ -32,9 +37,10 @@ namespace Syroot.Worms.OnlineWorms.Server
/// The port on which to listen for new client connections.
internal void Listen(int port)
{
- TcpListener tcpListener = new TcpListener(IPAddress.Any, port);
+ Port = port;
+ TcpListener tcpListener = new TcpListener(IPAddress.Any, Port);
tcpListener.Start();
- Log.Write(LogCategory.Server, $"Listening on port {port}...");
+ Log.Write(LogCategory.Server, $"Listening on port {Port}...");
while (true)
{