Banner Image

Module Wrapper.Net

Wrapper - DCS net functions.

Encapsules multiplayer server environment scripting functions from net


Author: Applevangelist

Last Update Oct 2023


Global(s)

Global NET

Encapsules multiplayer environment scripting functions from net with some added FSM functions and options to block/unblock players in MP environments.

#NET NET

Encapsules multiplayer environment scripting functions from net with some added FSM functions and options to block/unblock players in MP environments.

Type(s)

NET , extends Core.Fsm#FSM
Fields and Methods inherited from NET Description

NET.BlockMessage

NET:BlockPlayer(Client, PlayerName, Seconds, Message)

Block a player.

NET:BlockPlayerSet(PlayerSet, Seconds, Message)

Block a SET_CLIENT of players

NET:BlockSide(Side, Seconds)

Block a specific coalition side, does NOT automatically kick all players of that side or kick out joined players

NET:BlockSlot(slot, Seconds, Slot)

Block a specific player slot, does NOT automatically kick a player in that slot or kick out joined players

NET.BlockTime

NET:BlockUCID(ucid, Seconds)

Block a specific UCID of a player, does NOT automatically kick the player with the UCID if already joined.

NET.BlockedPilots

NET.BlockedSides

NET.BlockedSlots

NET.BlockedUCIDs

NET.ClassName

NET:DoStringIn(State, DoString)

Executes a lua string in a given lua environment in the game.

NET:ForceSlot(Client, SideID, SlotID)

Force the slot for a specific client.

NET:GetKnownPilotData(Client, Name)

Get some data of pilots who have currently joined

NET:GetMyPlayerID()

Returns the playerID of the local player.

NET:GetName(Client)

Return the name of a given client.

NET:GetPlayerIDByName(Name)

Find the PlayerID by name

NET:GetPlayerIDFromClient(Client)

Find the PlayerID from a CLIENT object.

NET:GetPlayerInfo(Client, Attribute)

Return a table of attributes for a given client.

NET:GetPlayerList()

Return a table of players currently connected to the server.

NET:GetPlayerStatistic(Client, StatisticID)

Return a statistic for a given client.

NET:GetPlayerUCID(Client, Name)

Get player UCID from player CLIENT object or player name.

NET:GetServerID()

Returns the playerID of the server.

NET:GetSlot(Client)

Returns the SideId and SlotId of a given client.

NET:IsAnyBlocked(UCID, Name, PlayerID, PlayerSide, PlayerSlot)

[Internal] Check any blockers

NET.Json2Lua(Json)

Converts a JSON string to a lua value.

NET:Kick(Client, Message)

Kicks a player from the server.

NET.KnownPilots

NET:Log(Message)

Write an "INFO" entry to the DCS log file, with the message Message.

NET.Lua2Json(Lua)

Converts a lua value to a JSON string.

NET:New()

Instantiate a new NET object.

NET:OnAfterPlayerBlocked(From, Event, To, Client, Name, Seconds)

FSM Function OnAfterPlayerBlocked.

NET:OnAfterPlayerDied(From, Event, To, Client, Name)

FSM Function OnAfterPlayerDied.

NET:OnAfterPlayerEjected(From, Event, To, Client, Name)

FSM Function OnAfterPlayerEjected.

NET:OnAfterPlayerJoined(From, Event, To, Client, Name)

FSM Function OnAfterPlayerJoined.

NET:OnAfterPlayerLeft(From, Event, To, Client, Name)

FSM Function OnAfterPlayerLeft.

NET:OnAfterPlayerUnblocked(From, Event, To, Client, Name)

FSM Function OnAfterPlayerUnblocked.

NET:ReturnToSpectators(Client)

Force a client back to spectators.

NET:SendChat(Message, ToAll)

Send chat message.

NET:SendChatToClient(Message, ToClient, FromClient)

Send chat message to a specific player using the CLIENT object.

NET:SendChatToPlayer(Message, ToPlayer, FromPlayer)

Send chat message to a specific player using the player name

NET:SetBlockMessage(Text)

Set block chat message.

NET:SetBlockTime(Seconds)

Set block time in seconds.

NET:SetUnblockMessage(Text)

Set unblock chat message.

NET.UnblockMessage

NET:UnblockPlayer(Client, PlayerName, Message)

Unblock a player.

NET:UnblockPlayerSet(PlayerSet, Message)

Unblock a SET_CLIENT of players

NET.UnblockSide(side, Seconds, self, Side)

Unblock a specific coalition side.

NET.UnblockSlot(slot, self, Slot)

Unblock a specific slot.

NET:UnblockUCID(ucid)

Unblock a specific UCID of a player

NET.Version

NET:_EventHandler(EventData)

[Internal] Event Handler

NET.lid

NET:onafterRun(From, Event, To)

Stop the event functions

NET:onafterStatus(From, Event, To)

Status - housekeeping

NET:onafterStop(From, Event, To)

Stop the event functions

Fields and Methods inherited from FSM Description

NET:AddEndState(State)

Adds an End state.

NET:AddProcess(From, Event, Process, ReturnEvents)

Set the default #FSM_PROCESS template with key ProcessName providing the ProcessClass and the process object when it is assigned to a Wrapper.Controllable by the task.

NET:AddScore(State, ScoreText, Score)

Adds a score for the FSM to be achieved.

NET:AddScoreProcess(From, Event, State, ScoreText, Score)

Adds a score for the FSM_PROCESS to be achieved.

NET:AddTransition(From, Event, To)

Add a new transition rule to the FSM.

NET.CallScheduler

NET.Events

NET:GetCurrentState()

Get current state.

NET:GetEndStates()

Returns the End states.

NET:GetProcess(From, Event)

NET:GetProcesses()

Returns a table of the SubFSM rules defined within the FSM.

NET:GetScores()

Returns a table with the scores defined.

NET:GetStartState()

Returns the start state of the FSM.

NET:GetState()

Get current state.

NET:GetSubs()

Returns a table with the Subs defined.

NET:GetTransitions()

Returns a table of the transition rules defined within the FSM.

NET:Is(State)

Check if FSM is in state.

NET:LoadCallBacks(CallBackTable)

Load call backs.

NET:New()

Creates a new FSM object.

NET.Scores

NET:SetProcess(From, Event, Fsm)

NET:SetStartState(State)

Sets the start state of the FSM.

NET._EndStates

NET._EventSchedules

NET._Processes

NET._Scores

NET._StartState

NET._Transitions

NET:_add_to_map(Map, Event)

Add to map.

NET:_call_handler(step, trigger, params, EventName)

Call handler.

NET:_create_transition(EventName)

Create transition.

NET:_delayed_transition(EventName)

Delayed transition.

NET:_eventmap(Events, EventStructure)

Event map.

NET:_gosub(ParentFrom, ParentEvent)

Go sub.

NET:_handler(EventName, ...)

Handler.

NET:_isendstate(Current)

Is end state.

NET:_submap(subs, sub, name)

Sub maps.

NET:can(e)

Check if can do an event.

NET:cannot(e)

Check if cannot do an event.

NET.current

NET.endstates

NET:is(State, state)

Check if FSM is in state.

NET.options

NET.subs

The NET class

Field(s)

#number NET.BlockTime
#string NET.ClassName
#string NET.Version
#string NET.lid

Function(s)

Block a player.

Defined in:

NET

Parameters:

CLIENT object.

#string PlayerName

(optional) Name of the player.

#number Seconds

(optional) Number of seconds the player has to wait before rejoining.

#string Message

(optional) Message to be sent via chat.

Return value:

#NET:

self

Block a SET_CLIENT of players

Defined in:

NET

Parameters:

The SET to block.

#number Seconds

Seconds (optional) Number of seconds the player has to wait before rejoining.

#string Message

(optional) Message to be sent via chat.

Return value:

#NET:

self

Block a specific coalition side, does NOT automatically kick all players of that side or kick out joined players

Defined in:

NET

Parameters:

#number Side

The side to block - 1 : Red, 2 : Blue

#number Seconds

Seconds (optional) Number of seconds the player has to wait before rejoining.

Return value:

#NET:

self

Block a specific player slot, does NOT automatically kick a player in that slot or kick out joined players

Defined in:

NET

Parameters:

#string slot

The slot to block

#number Seconds

Seconds (optional) Number of seconds the player has to wait before rejoining.

Slot

Return value:

#NET:

self

Block a specific UCID of a player, does NOT automatically kick the player with the UCID if already joined.

Defined in:

NET

Parameters:

#string ucid

#number Seconds

Seconds (optional) Number of seconds the player has to wait before rejoining.

Return value:

#NET:

self

Executes a lua string in a given lua environment in the game.

Defined in:

NET

Parameters:

#string State

The state in which to execute - see below.

#string DoString

The lua string to be executed.

Return value:

#string:

Output

Usage:

States are:
'config': the state in which $INSTALL_DIR/Config/main.cfg is executed, as well as $WRITE_DIR/Config/autoexec.cfg  - used for configuration settings
'mission': holds current mission
'export': runs $WRITE_DIR/Scripts/Export.lua and the relevant export API

Force the slot for a specific client.

If this returns false, it didn't work via net (which is ALWAYS the case as of Nov 2024)!

Defined in:

NET

Parameters:

The client

#number SideID

i.e. 0 : spectators, 1 : Red, 2 : Blue

#number SlotID

Slot number

Return value:

#boolean:

Success

Get some data of pilots who have currently joined

Defined in:

NET

Parameters:

Provide either the client object whose data to find or

#string Name

The player name whose data to find

Return value:

#table:

Table of #NET.PlayerData or nil if not found

Returns the playerID of the local player.

Always returns 1 for server.

Defined in:

NET

Return value:

#number:

ID

Return the name of a given client.

Effectively the same as CLIENT:GetPlayerName().

Defined in:

NET

Parameter:

The client

Return value:

#string:

Name or nil if not obtainable

Find the PlayerID by name

Defined in:

NET

Parameter:

#string Name

The player name whose ID to find

Return value:

#number:

PlayerID or nil

Find the PlayerID from a CLIENT object.

Defined in:

NET

Parameter:

The client

Return value:

#number:

PlayerID or nil

Return a table of attributes for a given client.

If optional attribute is present, only that value is returned.

Defined in:

NET

Parameters:

The client.

#string Attribute

(Optional) The attribute to obtain. List see below.

Return value:

#table:

PlayerInfo or nil if it cannot be found

Usage:

Table holds these attributes:

         'id'    : playerID
         'name'  : player name
         'side'  : 0 - spectators, 1 - red, 2 - blue
         'slot'  : slotID of the player or 
         'ping'  : ping of the player in ms
         'ipaddr': IP address of the player, SERVER ONLY
         'ucid'  : Unique Client Identifier, SERVER ONLY

Return a table of players currently connected to the server.

Defined in:

NET

Return value:

#table:

PlayerList

Return a statistic for a given client.

Defined in:

NET

Parameters:

The client

#number StatisticID

The statistic to obtain

Return value:

#number:

Statistic or nil

Usage:

StatisticIDs are:

net.PS_PING  (0) - ping (in ms)
net.PS_CRASH (1) - number of crashes
net.PS_CAR   (2) - number of destroyed vehicles
net.PS_PLANE (3) - ... planes/helicopters
net.PS_SHIP  (4) - ... ships
net.PS_SCORE (5) - total score
net.PS_LAND  (6) - number of landings
net.PS_EJECT (7) - of ejects

         mynet:GetPlayerStatistic(Client,7) -- return number of ejects

Get player UCID from player CLIENT object or player name.

Provide either one.

Defined in:

NET

Parameters:

The client object to be used.

#string Name

Player name to be used.

Return value:

#boolean:

success

Returns the playerID of the server.

Currently always returns 1.

Defined in:

NET

Return value:

#number:

ID

Returns the SideId and SlotId of a given client.

Defined in:

NET

Parameter:

The client

Return values:

#number:

SideID i.e. 0 : spectators, 1 : Red, 2 : Blue

#number:

SlotID

[Internal] Check any blockers

Defined in:

NET

Parameters:

#string UCID

#string Name

#number PlayerID

#number PlayerSide

#string PlayerSlot

Return value:

#boolean:

IsBlocked

Converts a JSON string to a lua value.

Defined in:

NET

Parameter:

#string Json

Anything JSON

Return value:

#table:

Lua

Kicks a player from the server.

Can display a message to the user.

Defined in:

NET

Parameters:

The client

#string Message

(Optional) The message to send.

Return value:

#boolean:

success

Write an "INFO" entry to the DCS log file, with the message Message.

Defined in:

NET

Parameter:

#string Message

The message to be logged.

Return value:

#NET:

self

Converts a lua value to a JSON string.

Defined in:

NET

Parameter:

#string Lua

Anything lua

Return value:

#table:

Json

Instantiate a new NET object.

Defined in:

NET

Return value:

#NET:

self

FSM Function OnAfterPlayerBlocked.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Client Object, might be nil.

#string Name

Name of blocked Pilot.

#number Seconds

Blocked for this number of seconds

Return value:

#NET:

self

FSM Function OnAfterPlayerDied.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Unit Object, might be nil.

#string Name

Name of dead Pilot.

Return value:

#NET:

self

FSM Function OnAfterPlayerEjected.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Unit Object, might be nil.

#string Name

Name of leaving Pilot.

Return value:

#NET:

self

FSM Function OnAfterPlayerJoined.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Object.

#string Name

Name of joining Pilot.

Return value:

#NET:

self

FSM Function OnAfterPlayerLeft.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Unit Object, might be nil.

#string Name

Name of leaving Pilot.

Return value:

#NET:

self

FSM Function OnAfterPlayerUnblocked.

Defined in:

NET

Parameters:

#string From

State.

#string Event

Trigger.

#string To

State.

Client Object, might be nil.

#string Name

Name of unblocked Pilot.

Return value:

#NET:

self

Force a client back to spectators.

If this returns false, it didn't work via net (which is ALWAYS the case as of Nov 2024)!

Defined in:

NET

Parameter:

The client

Return value:

#boolean:

Succes

Send chat message.

Defined in:

NET

Parameters:

#string Message

Message to send

#boolean ToAll

(Optional)

Return value:

#NET:

self

Send chat message to a specific player using the CLIENT object.

Defined in:

NET

Parameters:

#string Message

The text message

Client receiving the message

(Optional) Client sending the message

Return value:

#NET:

self

Send chat message to a specific player using the player name

Defined in:

NET

Parameters:

#string Message

The text message

#string ToPlayer

Player receiving the message

#string FromPlayer

Optional) Player sending the message

Return value:

#NET:

self

Set block chat message.

Defined in:

NET

Parameter:

#string Text

The message

Return value:

#NET:

self

Set block time in seconds.

Defined in:

NET

Parameter:

#number Seconds

Numnber of seconds this block will last. Defaults to 600.

Return value:

#NET:

self

Set unblock chat message.

Defined in:

NET

Parameter:

#string Text

The message

Return value:

#NET:

self

Unblock a player.

Defined in:

NET

Parameters:

CLIENT object

#string PlayerName

(optional) Name of the player.

#string Message

(optional) Message to be sent via chat.

Return value:

#NET:

self

Unblock a SET_CLIENT of players

Defined in:

NET

Parameters:

The SET to unblock.

#string Message

(optional) Message to be sent via chat.

Return value:

#NET:

self

Unblock a specific coalition side.

Does NOT unblock specifically blocked playernames or UCIDs.

Defined in:

NET

Parameters:

#number side

The side to block - 1 : Red, 2 : Blue

#number Seconds

Seconds (optional) Number of seconds the player has to wait before rejoining.

self

Side

Return value:

#NET:

self

Unblock a specific slot.

Defined in:

NET

Parameters:

#string slot

The slot to block

self

Slot

Return value:

#NET:

self

Unblock a specific UCID of a player

Defined in:

NET

Parameter:

#string ucid

Return value:

#NET:

self

[Internal] Event Handler

Defined in:

NET

Parameter:

Return value:

#NET:

self

Stop the event functions

Defined in:

NET

Parameters:

#string From

#string Event

#string To

Return value:

#NET:

self

Status - housekeeping

Defined in:

NET

Parameters:

#string From

#string Event

#string To

Return value:

#NET:

self

Stop the event functions

Defined in:

NET

Parameters:

#string From

#string Event

#string To

Return value:

#NET:

self

Field(s)

#number NET.BlockTime
#string NET.ClassName
#string NET.Version
#string NET.lid

Function(s)

Adds an End state.

Defined in:

Parameter:

#string State

The FSM state.

Set the default #FSM_PROCESS template with key ProcessName providing the ProcessClass and the process object when it is assigned to a Wrapper.Controllable by the task.

Defined in:

Parameters:

#table From

Can contain a string indicating the From state or a table of strings containing multiple From states.

#string Event

The Event name.

An sub-process FSM.

#table ReturnEvents

A table indicating for which returned events of the SubFSM which Event must be triggered in the FSM.

Return value:

The SubFSM.

Adds a score for the FSM to be achieved.

Defined in:

Parameters:

#string State

is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).

#string ScoreText

is a text describing the score that is given according the status.

#number Score

is a number providing the score of the status.

Return value:

#FSM:

self

Adds a score for the FSM_PROCESS to be achieved.

Defined in:

Parameters:

#string From

is the From State of the main process.

#string Event

is the Event of the main process.

#string State

is the state of the process when the score needs to be given. (See the relevant state descriptions of the process).

#string ScoreText

is a text describing the score that is given according the status.

#number Score

is a number providing the score of the status.

Return value:

#FSM:

self

Add a new transition rule to the FSM.

A transition rule defines when and if the FSM can transition from a state towards another state upon a triggered event.

Defined in:

Parameters:

#table From

Can contain a string indicating the From state or a table of strings containing multiple From states.

#string Event

The Event name.

#string To

The To state.

Get current state.

Defined in:

Return value:

#string:

Current FSM state.

Returns the End states.

Defined in:

Return value:

#table:

End states.

Defined in:

Parameters:

From

Event

Returns a table of the SubFSM rules defined within the FSM.

Defined in:

Return value:

#table:

Sub processes.

Returns a table with the scores defined.

Defined in:

Return value:

#table:

Scores.

Returns the start state of the FSM.

Defined in:

Return value:

#string:

A string containing the start state.

Get current state.

Defined in:

Return value:

#string:

Current FSM state.

Returns a table with the Subs defined.

Defined in:

Return value:

#table:

Sub processes.

Returns a table of the transition rules defined within the FSM.

Defined in:

Return value:

#table:

Transitions.

Check if FSM is in state.

Defined in:

Parameter:

#string State

State name.

Return value:

#boolean:

If true, FSM is in this state.

Load call backs.

Defined in:

Parameter:

#table CallBackTable

Table of call backs.

Creates a new FSM object.

Defined in:

Return value:

#FSM:

Defined in:

Parameters:

From

Event

Fsm

Sets the start state of the FSM.

Defined in:

Parameter:

#string State

A string defining the start state.

Add to map.

Defined in:

Parameters:

#table Map

Map.

#table Event

Event table.

Call handler.

Defined in:

Parameters:

#string step

Step "onafter", "onbefore", "onenter", "onleave".

#string trigger

Trigger.

#table params

Parameters.

#string EventName

Event name.

Return value:

Value.

Create transition.

Defined in:

Parameter:

#string EventName

Event name.

Return value:

#function:

Function.

Delayed transition.

Defined in:

Parameter:

#string EventName

Event name.

Return value:

#function:

Function.

Event map.

Defined in:

Parameters:

#table Events

Events.

#table EventStructure

Event structure.

Go sub.

Defined in:

Parameters:

#string ParentFrom

Parent from state.

#string ParentEvent

Parent event name.

Return value:

#table:

Subs.

Handler.

Defined in:

Parameters:

#string EventName

Event name.

...

Arguments.

Is end state.

Defined in:

Parameter:

#string Current

Current state name.

Return values:

#table:

FSM parent.

#string:

Event name.

Sub maps.

Defined in:

Parameters:

#table subs

Subs.

#table sub

Sub.

#string name

Name.

Check if can do an event.

Defined in:

Parameter:

#string e

Event name.

Return values:

#boolean:

If true, FSM can do the event.

#string:

To state.

Check if cannot do an event.

Defined in:

Parameter:

#string e

Event name.

Return value:

#boolean:

If true, FSM cannot do the event.

Check if FSM is in state.

Defined in:

Parameters:

#string State

State name.

state

Return value:

#boolean:

If true, FSM is in this state.