feat: add ListServerResponseMessage, refactor
This commit is contained in:
parent
1ef186c46c
commit
861dc7ab01
8 changed files with 60 additions and 43 deletions
|
@ -10,20 +10,12 @@ internal class Program
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// var sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
IPEndPoint serverEP = new(IPAddress.Any, SERVER_PORT);
|
||||||
|
|
||||||
var serverEP = new IPEndPoint(IPAddress.Any, SERVER_PORT);
|
|
||||||
|
|
||||||
UdpClient udpClient = new();
|
UdpClient udpClient = new();
|
||||||
udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
udpClient.Connect(serverEP);
|
udpClient.Connect(serverEP);
|
||||||
|
|
||||||
|
|
||||||
// byte[] username = "helloworld123".ToUTF8String();
|
|
||||||
// byte[] password = "password&(*$())".ToUTF8String();
|
|
||||||
|
|
||||||
// byte[] sendBuffer = [(byte)ServerPacketIn.AUTH, (byte)username.Length, .. username, (byte)password.Length, .. password];
|
|
||||||
|
|
||||||
Console.WriteLine("Username...");
|
Console.WriteLine("Username...");
|
||||||
string username = Console.ReadLine()!;
|
string username = Console.ReadLine()!;
|
||||||
|
|
||||||
|
@ -58,8 +50,6 @@ internal class Program
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Console.WriteLine($"Received unsupported packet.");
|
Console.WriteLine($"Received unsupported packet.");
|
||||||
// byte[] response = [(byte)ClientPacketIn.UNKNOWN];
|
|
||||||
// listener.Send(response);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
namespace GServer.Common.Networking.Enums
|
namespace GServer.Common.Networking.Enums;
|
||||||
{
|
|
||||||
public enum ClientPacketIn : byte
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents an auth result from the server.
|
|
||||||
/// Format: {1(success) | 2(error)}{error msg length}{error msg}
|
|
||||||
/// </summary>
|
|
||||||
AUTH_RESPONSE = 1,
|
|
||||||
|
|
||||||
UNKNOWN = 255
|
public enum ClientPacketIn : byte
|
||||||
}
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents an auth result from the server.
|
||||||
|
/// </summary>
|
||||||
|
AUTH_RESPONSE = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains a list of server listings.
|
||||||
|
/// </summary>
|
||||||
|
LIST_SERVERS_RESPONSE = 2,
|
||||||
|
|
||||||
|
UNKNOWN = 255
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
namespace GServer.Common.Networking.Enums
|
namespace GServer.Common.Networking.Enums;
|
||||||
|
|
||||||
|
public enum ServerPacketIn : byte
|
||||||
{
|
{
|
||||||
public enum ServerPacketIn : byte
|
AUTH = 1,
|
||||||
{
|
LIST_SERVERS = 2
|
||||||
AUTH = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GServer.Common.Networking.Enums;
|
using GServer.Common.Networking.Enums;
|
||||||
using GServer.Common.Networking.Messages;
|
|
||||||
|
|
||||||
namespace GServer.Common;
|
namespace GServer.Common.Networking.Messages.Client;
|
||||||
|
|
||||||
public enum AuthResponseFailure : byte
|
public enum AuthResponseFailure : byte
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
using GServer.Common.Game.Entities;
|
||||||
|
using GServer.Common.Networking.Enums;
|
||||||
|
|
||||||
|
namespace GServer.Common.Networking.Messages.Client;
|
||||||
|
|
||||||
|
public class ListServersResponseMessage : BaseMessage, IMessage<ListServersResponseMessage>
|
||||||
|
{
|
||||||
|
public IEnumerable<ServerListing> ServerListings { get; set; }
|
||||||
|
|
||||||
|
public ListServersResponseMessage(IEnumerable<ServerListing> serverListings) : base((byte)ClientPacketIn.LIST_SERVERS_RESPONSE)
|
||||||
|
{
|
||||||
|
ServerListings = serverListings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListServersResponseMessage(MessageMemoryStream stream) : base((byte)ClientPacketIn.LIST_SERVERS_RESPONSE)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Serialize()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,16 +16,6 @@ public class AuthMessage : BaseMessage, IMessage<AuthMessage>
|
||||||
|
|
||||||
public AuthMessage(MessageMemoryStream stream) : base((byte)ServerPacketIn.AUTH)
|
public AuthMessage(MessageMemoryStream stream) : base((byte)ServerPacketIn.AUTH)
|
||||||
{
|
{
|
||||||
// byte usernameLength = (byte)stream.ReadByte();
|
|
||||||
// byte[] usernameBytes = new byte[usernameLength];
|
|
||||||
// _ = stream.Read(usernameBytes, 0, usernameLength);
|
|
||||||
// string username = Encoding.UTF8.GetString(usernameBytes);
|
|
||||||
|
|
||||||
// byte passwordLength = (byte)stream.ReadByte();
|
|
||||||
// byte[] passwordBytes = new byte[passwordLength];
|
|
||||||
// _ = stream.Read(passwordBytes, 0, passwordLength);
|
|
||||||
// string password = Encoding.UTF8.GetString(passwordBytes);
|
|
||||||
|
|
||||||
byte usernameLen = (byte)stream.ReadByte();
|
byte usernameLen = (byte)stream.ReadByte();
|
||||||
string username = stream.ReadUTF8String(usernameLen);
|
string username = stream.ReadUTF8String(usernameLen);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
using GServer.Common.Networking.Enums;
|
||||||
|
|
||||||
|
namespace GServer.Common.Networking.Messages.Server;
|
||||||
|
|
||||||
|
public class ListServersMessage : BaseMessage, IMessage<ListServersMessage>
|
||||||
|
{
|
||||||
|
public ListServersMessage() : base((byte)ServerPacketIn.LIST_SERVERS)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Serialize()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,10 +41,6 @@ internal class Program
|
||||||
case ServerPacketIn.AUTH:
|
case ServerPacketIn.AUTH:
|
||||||
var msg = new AuthMessage(stream);
|
var msg = new AuthMessage(stream);
|
||||||
|
|
||||||
Console.WriteLine($"Username = {msg.Username}, Length = {msg.Username.Length}");
|
|
||||||
|
|
||||||
Console.WriteLine($"Password = {msg.Password}, Length = {msg.Password.Length}");
|
|
||||||
|
|
||||||
AuthResponseMessage resp;
|
AuthResponseMessage resp;
|
||||||
|
|
||||||
if (msg.Username == "aaronyarbz" && msg.Password == "password123")
|
if (msg.Username == "aaronyarbz" && msg.Password == "password123")
|
||||||
|
|
Loading…
Add table
Reference in a new issue