protected virtual void ClientsSpawnRequestHandler(IIncommingMessage message) { var data = message.Deserialize(new ClientsSpawnRequestPacket()); var peer = message.Peer; logger.Info($"Client {peer.Id} requested to spawn room {data.Options[MsfDictKeys.roomName]}"); // Check if current request is authorized if (!CanClientSpawn(peer, data)) { // Client can't spawn message.Respond("Unauthorized", ResponseStatus.Unauthorized); return; } // Try to find existing request to prevent new one SpawnTask prevRequest = peer.GetProperty((int)MsfPropCodes.ClientSpawnRequest) as SpawnTask; if (prevRequest != null && !prevRequest.IsDoneStartingProcess) { // Client has unfinished request message.Respond("You already have an active request", ResponseStatus.Failed); return; } // Create a new spawn task var task = Spawn(data.Options, data.Region, data.CustomArgs); // If spawn task is not created if (task == null) { message.Respond("All the servers are busy. Try again later".ToBytes(), ResponseStatus.Failed); return; } // Save spawn task requester task.Requester = message.Peer; // Save the task peer.SetProperty((int)MsfPropCodes.ClientSpawnRequest, task); // Listen to status changes task.OnStatusChangedEvent += (status) => { // Send status update var msg = Msf.Create.Message((short)MsfMessageCodes.SpawnRequestStatusChange, new SpawnStatusUpdatePacket() { SpawnId = task.SpawnId, Status = status }); message.Peer.SendMessage(msg); }; message.Respond(task.SpawnId, ResponseStatus.Success); }
public void OnRoomDestroyed(RegisteredRoom room) { room.OnDestroyedEvent -= OnRoomDestroyed; GameIp = ""; GamePort = -1; Room = null; GameSpawnTask = null; State = Config.PlayAgainEnabled ? LobbyState.Preparations : LobbyState.GameOver; }
/// <summary> /// Requests a specific spawner to spawn a process /// </summary> /// <param name="properties"></param> /// <param name="customArgs"></param> /// <param name="spawner"></param> /// <returns></returns> public virtual SpawnTask Spawn(Dictionary <string, string> properties, string customArgs, RegisteredSpawner spawner) { var task = new SpawnTask(GenerateSpawnTaskId(), spawner, properties, customArgs); spawnTasksList[task.SpawnId] = task; spawner.AddTaskToQueue(task); logger.Debug("Spawner was found, and spawn task created: " + task); return(task); }
/// <summary> /// Requests a specific spawner to spawn a process /// </summary> /// <param name="properties"></param> /// <param name="customArgs"></param> /// <param name="spawner"></param> /// <returns></returns> public virtual SpawnTask Spawn(Dictionary <string, string> properties, string customArgs, RegisteredSpawner spawner, string spawnID) { var task = new SpawnTask(spawnID, spawner, properties, customArgs); if (SpawnTasks.ContainsKey(task.UniqueCode)) { Debug.LogError("Already have Spawner: " + task.UniqueCode); SpawnTasks.Remove(task.UniqueCode); } SpawnTasks.Add(task.UniqueCode, task); spawner.AddTaskToQueue(task); return(task); }
/// <summary> /// Start process on spawner side with given spawn <paramref name="options"/>, <paramref name="customOptions"/> and <paramref name="spawner"/> /// </summary> /// <param name="options"></param> /// <param name="customOptions"></param> /// <param name="spawner"></param> /// <returns></returns> public virtual SpawnTask Spawn(DictionaryOptions options, DictionaryOptions customOptions, RegisteredSpawner spawner) { // Create new spawn task var task = new SpawnTask(GenerateSpawnTaskId(), spawner, options, customOptions); // List this task spawnTasksList[task.Id] = task; // Add this task to queue spawner.AddTaskToQueue(task); logger.Debug("Spawner was found, and spawn task created: " + task); return(task); }
public void SetGameSpawnTask(SpawnTask task) { if (task == null) { return; } if (GameSpawnTask == task) { return; } if (GameSpawnTask != null) { // Unsubscribe from previous game GameSpawnTask.OnStatusChangedEvent -= OnSpawnServerStatusChanged; GameSpawnTask.Abort(); } GameSpawnTask = task; task.OnStatusChangedEvent += OnSpawnServerStatusChanged; }
public void AddTaskToQueue(SpawnTask task) { _queue.Enqueue(task); }
/// <summary> /// Fired whe connected client has made request to spawn process /// </summary> /// <param name="message"></param> protected virtual void ClientsSpawnRequestHandler(IIncommingMessage message) { // Parse data from message var spawnRequestData = message.Deserialize(new ClientsSpawnRequestPacket()); var peer = message.Peer; logger.Info($"Client {peer.Id} requested to spawn room with options: {spawnRequestData}"); if (spawnersList.Count == 0) { logger.Error("But no registered spawner was found!"); message.Respond("No registered spawner was found", ResponseStatus.Failed); return; } // Check if current request is authorized if (!CanClientSpawn(peer, spawnRequestData)) { logger.Error("Unauthorized request"); // Client can't spawn message.Respond("Unauthorized", ResponseStatus.Unauthorized); return; } // Try to find existing request to prevent new one SpawnTask prevRequest = peer.GetProperty((int)MsfPeerPropertyCodes.ClientSpawnRequest) as SpawnTask; if (prevRequest != null && !prevRequest.IsDoneStartingProcess) { logger.Warn("And he already has an active request"); // Client has unfinished request message.Respond("You already have an active request", ResponseStatus.Failed); return; } // Create a new spawn task var task = Spawn(spawnRequestData.Options, spawnRequestData.Options.AsString(MsfDictKeys.region), spawnRequestData.CustomOptions); // If spawn task is not created if (task == null) { logger.Warn("But all the servers are busy. Let him try again later"); message.Respond("All the servers are busy. Try again later".ToBytes(), ResponseStatus.Failed); return; } // Save spawn task requester task.Requester = message.Peer; // Save the task as peer property peer.SetProperty((int)MsfPeerPropertyCodes.ClientSpawnRequest, task); // Listen to status changes task.OnStatusChangedEvent += (status) => { // Send status update var msg = Msf.Create.Message((short)MsfMessageCodes.SpawnRequestStatusChange, new SpawnStatusUpdatePacket() { SpawnId = task.Id, Status = status }); if (task.Requester != null && task.Requester.IsConnected) { message.Peer.SendMessage(msg); } }; message.Respond(task.Id, ResponseStatus.Success); }