Ejemplo n.º 1
0
        public void WaitForProcess()
        {
            while (_gamePid < 0)
            {
                Thread.Sleep(500);
                if (Stopping)
                {
                    throw new OperationCanceledException("Parent exited while hunting");
                }
            }

            var gp = Process.GetProcessById(_gamePid);

            if (!Helper.IsChineseVersion(gp))
            {
                Log.Error("Game process not Chinese version");
                IpcClient.SendSignal(Signal.ClientProcessDown, new[] { _gamePid.ToString() });
                IpcClient.SendSignal(Signal.MilvanethComponentExit, new[] { "GameStatusManager", ".ctor" });
                throw new InvalidOperationException("Target process is not a FFXIV DX11 process");
            }

            if (!SystemInformation.IsAdmin())
            {
                Log.Error("Insufficient Privilege");
                IpcClient.SendSignal(Signal.ClientInsuffcientPrivilege, new[] { _gamePid.ToString() });
                IpcClient.SendSignal(Signal.MilvanethComponentExit, new[] { "GameStatusManager", ".ctor" });
                throw new InvalidOperationException("Insufficient Privilege");
            }

            GameProcess     = gp;
            GameConnection  = new List <Connection>();
            LobbyConnection = new List <Connection>();
            _connEqCp       = new ConnectionEqualityComparer();
            _connSetEqCp    = new MultiSetComparer <Connection>(_connEqCp);
            _lobbyEndPoint  = ConnectionPicker.GetLobbyEndPoint(GameProcess);
        }
Ejemplo n.º 2
0
        public void AuthorizerCountChanged(int count)
        {
            if (ConsensusService.IsThisNodeSeed0 && count >= ProtocolSettings.Default.StandbyValidators.Length)
            {
                //_log.LogInformation($"AuthorizerCountChanged: {count}");
                // look for changes. if necessary create a new svc block.
                Task.Run(async() =>
                {
                    if (!_creatingSvcBlock)
                    {
                        _creatingSvcBlock = true;

                        try
                        {
                            var prevSvcBlock = await GetLastServiceBlockAsync();

                            if (prevSvcBlock != null && DateTime.UtcNow - prevSvcBlock.TimeStamp > TimeSpan.FromMinutes(1))
                            {
                                var comp = new MultiSetComparer <string>();
                                if (!comp.Equals(prevSvcBlock.Authorizers.Select(a => a.AccountID), ConsensusService.Board.PrimaryAuthorizers))
                                {
                                    _log.LogInformation($"PrimaryAuthorizers Changed: {count} Creating new ServiceBlock.");

                                    var svcBlock = new ServiceBlock
                                    {
                                        NetworkId          = prevSvcBlock.NetworkId,
                                        Height             = prevSvcBlock.Height + 1,
                                        ServiceHash        = prevSvcBlock.Hash,
                                        TransferFee        = 1,    //zero for genesis. back to normal when genesis done
                                        TokenGenerationFee = 100,
                                        TradeFee           = 0.1m
                                    };

                                    svcBlock.Authorizers = new List <PosNode>();
                                    foreach (var accId in ConsensusService.Board.PrimaryAuthorizers)
                                    {
                                        if (ConsensusService.Board.AllNodes.ContainsKey(accId))
                                        {
                                            svcBlock.Authorizers.Add(ConsensusService.Board.AllNodes[accId]);
                                        }

                                        if (svcBlock.Authorizers.Count() >= LyraGlobal.MAXMIMUMAUTHORIZERS)
                                        {
                                            break;
                                        }
                                    }

                                    if (svcBlock.Authorizers.Count() >= prevSvcBlock.Authorizers.Count())
                                    {
                                        svcBlock.InitializeBlock(prevSvcBlock, NodeService.Instance.PosWallet.PrivateKey,
                                                                 NodeService.Instance.PosWallet.AccountId);

                                        await SendBlockToConsensusAsync(svcBlock);
                                    }
                                    else
                                    {
                                        _log.LogError($"Authorizers count can't be less than {prevSvcBlock.Authorizers.Count()}");
                                    }
                                }
                            }
                        }
                        finally
                        {
                            await Task.Delay(10000);
                            _creatingSvcBlock = false;
                        }
                    }
                });
            }
        }