Example #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;
            }
        }
Example #2
0
        public AceGameInfo CreateAceGameInfo(string gameName, string apianGroupType, int maxPlayers, int minValidators, int validatorWaitMs)
        {
            // TODO: does this belong here? Seems a little odd that it is here and CurrentGroupStatus() is in AceApian.
            // On the other hand, they really are kinda different and are created at different times.
            string netName = p2p.GetMainChannel()?.Name;

            if (netName == null)
            {
                logger.Error($"CreateAceGameInfo() - Must join network first"); // TODO: probably ought to assert? Can this be recoverable?
                return(null);
            }

            P2pNetChannelInfo groupChanInfo = new P2pNetChannelInfo(aceChannelData[kAceGameChannelInfo]);

            groupChanInfo.name = gameName;
            groupChanInfo.id   = $"{netName}/{gameName}";

            AceGameInfo gameInfo = new AceGameInfo(new ApianGroupInfo(apianGroupType, groupChanInfo, LocalP2pId(), gameName));

            gameInfo.MaxPlayers      = maxPlayers;
            gameInfo.MinValidators   = minValidators;
            gameInfo.ValidatorWaitMs = validatorWaitMs;

            return(gameInfo);
        }
Example #3
0
        protected AceAppCore CreateCorePair(AceGameInfo gameInfo)
        {
            // Create gameinstance and ApianInstance
            AceAppCore appCore = new AceAppCore();
            AceApian   apian   = AceApianFactory.Create(gameInfo.GroupType, appl.aceGameNet, appCore);

            return(appCore);
        }
Example #4
0
        public void JoinExistingGame(AceGameInfo gameInfo, AceApian apian, string localDataJson)
        {
            string netName = p2p.GetMainChannel()?.Name;

            if (netName == null)
            {
                logger.Error($"JoinExistingGame() - Must join network first"); // TODO: probably ought to assert? Can this be recoverable?
                return;
            }

            base.JoinExistingGroup(gameInfo, apian, localDataJson);
        }
Example #5
0
        private AceAppCore _SetupCorePair(AceGameInfo gameInfo)
        {
            if (gameInfo == null)
            {
                ExitAbruptly($"_SetupCorePair(): null gameInfo");
            }

            AceAppCore appCore = CreateCorePair(gameInfo);

            appl.AddAppCore(appCore);
            appCore.PlayerJoinedEvt += _OnPlayerJoinedEvt;
            appCore.Start(AceCoreModeFactory.kStart);
            return(appCore);
        }
        public override (bool, string) CheckQuorum()
        {
            AceGameInfo agi = GroupInfo as AceGameInfo;

            if (GroupMgr.GetMember(agi.GroupCreatorId) == null)
            {
                return(false, $"Creator Peer {agi.GroupCreatorId} not present");
            }

            if (GroupMgr.ActiveMemberCount < (agi.MaxPlayers + agi.MinValidators))
            {
                return(false, $"Not enough peers: {GroupMgr.ActiveMemberCount}. Need {(agi.MaxPlayers + agi.MinValidators)}");
            }

            return(true, "");
        }
Example #7
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;
            }
        }
Example #8
0
 public async Task <PeerJoinedGroupData> CreateAndJoinGameAsync(AceGameInfo gameInfo, AceApian apian, string localDataJson)
 {
     return(await base.CreateAndJoinGroupAsync(gameInfo, apian, localDataJson));
 }
Example #9
0
 public void CreateAndJoinGame(AceGameInfo gameInfo, AceApian apian, string localDataJson)
 {
     base.CreateAndJoinGroup(gameInfo, apian, localDataJson);
 }
Example #10
0
 public async Task <PeerJoinedGroupData> JoinExistingGameAsync(AceGameInfo gameInfo, AceApian apian, string localDataJson)
 {
     return(await base.JoinExistingGroupAsync(gameInfo, apian, localDataJson));
 }