/** * 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; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; /// /// A socket to interact with Nakama server. /// public interface ISocket : IDisposable { /// /// Receive chat channel messages. /// event EventHandler OnChannelMessage; /// /// Receive chat channel presences for when users join and leave. /// event EventHandler OnChannelPresence; /// /// Receive an event when the socket connects. /// event EventHandler OnConnect; /// /// Receive an event when the socket disconnects. /// event EventHandler OnDisconnect; /// /// Receive an event when the socket has an error. /// event EventHandler OnError; /// /// Receive an event when the player gets matched by the matchmaker. /// event EventHandler OnMatchmakerMatched; /// /// Receive state messages from a realtime match. /// event EventHandler OnMatchState; /// /// Receive match presences for when users join and leave. /// event EventHandler OnMatchPresence; /// /// Receive realtime notifications. /// event EventHandler OnNotification; /// /// Receive presence events for when a user updates their status. /// event EventHandler OnStatusPresence; /// /// Receive low level presence events from a realtime stream. /// event EventHandler OnStreamPresence; /// /// Receive state messages from a realtime stream. /// event EventHandler OnStreamState; /// /// Join the matchmaker pool and search for opponents on the server. /// /// A matchmaker query to search for opponents. /// The minimum number of players to compete against. /// The maximum number of players to compete against. /// A set of k/v properties to provide in searches. /// A set of k/v numeric properties to provide in searches. /// A task which resolves to a matchmaker ticket object. Task AddMatchmakerAsync(string query = "*", int minCount = 2, int maxCount = 8, Dictionary stringProperties = null, Dictionary numericProperties = null); /// /// Connect to the server. /// /// The session of the user. /// A cancellation token for the asynchronous operation. /// True if the socket should show the user as online to others. /// Time in millisecs before the connection attempt is considered failed. /// A task. Task ConnectAsync(ISession session, CancellationToken ct = default(CancellationToken), bool appearOnline = false, int connectTimeout = 5000); /// /// Create a multiplayer match on the server. /// /// A task. Task CreateMatchAsync(); /// /// Close the connection with the server. /// /// True if the disconnect should dispatch an on disconnect event. /// A close task. Task DisconnectAsync(bool dispatch = true); /// /// Follow one or more users for status updates. /// /// The user Ids to follow. /// A task. Task FollowUsersAsync(IEnumerable userIds); /// /// Join a chat channel on the server. /// /// The target channel to join. /// The type of channel to join. /// True if chat messages should be stored. /// True if the user should be hidden on the channel. /// A task which resolves to a Channel response. Task JoinChatAsync(string target, ChannelType type, bool persistence = false, bool hidden = false); /// /// Join a multiplayer match with a matchmaker. /// /// A matchmaker result object. /// A task which resolves to the match joined. Task JoinMatchAsync(IMatchmakerMatched matched); /// /// Join a multiplayer match by ID. /// /// A match ID. /// A task which resolves to the match joined. Task JoinMatchAsync(string matchId); /// /// Leave a chat channel on the server. /// /// The channel to leave. /// A task. Task LeaveChatAsync(IChannel channel); /// /// Leave a chat channel on the server. /// /// The ID of the channel to leave. /// A task. Task LeaveChatAsync(string channelId); /// /// Leave a match on the server. /// /// The match to leave. /// A task. Task LeaveMatchAsync(IMatch match); /// /// Leave a match on the server. /// /// The ID of the match to leave. /// A task. Task LeaveMatchAsync(string matchId); /// /// Remove a chat message from a channel on the server. /// /// The chat channel with the message. /// The ID of a chat message to update. /// A task. Task RemoveChatMessageAsync(IChannel channel, string messageId); /// /// Remove a chat message from a channel on the server. /// /// The ID of the chat channel with the message. /// The ID of a chat message to update. /// A task. Task RemoveChatMessageAsync(string channelId, string messageId); /// /// Leave the matchmaker pool by ticket. /// /// The ticket returned by the matchmaker on join. /// A task. Task RemoveMatchmakerAsync(IMatchmakerTicket ticket); /// /// Leave the matchmaker pool by ticket. /// /// The ticket returned by the matchmaker on join. See IMatchmakerTicket.Ticket. /// A task. Task RemoveMatchmakerAsync(string ticket); /// /// Send an RPC message to the server. /// /// The ID of the function to execute. /// The string content to send to the server. /// A task which resolves to an RPC response. Task RpcAsync(string id, string payload); /// /// Send new state to a match on the server. /// /// The Id of the match. /// An operation code for the match state. /// The new state to send to the match. /// The presences in the match to send the state. Task SendMatchStateAsync(string matchId, long opCode, string state, IEnumerable presences = null); /// /// Send a state change to a match on the server. /// /// /// When no presences are supplied the new match state will be sent to all presences. /// /// The Id of the match. /// An operation code for the match state. /// The new state to send to the match. /// The presences in the match to send the state. Task SendMatchStateAsync(string matchId, long opCode, byte[] state, IEnumerable presences = null); /// /// Send new state to a match on the server. /// /// The Id of the match. /// An operation code for the match state. /// The new state to send to the match. /// The presences in the match to send the state. void SendMatchState(string matchId, long opCode, string state, IEnumerable presences = null); /// /// Send a state change to a match on the server. /// /// /// When no presences are supplied the new match state will be sent to all presences. /// /// The Id of the match. /// An operation code for the match state. /// The new state to send to the match. /// The presences in the match to send the state. void SendMatchState(string matchId, long opCode, byte[] state, IEnumerable presences = null); /// /// Unfollow status updates for one or more users. /// /// The ids of users to unfollow. /// A task. Task UnfollowUsersAsync(IEnumerable userIds); /// /// Update a chat message to a channel on the server. /// /// The channel with the message to update. /// The ID of the message to update. /// The content update for the message. /// A task. Task UpdateChatMessageAsync(IChannel channel, string messageId, string content); /// /// Update a chat message to a channel on the server. /// /// The ID of the chat channel with the message. /// The ID of the message to update. /// The content update for the message. /// A task. Task UpdateChatMessageAsync(string channelId, string messageId, string content); /// /// Update the user's status online. /// /// The new status of the user. /// A task. Task UpdateStatusAsync(string status); /// /// Send a chat message to a channel on the server. /// /// The channel to send on. /// The content of the chat message. /// A task which resolves to a Channel Ack response. Task WriteChatMessageAsync(IChannel channel, string content); /// /// Send a chat message to a channel on the server. /// /// The ID of the channel as the destination for the message. /// The content of the chat message. /// A task which resolves to a Channel Ack response. Task WriteChatMessageAsync(string channelId, string content); } }