private void HandleJoinTeam(IIncommingMessage message) { var data = message.Deserialize <LobbyJoinTeamPacket>(); var lobbiesExt = GetOrCreateLobbiesExtension(message.Peer); var lobby = lobbiesExt.CurrentLobby; if (lobby == null) { message.Respond("You're not in a lobby", ResponseStatus.Failed); return; } var player = lobby.GetMember(lobbiesExt); if (player == null) { message.Respond("Invalid request", ResponseStatus.Failed); return; } if (!lobby.TryJoinTeam(data.TeamName, player)) { message.Respond("Failed to join a team: " + data.TeamName, ResponseStatus.Failed); return; } message.Respond(ResponseStatus.Success); }
/// <summary> /// Handles a message from spawned process. Spawned process send this message /// to notify server that it was started /// </summary> /// <param name="message"></param> protected virtual void RegisterSpawnedProcessRequestHandler(IIncommingMessage message) { var data = message.Deserialize(new RegisterSpawnedProcessPacket()); // Try get psawn task by ID if (!spawnTasksList.TryGetValue(data.SpawnId, out SpawnTask task)) { message.Respond("Invalid spawn task", ResponseStatus.Failed); logger.Error("Process tried to register to an unknown task"); return; } // Check spawn task unique code if (task.UniqueCode != data.SpawnCode) { message.Respond("Unauthorized", ResponseStatus.Unauthorized); logger.Error("Spawned process tried to register, but failed due to mismaching unique code"); return; } // Set task as registered task.OnRegistered(message.Peer); // Invoke event OnSpawnedProcessRegisteredEvent?.Invoke(task, message.Peer); // Respon to requester message.Respond(task.Options.ToDictionary().ToBytes(), ResponseStatus.Success); }
private void HandleSetLobbyProperties(IIncommingMessage message) { var data = message.Deserialize <LobbyPropertiesSetPacket>(); _lobbiesById.TryGetValue(data.LobbyId, out var lobby); if (lobby == null) { message.Respond("Lobby was not found", ResponseStatus.Failed); return; } var lobbiesExt = GetOrCreateLobbiesExtension(message.Peer); foreach (var dataProperty in data.Properties) { if (!lobby.SetProperty(lobbiesExt, dataProperty.Key, dataProperty.Value)) { message.Respond("Failed to set the property: " + dataProperty.Key, ResponseStatus.Failed); return; } } message.Respond(ResponseStatus.Success); }
protected virtual void HandleGetLobbyMemberData(IIncommingMessage message) { var data = message.Deserialize(new IntPairPacket()); var lobbyId = data.A; var peerId = data.B; ILobby lobby; Lobbies.TryGetValue(lobbyId, out lobby); if (lobby == null) { message.Respond("Lobby not found", ResponseStatus.Failed); return; } var member = lobby.GetMemberByPeerId(peerId); if (member == null) { message.Respond("Player is not in the lobby", ResponseStatus.Failed); return; } message.Respond(member.GenerateDataPacket(), ResponseStatus.Success); }
private void HandlePlayerLeftRoom(IIncommingMessage message) { var data = message.Deserialize(new PlayerLeftRoomPacket()); RegisteredRoom room; Rooms.TryGetValue(data.RoomId, out room); if (room == null) { message.Respond("Room does not exist", ResponseStatus.Failed); return; } if (message.Peer != room.Peer) { // Wrong peer unregistering the room message.Respond("You're not the creator of the room", ResponseStatus.Unauthorized); return; } room.OnPlayerLeft(data.PeerId); message.Respond(ResponseStatus.Success); }
protected virtual void HandleGetRoomAccess(IIncommingMessage message) { var data = message.Deserialize(new RoomAccessRequestPacket()); RegisteredRoom room; Rooms.TryGetValue(data.RoomId, out room); if (room == null) { message.Respond("Room does not exist", ResponseStatus.Failed); return; } if (!string.IsNullOrEmpty(room.Options.Password) && room.Options.Password != data.Password) { message.Respond("Invalid password", ResponseStatus.Unauthorized); return; } // Send room access request to peer who owns it room.GetAccess(message.Peer, data.Properties, (packet, error) => { if (packet == null) { message.Respond(error, ResponseStatus.Unauthorized); return; } message.Respond(packet, ResponseStatus.Success); }); }
protected virtual void HandleSaveRoomOptions(IIncommingMessage message) { var data = message.Deserialize(new SaveRoomOptionsPacket()); RegisteredRoom room; Rooms.TryGetValue(data.RoomId, out room); if (room == null) { message.Respond("Room does not exist", ResponseStatus.Failed); return; } if (message.Peer != room.Peer) { // Wrong peer unregistering the room message.Respond("You're not the creator of the room", ResponseStatus.Unauthorized); return; } ChangeRoomOptions(room, data.Options); message.Respond(ResponseStatus.Success); }
protected virtual void GetRoomAccessRequestHandler(IIncommingMessage message) { var data = message.Deserialize(new RoomAccessRequestPacket()); // Let's find a room by Id which the player wants to join if (!roomsList.TryGetValue(data.RoomId, out RegisteredRoom room)) { message.Respond("Room does not exist", ResponseStatus.Failed); return; } // If room requires the password and given password is not valid if (!string.IsNullOrEmpty(room.Options.Password) && room.Options.Password != data.Password) { message.Respond("Invalid password", ResponseStatus.Unauthorized); return; } // Send room access request to peer who owns it room.GetAccess(message.Peer, data.CustomOptions, (packet, error) => { if (packet == null) { message.Respond(error, ResponseStatus.Unauthorized); return; } message.Respond(packet, ResponseStatus.Success); }); }
private void HandleProvideRoomAccessCheck(IIncommingMessage message) { var data = message.Deserialize(new RoomAccessProvideCheckPacket()); var roomController = Msf.Server.Rooms.GetRoomController(data.RoomId); if (roomController == null) { message.Respond("There's no room controller with room id " + data.RoomId, ResponseStatus.NotHandled); return; } var accessProvider = roomController._accessProvider ?? DefaultAccessProvider; var isProviderDone = false; var requester = new UsernameAndPeerIdPacket() { PeerId = data.PeerId, Username = data.Username }; // Invoke the access provider accessProvider.Invoke(requester, (access, error) => { // In case provider timed out if (isProviderDone) { return; } isProviderDone = true; if (access == null) { // If access is not provided message.Respond(error ?? "", ResponseStatus.Failed); return; } message.Respond(access, ResponseStatus.Success); if (Logger.IsLogging(LogLevel.Trace)) { Logger.Trace("Room controller gave address to peer " + data.PeerId + ":" + access); } }); // Timeout the access provider MsfTimer.WaitForSeconds(Msf.Server.Rooms.AccessProviderTimeout, () => { if (!isProviderDone) { isProviderDone = true; message.Respond("Timed out", ResponseStatus.Timeout); Logger.Error("Access provider took longer than " + Msf.Server.Rooms.AccessProviderTimeout + " seconds to provide access. " + "If it's intended, increase the threshold at Msf.Server.Rooms.AccessProviderTimeout"); } }); }
private void HandleLobbyMemberJoinedMsg(IIncommingMessage message) { var data = message.Deserialize(new LobbyMemberData()); Members[data.Username] = data; Listener?.OnMemberJoined(data); }
private void HandleLobbyPropertyChanged(IIncommingMessage message) { var data = message.Deserialize(new StringPairPacket()); Properties[data.A] = data.B; Listener?.OnLobbyPropertyChanged(data.A, data.B); }
private static void handleTournamentStarted(IIncommingMessage rawMsg) { storedUpdates.Clear(); ClientUIStateManager.requestGotoState(ClientUIStates.PlayingTournament, () => { storedInitMsg = rawMsg.Deserialize <TournamentInfoMsg>(); initCurrentTree(storedInitMsg); }); }
private void HandleSpawnedProcessesCount(IIncommingMessage message) { var packet = message.Deserialize(new IntPairPacket()); Spawners.TryGetValue(packet.A, out var spawner); spawner?.UpdateProcessesCount(packet.B); }
private void OnChatMessageHandler(IIncommingMessage message) { var packet = message.Deserialize(new ChatMessagePacket()); if (OnMessageReceivedEvent != null) { OnMessageReceivedEvent.Invoke(packet); } }
private void handleRequestSpecificGameLogs(IIncommingMessage rawMsg) { SpectatorSpecificLogRequestMsg msg = rawMsg.Deserialize <SpectatorSpecificLogRequestMsg>(); try { rawMsg.Respond(new SpectatorGameLog() { gameLog = historyController.getSpecificStates(msg.IDs) }, ResponseStatus.Success); } catch { rawMsg.Respond(ResponseStatus.Error); } }
private void HandleChatMessage(IIncommingMessage message) { var packet = message.Deserialize(new ChatMessagePacket()); if (MessageReceived != null) { MessageReceived.Invoke(packet); } }
private void HandleLobbyChatMessageMsg(IIncommingMessage message) { var msg = message.Deserialize(new LobbyChatPacket()); if (_listener != null) { _listener.OnChatMessageReceived(msg); } }
private void SetSpawnedProcessesCountRequestHandler(IIncommingMessage message) { var packet = message.Deserialize(new IntPairPacket()); if (spawnersList.TryGetValue(packet.A, out RegisteredSpawner spawner)) { spawner.UpdateProcessesCount(packet.B); } }
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 handleForeceRoundWinner(IIncommingMessage rawMsg) { TournamentForceWinnerMessage info = rawMsg.Deserialize <TournamentForceWinnerMessage>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.forceIndexWinner(info.roundID, info.winIndex); } }
/// <summary> /// Fires when new status received /// </summary> /// <param name="message"></param> private static void StatusUpdateHandler(IIncommingMessage message) { var data = message.Deserialize(new SpawnStatusUpdatePacket()); if (Msf.Client.Spawners.TryGetRequestController(data.SpawnId, out SpawnRequestController controller)) { controller.Status = data.Status; controller.OnStatusChangedEvent?.Invoke(data.Status); } }
private void onIncominChatgMsg(IIncommingMessage msg) { AlbotChatMsg chatMsg = msg.Deserialize <AlbotChatMsg> (); Text newMsg = (Text)Instantiate(MessagePrefab, MessagesList.transform); string timeStamp = generateTimeStamp(); newMsg.text = timeStamp + " " + chatMsg.username + ": " + chatMsg.textMsg; newMsg.gameObject.SetActive(true); }
private void handlePlayerReadyUpdate(IIncommingMessage rawMsg) { PreGameReadyUpdate msg = rawMsg.Deserialize <PreGameReadyUpdate>(); PreGame targetGame; if (findGame(msg.roomID, out targetGame, rawMsg) && targetGame.containsPeer(rawMsg.Peer)) { targetGame.updatePeerReady(rawMsg.Peer, msg.isReady); } }
private void handleSlotTypeChanged(IIncommingMessage rawMsg) { PreGameSlotSTypeMsg msg = rawMsg.Deserialize <PreGameSlotSTypeMsg>(); PreGame targetGame; if (findGame(msg.roomID, out targetGame, rawMsg)) { targetGame.updateSlotType(msg.slot, rawMsg.Peer); } }
public void handleReconnectPlayer(IIncommingMessage rawMsg) { TournamentReconnectPlayer info = rawMsg.Deserialize <TournamentReconnectPlayer>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.reconnectPlayer(info.username); } }
private void handleGameOverMsg(IIncommingMessage rawMsg) { GameOverMsg result = rawMsg.Deserialize <GameOverMsg>(); PreGame game; if (findGame(result.roomID, out game)) { game.getGameOverMsg(result); } }
private void handleRoundStarted(IIncommingMessage rawMsg) { TournamentPreGameInfo info = rawMsg.Deserialize <TournamentPreGameInfo>(); RunningTournamentGame game; if (findGame(info.tournamentID, out game, rawMsg) && SpectatorAuthModule.existsAdmin(rawMsg.Peer)) { game.startRound(info.roundID); } }
private void HandleKillSpawnedProcessRequest(IIncommingMessage message) { var data = message.Deserialize <KillSpawnedProcessPacket>(); if (data == null) { message.Respond(ResponseStatus.Error); return; } message.Respond(_spawnerRequestsDelegate.HandleKillRequest(data.SpawnId) ? ResponseStatus.Success : ResponseStatus.Failed); }
private void HandleSpawnRequest(IIncommingMessage message) { var packet = message.Deserialize <SpawnRequestPacket>(); if (packet == null) { message.Respond(ResponseStatus.Error); return; } // Pass the request to handler _spawnerRequestsDelegate.HandleSpawnRequest(message, packet); }
private void HandleRegisterRoom(IIncommingMessage message) { if (!HasRoomRegistrationPermissions(message.Peer)) { message.Respond("Insufficient permissions", ResponseStatus.Unauthorized); return; } var options = message.Deserialize(new RoomOptions()); var room = RegisterRoom(message.Peer, options); // Respond with a room id message.Respond(room.RoomId, ResponseStatus.Success); }