-
Notifications
You must be signed in to change notification settings - Fork 0
newgroundsiodotnet.ngiocommunicator
Namespace: NewgroundsIODotNet
public abstract class NgioCommunicator
Inheritance Object → NgioCommunicator
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; }
Initializes the Communicator.
public void Initialize()
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)
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.
Gets the info of a preloaded medal. Returns null on failure.
public Nullable<Medal> GetMedal(int id)
id
Int32
Medal ID
Nullable<Medal>
The found medal.
Attempts to unlock a Medal.
public void UnlockMedal(Medal medal, Action<Medal> responseCallback)
medal
Medal
The Medal to unlock.
responseCallback
Action<Medal>
Callback to execute when the medal is unlocked
Gets the info of a Cloud Save slot. Returns null on failure.
public Nullable<SaveSlot> GetSaveSlot(int id)
id
Int32
ID of the Cloud Save slot
Nullable<SaveSlot>
The info for the Save Slot
Sets data in a Save Slot.
public void SetSaveSlot(SaveSlot slot, string data, Action<Nullable<SaveSlot>> responseCallback)
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
Gets the data from the Save Slot.
public abstract void GetSaveSlotData(SaveSlot slot, Action<string> responseCallback)
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.
Loads and opens a Loader URL.
public void LoadUrl(StandardLoaderType type, bool logStat)
type
StandardLoaderType
The kind of URL to get from Newgrounds
logStat
Boolean
Whether to log this load in the stats.
Loads and opens a Loader Referral URL.
public void LoadReferral(string referral, bool logStat)
referral
String
The ID of the referral from your API Tools dashboard.
logStat
Boolean
Whether to log this load in the stats.
ArgumentException
Thrown if the server returns unsuccessful.
Loads and opens a Loader URL.
public void LoadStandardUrl(StandardLoaderType type, bool logStat)
type
StandardLoaderType
The type of URL to open
logStat
Boolean
Whether to log this load in the stats.
ArgumentException
Thrown if the server returns unsuccessful.
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)
eventId
String
ID of the event to log.
responseCallback
Action<EventLogEventResponse>
Callback to execute when data is received
Exception
Thrown when the operation returns unsuccessful.
Gets the date and time from the Newgrounds.IO server.
public void GetDateTime(Action<DateTime> responseCallback)
responseCallback
Action<DateTime>
Action to execute when data is received
Exception
You know, this shouldn't happen unless the server is dying, or you're offline.
Gets the info of a Scoreboard. Returns null if unsuccessful.
public Nullable<ScoreBoard> GetScoreboard(int id)
id
Int32
ID of the Scoreboard
Nullable<ScoreBoard>
The info for the Scoreboard
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)
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
Posts a score to a given scoreboard.
public void PostScore(ScoreBoard scoreBoard, int amount, string tag, Action<Nullable<Score>> responseCallback)
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.
Resets login, session, caches for last saves/medals/scores and login-skip state.
public void ResetConnectionState()
Opens the Newgrounds Passport URL supplied by a given session, or starts a new session and then opens the page.
public void LogIn()
Cancels login if in progress and terminates the user session.
public void LogOut()
Cancels login if the login window was opened.
public void CancelLogin()
Skips login, sets NGIO.NET to be ready with no session. Scoreboards and medals disabled.
public void SkipLogin()
Opens the login page from an existing
public void OpenLoginPage()
Opens an URL. Implementation is platform dependent.
public abstract void OpenUrl(string url)
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.
Gives a Session ID to the Communicator and then talks to NG to populate it.
public void PopulateSessionFromId(string sessionId)
sessionId
String
The Session ID to use
public void SetStartupSessionId(string sessionId)
sessionId
String
public void HeartBeat()
Starts the session heartbeat and keeps it running until stopped or server stops responding.
public abstract void StartHeartbeat(float seconds)
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
Changes the Heartbeat's speed, mostly used to accelerate checking the session when the login page is open.
public abstract void SetHeartbeatSpeed(float newSeconds)
newSeconds
Single
Stops the session heartbeat.
public abstract void StopHeartbeat()
Uses the appropriate HTTP Client to send the components over the wire.
public abstract void SendRequest(INgioComponentRequest[] components, Action<NgioServerResponse> callback, Nullable<Session> forcedSession)
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
Uses the appropriate HTTP Client to send a single component over the wire.
public void SendRequest(INgioComponentRequest component, Action<NgioServerResponse> callback, Nullable<Session> forcedSession)
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
Uses the appropriate HTTP Client to send a single secure component over the wire.
public abstract void SendSecureRequest(INgioComponentRequest component, Action<NgioServerResponse> callback)
component
INgioComponentRequest
Component to send.
callback
Action<NgioServerResponse>
Callback to execute
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;