Initial
This commit is contained in:
1 parent
2674eb2a10
commit
840218f119
25 files changed
+650
-169
No files matched your search
@@ -1,8 +1,15 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to subscribe to a game id by guid to observe it's list of open lobbies
|
||||
/// </summary>
|
||||
/// <remarks>A client can only be subscribed to one game id, sending multiple observe requests with different game ids will overwrite the previous</remarks>
|
||||
[LobbyMessage]
|
||||
public partial class LobbiesObserve
|
||||
{
|
||||
/// <summary>
|
||||
/// The game id to subscribe to
|
||||
/// </summary>
|
||||
public Guid GameId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Stop observing and receiving updates on the lobby list
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbiesStopObserve
|
||||
{
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send to lobby client after connection is established
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyClientConnectionInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection id on the lobby server
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,47 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a lobby in the lobby list. The lobby will stay until either closed by the host or the host disconnects
|
||||
/// </summary>
|
||||
/// <remarks>A host can always have only one open lobby, if another lobby is already opened by the client it will be closed</remarks>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyCreate
|
||||
{
|
||||
/// <summary>
|
||||
/// Game Id for which game this lobby is for
|
||||
/// </summary>
|
||||
public Guid GameId { get; set; }
|
||||
/// <summary>
|
||||
/// Display name of the lobby
|
||||
/// </summary>
|
||||
[MaxLength(64)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// Game mode of lobby
|
||||
/// </summary>
|
||||
public int GameMode { get; set; }
|
||||
/// <summary>
|
||||
/// How many players are in the lobby
|
||||
/// </summary>
|
||||
public int PlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// Maximum players allowed in the lobby
|
||||
/// </summary>
|
||||
public int MaxPlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// The hash of a password to protect the lobby. Only users with the password can request host information/nat punch.
|
||||
/// </summary>
|
||||
[MaxLength(26)]
|
||||
public byte[]? PasswordHash { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts ip. Used the the host information send to clients on their request.
|
||||
/// </summary>
|
||||
[MaxLength(32)]
|
||||
public string? HostIp { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts port. Used the the host information send to clients on their request.
|
||||
/// </summary>
|
||||
public int HostPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,19 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// If send from host closes and deletes a lobby.
|
||||
/// If received by client, the lobby with the Id parameter has been closed
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyDelete
|
||||
{
|
||||
/// <summary>
|
||||
/// If received by client, this contains the lobby id. Does not need to be set if the host sends this request.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// If received by client, this contains the game id. Does not need to be set if the host sends this request.
|
||||
/// </summary>
|
||||
public Guid GameId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,24 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send to client upon request, this contains the connection info supplied by the host.
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyHostInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Lobby id this information is for
|
||||
/// </summary>
|
||||
public Guid LobbyId { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts ip, this could be an internal address
|
||||
/// </summary>
|
||||
[MaxLength(32)]
|
||||
public string? HostIp { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts port
|
||||
/// </summary>
|
||||
public int HostPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,34 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send when a lobby is created or updates, this contains the lobby information
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the lobby
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
/// <summary>
|
||||
/// Displayname of the lobby
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
/// <summary>
|
||||
/// Game mode of the lobby
|
||||
/// </summary>
|
||||
public int GameMode { get; set; }
|
||||
/// <summary>
|
||||
/// Count of currently joined players in the lobby
|
||||
/// </summary>
|
||||
public int PlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// Max players allowed in the lobby
|
||||
/// </summary>
|
||||
public int MaxPlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// True if the lobby requires a password to gain access
|
||||
/// </summary>
|
||||
public bool PasswordProtected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to read the message identifer from a received object
|
||||
/// </summary>
|
||||
public static class LobbyMessageIdentifier
|
||||
{
|
||||
/// <summary>
|
||||
/// Read the message identifiere from the stream
|
||||
/// </summary>
|
||||
/// <param name="buffer"></param>
|
||||
/// <returns>The message identifier or -1 if invalid</returns>
|
||||
public static int ReadLobbyMessageIdentifier(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
if(buffer.Length == 0)
|
||||
return -1;
|
||||
|
||||
int typeId = 0;
|
||||
int shift = 0;
|
||||
int offset = 0;
|
||||
byte currentByte;
|
||||
do
|
||||
{
|
||||
if (offset < buffer.Length)
|
||||
{
|
||||
// Check for a corrupted stream. Read a max of 5 bytes.
|
||||
// In a future version, add a DataFormatException.
|
||||
if (shift == 5 * 7) // 5 bytes max per Int32, shift += 7
|
||||
return -1;
|
||||
|
||||
// ReadByte handles end of stream cases for us.
|
||||
currentByte = buffer[offset++];
|
||||
typeId |= (currentByte & 0x7F) << shift;
|
||||
shift += 7;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
} while ((currentByte & 0x80) != 0);
|
||||
|
||||
return typeId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,29 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send from host to lobby server and releyed to the client by lobby server if the nat punch is finished.
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyNatPunchDone
|
||||
{
|
||||
/// <summary>
|
||||
/// The lobby this nat punch was for
|
||||
/// </summary>
|
||||
public Guid LobbyId { get; set; }
|
||||
/// <summary>
|
||||
/// Id of the nat punch that the lobby server requested from us in <see cref="LobbyRequestNatPunch"/>
|
||||
/// </summary>
|
||||
public int NatPunchId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The external ip of the host
|
||||
/// </summary>
|
||||
[MaxLength(32)]
|
||||
public string? ExternalIp { get; set; }
|
||||
/// <summary>
|
||||
/// The external port of the host
|
||||
/// </summary>
|
||||
public int ExternalPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,19 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Request the host address for a lobby
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyRequestHostInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the lobby
|
||||
/// </summary>
|
||||
public Guid LobbyId { get; set; }
|
||||
/// <summary>
|
||||
/// Hash of the password if the lobby requires one
|
||||
/// </summary>
|
||||
[MaxLength(26)]
|
||||
public byte[]? PasswordHash { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,16 +2,33 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Request a nat punch from the game host
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyRequestNatPunch
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the lobby
|
||||
/// </summary>
|
||||
public Guid LobbyId { get; set; }
|
||||
/// <summary>
|
||||
/// Password hash if the lobby is password protected
|
||||
/// </summary>
|
||||
[MaxLength(26)]
|
||||
public byte[]? PasswordHash { get; set; }
|
||||
/// <summary>
|
||||
/// Our external ip
|
||||
/// </summary>
|
||||
|
||||
public string? ClientIp { get; set; }
|
||||
/// <summary>
|
||||
/// Our external port
|
||||
/// </summary>
|
||||
public int ClientPort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set by the lobby server, this will be the NatPunchId send to the host
|
||||
/// </summary>
|
||||
public int NatPunchId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,40 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// If the host updates values of the lobby, it can send this request to update the lobby information on the lobby server
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyUpdate
|
||||
{
|
||||
/// <summary>
|
||||
/// The displayname of the lobby
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// The game mode of the lobby
|
||||
/// </summary>
|
||||
public int GameMode { get; set; }
|
||||
/// <summary>
|
||||
/// Current count of players in the lobby
|
||||
/// </summary>
|
||||
public int PlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// Max players in the lobby
|
||||
/// </summary>
|
||||
public int MaxPlayerCount { get; set; }
|
||||
/// <summary>
|
||||
/// The hash of the password required to enter this lobby
|
||||
/// </summary>
|
||||
public byte[]? PasswordHash { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts ip
|
||||
/// </summary>
|
||||
[MaxLength(32)]
|
||||
public string? HostIp { get; set; }
|
||||
/// <summary>
|
||||
/// The hosts port
|
||||
/// </summary>
|
||||
public int HostPort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send if a client requests information about a password protected lobby with an invalid password hash
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class LobbyWrongPassword
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the lobby
|
||||
/// </summary>
|
||||
public Guid LobbyId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
public class NatPuncher
|
||||
{
|
||||
public static void NatPunch(IPEndPoint localEndpoint, IPEndPoint remoteEndpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
|
||||
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.ReuseAddress, true);
|
||||
socket.ExclusiveAddressUse = false;
|
||||
socket.Bind(localEndpoint);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
socket.SendTo(new byte[] { }, remoteEndpoint);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Send from a client to the lobby server via udp to from the game port to retrieve the observerd external ip and port
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class QueryExternalPortAndIp
|
||||
{
|
||||
/// <summary>
|
||||
/// Lobby client id
|
||||
/// </summary>
|
||||
public int LobbyClientId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// The ip and port seen by the lobby udp server by an <see cref="QueryExternalPortAndIp"/> request.
|
||||
/// </summary>
|
||||
[LobbyMessage]
|
||||
public partial class SeenExternalIpAndPort
|
||||
{
|
||||
/// <summary>
|
||||
/// The seen ip of the client
|
||||
/// </summary>
|
||||
[MaxLength(32)]
|
||||
public string? Ip { get; set; }
|
||||
/// <summary>
|
||||
/// The seen port of the client
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
namespace LobbyServerDto
|
||||
{
|
||||
/// <summary>
|
||||
/// List of accepted game ips
|
||||
/// </summary>
|
||||
public static class GameGuids
|
||||
{
|
||||
public static Guid NFS = new Guid("0572706f-0fd9-46a9-8ea6-5a31a5363442");
|
||||
|
||||
Reference in new issue
Block a user