private void SyncServerTimeImpl() { if (_tcs == null) { _tcs = new TaskCompletionSource <bool>(); _scene.RpcTask("clock.time").Then(packet => { _knwonServerTimeTicks = packet.ReadObject <long>(); _knownServerTime = packet.ReadObject <DateTime>(); _tcs.SetResult(true); }) .ContinueWith(t => { if (t.IsFaulted) { _scene.DependencyResolver.Resolve <ILogger>().Error(t.Exception); } }); } }
/// <summary> /// Sends a remote procedure call with an object as input, expecting exactly one answer /// </summary> /// <typeparam name="TData">The type of data to send</typeparam> /// <typeparam name="TResponse">The expected type of the responses.</typeparam> /// <param name="scene">The target scene.</param> /// <param name="route">The target route.</param> /// <param name="data">The data object to send.</param> /// <param name="priority">The priority level used to send the request.</param> /// <returns>A tesk representing the remote procedure, whose return value is the deserialized value of the answer</returns> public static async Task <TResponse> RpcTask <TData, TResponse>(this Scene scene, string route, TData data, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { var result = await scene.RpcTask(route, s => scene.Host.Serializer().Serialize(data, s), priority); return(result.ReadObject <TResponse>()); }
public Task <LeaderboardResult> Query(LeaderboardQuery query) { return(_scene.RpcTask <LeaderboardQuery, LeaderboardResult>("leaderboard.query", query)); }
public Task <TOut> SendGameResult <Tin, TOut>(Tin result) { return(_scene.RpcTask <Tin, TOut>("gamesession.postresults", result)); }
public static Task <TResponse> RpcTask <TResponse>(this Scene scene, string route, Action <Stream> writer, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { return(scene.RpcTask <TResponse>(route, writer, CancellationToken.None, priority)); }
/// <summary> /// Sends a remote procedure call using raw binary data as input, expecting exactly one answer /// </summary> /// <typeparam name="TResponse">The expected type of the responses.</typeparam> /// <param name="scene">The target scene.</param> /// <param name="route">The target route.</param> /// <param name="writer">A writer method writing the data to send.</param> /// <param name="priority">The priority level used to send the request.</param> /// <returns>A task representing the remote procedure, whose return value is the deserialized value of the answer</returns> public static Task <TResponse> RpcTask <TResponse>(this Scene scene, string route, Action <Stream> writer, CancellationToken cancellationToken, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { return(scene.RpcTask(route, writer, cancellationToken, priority) .Then(result => result.ReadObject <TResponse>())); }
public static Task <TResponse> RpcTask <TData, TResponse>(this Scene scene, string route, TData data, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { return(scene.RpcTask <TData, TResponse>(route, data, CancellationToken.None, priority)); }
/// <summary> /// Sends a remote procedure call with an object as input, expecting exactly one answer /// </summary> /// <typeparam name="TData">The type of data to send</typeparam> /// <typeparam name="TResponse">The expected type of the responses.</typeparam> /// <param name="scene">The target scene.</param> /// <param name="route">The target route.</param> /// <param name="data">The data object to send.</param> /// <param name="priority">The priority level used to send the request.</param> /// <returns>A task representing the remote procedure, whose return value is the deserialized value of the answer</returns> public static Task <TResponse> RpcTask <TData, TResponse>(this Scene scene, string route, TData data, CancellationToken cancellationToken, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { return(scene.RpcTask(route, s => scene.Host.Serializer().Serialize(data, s), cancellationToken, priority) .Then(result => result.ReadObject <TResponse>())); }
public static Task <Packet <IScenePeer> > RpcTask(this Scene scene, string route, PacketPriority priority = PacketPriority.MEDIUM_PRIORITY) { return(scene.RpcTask(route, CancellationToken.None, priority)); }