public static bool ExecuteCommand(string alias, NetworkAccount senderAccount, CommandsClient sender, List <string> parms)
 {
     foreach (NetworkCommand command in NetworkCommandsList.commands)
     {
         if (command.Names.Contains(alias))
         {
             try
             {
                 if (senderAccount.PermissionLvl < command.permission)
                 {
                     sender.SendMessage($"You are not allowed to use that command. For command \'{command.Names[0]}\' you need lvl {command.permission}");
                     return(false);
                 }
                 command.CommandDelegate(new NetworkCommandArgs(alias, senderAccount, sender, parms));
             }
             catch (Exception ex)
             {
                 sender.SendMessage($"Something went wrong while executing your command. Error: {ex.Message}");
                 return(false);
             }
             return(true);
         }
     }
     return(false);
 }
 public NetworkCommandArgs(string CommandName, NetworkAccount senderAccount, CommandsClient sender, List <string> args)
 {
     this.CommandString = CommandName;
     this.senderAccount = senderAccount;
     this.sender        = sender;
     this.Parameters    = args;
 }
Exemplo n.º 3
0
        private async Task MonitorAccountAsync(NetworkAccount networkAccount)
        {
            if (!this._watchedContracts.ContainsKey(networkAccount))
            {
                SubscriptionToken subscriptionToken = await this._ethereumAccountWatcher.SubscribeAsync(this._ethereumAccountWatcher.Create(networkAccount)
                                                                                                        .InterestedInEthBalanceChange(NotifyEthBalanceChange)
                                                                                                        .InterestedInTokenBalanceChange(
                                                                                                            contract: this._tokenContract,
                                                                                                            balanceChangedCallback: NotifyTokenBalanceChange));

                this._watchedContracts.TryAdd(key: networkAccount, value: subscriptionToken);

                Task NotifyTokenBalanceChange(TokenBalanceChangeEventArgs args)
                {
                    return(this.NotifyForAllTokenBalanceChangesAsync(contractAccount: networkAccount, minimumTokenAmount: this._faucetBalanceConfiguration.MinimumAllowedTokenBalance, args: args));
                }

                Task NotifyEthBalanceChange(EthereumBalanceChangeEventArgs args)
                {
                    return(this.NotifyForAllEthBalanceChangesAsync(contractAccount: networkAccount,
                                                                   new EthereumAmount(this._faucetBalanceConfiguration.MinimumAllowedNativeCurrencyBalance.Value),
                                                                   args: args));
                }
            }
        }
Exemplo n.º 4
0
        protected override void OnAttached(InboundAuthenticationBroker broker, NetworkAccount account)
        {
            lock (_auxiliaryLock)
            {
                _auxiliaryRequests = null;
            }

            _account = account as StudioAccount;
        }
        private void StartConnectionWithClient()
        {
            this.ClientIP   = EndPoint.Address.ToString();
            this.ClientPort = EndPoint.Port;
            int AttemptionsCount = MainManager.AttemptionsCount(ClientIP);

            if (AttemptionsCount != -1)
            {
                if ((DateTime.Now - (MainManager.GetAttemptions(ClientIP).LastAttemption)).TotalHours < 24)
                {
                    if ((MainManager.GetAttemptions(ClientIP).Attemptions >= MainManager.MaxAttemptionsPerDay))
                    {
                        ClientSocket.Close();
                        return;
                    }
                }
                else
                {
                    MainManager.DischargeAttemptions(ClientIP);
                }
            }
            AuntificationState state;
            NetworkAccount     acc = Login(out state);

            this.Account = acc;
            switch (state)
            {
            case AuntificationState.WrongPassword:
                MainManager.AddAttemption(ClientIP);
                SendMessage("Wrong Password! Enter correct password");
                return;

            case AuntificationState.Error:
                SendMessage("Something went wrong, try again");
                return;

            case AuntificationState.Successfully:
                this.ClientID = MainManager.CommandsClients.Count + 1;
                ConnectedAt   = DateTime.Now;
                SendMessage("The password is correct, you have successfully entered to the RCON");
                Logger.NetworkCommandsLog($"User with IP: {ClientIP}:{ClientPort}, Login: {this.Account.Login}, Connected to the RCON. ClientID {this.ClientID}");
                MainManager.DischargeAttemptions(ClientIP);
                break;
            }
            MainManager.CommandsClients.Add(this);
            new Thread(CommandsChecker).Start();
        }
Exemplo n.º 6
0
        private async Task <IActionResult> RequestFromFaucetAsync(OpenFaucetDto request, CancellationToken cancellationToken)
        {
            try
            {
                JwtUser?jwtUser = this.JwtUser;

                if (jwtUser == null)
                {
                    return(ResultHelpers.ExceptionResult(message: "Not authorised (1).", nameof(FaucetController), statusCode: HttpStatusCode.Unauthorized));
                }

                IPAddress ipAddress = this._remoteIpAddressRetriever.Get(this.HttpContext);

                EthereumNetwork network = request.Network;

                if (!this._faucetContractInfo.IsSupported(network))
                {
                    return(ResultHelpers.ExceptionResult(message: "Faucet is not supported on network.", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
                }

                INetworkBlockHeader?networkBlockHeader = this._ethereumBlockStatus.GetLatestBlockRetrievedOnNetwork(network);

                if (networkBlockHeader == null)
                {
                    return(ResultHelpers.ExceptionResult($"Network {network.Name} is not ready [BNF].", nameof(FaucetController), statusCode: HttpStatusCode.ServiceUnavailable));
                }

                if (this._networkManager.Supported.All(x => x.Name != network.Name))
                {
                    return(ResultHelpers.ExceptionResult(message: "Faucet is not supported on network.", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
                }

                AccountAddress address = new(request.Address.ToSpan());

                if (jwtUser.AccountAddress != address)
                {
                    return(ResultHelpers.ExceptionResult(message: "Not authorised (2).", nameof(FaucetController), statusCode: HttpStatusCode.Unauthorized));
                }

                INetworkAccount account = new NetworkAccount(network: network, address: address);

                if (this._ethereumAccountManager.IsAccountConfiguredForUse(account))
                {
                    return(ResultHelpers.ExceptionResult(message: "Server cannot give itself token or eth.", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
                }

                FaucetDrip drip = await this._faucetManager.OpenAsync(ipAddress : ipAddress, recipient : account, networkBlockHeader : networkBlockHeader, cancellationToken : cancellationToken);

                return(ResultHelpers.JsonResult(drip.ToDto(), statusCode: HttpStatusCode.OK));
            }
            catch (TooMuchTokenException)
            {
                return(ResultHelpers.ExceptionResult(message: "Too much token!", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
            }
            catch (TooFrequentTokenException)
            {
                return(ResultHelpers.ExceptionResult(message: "Too much token!", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
            }
            catch (InsufficientTokenException)
            {
                return(ResultHelpers.ExceptionResult(message: "Insufficient token!", nameof(FaucetController), statusCode: HttpStatusCode.Forbidden));
            }
        }
Exemplo n.º 7
0
 protected override void OnAttached(InboundAuthenticationBroker broker, NetworkAccount account)
 {
 }
        private void UpdateBalanceStatus(NetworkAccount networkAccount, EthereumAmount ethereumAmount)
        {
            bool enoughBalance = ethereumAmount >= this._houseBalanceConfiguration.MinimumAllowedNativeCurrencyBalance;

            this._houseAccounts.AddOrUpdate(key: networkAccount, addValue: enoughBalance, updateValueFactory: (_, _) => enoughBalance);
        }
Exemplo n.º 9
0
 protected override void OnAttached(InboundAuthenticationBroker broker, NetworkAccount account)
 {
 }