/**
* Copyright 2018 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Nakama
{
using System.Collections.Generic;
using System.Threading.Tasks;
///
/// A client to interact with Nakama server.
///
public interface IClient
{
///
/// The host address of the server. Defaults to "127.0.0.1".
///
string Host { get; }
///
/// A logger which can write log messages. Defaults to NullLogger.
///
ILogger Logger { get; set; }
///
/// The port number of the server. Defaults to 7350.
///
int Port { get; }
///
/// The number of retries to attempt with each request with the server.
///
int Retries { get; set; }
///
/// The key used to authenticate with the server without a session. Defaults to "defaultkey".
///
string ServerKey { get; }
///
/// Set connection strings to use the secure mode with the server. Defaults to false.
///
/// The server must be configured to make use of this option. With HTTP, GRPC, and WebSockets the server must
/// be configured with an SSL certificate or use a load balancer which performs SSL termination. For rUDP you
/// must configure the server to expose it's IP address so it can be bundled within session tokens. See the
/// server documentation for more information.
///
///
bool Secure { get; }
///
/// Trace all actions performed by the client. Defaults to false.
///
bool Trace { get; set; }
///
/// Set the timeout on requests sent to the server.
///
int Timeout { get; set; }
///
/// Add one or more friends by id or username.
///
/// The session of the user.
/// The ids of the users to add or invite as friends.
/// The usernames of the users to add as friends.
/// A task.
Task AddFriendsAsync(ISession session, IEnumerable ids, IEnumerable usernames = null);
///
/// Add one or more users to the group.
///
/// The session of the user.
/// The id of the group to add users into.
/// The ids of the users to add or invite to the group.
/// A task.
Task AddGroupUsersAsync(ISession session, string groupId, IEnumerable ids);
///
/// Authenticate a user with a custom id.
///
/// A custom identifier usually obtained from an external authentication service.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateCustomAsync(string id, string username = null, bool create = true);
///
/// Authenticate a user with a device id.
///
/// A device identifier usually obtained from a platform API.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateDeviceAsync(string id, string username = null, bool create = true);
///
/// Authenticate a user with an email and password.
///
/// The email address of the user.
/// The password for the user.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateEmailAsync(string email, string password, string username = null,
bool create = true);
///
/// Authenticate a user with a Facebook auth token.
///
/// An OAuth access token from the Facebook SDK.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// True if the Facebook friends should be imported.
/// A task to resolve a session object.
Task AuthenticateFacebookAsync(string token, string username = null, bool create = true,
bool import = true);
///
/// Authenticate a user with Apple Game Center.
///
/// The bundle id of the Game Center application.
/// The player id of the user in Game Center.
/// The URL for the public encryption key.
/// A random NSString used to compute the hash and keep it randomized.
/// The verification signature data generated.
/// The date and time that the signature was created.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateGameCenterAsync(string bundleId, string playerId, string publicKeyUrl, string salt,
string signature, string timestampSeconds, string username = null, bool create = true);
///
/// Authenticate a user with a Google auth token.
///
/// An OAuth access token from the Google SDK.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateGoogleAsync(string token, string username = null, bool create = true);
///
/// Authenticate a user with a Steam auth token.
///
/// An authentication token from the Steam network.
/// A username used to create the user. May be null.
/// True if the user should be created when authenticated.
/// A task to resolve a session object.
Task AuthenticateSteamAsync(string token, string username = null, bool create = true);
///
/// Block one or more friends by id or username.
///
/// The session of the user.
/// The ids of the users to block.
/// The usernames of the users to block.
/// A task.
Task BlockFriendsAsync(ISession session, IEnumerable ids, IEnumerable usernames = null);
///
/// Create a group.
///
/// The session of the user.
/// The name for the group.
/// A description for the group.
/// An avatar url for the group.
/// A language tag in BCP-47 format for the group.
/// True if the group should have open membership.
/// A task to resolve a new group object.
Task CreateGroupAsync(ISession session, string name, string description = "",
string avatarUrl = null, string langTag = null, bool open = true);
///
/// Delete one more or users by id or username from friends.
///
/// The session of the user.
/// The user ids to remove as friends.
/// The usernames to remove as friends.
/// A task.
Task DeleteFriendsAsync(ISession session, IEnumerable ids, IEnumerable usernames = null);
///
/// Delete a group by id.
///
/// The session of the user.
/// The group id to to remove.
/// A task.
Task DeleteGroupAsync(ISession session, string groupId);
///
/// Delete a leaderboard record.
///
/// The session of the user.
/// The id of the leaderboard with the record to be deleted.
/// A task.
Task DeleteLeaderboardRecordAsync(ISession session, string leaderboardId);
///
/// Delete one or more notifications by id.
///
/// The session of the user.
/// The notification ids to remove.
/// A task.
Task DeleteNotificationsAsync(ISession session, IEnumerable ids);
///
/// Delete one or more storage objects.
///
/// The session of the user.
/// The ids of the objects to delete.
/// A task.
Task DeleteStorageObjectsAsync(ISession session, params StorageObjectId[] ids);
///
/// Fetch the user account owned by the session.
///
/// The session of the user.
/// A task to resolve an account object.
Task GetAccountAsync(ISession session);
///
/// Fetch one or more users by id, usernames, and Facebook ids.
///
/// The session of the user.
///
///
///
/// A task to resolve user objects.
Task GetUsersAsync(ISession session, IEnumerable ids, IEnumerable usernames = null,
IEnumerable facebookIds = null);
///
/// Import Facebook friends and add them to the user's account.
///
///
/// The server will import friends when the user authenticates with Facebook. This function can be used to be
/// explicit with the import operation.
///
/// The session of the user.
/// An OAuth access token from the Facebook SDK.
/// True if the Facebook friend import for the user should be reset.
/// A task.
Task ImportFacebookFriendsAsync(ISession session, string token, bool reset = false);
///
/// Join a group if it has open membership or request to join it.
///
/// The session of the user.
/// The id of the group to join.
/// A task.
Task JoinGroupAsync(ISession session, string groupId);
///
/// Join a tournament by ID.
///
/// The session of the user.
/// The ID of the tournament to join.
/// A task.
Task JoinTournamentAsync(ISession session, string tournamentId);
///
/// Kick one or more users from the group.
///
/// The session of the user.
/// The id of the group.
/// The ids of the users to kick.
/// A task.
Task KickGroupUsersAsync(ISession session, string groupId, IEnumerable ids);
///
/// Leave a group by id.
///
/// The session of the user.
/// The id of the group to leave.
/// A task.
Task LeaveGroupAsync(ISession session, string groupId);
///
/// Link a custom id to the user account owned by the session.
///
/// The session of the user.
/// A custom identifier usually obtained from an external authentication service.
/// A task.
Task LinkCustomAsync(ISession session, string id);
///
/// Link a device id to the user account owned by the session.
///
/// The session of the user.
/// A device identifier usually obtained from a platform API.
/// A task.
Task LinkDeviceAsync(ISession session, string id);
///
/// Link an email with password to the user account owned by the session.
///
/// The session of the user.
/// The email address of the user.
/// The password for the user.
/// A task.
Task LinkEmailAsync(ISession session, string email, string password);
///
/// Link a Facebook profile to a user account.
///
/// The session of the user.
/// An OAuth access token from the Facebook SDK.
/// True if the Facebook friends should be imported.
/// A task.
Task LinkFacebookAsync(ISession session, string token, bool import = true);
///
/// Link a Game Center profile to a user account.
///
/// The session of the user.
/// The bundle id of the Game Center application.
/// The player id of the user in Game Center.
/// The URL for the public encryption key.
/// A random NSString used to compute the hash and keep it randomized.
/// The verification signature data generated.
/// The date and time that the signature was created.
/// A task.
Task LinkGameCenterAsync(ISession session, string bundleId, string playerId, string publicKeyUrl, string salt,
string signature, string timestampSeconds);
///
/// Link a Google profile to a user account.
///
/// The session of the user.
/// An OAuth access token from the Google SDK.
/// A task.
Task LinkGoogleAsync(ISession session, string token);
///
/// Link a Steam profile to a user account.
///
/// The session of the user.
/// An authentication token from the Steam network.
/// A task.
Task LinkSteamAsync(ISession session, string token);
///
/// List messages from a chat channel.
///
/// The session of the user.
/// A channel identifier.
/// The number of chat messages to list.
/// Fetch messages forward from the current cursor (or the start).
/// A cursor for the current position in the messages history to list.
/// A task to resolve channel message objects.
Task ListChannelMessagesAsync(ISession session, string channelId, int limit = 1,
bool forward = true, string cursor = null);
///
/// List of friends of the current user.
///
/// The session of the user.
/// A task to resolve friend objects.
Task ListFriendsAsync(ISession session);
///
/// List all users part of the group.
///
/// The session of the user.
/// The id of the group.
/// A task to resolve group user objects.
Task ListGroupUsersAsync(ISession session, string groupId);
///
/// List groups on the server.
///
/// The session of the user.
/// The name filter to apply to the group list.
/// The number of groups to list.
/// A cursor for the current position in the groups to list.
/// A task to resolve group objects.
Task ListGroupsAsync(ISession session, string name = null, int limit = 1, string cursor = null);
///
/// List records from a leaderboard.
///
/// The session of the user.
/// The id of the leaderboard to list.
/// Record owners to fetch with the list of records.
/// The number of records to list.
/// A cursor for the current position in the leaderboard records to list.
/// A task to resolve leaderboard record objects.
Task ListLeaderboardRecordsAsync(ISession session, string leaderboardId,
IEnumerable ownerIds = null, int limit = 1, string cursor = null);
///
/// List leaderboard records that belong to a user.
///
/// The session for the user.
/// The id of the leaderboard to list.
/// The id of the user to list around.
/// The limit of the listings.
/// A task.
Task ListLeaderboardRecordsAroundOwnerAsync(ISession session, string leaderboardId,
string ownerId, int limit = 1);
///
/// Fetch a list of matches active on the server.
///
/// The session of the user.
/// The minimum number of match participants.
/// The maximum number of match participants.
/// The number of matches to list.
/// True to include authoritative matches.
/// The label to filter the match list on.
/// A query for the matches to filter.
///
Task ListMatchesAsync(ISession session, int min, int max, int limit, bool authoritative,
string label, string query);
///
/// List notifications for the user with an optional cursor.
///
/// The session of the user.
/// The number of notifications to list.
/// A cursor for the current position in notifications to list.
/// A task to resolve notifications objects.
Task ListNotificationsAsync(ISession session, int limit = 1,
string cacheableCursor = null);
///
/// List storage objects in a collection which have public read access.
///
/// The session of the user.
/// The collection to list over.
/// The number of objects to list.
/// A cursor to paginate over the collection.
/// A task which resolves to a storage object list.
Task ListStorageObjects(ISession session, string collection, int limit = 1,
string cursor = null);
///
/// List tournament records around the owner.
///
/// The session of the user.
/// The ID of the tournament.
///
///
///
Task ListTournamentRecordsAroundOwnerAsync(ISession session, string tournamentId,
string ownerId, int limit = 1);
///
/// List records from a tournament.
///
/// The session of the user.
/// The ID of the tournament.
/// The IDs of the record owners to return in the result.
/// The number of records to list.
/// An optional cursor for the next page of tournament records.
/// A task which resolves to a list of tournament records.
Task ListTournamentRecordsAsync(ISession session, string tournamentId,
IEnumerable ownerIds = null, int limit = 1, string cursor = null);
///
/// List current or upcoming tournaments.
///
/// The session of the user.
/// The start of the category of tournaments to include.
/// The end of the category of tournaments to include.
/// The start time of the tournaments. (UNIX timestamp)
/// The end time of the tournaments. (UNIX timestamp)
/// The number of tournaments to list.
/// An optional cursor for the next page of tournaments.
/// A task which resolves to a list of tournament objects.
Task ListTournamentsAsync(ISession session, int categoryStart, int categoryEnd,
int startTime, int endTime, int limit = 1, string cursor = null);
///
/// List of groups the current user is a member of.
///
/// The session of the user.
/// A task which resolves to group objects.
Task ListUserGroupsAsync(ISession session);
///
/// List groups a user is a member of.
///
/// The session of the user.
/// The id of the user whose groups to list.
/// A task which resolves to group objects.
Task ListUserGroupsAsync(ISession session, string userId);
///
/// List storage objects in a collection which belong to a specific user and have public read access.
///
/// The session of the user.
/// The collection to list over.
/// The user ID of the user to list objects for.
/// The number of objects to list.
/// A cursor to paginate over the collection.
/// A task which resolves to a storage object list.
Task ListUsersStorageObjectsAsync(ISession session, string collection, string userId,
int limit, string cursor);
///
/// Promote one or more users in the group.
///
/// The session of the user.
/// The id of the group to promote users into.
/// The ids of the users to promote.
/// A task.
Task PromoteGroupUsersAsync(ISession session, string groupId, IEnumerable ids);
///
/// Read one or more objects from the storage engine.
///
/// The session of the user.
/// The objects to read.
/// A task to resolve storage objects.
Task ReadStorageObjectsAsync(ISession session, params IApiReadStorageObjectId[] ids);
///
/// Execute a Lua function with an input payload on the server.
///
/// The session of the user.
/// The id of the function to execute on the server.
/// The payload to send with the function call.
/// A task to resolve an RPC response.
Task RpcAsync(ISession session, string id, string payload);
///
/// Execute a Lua function on the server.
///
/// The session of the user.
/// The id of the function to execute on the server.
/// A task to resolve an RPC response.
Task RpcAsync(ISession session, string id);
///
/// Execute a Lua function on the server without a session.
///
/// The secure HTTP key used to authenticate.
/// The id of the function to execute on the server.
/// A payload to send with the function call.
/// A task to resolve an RPC response.
Task RpcAsync(string httpkey, string id, string payload = null);
///
/// Unlink a custom id from the user account owned by the session.
///
/// The session of the user.
/// A custom identifier usually obtained from an external authentication service.
/// A task.
Task UnlinkCustomAsync(ISession session, string id);
///
/// Unlink a device id from the user account owned by the session.
///
/// The session of the user.
/// A device identifier usually obtained from a platform API.
/// A task.
Task UnlinkDeviceAsync(ISession session, string id);
///
/// Unlink an email with password from the user account owned by the session.
///
/// The session of the user.
/// The email address of the user.
/// The password for the user.
/// A task.
Task UnlinkEmailAsync(ISession session, string email, string password);
///
/// Unlink a Facebook profile from the user account owned by the session.
///
/// The session of the user.
/// An OAuth access token from the Facebook SDK.
/// A task.
Task UnlinkFacebookAsync(ISession session, string token);
///
/// Unlink a Game Center profile from the user account owned by the session.
///
/// The session of the user.
/// The bundle id of the Game Center application.
/// The player id of the user in Game Center.
/// The URL for the public encryption key.
/// A random NSString used to compute the hash and keep it randomized.
/// The verification signature data generated.
/// The date and time that the signature was created.
/// A task.
Task UnlinkGameCenterAsync(ISession session, string bundleId, string playerId, string publicKeyUrl, string salt,
string signature, string timestampSeconds);
///
/// Unlink a Google profile from the user account owned by the session.
///
/// The session of the user.
/// An OAuth access token from the Google SDK.
/// A task.
Task UnlinkGoogleAsync(ISession session, string token);
///
/// Unlink a Steam profile from the user account owned by the session.
///
/// The session of the user.
/// An authentication token from the Steam network.
/// A task.
Task UnlinkSteamAsync(ISession session, string token);
///
/// Update the current user's account on the server.
///
/// The session for the user.
/// The new username for the user.
/// A new display name for the user.
/// A new avatar url for the user.
/// A new language tag in BCP-47 format for the user.
/// A new location for the user.
/// New timezone information for the user.
/// A task to complete the account update.
Task UpdateAccountAsync(ISession session, string username, string displayName = null,
string avatarUrl = null, string langTag = null, string location = null, string timezone = null);
///
/// Update a group.
///
///
/// The user must have the correct access permissions for the group.
///
/// The session of the user.
/// The id of the group to update.
/// A new name for the group.
/// A new description for the group.
/// A new avatar url for the group.
/// A new language tag in BCP-47 format for the group.
/// True if the group should have open membership.
/// A task.
Task UpdateGroupAsync(ISession session, string groupId, string name, string description = null,
string avatarUrl = null, string langTag = null, bool open = false);
///
/// Write a record to a leaderboard.
///
/// The session for the user.
/// The id of the leaderboard to write.
/// The score for the leaderboard record.
/// The subscore for the leaderboard record.
/// The metadata for the leaderboard record.
/// A task to complete the leaderboard record write.
Task WriteLeaderboardRecordAsync(ISession session, string leaderboardId, long score,
long subscore = 0L, string metadata = null);
///
/// Write objects to the storage engine.
///
/// The session of the user.
/// The objects to write.
/// A task to resolve the acknowledgements with writes.
Task WriteStorageObjectsAsync(ISession session, params IApiWriteStorageObject[] objects);
///
/// Write a record to a tournament.
///
/// The session of the user.
/// The id of the tournament to write.
/// The score of the tournament record.
/// The subscore for the tournament record.
/// The metadata for the tournament record.
/// A task to complete the tournament record write.
Task WriteTournamentRecordAsync(ISession session, string tournamentId, long score,
long subscore = 0L, string metadata = null);
///
/// Create a new WebSocket from the client.
///
/// Set the number of retries to attempt after a disconnect.
/// A socket object.
ISocket CreateWebSocket(int reconnect = 3);
}
}