예제 #1
0
        /*
         * Sezione del ramo UDP dove sono elencate le funzioni che il server userà quando dovrà inviare pacchetti
         * broadcast sulla LAN.
         */
        public void EntryTalk()
        {
            Console.WriteLine("Mando un messsaggio UDP!");
            while (!SharedVariables.CloseEverything)
            {
                if (SharedVariables.Luh.Admin == null)
                {
                    SharedVariables.Luh.Admin = new Person(ListUserHandler.GetLocalIPAddress().Replace(".", "-"), "", true, ListUserHandler.GetLocalIPAddress(), 21, 0);
                }

                Console.WriteLine(SharedVariables.Luh.Admin.ToString());

                // Mando pacchetti broadcast ogni 5s, SOLO SE sono ONLINE
                if (SharedVariables.Luh.Admin.State)
                {
                    if (ListUserHandler.GetLocalIPAddress() != SharedVariables.Luh.Admin.GetIp().ToString())
                    {
                        SharedVariables.Luh.Admin.SetIp(ListUserHandler.GetLocalIPAddress());
                    }
                    BroadcastMessage("pds," + SharedVariables.Luh.Admin.GetString());
                }
                Thread.Sleep(5000);
            }
            Console.WriteLine("thread di segnalazione UDP chiuso");
        }
        private void LoadAdminCredentials()
        {
            try
            {
                using (StreamReader file = File.OpenText(System.Windows.Forms.Application.StartupPath + @"/Credentials.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    Credentials    admin      = (Credentials)serializer.Deserialize(file, typeof(Credentials));
                    SharedVariables.Luh.Admin     = new Person(admin.Name, admin.Surname, admin.State, ListUserHandler.GetLocalIPAddress(), admin.Port, admin.ImageKey, admin.Rnd);
                    SharedVariables.AutomaticSave = admin.AutoSave;

                    SharedVariables.PathSave = (admin.PathSave == null)? SharedVariables.PathSave: admin.PathSave;
                    Console.WriteLine("[APP] Admin: " + SharedVariables.Luh.Admin.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("[APP] File non ancora stato creato!");
                SharedVariables.NewUser = true;
            }
        }