Exemplo n.º 1
0
        public static void      RemoveInvoice(string invoice)
        {
            int i = NGLicensesManager.invoices.FindIndex(l => l.invoice == invoice);

            if (i != -1)
            {
                NGLicensesManager.invoices.RemoveAt(i);
                NGLicensesManager.SaveLicenses();
            }
        }
Exemplo n.º 2
0
        public static void      AddInvoice(string invoice)
        {
            invoice = invoice.Trim();
            License license = NGLicensesManager.invoices.Find(l => l.invoice == invoice);

            if (license == null)
            {
                NGLicensesManager.invoices.Add(new License()
                {
                    invoice = invoice
                });
                NGLicensesManager.SaveLicenses();
            }
        }
Exemplo n.º 3
0
        public static void      RevokeLicense(string invoice)
        {
            License license;

            lock (NGLicensesManager.invoices)
            {
                license = NGLicensesManager.invoices.Find(l => l.invoice == invoice);

                if (license == null)
                {
                    return;
                }
            }

            StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "revoke_invoice.php?i=");

            buffer.Append(invoice);
            buffer.Append("&dn=");
            buffer.Append(SystemInfo.deviceName);
            buffer.Append("&un=");
            buffer.Append(Environment.UserName);

            NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, result) =>
            {
                if (error == false)
                {
                    if (result == "1")
                    {
                        EditorApplication.delayCall += () =>
                        {
                            lock (NGLicensesManager.invoices)
                            {
                                license.status = 0;
                                license.active = false;
                                NGLicensesManager.SaveLicenses();
                            }

                            InternalEditorUtility.RepaintAllViews();
                            EditorUtility.DisplayDialog(NGLicensesManager.Title, "License revoked.", "OK");
                        };
                    }
                    else
                    {
                        string message;

                        if (result == "0")                         // Not using
                        {
                            message        = "You are not using this invoice.";
                            license.status = Status.Valid;
                            license.active = false;
                        }
                        else if (result == "-2")                         // Banned
                        {
                            message        = "You are not allowed to revoke this invoice. Please contact the author.";
                            license.status = Status.Banned;
                            license.active = false;
                        }
                        else
                        {
                            message = "Server has encountered an issue. Please contact the author.";
                        }

                        EditorApplication.delayCall += () =>
                        {
                            if (NGLicensesManager.RevokeFailed != null)
                            {
                                NGLicensesManager.RevokeFailed(invoice, message, result);
                            }
                        };
                    }
                }
                else
                {
                    EditorApplication.delayCall += () =>
                    {
                        if (NGLicensesManager.RevokeFailed != null)
                        {
                            NGLicensesManager.RevokeFailed(invoice, "Request has failed.", result);
                        }
                    };
                }
            }, invoice);
        }
Exemplo n.º 4
0
        public static void      RevokeSeat(string invoice, string deviceName, string userName, Action <string, string, string> onCompleted)
        {
            StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "revoke_seats.php?i=");

            buffer.Append(invoice);
            buffer.Append("&dn=");
            buffer.Append(SystemInfo.deviceName);
            buffer.Append("&un=");
            buffer.Append(Environment.UserName);
            buffer.Append("&sdn[]=");
            buffer.Append(deviceName);
            buffer.Append("&sun[]=");
            buffer.Append(userName);

            NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, result) =>
            {
                if (error == false)
                {
                    if (result == "1")
                    {
                        EditorApplication.delayCall += () =>
                        {
                            lock (NGLicensesManager.invoices)
                            {
                                License license = NGLicensesManager.invoices.Find(l => l.invoice == invoice);

                                if (license != null)
                                {
                                    license.active = false;
                                    license.status = 0;
                                    NGLicensesManager.SaveLicenses();
                                }
                            }

                            onCompleted(invoice, deviceName, userName);
                            InternalEditorUtility.RepaintAllViews();
                            EditorUtility.DisplayDialog(NGLicensesManager.Title, "Seat \"" + deviceName + " " + userName + "\" revoked.", "OK");
                        };
                    }
                    else
                    {
                        string message;

                        if (result == "0")                         // Not using
                        {
                            message = "The server could not revoke the seat \"" + deviceName + " " + userName + "\". Please contact the author.";
                        }
                        else
                        {
                            message = "Server has encountered an issue. Please contact the author.";
                        }

                        EditorApplication.delayCall += () =>
                        {
                            EditorUtility.DisplayDialog(NGLicensesManager.Title, message, "OK");
                        };
                    }
                }
                else
                {
                    EditorApplication.delayCall += () =>
                    {
                        EditorUtility.DisplayDialog(NGLicensesManager.Title, "Request has failed.", "OK");
                    };
                }
            }, invoice);
        }
Exemplo n.º 5
0
        public static void      ActivateLicense(string invoice)
        {
            License license;

            lock (NGLicensesManager.invoices)
            {
                license = NGLicensesManager.invoices.Find(l => l.invoice == invoice);

                if (license == null)
                {
                    return;
                }
            }

            StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "active_invoice.php?i=");

            buffer.Append(invoice);
            buffer.Append("&dn=");
            buffer.Append(SystemInfo.deviceName);
            buffer.Append("&un=");
            buffer.Append(Environment.UserName);

            NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, result) =>
            {
                if (error == false)
                {
                    if (result == "1")
                    {
                        EditorApplication.delayCall += () =>
                        {
                            lock (NGLicensesManager.invoices)
                            {
                                license.active = true;
                                if (NGLicensesManager.ActivationSucceeded != null)
                                {
                                    NGLicensesManager.ActivationSucceeded(license.invoice);
                                }
                                NGLicensesManager.SaveLicenses();
                            }

                            InternalEditorUtility.RepaintAllViews();
                            EditorUtility.DisplayDialog(NGLicensesManager.Title, "License activated.", "OK");
                        };
                    }
                    else
                    {
                        string message;

                        if (result == "-2")                         // Banned
                        {
                            message        = "You are not allowed to use this invoice. Please contact the author.";
                            license.status = Status.Banned;
                            license.active = false;
                        }
                        else if (result == "-3")                         // Invalid
                        {
                            message        = "Invoice is invalid.";
                            license.status = Status.Invalid;
                            license.active = false;
                        }
                        else if (result == "-4")                         // Max reached
                        {
                            message        = "No more activation is allowed, limitation per seat is already reached. Please first revoke your license on other computers before activating here.";
                            license.status = Status.Valid;
                            license.active = false;
                        }
                        else
                        {
                            message = "Server has encountered an issue. Please contact the author.";
                        }

                        EditorApplication.delayCall += () =>
                        {
                            if (NGLicensesManager.ActivationFailed != null)
                            {
                                NGLicensesManager.ActivationFailed(invoice, message, result);
                            }
                        };
                    }
                }
                else
                {
                    EditorApplication.delayCall += () =>
                    {
                        if (NGLicensesManager.ActivationFailed != null)
                        {
                            NGLicensesManager.ActivationFailed(invoice, "Request has failed.", result);
                        }
                    };
                }
            }, invoice);
        }
Exemplo n.º 6
0
        private static void     VerifyActiveLicenses(params string[] invoices)
        {
            if (invoices.Length == 0)
            {
                return;
            }

            StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "check_active_invoices.php?i=");

            buffer.Append(string.Join(",", invoices));
            buffer.Append("&dn=");
            buffer.Append(SystemInfo.deviceName);
            buffer.Append("&un=");
            buffer.Append(Environment.UserName);

            NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, json) =>
            {
                if (error == false)
                {
                    string[]                lines = json.Split('\n');
                    List <string> changes         = new List <string>();

                    lock (NGLicensesManager.invoices)
                    {
                        for (int i = 0; i + 2 < lines.Length; i += 3)
                        {
                            for (int j = 0; j < NGLicensesManager.invoices.Count; j++)
                            {
                                if (NGLicensesManager.invoices[j].invoice == lines[i])
                                {
                                    if (lines[i + 1] == "-1")                                     // Banned
                                    {
                                        if (NGLicensesManager.invoices[j].status != Status.Banned ||
                                            NGLicensesManager.invoices[j].active != false)
                                        {
                                            changes.Add("License \"" + NGLicensesManager.invoices[j].invoice + "\" has been revoked and blocked." + (string.IsNullOrEmpty(lines[i + 2]) == false ? " (" + lines[i + 2] + ")" : string.Empty));
                                            NGLicensesManager.invoices[j].status = Status.Banned;
                                            NGLicensesManager.invoices[j].active = false;
                                        }
                                    }
                                    else if (lines[i + 1] == "0")                                     // Revoked
                                    {
                                        if (NGLicensesManager.invoices[j].status != Status.Valid ||
                                            NGLicensesManager.invoices[j].active != false)
                                        {
                                            changes.Add("License \"" + NGLicensesManager.invoices[j].invoice + "\" has been revoked." + (string.IsNullOrEmpty(lines[i + 2]) == false ? " (" + lines[i + 2] + ")" : string.Empty));
                                            NGLicensesManager.invoices[j].status = Status.Valid;
                                            NGLicensesManager.invoices[j].active = false;
                                        }
                                    }
                                    else if (lines[i + 1] == "1")                                     // Activated
                                    {
                                        if (NGLicensesManager.invoices[j].status != Status.Valid ||
                                            NGLicensesManager.invoices[j].active != true)
                                        {
                                            changes.Add("License \"" + NGLicensesManager.invoices[j].invoice + "\" has been activated." + (string.IsNullOrEmpty(lines[i + 2]) == false ? " (" + lines[i + 2] + ")" : string.Empty));
                                            NGLicensesManager.invoices[j].status = Status.Valid;
                                            NGLicensesManager.invoices[j].active = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (changes.Count > 0)
                        {
                            NGLicensesManager.SaveLicenses();
                        }
                    }

                    if (changes.Count > 0)
                    {
                        EditorApplication.delayCall += () =>
                        {
                            for (int i = 0; i < changes.Count; i++)
                            {
                                Debug.LogWarning("[" + NGLicensesManager.Title + "] " + changes[i]);
                            }

                            InternalEditorUtility.RepaintAllViews();
                        };
                    }
                }
            }, invoices);
        }
Exemplo n.º 7
0
        public static void      VerifyLicenses(params string[] invoices)
        {
            if (invoices.Length == 0)
            {
                return;
            }

            StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "check_invoices.php?i=");

            buffer.Append(string.Join(",", invoices));
            buffer.Append("&dn=");
            buffer.Append(SystemInfo.deviceName);
            buffer.Append("&un=");
            buffer.Append(Environment.UserName);

            // Is is apparently possible to send an invoice and receive a completely different invoice, but still valid.
            bool soloInvoiceFallback = invoices.Length == 1;

            NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, json) =>
            {
                if (error == false)
                {
                    if (json == "[]")
                    {
                        lock (NGLicensesManager.invoices)
                        {
                            for (int j = 0; j < NGLicensesManager.invoices.Count; j++)
                            {
                                for (int i = 0; i < invoices.Length; i++)
                                {
                                    if (NGLicensesManager.invoices[j].invoice == invoices[i])
                                    {
                                        NGLicensesManager.invoices[j].status = Status.Invalid;
                                    }
                                }
                            }

                            EditorApplication.delayCall += () =>
                            {
                                NGLicensesManager.SaveLicenses();
                                InternalEditorUtility.RepaintAllViews();
                            };
                        }
                    }
                    else if (json.StartsWith("[") == true)
                    {
                        string[]                results = json.Split('{');
                        List <string> unchangedInvoices = new List <string>(invoices);

                        lock (NGLicensesManager.invoices)
                        {
                            for (int i = 1; i < results.Length; i++)
                            {
                                string[]        values = results[i].Split(',');
                                string invoice         = values[0].Split(':')[1];

                                invoice = invoice.Substring(1, invoice.Length - 2);                                 // Remove quotes.

                                if (soloInvoiceFallback == true)
                                {
                                    soloInvoiceFallback = false;

                                    for (int j = 0; j < NGLicensesManager.invoices.Count; j++)
                                    {
                                        if (NGLicensesManager.invoices[j].invoice == invoices[0])
                                        {
                                            string asset_name = values[1].Split(':')[1];
                                            string rawStatus  = values[2].Split(':')[1];
                                            Status status     = (Status)int.Parse(rawStatus.Substring(0, rawStatus.Length - 2));

                                            if (asset_name.Length > 2)
                                            {
                                                asset_name = asset_name.Substring(1, asset_name.Length - 2);
                                                NGLicensesManager.invoices[j].assetName = asset_name;
                                            }
                                            NGLicensesManager.invoices[j].status = status;

                                            unchangedInvoices.Remove(invoices[0]);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int j = 0; j < NGLicensesManager.invoices.Count; j++)
                                    {
                                        if (NGLicensesManager.invoices[j].invoice.Contains(invoice) == true)
                                        {
                                            string asset_name = values[1].Split(':')[1];
                                            string rawStatus  = values[2].Split(':')[1];
                                            Status status     = (Status)int.Parse(rawStatus.Substring(0, rawStatus.Length - 2));

                                            if (asset_name.Length > 2)
                                            {
                                                asset_name = asset_name.Substring(1, asset_name.Length - 2);
                                                NGLicensesManager.invoices[j].assetName = asset_name;
                                            }
                                            NGLicensesManager.invoices[j].status = status;

                                            unchangedInvoices.RemoveAll(inv => inv.Contains(invoice));
                                            break;
                                        }
                                    }
                                }
                            }

                            NGLicensesManager.SaveLicenses();
                        }

                        EditorApplication.delayCall += () =>
                        {
                            if (unchangedInvoices.Count > 0)
                            {
                                buffer = Utility.GetBuffer("Invoice(s)");

                                for (int i = 0; i < unchangedInvoices.Count; i++)
                                {
                                    buffer.Append(" \"");
                                    buffer.Append(unchangedInvoices[i]);
                                    buffer.Append('"');
                                }

                                buffer.Append(" might be invalid.\nPlease use real invoice and not voucher.");
                                EditorUtility.DisplayDialog(NGLicensesManager.Title, Utility.ReturnBuffer(buffer), "OK");
                            }

                            InternalEditorUtility.RepaintAllViews();
                        };
                    }
                    else if (json == "-2")
                    {
                        EditorApplication.delayCall += () => EditorUtility.DisplayDialog(NGLicensesManager.Title, "Don't spam.", "OK");
                    }
                }
                else
                {
                    EditorApplication.delayCall += () => EditorUtility.DisplayDialog(NGLicensesManager.Title, "Request has failed. Please retry or contact the author.", "OK");
                }
            }, invoices);
        }