forked from Impostor/Impostor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BeforeGameCreatedEvent (Impostor#266)
Co-authored-by: js6pak <[email protected]>
- Loading branch information
1 parent
0bb5442
commit d47343d
Showing
9 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Impostor.Api.Games; | ||
using Impostor.Api.Net; | ||
|
||
namespace Impostor.Api.Events | ||
{ | ||
/// <summary> | ||
/// Called just before a new <see cref="IGame"/> is created. | ||
/// </summary> | ||
public interface IGameCreationEvent : IEventCancelable | ||
{ | ||
/// <summary> | ||
/// Gets the client that requested creation of the game. | ||
/// </summary> | ||
/// <remarks> | ||
/// Will be null if game creation was requested by a plugin. | ||
/// </remarks> | ||
IClient? Client { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the desired <see cref="Games.GameCode"/>. | ||
/// </summary> | ||
/// <exception cref="ImpostorException">If the GameCode is invalid or already used in another game.</exception> | ||
GameCode? GameCode { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Impostor.Api; | ||
using Impostor.Api.Events; | ||
using Impostor.Api.Games; | ||
using Impostor.Api.Games.Managers; | ||
using Impostor.Api.Net; | ||
|
||
namespace Impostor.Server.Events | ||
{ | ||
public class GameCreationEvent : IGameCreationEvent | ||
{ | ||
private readonly IGameManager _gameManager; | ||
private GameCode? _gameCode; | ||
|
||
public GameCreationEvent(IGameManager gameManager, IClient? client) | ||
{ | ||
_gameManager = gameManager; | ||
Client = client; | ||
} | ||
|
||
public IClient? Client { get; } | ||
|
||
public GameCode? GameCode | ||
{ | ||
get => _gameCode; | ||
set | ||
{ | ||
if (value.HasValue) | ||
{ | ||
if (value.Value.IsInvalid) | ||
{ | ||
throw new ImpostorException("GameCode is invalid."); | ||
} | ||
|
||
if (_gameManager.Find(value.Value) != null) | ||
{ | ||
throw new ImpostorException($"GameCode [{value.Value.Code}] is already used."); | ||
} | ||
} | ||
|
||
_gameCode = value; | ||
} | ||
} | ||
|
||
public bool IsCancelled { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters