public async override void Start(object param = null) { base.Start(); announcedGames = new Dictionary <string, AceGameInfo>(); settings = appl.frontend.GetUserSettings(); appl.AddAppCore(null); try { appl.ConnectToNetwork(kNetConnectionString); await appl.JoinGameNetworkAsync(kNetworkName); logger.Info("Local splash network joined"); AceGameInfo gameInfo = appl.aceGameNet.CreateAceGameInfo( kApianGroupName, SinglePeerGroupManager.kGroupType, 2, // maxPlayers 0, // min validators kValidatorWaitMs ); SplashAppCore = CreateCorePair(gameInfo); appl.AddAppCore(SplashAppCore); SplashAppCore.PlayerJoinedEvt += _OnPlayerJoinedEvt; SplashAppCore.Start(AceCoreModeFactory.kStart); LocalPeerJoinedGameData joinData = await appl.CreateAndJoinGameAsync(gameInfo, SplashAppCore); } catch (Exception ex) { ExitAbruptly($"{ex.Message}"); return; } }
protected const float kListenForGamesSecs = 2.0f; // TODO: belongs here? public async override void Start(object param = null) { base.Start(); announcedGames = new Dictionary <string, AceGameInfo>(); settings = appl.frontend.GetUserSettings(); appl.AddAppCore(null); try { appl.ConnectToNetwork(settings.p2pConnectionString); // should be async? GameNet.Connect() currently is not GameNet.PeerJoinedNetworkData netJoinData = await appl.JoinGameNetworkAsync(settings.apianNetworkName); Dictionary <string, AceGameAnnounceData> gamesAvail = await appl.GetExistingGamesAsync((int)(kListenForGamesSecs * 1000)); GameSelectedEventArgs selection = await appl.SelectGameAsync(gamesAvail); if (selection.result == GameSelectedEventArgs.ReturnCode.kCancel) { ExitAbruptly($"No Game Selected."); } AceGameInfo gameInfo = selection.gameInfo; AceAppCore appCore = _SetupCorePair(gameInfo); bool targetGameExisted = (gameInfo.GameName != null) && gamesAvail.ContainsKey(gameInfo.GameName); LocalPeerJoinedGameData gameJoinedResult = null; bool isValidator = settings.tempSettings.TryGetValue("validator", out var value) ? Convert.ToBoolean(value) : false; switch (selection.result) { case GameSelectedEventArgs.ReturnCode.kCreate: // Create and join if (targetGameExisted) { ExitAbruptly($"Cannot create. Beam Game \"{gameInfo.GameName}\" already exists"); } else { gameJoinedResult = await appl.CreateAndJoinGameAsync(gameInfo, appCore); } break; case GameSelectedEventArgs.ReturnCode.kJoin: // Join existing if (!targetGameExisted) { ExitAbruptly($"Cannot Join. Beam Game \"{gameInfo.GameName}\" not found"); return; } else { gameJoinedResult = await appl.JoinExistingGameAsync(gameInfo, appCore); } break; case GameSelectedEventArgs.ReturnCode.kMaxPlayers: gameJoinedResult = new LocalPeerJoinedGameData(gameInfo.GroupId, false, $"Cannot Join as player. Beam Game \"{gameInfo.GameName}\" already has {gameInfo.MaxPlayers} players."); break; case GameSelectedEventArgs.ReturnCode.kCancel: gameJoinedResult = new LocalPeerJoinedGameData(gameInfo.GroupId, false, "Join Cancelled"); break; } if (!gameJoinedResult.success) { ExitAbruptly(gameJoinedResult.failureReason); return; } if (isValidator) { logger.Info($"Validator setting is set. Will not create a player."); } else { logger.Info($"Requesting new player."); PlayerJoinedEventArgs joinData = await appl.CreateNewPlayerAsync(appCore, gameJoinedResult.groupId, appl.MakeAiPlayer()); if (joinData == null) { ExitAbruptly("Failed to Create New Player"); return; } } } catch (Exception ex) { ExitAbruptly($"{ex.Message}"); return; } }