Ejemplo n.º 1
0
        protected override void Load()
        {
            this.information = new WebstoreInfo();
            Instance         = this;


            logWarning("Tebex Loaded");
            if (Instance.Configuration.Instance.secret == "")
            {
                logError("You have not yet defined your secret key. Use /tebex:secret <secret> to define your key");
            }
            else
            {
                CommandTebexInfo infoCommand = new CommandTebexInfo();
                String[]         command     = new[] { "tebex:info" };
                infoCommand.Execute(new ConsolePlayer(), command);
            }

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

            ChatListener chatListener = new ChatListener();

            chatListener.Register(this);
        }
Ejemplo n.º 2
0
        public void HandleResponse(JObject response)
        {
            Tebex.Instance.information.id             = (int)response["account"]["id"];
            Tebex.Instance.information.domain         = (string)response["account"]["domain"];
            Tebex.Instance.information.gameType       = (string)response["account"]["game_type"];
            Tebex.Instance.information.name           = (string)response["account"]["name"];
            Tebex.Instance.information.currency       = (string)response["account"]["currency"]["iso_4217"];
            Tebex.Instance.information.currencySymbol = (string)response["account"]["currency"]["symbol"];
            Tebex.Instance.information.serverId       = (int)response["server"]["id"];
            Tebex.Instance.information.serverName     = (string)response["server"]["name"];

            Tebex.logWarning("Your secret key has been validated! Webstore Name: " + Tebex.Instance.information.name);
        }
Ejemplo n.º 3
0
 public void Execute(IRocketPlayer caller, string[] command)
 {
     try
     {
         TebexApiClient wc = new TebexApiClient();
         wc.setPlugin(Tebex.Instance);
         wc.DoGet("information", this);
         wc.Dispose();
     }
     catch (TimeoutException)
     {
         Tebex.logWarning("Timeout!");
     }
 }
Ejemplo n.º 4
0
 public void Execute(IRocketPlayer caller, string[] command)
 {
     Tebex.logWarning("Checking for commands to be executed...");
     try
     {
         TebexApiClient wc = new TebexApiClient();
         wc.setPlugin(Tebex.Instance);
         wc.DoGet("queue", this);
         wc.Dispose();
     }
     catch (TimeoutException)
     {
         Tebex.logWarning("Timeout!");
     }
 }
Ejemplo n.º 5
0
        public void Register(IRocketPlugin plugin)
        {
            UnturnedPlayerEvents.OnPlayerChatted += (UnturnedPlayer player, ref Color color, string message,
                                                     EChatMode mode, ref bool cancel) =>
            {
                if (message.Trim() == Tebex.Instance.Configuration.Instance.BuyCommand && Tebex.Instance.Configuration.Instance.BuyEnabled == true)
                {
                    Tebex.logWarning("Message received:" + message.Trim());

                    player.Player.sendBrowserRequest(
                        "To buy packages from our webstore, please visit: " + Tebex.Instance.information.domain,
                        Tebex.Instance.information.domain);
                }
            };
        }
Ejemplo n.º 6
0
        public void HandleResponse(JObject response)
        {
            Tebex.Instance.information.id             = (int)response["account"]["id"];
            Tebex.Instance.information.domain         = (string)response["account"]["domain"];
            Tebex.Instance.information.gameType       = (string)response["account"]["game_type"];
            Tebex.Instance.information.name           = (string)response["account"]["name"];
            Tebex.Instance.information.currency       = (string)response["account"]["currency"]["iso_4217"];
            Tebex.Instance.information.currencySymbol = (string)response["account"]["currency"]["symbol"];
            Tebex.Instance.information.serverId       = (int)response["server"]["id"];
            Tebex.Instance.information.serverName     = (string)response["server"]["name"];

            Tebex.logWarning("Server Information");
            Tebex.logWarning("=================");
            Tebex.logWarning("Server " + Tebex.Instance.information.serverName + " for webstore " + Tebex.Instance.information.name + "");
            Tebex.logWarning("Server prices are in " + Tebex.Instance.information.currency + "");
            Tebex.logWarning("Webstore domain: " + Tebex.Instance.information.domain + "");
        }
Ejemplo n.º 7
0
        public void DoGet(string endpoint, ITebexCommand command)
        {
            this.Headers.Add("X-Buycraft-Secret", this.plugin.Configuration.Instance.secret);
            String url = this.plugin.Configuration.Instance.baseUrl + endpoint;

            Tebex.logWarning("GET " + url);
            this.DownloadStringCompleted += (sender, e) =>
            {
                if (!e.Cancelled && e.Error == null)
                {
                    command.HandleResponse(JObject.Parse(e.Result));
                }
                else
                {
                    command.HandleError(e.Error);
                }
                this.Dispose();
            };
            this.DownloadStringAsync(new Uri(url));
        }
Ejemplo n.º 8
0
        public void HandleResponse(JObject response)
        {
            if ((int)response["meta"]["next_check"] > 0)
            {
                Tebex.Instance.nextCheck = (int)response["meta"]["next_check"];
            }

            if ((bool)response["meta"]["execute_offline"])
            {
                try
                {
                    TebexCommandRunner.doOfflineCommands();
                }
                catch (Exception e)
                {
                    Tebex.logError(e.ToString());
                }
            }

            JArray players = (JArray)response["players"];

            foreach (var player in players)
            {
                try
                {
                    CSteamID       steamId      = new CSteamID((ulong)player["uuid"]);
                    UnturnedPlayer targetPlayer = UnturnedPlayer.FromCSteamID(steamId);

                    if (targetPlayer.Player != null)
                    {
                        Tebex.logWarning("Execute commands for " + (string)targetPlayer.CharacterName + "(ID: " + targetPlayer.CSteamID.ToString() + ")");
                        TebexCommandRunner.doOnlineCommands((int)player["id"], (string)targetPlayer.CharacterName,
                                                            targetPlayer.CSteamID.ToString());
                    }
                }
                catch (Exception e)
                {
                    Tebex.logError(e.Message);
                }
            }
        }
Ejemplo n.º 9
0
        public static void deleteCommands(List <int> commandIds)
        {
            String url = Tebex.Instance.Configuration.Instance.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.Configuration.Instance.secret);

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

            thread.Start();
        }
Ejemplo n.º 10
0
 public void setPlugin(Tebex plugin)
 {
     this.plugin = plugin;
 }
Ejemplo n.º 11
0
 public void HandleError(Exception e)
 {
     Tebex.logError("We are unable to fetch your server queue. Please check your secret key.");
     Tebex.logError(e.ToString());
 }
Ejemplo n.º 12
0
 public void HandleError(Exception e)
 {
     Tebex.logError("We were unable to validate your secret key.");
 }
Ejemplo n.º 13
0
 public void HandleError(Exception e)
 {
     Tebex.logError("We are unable to fetch your server details. Please check your secret key.");
 }
Ejemplo n.º 14
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.Configuration.Instance.secret);
            String url = Tebex.Instance.Configuration.Instance.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);
                    ConsolePlayer executer = new ConsolePlayer();
                    R.Commands.Execute(executer, 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));
        }