Esempio n. 1
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            ViewModel = new ServerViewModel();
            WebUtility = new WebServiceClientUtility();

            MasterServerDispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 2),
                DispatcherPriority.Normal,
                new EventHandler(SendServerDetailsToMasterServerAsync),
                Dispatcher.CurrentDispatcher);
            MasterServerDispatcherTimer.Stop();

            GameServerDispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 5),
                DispatcherPriority.Normal,
                new EventHandler(ProcessGameServer),
                Dispatcher.CurrentDispatcher);
            GameServerDispatcherTimer.Stop();

            OpenFile = new OpenFileDialog();
            InitializeOpenFileDialog();

            SetViewModelBindings();
            LoadSettings();
            UpdateExternalIPAddressAsync();
        }
        /// <summary>
        /// Sends a server's details to the master server which
        /// tracks the active server list.
        /// </summary>
        /// <param name="details">The server details to send to the master server.</param>
        public string SendServerDetails(ServerViewModel viewModel)
        {
            try
            {
                bool isActive = false;
                if (viewModel.ServerStatus == ServerStatusEnum.Running ||
                   viewModel.ServerStatus == ServerStatusEnum.Starting)
                {
                    isActive = true;
                }

                MasterServerStatusPacket packet = new MasterServerStatusPacket
                {
                    GameTypeID = (byte)viewModel.ServerSettings.GameType,
                    IsAutoDownloadEnabled = viewModel.ServerSettings.AllowFileAutoDownload,
                    IsCharacterDeletionEnabled = viewModel.ServerSettings.AllowCharacterDeletion,
                    PVPTypeID = (byte)viewModel.ServerSettings.PVPSetting,
                    ServerCurrentPlayers = viewModel.ConnectedUsernames.Count(),
                    ServerDescription = viewModel.ServerSettings.Description,
                    ServerIPAddress = viewModel.ServerIPAddress,
                    ServerMaxLevel = viewModel.ServerSettings.MaxLevel,
                    ServerMaxPlayers = viewModel.ServerSettings.MaxPlayers,
                    ServerName = viewModel.ServerSettings.Name,
                    ServerPort = viewModel.ServerSettings.PortNumber,
                    IsActive = isActive
                };

                string json = JsonConvert.SerializeObject(packet);
                string result = SendJsonRequest("UpdateServerDetails", WebServiceMethodTypeEnum.Server, json);

                return result;
            }
            catch
            {
                throw;
            }
        }