protected virtual void CreateLobbyHandle(IIncomingMessage message) { // We may need to check permission of requester if (!CheckIfHasPermissionToCreate(message.Peer)) { message.Respond("Insufficient permissions", ResponseStatus.Unauthorized); return; } // Let's get or create new lobby user peer extension var lobbyUser = GetOrCreateLobbyUserPeerExtension(message.Peer); // If peer is already in a lobby and system does not allow to create if user is joined if (dontAllowCreatingIfJoined && lobbyUser.CurrentLobby != null) { message.Respond("You are already in a lobby", ResponseStatus.Failed); return; } // Deserialize properties of the lobby var options = MstProperties.FromBytes(message.AsBytes()); // Get lobby factory Id or empty string string lobbyFactoryId = options.AsString(MstDictKeys.LOBBY_FACTORY_ID); if (string.IsNullOrEmpty(lobbyFactoryId)) { message.Respond("Invalid request (undefined factory)", ResponseStatus.Failed); return; } // Get the lobby factory factories.TryGetValue(lobbyFactoryId, out ILobbyFactory factory); if (factory == null) { message.Respond("Unavailable lobby factory", ResponseStatus.Failed); return; } var newLobby = factory.CreateLobby(options, message.Peer); if (!AddLobby(newLobby)) { message.Respond("Lobby registration failed", ResponseStatus.Error); return; } logger.Info("Lobby created: " + newLobby.Id); // Respond with success and lobby id message.Respond(newLobby.Id, ResponseStatus.Success); }
protected virtual void CreateLobbyRequestHandle(IIncommingMessage message) { if (!CheckIfHasPermissionToCreate(message.Peer)) { message.Respond("Insufficient permissions", ResponseStatus.Unauthorized); return; } var lobbyUser = GetOrCreateLobbyUserPeerExtension(message.Peer); if (dontAllowCreatingIfJoined && lobbyUser.CurrentLobby != null) { // If peer is already in a lobby message.Respond("You are already in a lobby", ResponseStatus.Failed); return; } // Deserialize properties of the lobby var options = MstProperties.FromBytes(message.AsBytes()); if (!options.Has(MstDictKeys.lobbyFactoryId)) { message.Respond("Invalid request (undefined factory)", ResponseStatus.Failed); return; } // Get the lobby factory factories.TryGetValue(options.AsString(MstDictKeys.lobbyFactoryId), out ILobbyFactory factory); if (factory == null) { message.Respond("Unavailable lobby factory", ResponseStatus.Failed); return; } var newLobby = factory.CreateLobby(options, message.Peer); if (!AddLobby(newLobby)) { message.Respond("Lobby registration failed", ResponseStatus.Error); return; } logger.Info("Lobby created: " + newLobby.Id); // Respond with success and lobby id message.Respond(newLobby.Id, ResponseStatus.Success); }
protected virtual void FindGamesRequestHandler(IIncomingMessage message) { var list = new List <GameInfoPacket>(); var filters = MstProperties.FromBytes(message.AsBytes()); foreach (var provider in GameProviders) { list.AddRange(provider.GetPublicGames(message.Peer, filters)); } // Convert to generic list and serialize to bytes var bytes = list.Select(l => (ISerializablePacket)l).ToBytes(); message.Respond(bytes, ResponseStatus.Success); }