mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-19 15:51:42 +00:00
Change all events to use interfaces and move them to a better namespace
This commit is contained in:
1 parent
d1daf1623a
commit
961bd90ef6
52 files changed
+305
-216
No files matched your search
@@ -150,6 +150,7 @@ Create a new class called `GameEventListener`. Example code:
|
||||
|
||||
```csharp
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Impostor.Plugins.Example.Handlers
|
||||
@@ -176,7 +177,7 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
/// The event you want to listen for.
|
||||
/// </param>
|
||||
[EventListener]
|
||||
public void OnGameStarted(GameStartedEvent e)
|
||||
public void OnGameStarted(IGameStartedEvent e)
|
||||
{
|
||||
_logger.LogInformation($"Game is starting.");
|
||||
|
||||
@@ -197,13 +198,13 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnGameEnded(GameEndedEvent e)
|
||||
public void OnGameEnded(IGameEndedEvent e)
|
||||
{
|
||||
_logger.LogInformation($"Game has ended.");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnPlayerChat(PlayerChatEvent e)
|
||||
public void OnPlayerChat(IPlayerChatEvent e)
|
||||
{
|
||||
_logger.LogInformation($"{e.PlayerControl.PlayerInfo.PlayerName} said {e.Message}");
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ indent_style = space
|
||||
# Code files
|
||||
[*.{cs,csx,vb,vbx}]
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
|
||||
# XML project files
|
||||
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called whenever a new <see cref="IGame"/> is created.
|
||||
/// </summary>
|
||||
public sealed class GameCreatedEvent : IGameEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameCreatedEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="game">Instance of the game.</param>
|
||||
public GameCreatedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called whenever a new <see cref="IGame"/> is destroyed.
|
||||
/// </summary>
|
||||
public sealed class GameDestroyedEvent : IGameEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameDestroyedEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="game">Instance of the game.</param>
|
||||
public GameDestroyedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
public class GameEndedEvent : IGameEvent
|
||||
{
|
||||
public GameEndedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The game is started here and players have been initialized.
|
||||
/// </summary>
|
||||
public class GameStartedEvent : IGameEvent
|
||||
{
|
||||
public GameStartedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the game is going to start.
|
||||
/// When this is called, not all players are initialized properly yet.
|
||||
/// If you want to get correct player states, use <see cref="GameStartedEvent"/>.
|
||||
/// </summary>
|
||||
public class GameStartingEvent : IGameEvent
|
||||
{
|
||||
public GameStartingEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called whenever a new <see cref="IGame"/> is created.
|
||||
/// </summary>
|
||||
public interface IGameCreatedEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called whenever a new <see cref="IGame"/> is destroyed.
|
||||
/// </summary>
|
||||
public interface IGameDestroyedEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
public interface IGameEndedEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ namespace Impostor.Api.Events
|
||||
{
|
||||
public interface IGameEvent : IEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IGame"/> this event belongs to.
|
||||
/// </summary>
|
||||
IGame Game { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
public interface IGamePlayerJoinedEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
public interface IGamePlayerLeftEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// The game is started here and players have been initialized.
|
||||
/// </summary>
|
||||
public interface IGameStartedEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the game is going to start.
|
||||
/// When this is called, not all players are initialized properly yet.
|
||||
/// If you want to get correct player states, use <see cref="IGameStartedEvent"/>.
|
||||
/// </summary>
|
||||
public interface IGameStartingEvent : IGameEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events.Meeting
|
||||
{
|
||||
public interface IMeetingEndedEvent : IMeetingEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Meeting
|
||||
{
|
||||
public interface IMeetingEvent : IGameEvent
|
||||
{
|
||||
IInnerMeetingHud MeetingHud { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events.Meeting
|
||||
{
|
||||
public interface IMeetingStartedEvent : IMeetingEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Impostor.Api.Events.Player
|
||||
{
|
||||
public interface IPlayerChatEvent : IPlayerEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message sent by the player.
|
||||
/// </summary>
|
||||
string Message { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events.Player
|
||||
{
|
||||
public interface IPlayerDestroyedEvent : IPlayerEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Impostor.Api.Events.Player
|
||||
{
|
||||
public interface IPlayerSpawnedEvent : IPlayerEvent
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// using Impostor.Api.Games;
|
||||
// using Impostor.Api.Net;
|
||||
// using Impostor.Api.Net.Inner.Objects;
|
||||
//
|
||||
// namespace Impostor.Api.Events.Player
|
||||
// {
|
||||
// public class PlayerMovementEvent : IPlayerEvent
|
||||
// {
|
||||
// public PlayerMovementEvent(IGame game, IClientPlayer clientPlayer, IInnerPlayerControl playerControl)
|
||||
// {
|
||||
// Game = game;
|
||||
// ClientPlayer = clientPlayer;
|
||||
// PlayerControl = playerControl;
|
||||
// }
|
||||
//
|
||||
// public IGame Game { get; }
|
||||
//
|
||||
// public IClientPlayer ClientPlayer { get; }
|
||||
//
|
||||
// public IInnerPlayerControl PlayerControl { get; }
|
||||
// }
|
||||
// }
|
||||
@@ -1,18 +0,0 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
{
|
||||
public class PlayerJoinedGameEvent : IGameEvent
|
||||
{
|
||||
public PlayerJoinedGameEvent(IGame game, IClientPlayer player)
|
||||
{
|
||||
Game = game;
|
||||
Player = player;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
|
||||
public IClientPlayer Player { get; }
|
||||
}
|
||||
}
|
||||
@@ -48,10 +48,10 @@
|
||||
@code {
|
||||
private IDisposable _disposable;
|
||||
|
||||
[EventListener(typeof(GameCreatedEvent))]
|
||||
[EventListener(typeof(GameDestroyedEvent))]
|
||||
[EventListener(typeof(PlayerJoinedGameEvent))]
|
||||
[EventListener(typeof(PlayerLeftGameEvent))]
|
||||
[EventListener(typeof(IGameCreatedEvent))]
|
||||
[EventListener(typeof(IGameDestroyedEvent))]
|
||||
[EventListener(typeof(IGamePlayerJoinedEvent))]
|
||||
[EventListener(typeof(IGamePlayerLeftEvent))]
|
||||
public void OnGameCreated(IGameEvent e)
|
||||
{
|
||||
StateHasChanged();
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Player;
|
||||
|
||||
namespace Impostor.Plugins.Example.Handlers
|
||||
{
|
||||
public class GameEventListener : IEventListener
|
||||
{
|
||||
[EventListener]
|
||||
public void OnGameCreated(GameCreatedEvent e)
|
||||
public void OnGameCreated(IGameCreatedEvent e)
|
||||
{
|
||||
Console.WriteLine("Game > created");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnGameStarting(GameStartingEvent e)
|
||||
public void OnGameStarting(IGameStartingEvent e)
|
||||
{
|
||||
Console.WriteLine("Game > starting");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnGameStarted(GameStartedEvent e)
|
||||
public void OnGameStarted(IGameStartedEvent e)
|
||||
{
|
||||
Console.WriteLine("Game > started");
|
||||
|
||||
@@ -32,27 +31,27 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnGameEnded(GameEndedEvent e)
|
||||
public void OnGameEnded(IGameEndedEvent e)
|
||||
{
|
||||
Console.WriteLine("Game > ended");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnGameDestroyed(GameDestroyedEvent e)
|
||||
public void OnGameDestroyed(IGameDestroyedEvent e)
|
||||
{
|
||||
Console.WriteLine("Game > destroyed");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnPlayerJoined(PlayerJoinedGameEvent e)
|
||||
public void OnPlayerJoined(IGamePlayerJoinedEvent e)
|
||||
{
|
||||
Console.WriteLine("Player joined a game.");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnPlayerLeftGame(PlayerLeftGameEvent e)
|
||||
public void OnPlayerLeftGame(IGamePlayerLeftEvent e)
|
||||
{
|
||||
Console.WriteLine("Player left a game.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,15 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
public class MeetingEventListener : IEventListener
|
||||
{
|
||||
[EventListener]
|
||||
public void OnMeetingStarted(MeetingStartedEvent e)
|
||||
public void OnMeetingStarted(IMeetingStartedEvent e)
|
||||
{
|
||||
Console.WriteLine("Meeting > started");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnMeetingEnded(MeetingEndedEvent e)
|
||||
public void OnMeetingEnded(IMeetingEndedEvent e)
|
||||
{
|
||||
Console.WriteLine("Meeting > ended");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,19 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
public class PlayerEventListener : IEventListener
|
||||
{
|
||||
[EventListener]
|
||||
public void OnPlayerSpawned(PlayerSpawnedEvent e)
|
||||
public void OnPlayerSpawned(IPlayerSpawnedEvent e)
|
||||
{
|
||||
Console.WriteLine(e.PlayerControl.PlayerInfo.PlayerName + " spawned");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public void OnPlayerDestroyed(PlayerDestroyedEvent e)
|
||||
public void OnPlayerDestroyed(IPlayerDestroyedEvent e)
|
||||
{
|
||||
Console.WriteLine(e.PlayerControl.PlayerInfo.PlayerName + " destroyed");
|
||||
}
|
||||
|
||||
[EventListener]
|
||||
public async ValueTask OnPlayerChat(PlayerChatEvent e)
|
||||
public async ValueTask OnPlayerChat(IPlayerChatEvent e)
|
||||
{
|
||||
Console.WriteLine(e.PlayerControl.PlayerInfo.PlayerName + " said " + e.Message);
|
||||
|
||||
@@ -37,4 +37,4 @@ namespace Impostor.Plugins.Example.Handlers
|
||||
await e.PlayerControl.SendChatAsync(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Managers;
|
||||
@@ -88,6 +89,16 @@ namespace Impostor.Server.Events
|
||||
private IEnumerable<EventHandler> GetHandlers<TEvent>(IServiceProvider services)
|
||||
where TEvent : IEvent
|
||||
{
|
||||
var eventType = typeof(TEvent);
|
||||
var interfaces = eventType.GetInterfaces();
|
||||
if (interfaces.Length > 0 && _temporaryEventListeners.TryGetValue(interfaces[0], out var cb))
|
||||
{
|
||||
foreach (var eventListener in cb.GetEventListeners())
|
||||
{
|
||||
yield return new EventHandler(null, eventListener);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var handler in services.GetServices<IEventListener>())
|
||||
{
|
||||
if (handler is IManualEventListener manualEventListener && manualEventListener.CanExecute<TEvent>())
|
||||
@@ -109,7 +120,7 @@ namespace Impostor.Server.Events
|
||||
}
|
||||
}
|
||||
|
||||
if (_temporaryEventListeners.TryGetValue(typeof(TEvent), out var cb))
|
||||
if (_temporaryEventListeners.TryGetValue(eventType, out cb))
|
||||
{
|
||||
foreach (var eventListener in cb.GetEventListeners())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GameCreatedEvent : IGameCreatedEvent
|
||||
{
|
||||
public GameCreatedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GameDestroyedEvent : IGameDestroyedEvent
|
||||
{
|
||||
public GameDestroyedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GameEndedEvent : IGameEndedEvent
|
||||
{
|
||||
public GameEndedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GamePlayerJoinedEvent : IGamePlayerJoinedEvent
|
||||
{
|
||||
public GamePlayerJoinedEvent(IGame game, IClientPlayer player)
|
||||
{
|
||||
Game = game;
|
||||
Player = player;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
|
||||
public IClientPlayer Player { get; }
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,11 +1,12 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
|
||||
namespace Impostor.Api.Events
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class PlayerLeftGameEvent : IGameEvent
|
||||
public class GamePlayerLeftEvent : IGamePlayerLeftEvent
|
||||
{
|
||||
public PlayerLeftGameEvent(IGame game, IClientPlayer player, bool isBan)
|
||||
public GamePlayerLeftEvent(IGame game, IClientPlayer player, bool isBan)
|
||||
{
|
||||
Game = game;
|
||||
Player = player;
|
||||
@@ -18,4 +19,4 @@ namespace Impostor.Api.Events
|
||||
|
||||
public bool IsBan { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GameStartedEvent : IGameStartedEvent
|
||||
{
|
||||
public GameStartedEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
|
||||
namespace Impostor.Server.Events
|
||||
{
|
||||
public class GameStartingEvent : IGameStartingEvent
|
||||
{
|
||||
public GameStartingEvent(IGame game)
|
||||
{
|
||||
Game = game;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events.Meeting;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Meeting
|
||||
namespace Impostor.Server.Events.Meeting
|
||||
{
|
||||
public class MeetingEndedEvent : IEvent
|
||||
public class MeetingEndedEvent : IMeetingEndedEvent
|
||||
{
|
||||
public MeetingEndedEvent(IGame game, IInnerMeetingHud meetingHud)
|
||||
{
|
||||
@@ -15,4 +16,4 @@ namespace Impostor.Api.Events.Meeting
|
||||
|
||||
public IInnerMeetingHud MeetingHud { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events.Meeting;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Meeting
|
||||
namespace Impostor.Server.Events.Meeting
|
||||
{
|
||||
public class MeetingStartedEvent : IEvent
|
||||
public class MeetingStartedEvent : IMeetingStartedEvent
|
||||
{
|
||||
public MeetingStartedEvent(IGame game, IInnerMeetingHud meetingHud)
|
||||
{
|
||||
@@ -15,4 +16,4 @@ namespace Impostor.Api.Events.Meeting
|
||||
|
||||
public IInnerMeetingHud MeetingHud { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-10
@@ -1,10 +1,11 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Player
|
||||
namespace Impostor.Server.Events.Player
|
||||
{
|
||||
public class PlayerChatEvent : IPlayerEvent
|
||||
public class PlayerChatEvent : IPlayerChatEvent
|
||||
{
|
||||
public PlayerChatEvent(IGame game, IClientPlayer clientPlayer, IInnerPlayerControl playerControl, string message)
|
||||
{
|
||||
@@ -14,18 +15,12 @@ namespace Impostor.Api.Events.Player
|
||||
Message = message;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGame Game { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IClientPlayer ClientPlayer { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IInnerPlayerControl PlayerControl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message sent by the player.
|
||||
/// </summary>
|
||||
public string Message { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,10 +1,11 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Player
|
||||
namespace Impostor.Server.Events.Player
|
||||
{
|
||||
public class PlayerDestroyedEvent : IPlayerEvent
|
||||
public class PlayerDestroyedEvent : IPlayerDestroyedEvent
|
||||
{
|
||||
public PlayerDestroyedEvent(IGame game, IClientPlayer clientPlayer, IInnerPlayerControl playerControl)
|
||||
{
|
||||
@@ -13,13 +14,10 @@ namespace Impostor.Api.Events.Player
|
||||
PlayerControl = playerControl;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGame Game { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IClientPlayer ClientPlayer { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IInnerPlayerControl PlayerControl { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Server.Events.Player
|
||||
{
|
||||
// TODO: Finish and use event, needs to be pooled
|
||||
public class PlayerMovementEvent : IPlayerEvent
|
||||
{
|
||||
public PlayerMovementEvent(IGame game, IClientPlayer clientPlayer, IInnerPlayerControl playerControl)
|
||||
{
|
||||
Game = game;
|
||||
ClientPlayer = clientPlayer;
|
||||
PlayerControl = playerControl;
|
||||
}
|
||||
|
||||
public IGame Game { get; }
|
||||
|
||||
public IClientPlayer ClientPlayer { get; }
|
||||
|
||||
public IInnerPlayerControl PlayerControl { get; }
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,10 +1,11 @@
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
|
||||
namespace Impostor.Api.Events.Player
|
||||
namespace Impostor.Server.Events.Player
|
||||
{
|
||||
public class PlayerSpawnedEvent : IPlayerEvent
|
||||
public class PlayerSpawnedEvent : IPlayerSpawnedEvent
|
||||
{
|
||||
public PlayerSpawnedEvent(IGame game, IClientPlayer clientPlayer, IInnerPlayerControl playerControl)
|
||||
{
|
||||
@@ -13,13 +14,10 @@ namespace Impostor.Api.Events.Player
|
||||
PlayerControl = playerControl;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGame Game { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IClientPlayer ClientPlayer { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IInnerPlayerControl PlayerControl { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cgame/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
@@ -9,7 +9,6 @@ using Impostor.Api.Net.Messages.C2S;
|
||||
using Impostor.Api.Net.Messages.S2C;
|
||||
using Impostor.Hazel;
|
||||
using Impostor.Server.Config;
|
||||
using Impostor.Server.Net.Hazel;
|
||||
using Impostor.Server.Net.Manager;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Managers;
|
||||
using Impostor.Api.Events.Meeting;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Server.Events.Meeting;
|
||||
using Impostor.Server.Net.State;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Managers;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Inner.Objects;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Server.Events.Player;
|
||||
using Impostor.Server.Net.Inner.Objects.Components;
|
||||
using Impostor.Server.Net.State;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Manager;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Api.Net.Messages.S2C;
|
||||
using Impostor.Hazel;
|
||||
|
||||
@@ -5,12 +5,12 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Managers;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Games.Managers;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Server.Config;
|
||||
using Impostor.Server.Events;
|
||||
using Impostor.Server.Net.Redirector;
|
||||
using Impostor.Server.Net.State;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -147,4 +147,4 @@ namespace Impostor.Server.Net.Manager
|
||||
await _eventManager.CallAsync(new GameDestroyedEvent(game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Meeting;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Api.Net.Messages.S2C;
|
||||
using Impostor.Hazel;
|
||||
using Impostor.Server.Events.Meeting;
|
||||
using Impostor.Server.Events.Player;
|
||||
using Impostor.Server.Net.Inner;
|
||||
using Impostor.Server.Net.Inner.Objects;
|
||||
using Impostor.Server.Net.Inner.Objects.Components;
|
||||
@@ -120,7 +119,7 @@ namespace Impostor.Server.Net.State
|
||||
{
|
||||
switch (netObj)
|
||||
{
|
||||
case InnerLobbyBehaviour lobby:
|
||||
case InnerLobbyBehaviour:
|
||||
{
|
||||
GameNet.LobbyBehaviour = null;
|
||||
break;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Hazel;
|
||||
using Impostor.Server.Events;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Api.Net.Messages.S2C;
|
||||
using Impostor.Hazel;
|
||||
using Impostor.Hazel.Udp;
|
||||
using Impostor.Server.Net.Inner;
|
||||
|
||||
namespace Impostor.Server.Net.State
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Player;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Hazel;
|
||||
using Impostor.Server.Events;
|
||||
using Impostor.Server.Net.Hazel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -29,7 +28,7 @@ namespace Impostor.Server.Net.State
|
||||
await InitGameDataAsync(player);
|
||||
}
|
||||
|
||||
await _eventManager.CallAsync(new PlayerJoinedGameEvent(this, player));
|
||||
await _eventManager.CallAsync(new GamePlayerJoinedEvent(this, player));
|
||||
}
|
||||
|
||||
private async ValueTask<bool> PlayerRemove(int playerId, bool isBan = false)
|
||||
@@ -73,7 +72,7 @@ namespace Impostor.Server.Net.State
|
||||
BanIp(player.Client.Connection.EndPoint.Address);
|
||||
}
|
||||
|
||||
await _eventManager.CallAsync(new PlayerLeftGameEvent(this, player, isBan));
|
||||
await _eventManager.CallAsync(new GamePlayerLeftEvent(this, player, isBan));
|
||||
|
||||
// Player can refuse to be kicked and keep the connection open, check for this.
|
||||
_ = Task.Run(async () =>
|
||||
|
||||
@@ -4,13 +4,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Events;
|
||||
using Impostor.Api.Events.Managers;
|
||||
using Impostor.Api.Games;
|
||||
using Impostor.Api.Innersloth;
|
||||
using Impostor.Api.Net;
|
||||
using Impostor.Api.Net.Messages;
|
||||
using Impostor.Api.Net.Messages.S2C;
|
||||
using Impostor.Server.Events;
|
||||
using Impostor.Server.Net.Manager;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
Reference in new issue
Block a user