first commit
This commit is contained in:
18
NitroxModel/MultiplayerSession/AuthenticationContext.cs
Normal file
18
NitroxModel/MultiplayerSession/AuthenticationContext.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
|
||||
namespace NitroxModel.MultiplayerSession
|
||||
{
|
||||
[Serializable]
|
||||
public class AuthenticationContext
|
||||
{
|
||||
public string Username { get; }
|
||||
public Optional<string> ServerPassword { get; }
|
||||
|
||||
public AuthenticationContext(string username, Optional<string> serverPassword)
|
||||
{
|
||||
Username = username;
|
||||
ServerPassword = serverPassword;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
namespace NitroxModel.MultiplayerSession
|
||||
{
|
||||
public enum MultiplayerSessionAuthenticationAuthority
|
||||
{
|
||||
SERVER,
|
||||
OTHER //That which shall not be mentioned - yet...
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace NitroxModel.MultiplayerSession
|
||||
{
|
||||
[Flags]
|
||||
public enum MultiplayerSessionReservationState
|
||||
{
|
||||
RESERVED = 0,
|
||||
REJECTED = 1 << 0,
|
||||
|
||||
[Description("The player name is already in use. Please try again with a different name.")]
|
||||
UNIQUE_PLAYER_NAME_CONSTRAINT_VIOLATED = 1 << 1,
|
||||
|
||||
// These are all intended for future use. Maybe YAGNI, but this is where we should look to expand upon server reservations
|
||||
[Description("The server is currently at capacity. Please try again later.")]
|
||||
SERVER_PLAYER_CAPACITY_REACHED = 1 << 2,
|
||||
|
||||
[Description("The password that you provided for the server is incorrect.")]
|
||||
AUTHENTICATION_FAILED = 1 << 3,
|
||||
|
||||
[Description("The server is using hardcore gamemode, player is dead.")]
|
||||
HARDCORE_PLAYER_DEAD = 1 << 4,
|
||||
|
||||
[Description("Another user is currently joining the server.")]
|
||||
ENQUEUED_IN_JOIN_QUEUE = 1 << 5,
|
||||
|
||||
[Description("The player name is invalid, It must not contain any space or doubtful characters\n Allowed characters : A-Z a-z 0-9 _ . -\nLength : [3, 25]")]
|
||||
INCORRECT_USERNAME = 1 << 6
|
||||
}
|
||||
|
||||
public static class MultiplayerSessionReservationStateExtensions
|
||||
{
|
||||
public static bool HasStateFlag(this MultiplayerSessionReservationState currentState, MultiplayerSessionReservationState checkedState)
|
||||
{
|
||||
return (currentState & checkedState) == checkedState;
|
||||
}
|
||||
|
||||
public static string Describe(this MultiplayerSessionReservationState currentState)
|
||||
{
|
||||
StringBuilder descriptionBuilder = new();
|
||||
|
||||
foreach (string reservationStateName in Enum.GetNames(typeof(MultiplayerSessionReservationState)))
|
||||
{
|
||||
MultiplayerSessionReservationState reservationState = (MultiplayerSessionReservationState)Enum.Parse(typeof(MultiplayerSessionReservationState), reservationStateName);
|
||||
if (currentState.HasStateFlag(reservationState))
|
||||
{
|
||||
DescriptionAttribute descriptionAttribute = reservationState.GetAttribute<DescriptionAttribute>();
|
||||
|
||||
if (!string.IsNullOrEmpty(descriptionAttribute?.Description))
|
||||
{
|
||||
descriptionBuilder.AppendLine(descriptionAttribute.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return descriptionBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
42
NitroxModel/MultiplayerSession/PlayerContext.cs
Normal file
42
NitroxModel/MultiplayerSession/PlayerContext.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.Server;
|
||||
|
||||
namespace NitroxModel.MultiplayerSession;
|
||||
|
||||
[Serializable]
|
||||
public class PlayerContext
|
||||
{
|
||||
public string PlayerName { get; }
|
||||
public ushort PlayerId { get; }
|
||||
public NitroxId PlayerNitroxId { get; }
|
||||
public bool WasBrandNewPlayer { get; }
|
||||
public PlayerSettings PlayerSettings { get; }
|
||||
public bool IsMuted { get; set; }
|
||||
public NitroxGameMode GameMode { get; set; }
|
||||
/// <summary>
|
||||
/// Not null if the player is currently driving a vehicle.
|
||||
/// </summary>
|
||||
public NitroxId DrivingVehicle { get; set; }
|
||||
public IntroCinematicMode IntroCinematicMode { get; set; }
|
||||
|
||||
public PlayerContext(string playerName, ushort playerId, NitroxId playerNitroxId, bool wasBrandNewPlayer, PlayerSettings playerSettings, bool isMuted,
|
||||
NitroxGameMode gameMode, NitroxId drivingVehicle, IntroCinematicMode introCinematicMode)
|
||||
{
|
||||
PlayerName = playerName;
|
||||
PlayerId = playerId;
|
||||
PlayerNitroxId = playerNitroxId;
|
||||
WasBrandNewPlayer = wasBrandNewPlayer;
|
||||
PlayerSettings = playerSettings;
|
||||
IsMuted = isMuted;
|
||||
GameMode = gameMode;
|
||||
DrivingVehicle = drivingVehicle;
|
||||
IntroCinematicMode = introCinematicMode;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[PlayerContext - PlayerName: {PlayerName}, PlayerId: {PlayerId}, PlayerNitroxId: {PlayerNitroxId}, WasBrandNewPlayer: {WasBrandNewPlayer}, PlayerSettings: {PlayerSettings}, GameMode: {GameMode}, DrivingVehicle: {DrivingVehicle}, IntroCinematicMode: {IntroCinematicMode}]";
|
||||
}
|
||||
}
|
21
NitroxModel/MultiplayerSession/PlayerSettings.cs
Normal file
21
NitroxModel/MultiplayerSession/PlayerSettings.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
|
||||
namespace NitroxModel.MultiplayerSession
|
||||
{
|
||||
[Serializable]
|
||||
public class PlayerSettings
|
||||
{
|
||||
public NitroxColor PlayerColor { get; }
|
||||
|
||||
public PlayerSettings(NitroxColor playerColor)
|
||||
{
|
||||
PlayerColor = playerColor;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[{nameof(PlayerSettings)}: PlayerColor: {PlayerColor}]";
|
||||
}
|
||||
}
|
||||
}
|
15
NitroxModel/MultiplayerSession/RandomColorGenerator.cs
Normal file
15
NitroxModel/MultiplayerSession/RandomColorGenerator.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
|
||||
namespace NitroxModel.MultiplayerSession
|
||||
{
|
||||
public static class RandomColorGenerator
|
||||
{
|
||||
private static readonly System.Random random = new System.Random();
|
||||
|
||||
public static NitroxColor GenerateColor()
|
||||
{
|
||||
int r = random.Next();
|
||||
return new NitroxColor((byte)r / 255f, (byte)(r >> 8) / 255f, (byte)(r >> 16) / 255f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user