Exemplo n.º 1
0
        private void update()
        {
            JObject response = new JObject();

            JObject version = new JObject();

            version.Add("name", this.Version.VersionName);
            version.Add("protocol", this.Version.ProtocolVersion);
            response.Add("version", version);

            JObject players = new JObject();

            players.Add("max", MaxPlayers);
            players.Add("online", OnlinePlayers);
            players.Add("sample", new JArray());
            response.Add("players", players);

            response.Add("description", ServerDescription.ToJSON());
            if (FaviconBase64 != "")
            {
                response.Add("favicon", "data:image/png;base64," + FaviconBase64);
            }

            JSON        = response.ToString();
            invalidated = false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private BitmapSource GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();

                desc.QRVersion    = QR_VERSION;
                desc.GeneratorApp = GENERATOR_APP;

                desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses());
                desc.Addresses         = String.Join(";", NetworkInformation.GetIPAddresses());
                desc.Name        = Configuration.Services.GetServiceName();
                desc.NetbiosName = System.Environment.MachineName;
                desc.ExternalIp  = ExternalAddress.GetAddress();

                desc.Services = new List <ServiceDescription>();
                User wifiRemoteAuth = WifiRemote.IsInstalled ? WifiRemote.GetAuthentication() : null;
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.Service,
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        srvdesc.User     = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).Username;
                        srvdesc.Password = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).GetPassword();
                    }

                    desc.Services.Add(srvdesc);
                }

                var writer = new BarcodeWriter()
                {
                    Format  = BarcodeFormat.QR_CODE,
                    Options = new EncodingOptions()
                    {
                        Height = 400,
                        Width  = 400
                    }
                };

                var bitmap = writer.Write(desc.ToJSON());
                return(bitmap.ToWpfBitmap());
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private void GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();
                desc.HardwareAddresses = String.Join(";", GetHardwareAddresses());
                desc.Addresses         = String.Join(";", GetIPAddresses());
                desc.Name      = GetServiceName();
                desc.QRVersion = 1;

                desc.Services = new List <ServiceDescription>();
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.ServiceName.ToString(),
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        string usernameOut, passwordOut;
                        srv.GetUsernameAndPassword(auth, out usernameOut, out passwordOut);
                        srvdesc.User     = usernameOut;
                        srvdesc.Password = passwordOut;
                    }

                    desc.Services.Add(srvdesc);
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                imgQRCode.Source = bm.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
            }
        }