-
Notifications
You must be signed in to change notification settings - Fork 0
newgroundsiodotnet.ngiotaskcommunicator
Namespace: NewgroundsIODotNet
Communicator implementation for use in Desktop/Task supported platforms (Windows, Linux, Unity Desktop).
public class NgioTaskCommunicator : NgioCommunicator
Inheritance Object → NgioCommunicator → NgioTaskCommunicator
Remarks:
Do NOT use with WebGL runtimes unless Task/await async
is supported by the target platform. Usage on Mobile has not been tested.
public string NewgroundsGatewayUrl { get; }
The App ID to use with this Communicator.
public string AppId { get; }
Whether this Communicator was created with an Encryption key.
public bool Secured { get; }
Toggles NGIO's debug mode
public bool DebugMode { get; set; }
The current Session. null
if the session is uninitialized.
public Nullable<Session> Session { get; protected set; }
public ConnectionStatus ConnectionStatus { get; protected set; }
The current User. null
if there's nobody logged in.
public Nullable<User> CurrentUser { get; protected set; }
Is this game running on a legal host? Defaults to true
unless server responds otherwise at any point.
public bool LegalHost { get; protected set; }
Is this the latest version of the game? Defaults to true
unless server responds otherwise at any point.
public bool IsLatestVersion { get; protected set; }
Whether the login page is open.
public bool LoginPageOpen { get; protected set; }
App's version defined by the constructor
public string AppVersion { get; }
true
if medals have been preloaded inside the Communicator. Required to unlock Medals through the friendly methods.
public bool MedalsPreloaded { get; protected set; }
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; }
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; }
public IReadOnlyDictionary<int, Medal> LoadedMedals { get; }
IReadOnlyDictionary<Int32, Medal>
public IReadOnlyDictionary<int, ScoreBoard> LoadedScoreboards { get; }
IReadOnlyDictionary<Int32, ScoreBoard>
public IReadOnlyDictionary<int, SaveSlot> LoadedSaveSlots { get; }
IReadOnlyDictionary<Int32, SaveSlot>
public bool LoginSkipped { get; protected set; }
public bool IsReady { get; }
public bool HasUser { get; }
Last time a Gateway.ping or App.checkSession request replies successfully.
public DateTime LastSuccessfulPing { get; protected set; }
Last time any component was executed.
public DateTime LastExecution { get; protected set; }
Last scores fetched by the Communicator through GetScoreboardScores.
public Nullable<ValueTuple<Score[], ScoreBoardPeriod>> LastScoresResult { get; protected set; }
Nullable<ValueTuple<Score[], ScoreBoardPeriod>>
Last score posted through PostScore.
public Nullable<Score> LastScorePosted { get; protected set; }
Remarks:
NOTE:User in this Score will always be null; assume it's the current player.
Last save slot saved to through SetSaveSlot.
public Nullable<SaveSlot> LastSlotSaved { get; protected set; }
Last save slot that has been fetched data using GetSaveSlotData.
public Nullable<SaveSlot> LastSlotLoaded { get; protected set; }
Last medal unlocked through UnlockMedal.
public Nullable<Medal> LastUnlockedMedal { get; protected set; }
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)
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".
Fetches the data from a Save Slot, if populated.
public void GetSaveSlotData(SaveSlot slot, Action<string> responseCallback)
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.
Fetches a slot's data asynchronously, if populated.
public Task<string> GetSaveSlotDataAsync(SaveSlot slot)
slot
SaveSlot
The Save Slot from which to get data.
Task<String>
The data of the Save Slot if populated, null if nothing.
T:System.Net.Http.HttpRequestException
Thrown if the request fails for any reason.
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)
url
String
The URL to open
public void StartHeartbeat(float seconds)
seconds
Single
public void SetHeartbeatSpeed(float newSeconds)
newSeconds
Single
public void StopHeartbeat()
public void SendRequest(INgioComponentRequest[] components, Action<NgioServerResponse> callback, Nullable<Session> forceSession)
components
INgioComponentRequest[]
callback
Action<NgioServerResponse>
forceSession
Nullable<Session>
public void SendSecureRequest(INgioComponentRequest component, Action<NgioServerResponse> callback)
component
INgioComponentRequest
callback
Action<NgioServerResponse>
public Task<NgioServerResponse> SendRequestAsync(INgioComponentRequest[] components, Nullable<Session> forceSession)
components
INgioComponentRequest[]
forceSession
Nullable<Session>
public Task<NgioServerResponse> SendSecureRequestAsync(INgioComponentRequest component)
component
INgioComponentRequest
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;
Fires when a medal that wasn't previously unlocked is successfully unlocked through the friendly method.
public event EventHandler<Medal> MedalUnlocked;
Fires when a response is received, prior to the Communicator knowing they came through.
public event EventHandler<NgioServerResponse> ResponseReceived;
Fires when the HTTP client of the Communicator fails to connect to NG.
public event EventHandler CommunicationError;
Fires the moment that NG does not report an HTTP 200 when making a request.
public event EventHandler ServerUnavailable;
Fires when the response has an error.
public event EventHandler<NgioServerResponse> ResponseError;
Fires when any components inside a response have an error.
public event EventHandler<INgioComponentResponse[]> ComponentResponseError;
Fires when anywhere within the code a Log is sent.
public event EventHandler<LogInfo> LogMessageReceived;
Fires the moment the communicator signals Ready.
public event EventHandler Ready;
Fires whenever the connection status changes.
public event EventHandler<ConnectionStatus> ConnectionStatusChange;