Пример #1
0
    public static void NetworkTest(string message)
    {
        DebugConsole.Log("network test started");

        HttpPoster.Post("app_test.php", message);

        DebugConsole.Log("network test passed");
    }
Пример #2
0
    public static string GetUpdateUrl()
    {
        DebugConsole.Log("network update url requested");

        var bytes = HttpPoster.Post("app_update.php", Version);
        var url   = Encoding.ASCII.GetString(bytes);

        DebugConsole.Log("<color=cyan>url</color> " + url);

        return(url);
    }
Пример #3
0
    public static bool VersionCheck()
    {
        DebugConsole.Log("network version check started");

        var bytes         = HttpPoster.Post("app_version.php", Version);
        var serverVersion = BitConverter.ToUInt32(bytes, 0);

        DebugConsole.Log("<color=cyan>servr</color> " + serverVersion);
        DebugConsole.Log("<color=cyan>local</color> " + Version);

        return(Version >= serverVersion);
    }
Пример #4
0
        private void Initialize(Client client)
        {
            Application.ClientStarted -= Initialize;

            var handler = Started;

            if (handler != null)
            {
                handler();
            }

            Application.RunTimeout(5 * 1000, delegate {
                if (BansheeMetrics.Instance == null)
                {
                    return(false);
                }

                ThreadAssist.SpawnFromMain(delegate {
                    metrics.AddDefaults();
                    AddMetrics();

                    if (ApplicationContext.CommandLine.Contains("debug-metrics"))
                    {
                        Log.InformationFormat("Anonymous usage data collected:\n{0}", metrics.ToJsonString());
                        System.IO.File.WriteAllText("usage-data.json", metrics.ToJsonString());
                    }

                    if (!ServiceManager.Get <Network> ().Connected)
                    {
                        return;
                    }

                    // Don't post to server more than every 48 hours
                    var last_post_time = DatabaseConfigurationClient.Client.Get <DateTime> (last_post_key, DateTime.MinValue);
                    var last_post_rel  = (DateTime.Now - last_post_time).TotalDays;
                    if (last_post_rel < 0 || last_post_rel > 4.0)
                    {
                        var poster  = new HttpPoster("http://metrics.banshee.fm/submit/", metrics);
                        bool posted = poster.Post();
                        Log.InformationFormat("Posted usage data? {0}", posted);

                        // Clear the old metrics, even if we failed to post them; it might be a server-side
                        // problem w/ the data we want to send (eg too big, out of space) and we don't want
                        // to keep retrying to send the same data.
                        metrics.Store.Clear();
                        DatabaseConfigurationClient.Client.Set <DateTime> (last_post_key, DateTime.Now);
                    }
                });

                return(false);
            });
        }
Пример #5
0
    public static bool Register(string mail, string pass)
    {
        DebugConsole.Log("network register with " + mail);
        //		if (!IsValidName(name)) {
        //			DebugConsole.Log("<color=red>register fail</color> invalid name");
        //			return false;
        //		} else if (!IsValidMail(mail)) {
        //			DebugConsole.Log("<color=red>register fail</color> invalid mail");
        //			return false;
        //		} else if (!IsValidPass(pass)) {
        //			DebugConsole.Log("<color=red>register fail</color> invalid hash");
        //			return false;
        //		}

        var bytes = HttpPoster.Post("user_register.php", Version, mail + "|" + pass);

        if ((bytes.Length != 4) && (bytes.Length != 20))
        {
            DebugConsole.Log("<color=red>register fail</color> invalid bytes");
            return(false);
        }

        if (bytes.Length == 4)
        {
            var errno = BitConverter.ToInt32(bytes, 0);
            switch (errno)
            {
            case 0:
                DebugConsole.Log("<color=red>register fail</color> existing name");
                return(false);

            case 1:
                DebugConsole.Log("<color=red>register fail</color> existing mail");
                return(false);

            default:
                DebugConsole.Log("<color=red>register fail</color> invalid errno");
                return(false);
            }
        }

        lsid   = BitConverter.ToInt32(bytes, 0);
        lshash = Encoding.UTF8.GetString(bytes, 4, bytes.Length - 4);

        DebugConsole.Log("<color=cyan>lsid</color> " + lsid);
        DebugConsole.Log("<color=cyan>lshash</color> " + lshash);

        return(true);
    }
Пример #6
0
    public static bool SetName(string name)
    {
        DebugConsole.Log("network setname ");

        if (!IsLoggedIn())
        {
            DebugConsole.Log("<color=red>setname fail</color> not logged in");
            return(false);
        }

        var bytes = HttpPoster.Post("user_set_name.php", lsid, lshash + '|' + name);

        if ((bytes.Length != 4))
        {
            DebugConsole.Log("<color=red>setname fail</color> invalid bytes");
            return(false);
        }

        var no = BitConverter.ToInt32(bytes, 0);

        switch (no)
        {
        case 0:
            DebugConsole.Log("<color=red>getinfo fail</color> invalid session");
            return(false);

        case 1:
            DebugConsole.Log("<color=red>getinfo fail</color> invalid userid");
            return(false);

        case 2:
            return(true);

        default:
            DebugConsole.Log("<color=red>getinfo fail</color> invalid errno");
            return(false);
        }
    }