mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-27 22:27:58 +03:00
Add ChannelEnterQuery and Reply.
This commit is contained in:
parent
ee17e5886e
commit
1d8c090957
@ -63,7 +63,7 @@ namespace Syroot.Worms.OnlineWorms.Server
|
||||
Text = "Welcome to the Online Worms Server."
|
||||
});
|
||||
|
||||
// Send channels.
|
||||
// Send channels. The port is abused to identify the channel later on.
|
||||
SendPacket(new ChannelInfosReply
|
||||
{
|
||||
Channels = new[]
|
||||
@ -71,7 +71,7 @@ namespace Syroot.Worms.OnlineWorms.Server
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Test Channel",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 1),
|
||||
Type = ChannelType.Normal,
|
||||
Color = Color.LightGreen,
|
||||
UserLoad = 5
|
||||
@ -79,15 +79,20 @@ namespace Syroot.Worms.OnlineWorms.Server
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Real Channel",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 2),
|
||||
Type = ChannelType.Normal
|
||||
},
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Boredom Time",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 3),
|
||||
Type = ChannelType.Normal,
|
||||
Color = Color.Yellow,
|
||||
UserLoad = 1
|
||||
UserLoad = 3
|
||||
},
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Nothing Goes",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 4),
|
||||
Type = ChannelType.Roping,
|
||||
Color = Color.Orange,
|
||||
Coins = 2,
|
||||
@ -95,25 +100,32 @@ namespace Syroot.Worms.OnlineWorms.Server
|
||||
},
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Boredom Time",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
|
||||
Name = "Doper's Heaven",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 5),
|
||||
Type = ChannelType.Roping,
|
||||
Color = Color.HotPink,
|
||||
Color = Color.Orange,
|
||||
Coins = 1,
|
||||
UserLoad = 3
|
||||
UserLoad = 5
|
||||
},
|
||||
new ChannelInfo
|
||||
{
|
||||
Name = "Unhelpful Channel",
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port),
|
||||
Type = ChannelType.Special,
|
||||
Color = Color.White,
|
||||
UserLoad = 1
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, 6),
|
||||
Type = ChannelType.Special
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleChannelEnter(ChannelEnterQuery packet)
|
||||
{
|
||||
// Simply allow joining a channel running on the same server port.
|
||||
SendPacket(new ChannelEnterReply
|
||||
{
|
||||
EndPoint = new IPEndPoint(IPAddress.Loopback, _server.Port)
|
||||
});
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
public void HandleRaw(RawQuery packet) { }
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
@ -18,87 +19,7 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
|
||||
public override string ToString()
|
||||
{
|
||||
#if DEBUG
|
||||
string dump(object obj, int indentLevel)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string indent = new string(' ', indentLevel * 4);
|
||||
switch (obj)
|
||||
{
|
||||
case null:
|
||||
sb.Append(indent);
|
||||
sb.Append("null");
|
||||
break;
|
||||
case String stringValue:
|
||||
sb.Append(indent);
|
||||
sb.Append('"');
|
||||
sb.Append(stringValue);
|
||||
sb.Append('"');
|
||||
break;
|
||||
case Byte[] byteArrayValue:
|
||||
sb.Append(indent);
|
||||
sb.Append(String.Join(" ", byteArrayValue.Select(x => x.ToString("X2"))));
|
||||
break;
|
||||
case IEnumerable iEnumerableValue:
|
||||
sb.Append(indent);
|
||||
sb.Append("[ ");
|
||||
foreach (object element in iEnumerableValue)
|
||||
sb.Append(dump(element, indentLevel)).Append(" ");
|
||||
sb.Append("]");
|
||||
break;
|
||||
case Byte byteValue:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + byteValue.ToString("X2"));
|
||||
break;
|
||||
case Int16 int16Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int16Value.ToString("X4"));
|
||||
break;
|
||||
case Int32 int32Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int32Value.ToString("X8"));
|
||||
break;
|
||||
case Int64 int64Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int64Value.ToString("X16"));
|
||||
break;
|
||||
case UInt16 uint16Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint16Value.ToString("X4"));
|
||||
break;
|
||||
case UInt32 uint32Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint32Value.ToString("X8"));
|
||||
break;
|
||||
case UInt64 uint64Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint64Value.ToString("X16"));
|
||||
break;
|
||||
case Enum enumValue:
|
||||
sb.Append(indent);
|
||||
sb.Append(enumValue.ToString());
|
||||
break;
|
||||
case IPAddress ipAddress:
|
||||
sb.Append(indent);
|
||||
sb.Append(ipAddress.ToString());
|
||||
break;
|
||||
default:
|
||||
foreach (PropertyInfo property in obj.GetType().GetProperties(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||
{
|
||||
// Ignore indexers.
|
||||
if (property.GetIndexParameters().Length > 0)
|
||||
continue;
|
||||
sb.AppendLine();
|
||||
sb.Append((indent + property.Name).PadRight(20));
|
||||
sb.Append(" ");
|
||||
sb.Append(dump(property.GetValue(obj), indentLevel + 1));
|
||||
}
|
||||
sb.AppendLine();
|
||||
break;
|
||||
}
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
return String.Concat(GetType().Name, dump(this, 1));
|
||||
return String.Concat(GetType().Name, DumpClass(this, 1));
|
||||
#else
|
||||
return GetType().Name;
|
||||
#endif
|
||||
@ -109,5 +30,98 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
|
||||
internal abstract void Deserialize(PacketStream stream);
|
||||
|
||||
internal abstract void Serialize(PacketStream stream);
|
||||
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
#if DEBUG
|
||||
private string DumpClass(object obj, int indentLevel)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
string indent = new string(' ', indentLevel * 4);
|
||||
switch (obj)
|
||||
{
|
||||
case null:
|
||||
sb.Append(indent);
|
||||
sb.Append("null");
|
||||
break;
|
||||
case String stringValue:
|
||||
sb.Append(indent);
|
||||
sb.Append('"');
|
||||
sb.Append(stringValue);
|
||||
sb.Append('"');
|
||||
break;
|
||||
case Byte[] byteArrayValue:
|
||||
sb.Append(indent);
|
||||
sb.Append(String.Join(" ", byteArrayValue.Select(x => x.ToString("X2"))));
|
||||
break;
|
||||
case IEnumerable iEnumerableValue:
|
||||
sb.Append(indent);
|
||||
sb.Append("[ ");
|
||||
foreach (object element in iEnumerableValue)
|
||||
sb.Append(DumpClass(element, indentLevel)).Append(" ");
|
||||
sb.Append("]");
|
||||
break;
|
||||
case Byte byteValue:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + byteValue.ToString("X2"));
|
||||
break;
|
||||
case Int16 int16Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int16Value.ToString("X4"));
|
||||
break;
|
||||
case Int32 int32Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int32Value.ToString("X8"));
|
||||
break;
|
||||
case Int64 int64Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + int64Value.ToString("X16"));
|
||||
break;
|
||||
case UInt16 uint16Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint16Value.ToString("X4"));
|
||||
break;
|
||||
case UInt32 uint32Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint32Value.ToString("X8"));
|
||||
break;
|
||||
case UInt64 uint64Value:
|
||||
sb.Append(indent);
|
||||
sb.Append("0x" + uint64Value.ToString("X16"));
|
||||
break;
|
||||
case Enum enumValue:
|
||||
sb.Append(indent);
|
||||
sb.Append(enumValue.ToString());
|
||||
break;
|
||||
case Color color:
|
||||
sb.Append(indent);
|
||||
sb.Append(color.ToString());
|
||||
break;
|
||||
case IPEndPoint ipEndPoint:
|
||||
sb.Append(indent);
|
||||
sb.Append($"{ipEndPoint.Address}:{ipEndPoint.Port}");
|
||||
break;
|
||||
case IPAddress ipAddress:
|
||||
sb.Append(indent);
|
||||
sb.Append(ipAddress.ToString());
|
||||
break;
|
||||
default:
|
||||
foreach (PropertyInfo property in obj.GetType().GetProperties(
|
||||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||
{
|
||||
// Ignore indexers.
|
||||
if (property.GetIndexParameters().Length > 0)
|
||||
continue;
|
||||
sb.AppendLine();
|
||||
sb.Append((indent + property.Name).PadRight(20));
|
||||
sb.Append(" ");
|
||||
sb.Append(DumpClass(property.GetValue(obj), indentLevel + 1));
|
||||
}
|
||||
sb.AppendLine();
|
||||
break;
|
||||
}
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.OnlineWorms.Server.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the client request for a <see cref="ChannelEnterReply"/>.
|
||||
/// </summary>
|
||||
[Packet(0x8034)]
|
||||
internal class ChannelEnterQuery : Packet
|
||||
{
|
||||
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
|
||||
|
||||
public string PlayerID { get; set; }
|
||||
|
||||
public IPEndPoint ChannelEndPoint { get; set; }
|
||||
|
||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
||||
|
||||
internal override void Deserialize(PacketStream stream)
|
||||
{
|
||||
PlayerID = stream.ReadString();
|
||||
ChannelEndPoint = new IPEndPoint(IPAddress.Parse(stream.ReadString()), stream.ReadUInt16());
|
||||
}
|
||||
|
||||
internal override void Serialize(PacketStream stream) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.OnlineWorms.Server.Net
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the server response to a <see cref="ChannelEnterQuery"/>.
|
||||
/// </summary>
|
||||
[Packet(0x8035)]
|
||||
internal class ChannelEnterReply : Packet
|
||||
{
|
||||
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IPEndPoint"/> to which the game client connects to enter the channel.
|
||||
/// </summary>
|
||||
public IPEndPoint EndPoint { get; set; }
|
||||
|
||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
||||
|
||||
internal override void Deserialize(PacketStream stream) => throw new NotImplementedException();
|
||||
|
||||
internal override void Serialize(PacketStream stream)
|
||||
{
|
||||
stream.WriteString(EndPoint.Address.ToString());
|
||||
stream.WriteUInt16((ushort)EndPoint.Port);
|
||||
}
|
||||
}
|
||||
}
|
@ -65,13 +65,13 @@ namespace Syroot.Worms.OnlineWorms.Server.Net
|
||||
/// <summary>
|
||||
/// Gets or sets the text color of the channel.
|
||||
/// </summary>
|
||||
internal Color Color { get; set; }
|
||||
internal Color Color { get; set; } = Color.White;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an indicator of the number of players in this channel. 0 hides the channel, and 6 represents a
|
||||
/// full channel.
|
||||
/// </summary>
|
||||
internal byte UserLoad { get; set; }
|
||||
internal byte UserLoad { get; set; } = 1;
|
||||
}
|
||||
|
||||
internal enum ChannelType : byte
|
||||
|
Loading…
x
Reference in New Issue
Block a user