Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
        public void DoGet(string endpoint, TebexCommandModule command)
        {
            this.Headers.Add("X-Buycraft-Secret", Tebex.Instance.Config.Secret);
            String url = Tebex.Instance.Config.BaseUrl + endpoint;

            Tebex.logWarning("GET " + url);
            this.DownloadStringCompleted += (sender, e) =>
            {
                if (!e.Cancelled && e.Error == null)
                {
                    command.HandleResponse(JObject.Parse(e.Result));
                }
                else
                {
                    Tebex.logWarning(e.Error.ToString());
                    command.HandleError(e.Error);
                }
                this.Dispose();
            };
            this.DownloadStringAsync(new Uri(url));
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        public static void deleteCommands(List <int> commandIds)
        {
            String url = Tebex.Instance.Config.BaseUrl + "queue?";
            String amp = "";

            foreach (int CommandId in commandIds)
            {
                url = url + amp + "ids[]=" + CommandId;
                amp = "&";
            }

            Tebex.logWarning("DELETE " + url);

            var request = WebRequest.Create(url);

            request.Method = "DELETE";
            request.Headers.Add("X-Buycraft-Secret", Tebex.Instance.Config.Secret);

            Thread thread = new Thread(() => request.GetResponse());

            thread.Start();
        }
Exemplo n.º 5
0
 public void setPlugin(Tebex plugin)
 {
     this.plugin = plugin;
 }
Exemplo n.º 6
0
        public static void doOnlineCommands(int playerPluginId, string playerName, string playerId)
        {
            Tebex.logWarning("Running online commands for " + playerName + " (" + playerId + ")");

            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/online-commands/" +
                         playerPluginId.ToString();

            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"], playerName, playerId);

                    Tebex.logWarning("Run command " + commandToRun);
                    if ((int)command["conditions"]["delay"] > 0)
                    {
                        // 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() + " online commands executed for " + playerName);
                if (exCount % deleteAfter != 0)
                {
                    try
                    {
                        deleteCommands(executedCommands);
                        executedCommands.Clear();
                    }
                    catch (Exception ex)
                    {
                        Tebex.logError(ex.ToString());
                    }
                }

                wc.Dispose();
            };

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