Skip to content

newgroundsiodotnet.ngiocommunicator

GlitchyPSIX edited this page Mar 30, 2025 · 5 revisions

NgioCommunicator

Namespace: NewgroundsIODotNet

public abstract class NgioCommunicator

Inheritance ObjectNgioCommunicator

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>

Methods

Initialize()

Initializes the Communicator.

public void Initialize()

OnLogMessage(String, Object, LogSeverity)

Triggers the event in which an instance of the Communicator sends a log to console, event log, etc.

public void OnLogMessage(string message, object context, LogSeverity severity)

Parameters

message String
Message to log

context Object
Additional context to the log, such as an Exception or something of the sort.

severity LogSeverity
Severity of the log. How this is handled is dependent on the target platform.

GetMedal(Int32)

Gets the info of a preloaded medal. Returns null on failure.

public Nullable<Medal> GetMedal(int id)

Parameters

id Int32
Medal ID

Returns

Nullable<Medal>
The found medal.

UnlockMedal(Medal, Action<Medal>)

Attempts to unlock a Medal.

public void UnlockMedal(Medal medal, Action<Medal> responseCallback)

Parameters

medal Medal
The Medal to unlock.

responseCallback Action<Medal>
Callback to execute when the medal is unlocked

GetSaveSlot(Int32)

Gets the info of a Cloud Save slot. Returns null on failure.

public Nullable<SaveSlot> GetSaveSlot(int id)

Parameters

id Int32
ID of the Cloud Save slot

Returns

Nullable<SaveSlot>
The info for the Save Slot

Exceptions

ApplicationException

ArgumentException

SetSaveSlot(SaveSlot, String, Action<Nullable<SaveSlot>>)

Sets data in a Save Slot.

public void SetSaveSlot(SaveSlot slot, string data, Action<Nullable<SaveSlot>> responseCallback)

Parameters

slot SaveSlot
Save Slot to save to.

data String
Data to save in the Save Slot

responseCallback Action<Nullable<SaveSlot>>
Callback to execute when data is received

GetSaveSlotData(SaveSlot, Action<String>)

Gets the data from the Save Slot.

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

Parameters

slot SaveSlot
The Save slot to get data from.

responseCallback Action<String>
Callback to execute when the data arrives.

Remarks:

All Cloud Save data is stored as string.

LoadUrl(StandardLoaderType, Boolean)

Loads and opens a Loader URL.

public void LoadUrl(StandardLoaderType type, bool logStat)

Parameters

type StandardLoaderType
The kind of URL to get from Newgrounds

logStat Boolean
Whether to log this load in the stats.

LoadReferral(String, Boolean)

Loads and opens a Loader Referral URL.

public void LoadReferral(string referral, bool logStat)

Parameters

referral String
The ID of the referral from your API Tools dashboard.

logStat Boolean
Whether to log this load in the stats.

Exceptions

ArgumentException
Thrown if the server returns unsuccessful.

LoadStandardUrl(StandardLoaderType, Boolean)

Loads and opens a Loader URL.

public void LoadStandardUrl(StandardLoaderType type, bool logStat)

Parameters

type StandardLoaderType
The type of URL to open

logStat Boolean
Whether to log this load in the stats.

Exceptions

ArgumentException
Thrown if the server returns unsuccessful.

LogEvent(String, Action<EventLogEventResponse>)

Logs an event with an ID as specified in your Referrals and Events page. Newgrounds.IO Documentation

public void LogEvent(string eventId, Action<EventLogEventResponse> responseCallback)

Parameters

eventId String
ID of the event to log.

responseCallback Action<EventLogEventResponse>
Callback to execute when data is received

Exceptions

Exception
Thrown when the operation returns unsuccessful.

GetDateTime(Action<DateTime>)

Gets the date and time from the Newgrounds.IO server.

public void GetDateTime(Action<DateTime> responseCallback)

Parameters

responseCallback Action<DateTime>
Action to execute when data is received

Exceptions

Exception
You know, this shouldn't happen unless the server is dying, or you're offline.

GetScoreboard(Int32)

Gets the info of a Scoreboard. Returns null if unsuccessful.

public Nullable<ScoreBoard> GetScoreboard(int id)

Parameters

id Int32
ID of the Scoreboard

Returns

Nullable<ScoreBoard>
The info for the Scoreboard

Exceptions

ApplicationException

ArgumentException

GetScoreboardScores(ScoreBoard, ScoreBoardPeriod, Int32, Int32, Boolean, String, Action<ScoreBoardGetScoresResponse>)

Gets the scores of a Scoreboard

public void GetScoreboardScores(ScoreBoard scoreBoard, ScoreBoardPeriod period, int limit, int skip, bool social, string filterTag, Action<ScoreBoardGetScoresResponse> responseCallback)

Parameters

scoreBoard ScoreBoard
Scoreboard to get scores from

period ScoreBoardPeriod
Period from which to get scores

limit Int32
Limit number of scores returned

skip Int32
Skip number of scores, used for pagination

social Boolean
Whether to only include the logged in user's friends

filterTag String
Tag to filter scores with

responseCallback Action<ScoreBoardGetScoresResponse>
Callback to execute when data is received

PostScore(ScoreBoard, Int32, String, Action<Nullable<Score>>)

Posts a score to a given scoreboard.

public void PostScore(ScoreBoard scoreBoard, int amount, string tag, Action<Nullable<Score>> responseCallback)

Parameters

scoreBoard ScoreBoard

amount Int32

tag String

responseCallback Action<Nullable<Score>>

Remarks:

NOTE: Depending on your Scoreboard display setting, the argument amount might be interpreted differently:

  • Simple: interpreted as-is, displayed as-is.
  • Decimal: interpreted as-is, displayed as amount divided by 100.
  • Currency: interpreted as-is, displayed like Decimal with a "$" symbol as prefix.
  • Time: amount is interpreted as milliseconds, displayed as HH:mm:ss.SS .
  • Distance: amount is interpreted as inches, displayed as ft' in''.
  • Metric Distance (m): amount is interpreted as centimeters, displayed as meters.
  • Metric distance (km): amount is interpreted as meters, displayed as kilometers.

ResetConnectionState()

Resets login, session, caches for last saves/medals/scores and login-skip state.

public void ResetConnectionState()

LogIn()

Opens the Newgrounds Passport URL supplied by a given session, or starts a new session and then opens the page.

public void LogIn()

LogOut()

Cancels login if in progress and terminates the user session.

public void LogOut()

CancelLogin()

Cancels login if the login window was opened.

public void CancelLogin()

SkipLogin()

Skips login, sets NGIO.NET to be ready with no session. Scoreboards and medals disabled.

public void SkipLogin()

OpenLoginPage()

Opens the login page from an existing

public void OpenLoginPage()

OpenUrl(String)

Opens an URL. Implementation is platform dependent.

public abstract void OpenUrl(string url)

Parameters

url String
The URL to open

Remarks:

This is intended to be used with any methods that return a URL, such as the NG Passport URL or referrals.

PopulateSessionFromId(String)

Gives a Session ID to the Communicator and then talks to NG to populate it.

public void PopulateSessionFromId(string sessionId)

Parameters

sessionId String
The Session ID to use

SetStartupSessionId(String)

public void SetStartupSessionId(string sessionId)

Parameters

sessionId String

HeartBeat()

public void HeartBeat()

StartHeartbeat(Single)

Starts the session heartbeat and keeps it running until stopped or server stops responding.

public abstract void StartHeartbeat(float seconds)

Parameters

seconds Single

Remarks:

Turning this on will keep the session alive by sending Gateway pings every seconds. Normally, a Communicator implementation would send session checks instead if the login page is opened to catch the user info. Newgrounds.IO Documentation

SetHeartbeatSpeed(Single)

Changes the Heartbeat's speed, mostly used to accelerate checking the session when the login page is open.

public abstract void SetHeartbeatSpeed(float newSeconds)

Parameters

newSeconds Single

StopHeartbeat()

Stops the session heartbeat.

public abstract void StopHeartbeat()

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

Uses the appropriate HTTP Client to send the components over the wire.

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

Parameters

components INgioComponentRequest[]
Components to send.

callback Action<NgioServerResponse>
Callback to execute.

forcedSession Nullable<Session>
Whether to use this provided Session instead of the Communicator's

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

Uses the appropriate HTTP Client to send a single component over the wire.

public void SendRequest(INgioComponentRequest component, Action<NgioServerResponse> callback, Nullable<Session> forcedSession)

Parameters

component INgioComponentRequest
Component to send.

callback Action<NgioServerResponse>
Callback to execute.

forcedSession Nullable<Session>
Whether to use this provided Session instead of the Communicator's

SendSecureRequest(INgioComponentRequest, Action<NgioServerResponse>)

Uses the appropriate HTTP Client to send a single secure component over the wire.

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

Parameters

component INgioComponentRequest
Component to send.

callback Action<NgioServerResponse>
Callback to execute

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