Beispiel #1
0
        private void SessionChanged(ITorchSession session, TorchSessionState state)
        {
            switch (state)
            {
            case TorchSessionState.Loaded:
                Tebex.logInfo($"Game started....");

                if (Instance.Config.Secret == "")
                {
                    logError("You have not yet defined your secret key. Use !tebex:secret <secret> to define your key");
                }
                else
                {
                    TebexInfoModule infoCommand = new TebexInfoModule();
                    infoCommand.TebexInfo();
                }

                // Create a timer with a two second interval.
                aTimer = new System.Timers.Timer(60000);
                // Hook up the Elapsed event for the timer.
                aTimer.Elapsed  += checkQueue;
                aTimer.AutoReset = true;
                aTimer.Enabled   = true;


                break;

            case TorchSessionState.Unloading:
                Tebex.logInfo($"Game ending....");
                aTimer.Enabled = false;
                aTimer.Dispose();
                break;
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public override void Init(ITorchBase torch)
        {
            base.Init(torch);
            string path = Path.Combine(StoragePath, "TebexTorchAPI.cfg");

            Tebex.logInfo($"Attempting to load config from {path}");
            _config = Persistent <TebexConfig> .Load(path);

            _sessionManager = Torch.Managers.GetManager <TorchSessionManager>();
            if (_sessionManager != null)
            {
                _sessionManager.SessionStateChanged += SessionChanged;
            }

            System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, errors) => { return(true); };

            Torch.GameStateChanged += GameStateChanged;

            this.information = new WebstoreInfo();
            Instance         = this;
        }
Beispiel #3
0
        public static void doOfflineCommands()
        {
            TebexApiClient wc = new TebexApiClient();

            wc.setPlugin(Tebex.Instance);
            wc.Headers.Add("X-Buycraft-Secret", Tebex.Instance.Config.Secret);
            String url = Tebex.Instance.Config.BaseUrl + "queue/offline-commands";

            Tebex.logWarning("GET " + url);

            wc.DownloadStringCompleted += (sender, e) =>
            {
                JObject json     = JObject.Parse(e.Result);
                JArray  commands = (JArray)json["commands"];

                int        exCount          = 0;
                List <int> executedCommands = new List <int>();

                foreach (var command in commands.Children())
                {
                    String commandToRun = buildCommand((string)command["command"], (string)command["player"]["name"],
                                                       (string)command["player"]["uuid"]);

                    Tebex.logWarning("Run command " + commandToRun);
                    if ((int)command["conditions"]["delay"] > 0)
                    {
                        Tebex.logInfo("Delay...");
                        // Create a timer with a two second interval.
                        var aTimer = new System.Timers.Timer((int)command["conditions"]["delay"] * 1000);
                        aTimer.Elapsed += (Object source, System.Timers.ElapsedEventArgs ev) =>
                        {
                            RunCommand(commandToRun);
                            ((Timer)source).Dispose();
                        };
                        aTimer.AutoReset = false;
                        aTimer.Enabled   = true;
                    }
                    else
                    {
                        RunCommand(commandToRun);
                    }
                    executedCommands.Add((int)command["id"]);

                    exCount++;

                    if (exCount % deleteAfter == 0)
                    {
                        try
                        {
                            deleteCommands(executedCommands);
                            executedCommands.Clear();
                        }
                        catch (Exception ex)
                        {
                            Tebex.logError(ex.ToString());
                        }
                    }
                }

                Tebex.logWarning(exCount.ToString() + " offline commands executed");
                if (exCount % deleteAfter != 0)
                {
                    try
                    {
                        deleteCommands(executedCommands);
                        executedCommands.Clear();
                    }
                    catch (Exception ex)
                    {
                        Tebex.logError(ex.ToString());
                    }
                }

                wc.Dispose();
            };

            wc.DownloadStringAsync(new Uri(url));
        }