예제 #1
0
        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;
            }
        }
예제 #2
0
        public static void Save(AceUserSettings settings)
        {
            System.IO.Directory.CreateDirectory(path);
            string          filePath     = path + Path.DirectorySeparatorChar + fileBaseName + ".json";
            AceUserSettings saveSettings = new AceUserSettings(settings);

            saveSettings.tempSettings = new Dictionary <string, string>(); // Don't persist temp settings
            File.WriteAllText(filePath, JsonConvert.SerializeObject(saveSettings, Formatting.Indented));
        }
예제 #3
0
 public AceUserSettings(AceUserSettings source)
 {
     if (version != source.version)
     {
         throw(new Exception($"Invalid settings version: {source.version}"));
     }
     startMode           = source.startMode;
     screenName          = source.screenName;
     p2pConnectionString = source.p2pConnectionString;
     apianNetworkName    = source.apianNetworkName;
     ethNodeUrl          = source.ethNodeUrl;
     ethAcct             = source.ethAcct;
     defaultLogLevel     = source.defaultLogLevel;
     logLevels           = source.logLevels ?? new Dictionary <string, string>();
     tempSettings        = source.tempSettings ?? new Dictionary <string, string>();
     platformSettings    = source.platformSettings ?? new Dictionary <string, string>();
 }
예제 #4
0
        public static AceUserSettings Load(string baseName = defaultBaseName)
        {
            fileBaseName = baseName;
            AceUserSettings settings;
            string          filePath = path + Path.DirectorySeparatorChar + fileBaseName + ".json";

            try {
                settings = JsonConvert.DeserializeObject <AceUserSettings>(File.ReadAllText(filePath));
            } catch (Exception) {
                settings = AceUserSettings.CreateDefault();
            }

            // TODO: in real life this should do at least 1 version's worth of updating.
            if (settings.version != currentVersion)
            {
                throw(new Exception($"Invalid settings version: {settings.version}"));
            }

            return(settings);
        }
예제 #5
0
        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;
            }
        }