Merge pull request #107 from danbudworthmead/InnerPlayerControl-API-Functionallity-Additions

Inner player control API functionality additions
This commit is contained in:
AeonLucid authored and GitHub committed 2020-11-02 19:28:31 +01:00
commit 587b0bf3b7
3 files changed
+53 -6

No files matched your search

@@ -1,9 +1,9 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Impostor.Api.Innersloth.Customization;
namespace Impostor.Api.Net.Inner.Objects
{
public interface IInnerPlayerControl
public interface IInnerPlayerControl : IInnerNetObject
{
/// <summary>
/// Gets the <see cref="IInnerPlayerInfo"/> of the <see cref="IInnerPlayerControl"/>.
@@ -74,5 +74,28 @@ namespace Impostor.Api.Net.Inner.Objects
/// <param name="text">The message to send.</param>
/// <returns>Task that must be awaited.</returns>
ValueTask SendChatAsync(string text);
/// <summary>
/// Send a chat message as the current <see cref="IInnerPlayerControl"/>.
/// Visible to only the current.
/// </summary>
/// <param name="text">The message to send.</param>
/// <param name="player">The player that should receive this chat message.</param>
/// <returns>Task that must be awaited.</returns>
ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl player);
/// <summary>
/// Sets the current to infected (impostor) <see cref="IInnerPlayerControl"/>.
/// Visible to all players.
/// </summary>
/// <returns>Task that must be awaited.</returns>
ValueTask SetInfectedAsync();
/// <summary>
/// Sets the current to be murdered <see cref="IInnerPlayerControl"/>.
/// Visible to all players.
/// </summary>
/// <returns>Task that must be awaited.</returns>
ValueTask SetMurderedAsync();
}
}
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Impostor.Api.Innersloth.Customization;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner.Objects;
namespace Impostor.Server.Net.Inner.Objects
@@ -79,5 +80,26 @@ namespace Impostor.Server.Net.Inner.Objects
writer.Write(text);
await _game.FinishRpcAsync(writer);
}
public async ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl player)
{
using var writer = _game.StartRpc(NetId, RpcCalls.SendChat);
writer.Write(text);
await _game.FinishRpcAsync(writer, player.OwnerId);
}
public async ValueTask SetMurderedAsync()
{
var writer = _game.StartRpc(NetId, RpcCalls.MurderPlayer);
writer.Write((byte)NetId);
await _game.FinishRpcAsync(writer);
}
public async ValueTask SetInfectedAsync()
{
var writer = _game.StartRpc(NetId, RpcCalls.SetInfected);
writer.Write((byte)NetId);
await _game.FinishRpcAsync(writer);
}
}
}
@@ -60,12 +60,14 @@ namespace Impostor.Server.Net.State
return writer;
}
internal ValueTask FinishRpcAsync(IMessageWriter writer)
internal ValueTask FinishRpcAsync(IMessageWriter writer, int? targetClientId = null)
{
writer.EndMessage();
writer.EndMessage();
return SendToAllAsync(writer);
return targetClientId.HasValue
? SendToAsync(writer, targetClientId.Value)
: SendToAllAsync(writer);
}
private void WriteRemovePlayerMessage(IMessageWriter message, bool clear, int playerId, DisconnectReason reason)
@@ -98,4 +100,4 @@ namespace Impostor.Server.Net.State
Message12WaitForHostS2C.Serialize(message, clear, Code, player.Client.Id);
}
}
}
}