Browse Source

Change comment style for `ChatApi`

pull/14/head
Anton Tarasenko 2 years ago
parent
commit
26ed844044
  1. 143
      sources/Chat/ChatAPI.uc

143
sources/Chat/ChatAPI.uc

@ -1,6 +1,8 @@
/** /**
* API that provides functions for working with chat. * Author: dkanus
* Copyright 2022 Anton Tarasenko * Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore
* License: GPL
* Copyright 2022-2023 Anton Tarasenko
*------------------------------------------------------------------------------ *------------------------------------------------------------------------------
* This file is part of Acedia. * This file is part of Acedia.
* *
@ -17,23 +19,20 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>. * along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/ */
class ChatAPI extends AcediaObject; class ChatApi extends AcediaObject;
var protected bool connectedToBroadcastAPI; var protected bool connectedToBroadcastAPI;
var protected ChatAPI_OnMessage_Signal onMessageSignal; var protected ChatAPI_OnMessage_Signal onMessageSignal;
var protected ChatAPI_OnMessageFor_Signal onMessageForSignal; var protected ChatAPI_OnMessageFor_Signal onMessageForSignal;
protected function Constructor() protected function Constructor() {
{ onMessageSignal = ChatAPI_OnMessage_Signal(_.memory.Allocate(class'ChatAPI_OnMessage_Signal'));
onMessageSignal = ChatAPI_OnMessage_Signal( onMessageForSignal =
_.memory.Allocate(class'ChatAPI_OnMessage_Signal')); ChatAPI_OnMessageFor_Signal(_.memory.Allocate(class'ChatAPI_OnMessageFor_Signal'));
onMessageForSignal = ChatAPI_OnMessageFor_Signal(
_.memory.Allocate(class'ChatAPI_OnMessageFor_Signal'));
} }
protected function Finalizer() protected function Finalizer() {
{
_.memory.Free(onMessageSignal); _.memory.Free(onMessageSignal);
_.memory.Free(onMessageForSignal); _.memory.Free(onMessageForSignal);
onMessageSignal = none; onMessageSignal = none;
@ -43,8 +42,7 @@ protected function Finalizer()
connectedToBroadcastAPI = false; connectedToBroadcastAPI = false;
} }
private final function TryConnectingBroadcastSignals() private final function TryConnectingBroadcastSignals() {
{
if (connectedToBroadcastAPI) { if (connectedToBroadcastAPI) {
return; return;
} }
@ -53,62 +51,58 @@ private final function TryConnectingBroadcastSignals()
_server.unreal.broadcasts.OnHandleTextFor(self).connect = HandleTextFor; _server.unreal.broadcasts.OnHandleTextFor(self).connect = HandleTextFor;
} }
/** /// Signal that will be emitted when a player sends a message into the chat.
* Signal that will be emitted when a player sends a message into the chat. ///
* Allows to modify message before sending it, as well as prevent it from /// Allows to modify message before sending it, as well as prevent it from being sent at all.
* being sent at all. ///
* /// Return `false` to prevent message from being sent.
* Return `false` to prevent message from being sent. /// If `false` is returned, signal propagation to the remaining handlers will also be interrupted.
* If `false` is returned, signal propagation to the remaining handlers will ///
* also be interrupted. /// # Slot description
* ///
* [Signature] /// bool <slot>(EPlayer sender, MutableText message, bool teamMessage)
* bool <slot>(EPlayer sender, MutableText message, bool teamMessage) ///
* /// ## Parameters
* @param sender `EPlayer` that has sent the message. ///
* @param message Message that `sender` has sent. This is a mutable /// * [`sender`]: `EPlayer` that has sent the message.
* variable and can be modified from message will be sent. /// * [`message`]: Message that `sender` has sent.
* @param teamMessage Is this a team message /// This is a mutable variable and can be modified from message will be sent.
* (to be sent only to players on the same team)? /// * [`teamMessage`]: Is this a team message (to be sent only to players on the same team)?
* @return Return `false` to prevent this message from being sent at all ///
* and `true` otherwise. Message will be sent only if all handlers will /// ## Returns
* return `true`. ///
*/ /// Return `false` to prevent this message from being sent at all and `true` otherwise.
/* SIGNAL */ /// Message will be sent only if all handlers will return `true`.
public function ChatAPI_OnMessage_Slot OnMessage( public /*signal*/ function ChatAPI_OnMessage_Slot OnMessage(AcediaObject receiver) {
AcediaObject receiver)
{
TryConnectingBroadcastSignals(); TryConnectingBroadcastSignals();
return ChatAPI_OnMessage_Slot(onMessageSignal.NewSlot(receiver)); return ChatAPI_OnMessage_Slot(onMessageSignal.NewSlot(receiver));
} }
/** /// Signal that will be emitted when a player sends a message into the chat.
* Signal that will be emitted when a player sends a message into the chat. ///
* Allows to modify message before sending it, as well as prevent it from /// Allows to modify message before sending it, as well as prevent it from being sent at all.
* being sent at all. ///
* /// Return `false` to prevent message from being sent to a specific player.
* Return `false` to prevent message from being sent to a specific player. /// If `false` is returned, signal propagation to the remaining handlers will also be interrupted.
* If `false` is returned, signal propagation to the remaining handlers will ///
* also be interrupted. /// # Slot description
* ///
* [Signature] /// bool <slot>(EPlayer receiver, EPlayer sender, BaseText message)
* bool <slot>(EPlayer receiver, EPlayer sender, BaseText message) ///
* /// ## Parameters
* @param receiver `EPlayer` that will receive the message. ///
* @param sender `EPlayer` that has sent the message. /// * [`receiver`]: `EPlayer` that will receive the message.
* @param message Message that `sender` has sent. This is an immutable /// * [`sender`]: `EPlayer` that has sent the message.
* variable and cannot be changed at this point. Use `OnMessage()` /// * [`message`]: Message that `sender` has sent. This is an immutable variable and cannot
* signal function for that. /// be changed at this point. Use `OnMessage()` signal function for that.
* @return Return `false` to prevent this message from being sent to ///
* a particular player and `true` otherwise. Message will be sent only if /// ## Returns
* all handlers will return `true`. ///
* However decision whether to send message or not is made for /// Return `false` to prevent this message from being sent to a particular player and
* every player separately. /// `true` otherwise.
*/ /// Message will be sent only if all handlers will return `true`.
/* SIGNAL */ /// However decision whether to send message or not is made for every player separately.
public function ChatAPI_OnMessageFor_Slot OnMessageFor( public /*signal*/ function ChatAPI_OnMessageFor_Slot OnMessageFor(AcediaObject receiver) {
AcediaObject receiver)
{
TryConnectingBroadcastSignals(); TryConnectingBroadcastSignals();
return ChatAPI_OnMessageFor_Slot(onMessageForSignal.NewSlot(receiver)); return ChatAPI_OnMessageFor_Slot(onMessageForSignal.NewSlot(receiver));
} }
@ -117,11 +111,12 @@ private function bool HandleText(
Actor sender, Actor sender,
out string message, out string message,
name messageType, name messageType,
bool teamMessage) bool teamMessage
{ ) {
local bool result; local bool result;
local MutableText messageAsText; local MutableText messageAsText;
local EPlayer senderPlayer; local EPlayer senderPlayer;
// We only want to catch chat messages from a player // We only want to catch chat messages from a player
if (messageType != 'Say' && messageType != 'TeamSay') return true; if (messageType != 'Say' && messageType != 'TeamSay') return true;
senderPlayer = _.players.FromController(PlayerController(sender)); senderPlayer = _.players.FromController(PlayerController(sender));
@ -148,31 +143,29 @@ private function bool HandleTextFor(
PlayerController receiver, PlayerController receiver,
Actor sender, Actor sender,
out string message, out string message,
name messageType) name messageType
{ ) {
local bool result; local bool result;
local Text messageAsText; local Text messageAsText;
local EPlayer senderPlayer, receiverPlayer; local EPlayer senderPlayer, receiverPlayer;
// We only want to catch chat messages from another player // We only want to catch chat messages from another player
if (messageType != 'Say' && messageType != 'TeamSay') return true; if (messageType != 'Say' && messageType != 'TeamSay') return true;
senderPlayer = _.players.FromController(PlayerController(sender)); senderPlayer = _.players.FromController(PlayerController(sender));
if (senderPlayer == none) return true; if (senderPlayer == none) return true;
receiverPlayer = _.players.FromController(receiver); receiverPlayer = _.players.FromController(receiver);
if (receiverPlayer == none) if (receiverPlayer == none) {
{
_.memory.Free(senderPlayer); _.memory.Free(senderPlayer);
return true; return true;
} }
messageAsText = __().text.FromColoredString(message); messageAsText = __().text.FromColoredString(message);
result = onMessageForSignal.Emit( receiverPlayer, senderPlayer, result = onMessageForSignal.Emit(receiverPlayer, senderPlayer, messageAsText);
messageAsText);
_.memory.Free(messageAsText); _.memory.Free(messageAsText);
_.memory.Free(senderPlayer); _.memory.Free(senderPlayer);
_.memory.Free(receiverPlayer); _.memory.Free(receiverPlayer);
return result; return result;
} }
defaultproperties defaultproperties {
{
} }
Loading…
Cancel
Save