Browse Source

Document broadcasting events and related classes

pull/8/head
Anton Tarasenko 4 years ago
parent
commit
64f7108499
  1. 24
      sources/Events/Broadcast/BroadcastEvents.uc
  2. 2
      sources/Events/Broadcast/BroadcastEventsObserver.uc
  3. 165
      sources/Events/Broadcast/BroadcastListenerBase.uc

24
sources/Events/Broadcast/BroadcastEvents.uc

@ -56,12 +56,10 @@ static function bool CallCanBroadcast(Actor broadcaster, int recentSentTextSize)
return true; return true;
} }
static function bool CallHandleText static function bool CallHandleText(
(
Actor sender, Actor sender,
out string message, out string message,
name messageType name messageType)
)
{ {
local int i; local int i;
local bool result; local bool result;
@ -76,13 +74,11 @@ static function bool CallHandleText
return true; return true;
} }
static function bool CallHandleTextFor static function bool CallHandleTextFor(
(
PlayerController receiver, PlayerController receiver,
Actor sender, Actor sender,
out string message, out string message,
name messageType name messageType)
)
{ {
local int i; local int i;
local bool result; local bool result;
@ -97,11 +93,9 @@ static function bool CallHandleTextFor
return true; return true;
} }
static function bool CallHandleLocalized static function bool CallHandleLocalized(
(
Actor sender, Actor sender,
LocalizedMessage message LocalizedMessage message)
)
{ {
local int i; local int i;
local bool result; local bool result;
@ -116,12 +110,10 @@ static function bool CallHandleLocalized
return true; return true;
} }
static function bool CallHandleLocalizedFor static function bool CallHandleLocalizedFor(
(
PlayerController receiver, PlayerController receiver,
Actor sender, Actor sender,
LocalizedMessage message LocalizedMessage message)
)
{ {
local int i; local int i;
local bool result; local bool result;

2
sources/Events/Broadcast/BroadcastEventsObserver.uc

@ -40,7 +40,7 @@ enum InjectionLevel
// `BroadcastEventsObserver` will be places in the broadcast handlers' // `BroadcastEventsObserver` will be places in the broadcast handlers'
// chain as a normal `BroadcastHandler` // chain as a normal `BroadcastHandler`
// (through `RegisterBroadcastHandler()` call), which can lead to incorrect // (through `RegisterBroadcastHandler()` call), which can lead to incorrect
// handling of `HandleText` and `HandleLocalized` events. // handling of `HandleText()` and `HandleLocalized()` events.
BHIJ_Registered, BHIJ_Registered,
// `BroadcastEventsObserver` will be injected at the very beginning of // `BroadcastEventsObserver` will be injected at the very beginning of
// the broadcast handlers' chain. // the broadcast handlers' chain.

165
sources/Events/Broadcast/BroadcastListenerBase.uc

@ -24,89 +24,147 @@
class BroadcastListenerBase extends Listener class BroadcastListenerBase extends Listener
abstract; abstract;
static final function PlayerController GetController(Actor sender) /**
* Helper function for extracting `PlayerController` of the `sender` Actor,
* if it has one / is one.
*/
static public final function PlayerController GetController(Actor sender)
{ {
local Pawn senderPawn; local Pawn senderPawn;
senderPawn = Pawn(sender); senderPawn = Pawn(sender);
if (senderPawn != none) return PlayerController(senderPawn.controller); if (senderPawn != none) {
return PlayerController(senderPawn.controller);
}
return PlayerController(sender); return PlayerController(sender);
} }
// This event is called whenever registered broadcast handlers are asked if /**
// they'd allow given actor ('broadcaster') to broadcast a text message, * This event is called whenever registered broadcast handlers are asked if
// given that none so far rejected it and he recently already broadcasted * they'd allow given actor ('broadcaster') to broadcast a text message.
// or tried to broadcast 'recentSentTextSize' symbols of text *
// (that value is periodically reset in 'GameInfo', * If injection level for Acedia's broadcast handler is `BHIJ_Root`, this event
// by default should be each second). * is guaranteed to be generated before any of the other `BroadcastHandler`s
// NOTE: this function is ONLY called when someone tries to * receive it.
// broadcast TEXT messages. *
// If one of the listeners returns 'false', - * NOTE: this function is ONLY called when someone tries to
// it will be treated just like one of broadcasters returning 'false' * broadcast TEXT messages.
// in 'AllowsBroadcast' and this method won't be called for remaining *
// active listeners. * You can also reject a broadcast after looking at the message itself by
* using `HandleText()` event.
*
* @param broadcaster `Actor` that requested broadcast in question.
* @param recentSentTextSize Amount of recently broadcasted symbols of text
* by `broadcaster`. This value is periodically reset in 'GameInfo',
* by default should be each second.
* @return If one of the listeners returns 'false', -
* it will be treated just like one of broadcasters returning 'false'
* in 'AllowsBroadcast' and this method won't be called for remaining
* active listeners. Return `true` if you do not wish to block
* `broadcaster` from broadcasting his next message.
* By default returns `true`.
*/
static function bool CanBroadcast(Actor broadcaster, int recentSentTextSize) static function bool CanBroadcast(Actor broadcaster, int recentSentTextSize)
{ {
return true; return true;
} }
// This event is called whenever a someone is trying to broadcast /**
// a text message (typically the typed by a player). * This event is called whenever a someone is trying to broadcast
// This function is called once per message and allows you to change it * a text message (typically the typed by a player).
// (by changing 'message' argument) before any of the players receive it. * It is called once per message and allows you to change it
// Return 'true' to allow the message through. * (by changing 'message' argument) before any of the players receive it.
// If one of the listeners returns 'false', - *
// it will be treated just like one of broadcasters returning 'false' * See also `HandleTextFor()`.
// in 'AcceptBroadcastText' and this method won't be called for remaining *
// active listeners. * @param sender `Actor` that requested broadcast in question.
static function bool HandleText * @param message Message that `sender` wants to broadcast, possibly
( * altered by other broadcast listeners.
* @param messageType Name variable that describes a type of the message.
* Examples are 'Say' and 'CriticalEvent'.
* @return If one of the listeners returns 'false', -
* it will be treated just like one of broadcasters returning 'false'
* in `AcceptBroadcastText()`: this event won't be called for remaining
* active listeners and message will not be broadcasted.
*/
static function bool HandleText(
Actor sender, Actor sender,
out string message, out string message,
optional name messageType optional name messageType)
)
{ {
return true; return true;
} }
// This event is similar to 'HandleText', but is called for every player /**
// the message is sent to. * This event is called whenever a someone is trying to broadcast
// If allows you to alter the message, but the changes are accumulated * a text message (typically the typed by a player).
// as events go through the players. * This event is similar to 'HandleText', but is called for every player
static function bool HandleTextFor * the message is sent to.
( *
* Method allows you to alter the message, but note that changes are
* accumulated as events go through the players.
*
* @param receiver Player, to which message is supposed to be sent next.
* @param sender `Actor` that requested broadcast in question.
* @param message Message that `sender` wants to broadcast, possibly
* altered by other broadcast listeners.
* But keep in mind that if you do change the message for one client, -
* clients that come after it will get an already altered version.
* That is, changes to the message accumulate between different
* `HandleTextFor()` calls for one broadcast.
* @param messageType Name variable that describes a type of the message.
* Examples are 'Say' and 'CriticalEvent'.
* @return If one of the listeners returns 'false', -
* message would not be sent to `receiver` at all
* (but it would not prevent broadcasting it to the rest of the players).
* Return `true` if you want it to be broadcasted.
*/
static function bool HandleTextFor(
PlayerController receiver, PlayerController receiver,
Actor sender, Actor sender,
out string message, out string message,
optional name messageType optional name messageType)
)
{ {
return true; return true;
} }
// This event is called whenever a localized message is trying to /**
// get broadcasted to a certain player ('receiver'). * This event is called whenever a someone is trying to broadcast
// Return 'true' to allow the message through. * a localized message. It is called once per message, but,
// If one of the listeners returns 'false', - * unlike `HandleText()`, does not allow you to change it.
// it will be treated just like one of broadcasters returning 'false' *
// in 'AcceptBroadcastText' and this method won't be called for remaining * @param sender `Actor` that requested broadcast in question.
// active listeners. * @param message Message that `sender` wants to broadcast.
static function bool HandleLocalized * @return If one of the listeners returns 'false', -
( * it will be treated just like one of broadcasters returning 'false'
* in `AcceptBroadcastLocalized()`: this event won't be called for
* remaining active listeners and message will not be broadcasted.
*/
static function bool HandleLocalized(
Actor sender, Actor sender,
BroadcastEvents.LocalizedMessage message BroadcastEvents.LocalizedMessage message)
)
{ {
return true; return true;
} }
// This event is similar to 'HandleLocalized', but is called for /**
// every player the message is sent to. * This event is called whenever a someone is trying to broadcast
static function bool HandleLocalizedFor * a localized message. This event is similar to 'HandleLocalized', but is
( * called for every player the message is sent to.
*
* Unlike `HandleTextFor()` method does not allow you to alter the message.
*
* @param receiver Player, to which message is supposed to be sent next.
* @param sender `Actor` that requested broadcast in question.
* @param message Message that `sender` wants to broadcast.
* @return If one of the listeners returns 'false', -
* message would not be sent to `receiver` at all
* (but it would not prevent broadcasting it to the rest of the players).
* Return `true` if you want it to be broadcasted.
*/
static function bool HandleLocalizedFor(
PlayerController receiver, PlayerController receiver,
Actor sender, Actor sender,
BroadcastEvents.LocalizedMessage message BroadcastEvents.LocalizedMessage message)
)
{ {
return true; return true;
} }
@ -115,6 +173,3 @@ defaultproperties
{ {
relatedEvents = class'BroadcastEvents' relatedEvents = class'BroadcastEvents'
} }
// Text messages can (optionally) have their type specified.
// Examples of it are names 'Say' and 'CriticalEvent'.
Loading…
Cancel
Save