/// <summary> /// Sends a request to master server, to register an existing spawner with given options /// </summary> public void Register(RegisterSpawnerCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } _logger.Info("Registering Spawner..."); Client.SendMessage((ushort)OpCodes.RegisterSpawner, new SpawnerOptions { MaxProcesses = _config.MaxProcesses, Region = _config.Region }, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } SpawnerId = response.AsInt(); callback.Invoke(SpawnerId); }); }
/// <summary> /// Sends a request to destroy a room of a given room id /// </summary> public void DestroyRoom(int roomId, SuccessCallback successCallback, ErrorCallback errorCallback, IClient client) { if (!client.IsConnected) { errorCallback.Invoke("Not connected"); return; } client.SendMessage((ushort)OpCodes.DestroyRoom, roomId, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } _localCreatedRooms.TryGetValue(roomId, out var destroyedRoom); _localCreatedRooms.Remove(roomId); successCallback.Invoke(); // Invoke event if (destroyedRoom != null) { RoomDestroyed?.Invoke(destroyedRoom); } }); }
/// <summary> /// Notifies master server that a user with a given peer id has left the room /// </summary> /// <param name="roomId"></param> /// <param name="peerId"></param> /// <param name="callback"></param> public void NotifyPlayerLeft(int roomId, int peerId, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("NotConnected"); return; } var packet = new PlayerLeftRoomPacket { PeerId = peerId, RoomId = roomId }; Client.SendMessage((ushort)OpCodes.PlayerLeftRoom, packet, (status, response) => { if (status == ResponseStatus.Success) { callback.Invoke(); } else { errorCallback.Invoke(response.AsString("Unknown Error")); } }); }
/// <summary> /// Sends a request to master server, to see if a given token is valid /// </summary> /// <param name="roomId"></param> /// <param name="token"></param> /// <param name="callback"></param> /// <param name="errorCallback"></param> public void ValidateAccess(int roomId, string token, RoomAccessValidateCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } var packet = new RoomAccessValidatePacket { RoomId = roomId, Token = token }; Client.SendMessage((ushort)OpCodes.ValidateRoomAccess, packet, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } callback.Invoke(response.Deserialize <UsernameAndPeerIdPacket>()); }); }
/// <summary> /// Updates the options of the registered room /// </summary> public void SaveOptions(int roomId, RoomOptions options, SuccessCallback successCallback, ErrorCallback errorCallback, IClient client) { if (!client.IsConnected) { errorCallback.Invoke("Not connected"); return; } var changePacket = new SaveRoomOptionsPacket { Options = options, RoomId = roomId }; client.SendMessage((ushort)OpCodes.SaveRoomOptions, changePacket, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } successCallback.Invoke(); }); }
/// <summary> /// This method should be called, when spawn process is finalized (finished spawning). /// For example, when spawned game server fully starts /// </summary> public void FinalizeSpawnedProcess(int spawnId, CompleteSpawnedProcessCallback callback, ErrorCallback errorCallback, Dictionary <string, string> finalizationData = null) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } var packet = new SpawnFinalizationPacket { SpawnId = spawnId, FinalizationData = finalizationData ?? new Dictionary <string, string>() }; Client.SendMessage((ushort)OpCodes.CompleteSpawnProcess, packet, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to register a room to master server /// </summary> public void RegisterRoom(RoomOptions options, RoomCreationCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.RegisterRoom, options, (status, response) => { if (status != ResponseStatus.Success) { // Failed to register room errorCallback.Invoke(response.AsString("Unknown Error")); return; } var roomId = response.AsInt(); var controller = new RoomController(this, roomId, Client, options); // Save the reference _localCreatedRooms[roomId] = controller; callback.Invoke(controller); // Invoke event RoomRegistered?.Invoke(controller); }); }
/// <summary> /// Sends a request to master server, to spawn a process in a given region, and with given options /// </summary> public void RequestSpawn(Dictionary <string, string> options, string region, ClientSpawnRequestCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } var packet = new ClientsSpawnRequestPacket { Options = options, Region = region }; Client.SendMessage((ushort)OpCodes.ClientsSpawnRequest, packet, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } // Spawn id var spawnId = response.AsInt(); var controller = new SpawnRequestController(this, spawnId, Client); _localSpawnRequests[controller.SpawnId] = controller; callback.Invoke(controller); }); }
/// <summary> /// Sends a new password to server /// </summary> public void ChangePassword(PasswordChangeData data, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected to server"); return; } var dictionary = new Dictionary <string, string>() { { "email", data.Email }, { "code", data.Code }, { "password", data.NewPassword } }; Client.SendMessage((ushort)OpCodes.PasswordChange, dictionary.ToBytes(), (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to server, retrieves all profile values, and applies them to a provided /// profile /// </summary> public void GetProfileValues(ObservableProfile profile, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.ClientProfileRequest, profile.PropertyCount, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } // Use the bytes received, to replicate the profile profile.FromBytes(response.AsBytes()); // Listen to profile updates, and apply them Client.SetHandler((ushort)OpCodes.UpdateClientProfile, message => { profile.ApplyUpdates(message.AsBytes()); }); callback.Invoke(); }); }
/// <summary> /// This should be called from a process which is spawned. /// For example, it can be called from a game server, which is started by the spawner /// On successfull registration, callback contains <see cref="SpawnTaskController"/>, which /// has a dictionary of properties, that were given when requesting a process to be spawned /// </summary> public void RegisterSpawnedProcess(int spawnId, string spawnCode, RegisterSpawnedProcessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } var packet = new RegisterSpawnedProcessPacket() { SpawnCode = spawnCode, SpawnId = spawnId }; Client.SendMessage((ushort)OpCodes.RegisterSpawnedProcess, packet, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } var properties = new Dictionary <string, string>().FromBytes(response.AsBytes()); var process = new SpawnTaskController(this, spawnId, properties); callback.Invoke(process); }); }
/// <summary> /// Sends a request to server, retrieves all profile values, and applies them to a provided /// profile /// </summary> public void FillProfileValues(ObservableServerProfile profile, SuccessCallback successCallback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.ServerProfileRequest, profile.Username, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } // Use the bytes received, to replicate the profile profile.FromBytes(response.AsBytes()); profile.ClearUpdates(); _profiles[profile.Username] = profile; profile.ModifiedInServer += serverProfile => { OnProfileModified(profile); }; profile.Disposed += OnProfileDisposed; successCallback.Invoke(); }); }
/// <summary> /// Sends a request to server, to ask for an e-mail confirmation code /// </summary> public void RequestEmailConfirmationCode(SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected to server"); return; } if (!IsLoggedIn) { errorCallback.Invoke("You're not logged in"); return; } Client.SendMessage((ushort)OpCodes.RequestEmailConfirmCode, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to join a lobby /// </summary> public void JoinLobby(int lobbyId, JoinLobbyCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } // Send the message Client.SendMessage((ushort)OpCodes.JoinLobby, lobbyId, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown Error")); return; } var data = response.Deserialize <LobbyDataPacket>(); var joinedLobby = new JoinedLobby(this, data, Client); LastJoinedLobby = joinedLobby; callback.Invoke(joinedLobby); LobbyJoined?.Invoke(joinedLobby); }); }
/// <summary> /// Sends a request to create a lobby and joins it /// </summary> public void CreateAndJoin(string lobbytypeid, Dictionary <string, string> properties, JoinLobbyCallback callback, ErrorCallback errorCallback) { CreateLobby(lobbytypeid, properties, id => { JoinLobby(id, callback.Invoke, error => { errorCallback.Invoke("Failed to join the lobby: " + error); }); }, error => errorCallback.Invoke("Failed to create lobby: " + error)); }
public void ShouldHandleInternalErrorsAndNotifyCallbacks() { IClientOperation errorSubscribeOperation = Substitute.For <IClientOperation>(); errorSubscribeOperation.ToJson().Returns(x => throw new Exception("forced error")); ParseQuery <ParseObject> query = new ParseQuery <ParseObject>(); _subscriptionFactory.CreateSubscriptionFunction = () => new TestSubscription(1, query) { CreateSubscribeClientOperationFunction = _ => errorSubscribeOperation }; LiveQueryException exception = null; ErrorCallback <ParseObject> errorCallback = Substitute.For <ErrorCallback <ParseObject> >(); errorCallback.Invoke(query, Arg.Do <LiveQueryException>(e => exception = e)); _parseLiveQueryClient.Subscribe(query).HandleError(errorCallback); _webSocketClientCallback.OnMessage(MockConnectedMessage()); // Trigger a re-subscribe // This will never get a chance to call op=subscribe, because an exception was thrown _webSocketClient.DidNotReceive().Send(Arg.Any <string>()); errorCallback.Received().Invoke(query, exception); Assert.AreEqual("Error when subscribing", exception.Message); Assert.NotNull(exception.GetBaseException()); }
/// <summary> /// This attempts to connect to the server at the ip provided. /// </summary> /// <param name="server">String ip of the server.</param> /// <param name="name">Name to send.</param> public void ConnectToServer(String server, String name = "Tarun") { // This is where we connect to the server for the first time. After the setup is done we // want our callback to be FirstContact. ClientNetworking.ConnectToServer(server, state => { SuccessfulConnection?.Invoke("Connected to host: " + server); _socketState = state; // Listen for when data is received on the socket. _socketState.DataReceived += DataReceived; // Listen for when the socket disconnects. _socketState.Disconnected += () => { Disconnected?.Invoke(); }; // Send the register message with the server. Debug.WriteLine(REGISTER, "sending register message"); AbstractNetworking.Send(state, REGISTER); // Wait for data. AbstractNetworking.GetData(state); }, reason => ErrorCallback?.Invoke(reason)); }
private async Task <bool> PerformPowershellAsync(string command, bool importNavContainerHelper) { if (asyncScript.InvocationStateInfo.State == PSInvocationState.Running) { ErrorCallback?.Invoke(this, Resources.GlobalRessources.ErrorWaitForPreviousTask); return(false); } StringBuilder sb = new StringBuilder(); if (importNavContainerHelper) { sb.AppendLine("import-module navcontainerhelper"); } sb.AppendLine(command); asyncScript.AddScript(sb.ToString()); StartScriptCallback?.Invoke(this, command); var result = asyncScript.BeginInvoke <PSObject, PSObject>(null, pso); await Task.Factory.FromAsync(result, x => { }); if (asyncScript.HadErrors) { ErrorCallback?.Invoke(this, GlobalRessources.ErrorScriptCompletedWithError); } EndScriptCallback?.Invoke(this, null); return(true); }
private void triggerErrorCallback(AsyncTaskResponse response) { // Si el primer callback existe, ejecutarlo con la información dada if (ErrorCallback != null) { ErrorCallback.Invoke(this, response); } }
public Task NotifyErrorMessage(string errorMessage) { if (ErrorCallback is not null) { return(ErrorCallback.Invoke(errorMessage)); } return(Task.CompletedTask); }
/// <summary> /// Sends a registration request to given connection /// </summary> public void Register(Dictionary <string, string> data, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected to server"); return; } if (_isLoggingIn) { errorCallback.Invoke("Log in is already in progress"); return; } if (IsLoggedIn) { errorCallback.Invoke("Already logged in"); return; } // We first need to get an aes key // so that we can encrypt our login data _securityPlugin.GetAesKey(aesKey => { if (aesKey == null) { errorCallback.Invoke("Failed to register due to security issues"); return; } var encryptedData = Util.EncryptAES(data.ToBytes(), aesKey); Client.SendMessage((ushort)OpCodes.RegisterAccount, encryptedData, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }); }
public void ErrorDataAdded(Object sender, DataAddedEventArgs e) { PSDataCollection <ErrorRecord> dc = asyncScript.Streams.Error; for (int i = 0; i < dc.Count; i++) { ErrorCallback?.Invoke(this, dc[i].Exception.Message); } dc.Clear(); }
public void ErrorDataAdded(Object sender, DataAddedEventArgs e) { PSDataCollection <ErrorRecord> dc = asyncScript.Streams.Error; foreach (ErrorRecord error in dc) { ErrorCallback?.Invoke(this, error.Exception.Message); } dc.Clear(); }
/// <summary> /// Sets a ready status of current player /// </summary> public void SetReadyStatus(bool isReady, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.LobbySetReady, isReady ? 1 : 0, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to server, to ask for a password reset /// </summary> public void RequestPasswordReset(string email, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected to server"); return; } Client.SendMessage((ushort)OpCodes.PasswordResetCodeRequest, email, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to leave a specified channel /// </summary> public void LeaveChannel(string channel, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.LeaveChannel, channel, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a request to set chat username /// </summary> public void PickUsername(string username, SuccessCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.PickUsername, username, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Retrieves data, which was given to master server by a spawned process, /// which was finalized /// </summary> public void GetFinalizationData(int spawnId, FinalizationDataHandler callback, ErrorCallback errorCallback, IClient client) { if (!client.IsConnected) { errorCallback.Invoke("Not connected"); return; } client.SendMessage((ushort)OpCodes.GetSpawnFinalizationData, spawnId, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(new Dictionary <string, string>().FromBytes(response.AsBytes())); }); }
/// <summary> /// Sends a request to abort spawn request, which was not yet finalized /// </summary> public void AbortSpawn(int spawnId, AbortSpawnHandler callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected"); return; } Client.SendMessage((ushort)OpCodes.AbortSpawnRequest, spawnId, (status, response) => { if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } callback.Invoke(); }); }
/// <summary> /// Sends a generic login request /// </summary> public void LogIn(Dictionary <string, string> data, LoginCallback callback, ErrorCallback errorCallback) { if (!Client.IsConnected) { errorCallback.Invoke("Not connected to server"); return; } _isLoggingIn = true; // We first need to get an aes key // so that we can encrypt our login data _securityPlugin.GetAesKey(aesKey => { if (aesKey == null) { _isLoggingIn = false; errorCallback.Invoke("Failed to log in due to security issues"); return; } var encryptedData = Util.EncryptAES(data.ToBytes(), aesKey); Client.SendMessage((ushort)OpCodes.LogIn, encryptedData, (status, response) => { _isLoggingIn = false; if (status != ResponseStatus.Success) { errorCallback.Invoke(response.AsString("Unknown error")); return; } IsLoggedIn = true; AccountInfo = response.Deserialize <AccountInfoPacket>(); callback.Invoke(AccountInfo); }); }); }