Skip to content

newgroundsiodotnet.ngiotaskcommunicator

GlitchyPSIX edited this page Mar 30, 2025 · 4 revisions

NgioTaskCommunicator

Namespace: NewgroundsIODotNet

Communicator implementation for use in Desktop/Task supported platforms (Windows, Linux, Unity Desktop).

public class NgioTaskCommunicator : NgioCommunicator

Inheritance ObjectNgioCommunicatorNgioTaskCommunicator

Remarks:

Do NOT use with WebGL runtimes unless Task/await async is supported by the target platform. Usage on Mobile has not been tested.

Properties

NewgroundsGatewayUrl

public string NewgroundsGatewayUrl { get; }

Property Value

String

AppId

The App ID to use with this Communicator.

public string AppId { get; }

Property Value

String

Secured

Whether this Communicator was created with an Encryption key.

public bool Secured { get; }

Property Value

Boolean

DebugMode

Toggles NGIO's debug mode

public bool DebugMode { get; set; }

Property Value

Boolean

Session

The current Session. null if the session is uninitialized.

public Nullable<Session> Session { get; protected set; }

Property Value

Nullable<Session>

ConnectionStatus

public ConnectionStatus ConnectionStatus { get; protected set; }

Property Value

ConnectionStatus

CurrentUser

The current User. null if there's nobody logged in.

public Nullable<User> CurrentUser { get; protected set; }

Property Value

Nullable<User>

LegalHost

Is this game running on a legal host? Defaults to true unless server responds otherwise at any point.

public bool LegalHost { get; protected set; }

Property Value

Boolean

IsLatestVersion

Is this the latest version of the game? Defaults to true unless server responds otherwise at any point.

public bool IsLatestVersion { get; protected set; }

Property Value

Boolean

LoginPageOpen

Whether the login page is open.

public bool LoginPageOpen { get; protected set; }

Property Value

Boolean

AppVersion

App's version defined by the constructor

public string AppVersion { get; }

Property Value

String

MedalsPreloaded

true if medals have been preloaded inside the Communicator. Required to unlock Medals through the friendly methods.

public bool MedalsPreloaded { get; protected set; }

Property Value

Boolean

ScoreboardsPreloaded

true if scoreboards have been preloaded inside the Communicator. Required to post and get Scores through the friendly methods.

public bool ScoreboardsPreloaded { get; protected set; }

Property Value

Boolean

SaveSlotsPreloaded

true if save slots have been preloaded inside the Communicator. Required to load and save to Save Slots through the friendly methods.

public bool SaveSlotsPreloaded { get; protected set; }

Property Value

Boolean

LoadedMedals

public IReadOnlyDictionary<int, Medal> LoadedMedals { get; }

Property Value

IReadOnlyDictionary<Int32, Medal>

LoadedScoreboards

public IReadOnlyDictionary<int, ScoreBoard> LoadedScoreboards { get; }

Property Value

IReadOnlyDictionary<Int32, ScoreBoard>

LoadedSaveSlots

public IReadOnlyDictionary<int, SaveSlot> LoadedSaveSlots { get; }

Property Value

IReadOnlyDictionary<Int32, SaveSlot>

LoginSkipped

public bool LoginSkipped { get; protected set; }

Property Value

Boolean

IsReady

public bool IsReady { get; }

Property Value

Boolean

HasUser

public bool HasUser { get; }

Property Value

Boolean

LastSuccessfulPing

Last time a Gateway.ping or App.checkSession request replies successfully.

public DateTime LastSuccessfulPing { get; protected set; }

Property Value

DateTime

LastExecution

Last time any component was executed.

public DateTime LastExecution { get; protected set; }

Property Value

DateTime

LastScoresResult

Last scores fetched by the Communicator through GetScoreboardScores.

public Nullable<ValueTuple<Score[], ScoreBoardPeriod>> LastScoresResult { get; protected set; }

Property Value

Nullable<ValueTuple<Score[], ScoreBoardPeriod>>

LastScorePosted

Last score posted through PostScore.

public Nullable<Score> LastScorePosted { get; protected set; }

Property Value

Nullable<Score>

Remarks:

NOTE:User in this Score will always be null; assume it's the current player.

LastSlotSaved

Last save slot saved to through SetSaveSlot.

public Nullable<SaveSlot> LastSlotSaved { get; protected set; }

Property Value

Nullable<SaveSlot>

LastSlotLoaded

Last save slot that has been fetched data using GetSaveSlotData.

public Nullable<SaveSlot> LastSlotLoaded { get; protected set; }

Property Value

Nullable<SaveSlot>

LastUnlockedMedal

Last medal unlocked through UnlockMedal.

public Nullable<Medal> LastUnlockedMedal { get; protected set; }

Property Value

Nullable<Medal>

Constructors

NgioTaskCommunicator(String, String, String, Boolean, Boolean, Boolean, Boolean, String, String)

Creates a new Desktop Communicator instance.

public NgioTaskCommunicator(string appId, string encryptionKey, string appVersion, bool debugMode, bool preloadMedals, bool preloadScores, bool logViewOnInit, string sessionId, string host)

Parameters

appId String
Required. The App ID of your Newgrounds Game project.

encryptionKey String
Required if you want to use medals. The Encryption Key of your Newgrounds Game project.

appVersion String
App version as defined in your Game project's API Tools. Defaults to "0.0.0".

debugMode Boolean
Whether to enable the debug mode for extra NGIO developer-related info.

preloadMedals Boolean
Whether to preload Medals from the server. Required to use the Medal methods.

preloadScores Boolean
Whether to preload Scoreboards from the server. Required to use the Score methods.

logViewOnInit Boolean
Whether to log a view when the Communicator is initialized.

sessionId String
Optional session ID to pass and use right after initialization. Usually given by Newgrounds through the browser.

host String
Where your game is running. Extract this from the browser's URI. Defaults to "localhost".

Methods

GetSaveSlotData(SaveSlot, Action<String>)

Fetches the data from a Save Slot, if populated.

public void GetSaveSlotData(SaveSlot slot, Action<string> responseCallback)

Parameters

slot SaveSlot
The Save Slot from which to get data.

responseCallback Action<String>
The function to execute with the save data, if any.

Remarks:

All Save Slot data is saved and fetched as string.

GetSaveSlotDataAsync(SaveSlot)

Fetches a slot's data asynchronously, if populated.

public Task<string> GetSaveSlotDataAsync(SaveSlot slot)

Parameters

slot SaveSlot
The Save Slot from which to get data.

Returns

Task<String>
The data of the Save Slot if populated, null if nothing.

Exceptions

T:System.Net.Http.HttpRequestException
Thrown if the request fails for any reason.

OpenUrl(String)

Opens an URL with shell execution. Intended to open the browser for an URl given from referral or NG Passport.

public void OpenUrl(string url)

Parameters

url String
The URL to open

StartHeartbeat(Single)

public void StartHeartbeat(float seconds)

Parameters

seconds Single

SetHeartbeatSpeed(Single)

public void SetHeartbeatSpeed(float newSeconds)

Parameters

newSeconds Single

StopHeartbeat()

public void StopHeartbeat()

SendRequest(INgioComponentRequest[], Action<NgioServerResponse>, Nullable<Session>)

public void SendRequest(INgioComponentRequest[] components, Action<NgioServerResponse> callback, Nullable<Session> forceSession)

Parameters

components INgioComponentRequest[]

callback Action<NgioServerResponse>

forceSession Nullable<Session>

SendSecureRequest(INgioComponentRequest, Action<NgioServerResponse>)

public void SendSecureRequest(INgioComponentRequest component, Action<NgioServerResponse> callback)

Parameters

component INgioComponentRequest

callback Action<NgioServerResponse>

SendRequestAsync(INgioComponentRequest[], Nullable<Session>)

public Task<NgioServerResponse> SendRequestAsync(INgioComponentRequest[] components, Nullable<Session> forceSession)

Parameters

components INgioComponentRequest[]

forceSession Nullable<Session>

Returns

Task<NgioServerResponse>

SendSecureRequestAsync(INgioComponentRequest)

public Task<NgioServerResponse> SendSecureRequestAsync(INgioComponentRequest component)

Parameters

component INgioComponentRequest

Returns

Task<NgioServerResponse>

Events

UserWriteFailure

Fires when a user write operation is performed (medal, save slot, scoreboard) with the friendly methods and was not successful

public event EventHandler<INgioComponentResponse> UserWriteFailure;

MedalUnlocked

Fires when a medal that wasn't previously unlocked is successfully unlocked through the friendly method.

public event EventHandler<Medal> MedalUnlocked;

ResponseReceived

Fires when a response is received, prior to the Communicator knowing they came through.

public event EventHandler<NgioServerResponse> ResponseReceived;

CommunicationError

Fires when the HTTP client of the Communicator fails to connect to NG.

public event EventHandler CommunicationError;

ServerUnavailable

Fires the moment that NG does not report an HTTP 200 when making a request.

public event EventHandler ServerUnavailable;

ResponseError

Fires when the response has an error.

public event EventHandler<NgioServerResponse> ResponseError;

ComponentResponseError

Fires when any components inside a response have an error.

public event EventHandler<INgioComponentResponse[]> ComponentResponseError;

LogMessageReceived

Fires when anywhere within the code a Log is sent.

public event EventHandler<LogInfo> LogMessageReceived;

Ready

Fires the moment the communicator signals Ready.

public event EventHandler Ready;

ConnectionStatusChange

Fires whenever the connection status changes.

public event EventHandler<ConnectionStatus> ConnectionStatusChange;
Clone this wiki locally