Ejemplo n.º 1
0
 /// <summary>
 /// Called on UI thread
 /// </summary>
 private void PerformUpdate(ServerModel server, string status)
 {
     if (server.ConnectionStatus != status)
     {
         server.ConnectionStatus = status;
     }
 }
Ejemplo n.º 2
0
        private async Task CheckServer(ServerModel server)
        {
            // Get our status for this server
            if (!_serverCheckStatuses.ContainsKey(server.ServerId))
            {
                _serverCheckStatuses[server.ServerId] = new ServerCheckStatus();
            }
            var checkStatus = _serverCheckStatuses[server.ServerId];
            int delaysec    = (server.UpStatus == ServerModel.ServerUpStatusEnum.Up ? server.StatusOnlineIntervalSeconds : server.StatusOfflineIntervalSeconds);

            // Is it time to check again
            if (DateTime.UtcNow - checkStatus.LastCheckedUtc < TimeSpan.FromSeconds(delaysec))
            {
                return;
            }
            checkStatus.LastCheckedUtc = DateTime.UtcNow;
            var address = AddressParser.Parse(server.ServerIpAndPort);

            if (string.IsNullOrEmpty(address.Ip) || address.Port <= 0)
            {
                return;
            }
            bool up = await IsUdpServerUp(address.Ip, address.Port);

            string status = GetStatusString(up);

            server.UpStatus = (up ? ServerModel.ServerUpStatusEnum.Up : ServerModel.ServerUpStatusEnum.Down);
            if (server.ConnectionStatus != status)
            {
                CallToUpdate(server, status);
            }
        }
Ejemplo n.º 3
0
        internal static ServerModel Create(ThwargLauncher.GameManagement.ServerPersister.ServerData data)
        {
            ServerModel server = new ServerModel();

            server.ServerId          = data.ServerId;
            server.ServerName        = data.ServerName;
            server.ServerAlias       = data.ServerAlias;
            server.ServerDescription = data.ServerDesc;
            server.ServerIpAndPort   = data.ConnectionString;
            server.GameApiUrl        = data.GameApiUrl;
            server.LoginServerUrl    = data.LoginServerUrl;
            server.DiscordUrl        = data.DiscordUrl;
            server.WebsiteUrl        = data.WebsiteUrl;
            server.EMU                          = data.EMU;
            server.RodatSetting                 = data.RodatSetting;
            server.SecureSetting                = data.SecureSetting;
            server.VisibilitySetting            = data.VisibilitySetting;
            server.ServerSource                 = data.ServerSource;
            server.ConnectionStatus             = "?";
            server.ConnectionColor              = System.Windows.Media.Brushes.AntiqueWhite;
            server.UpStatus                     = ServerUpStatusEnum.Unknown;
            server.StatusOfflineIntervalSeconds = 15;
            server.StatusOnlineIntervalSeconds  = 300;
            return(server);
        }
Ejemplo n.º 4
0
 private void ImportProfileServersIfNeeded()
 {
     try
     {
         if (!Properties.Settings.Default.HaveImportedProfileServers)
         {
             var persister  = new GameManagement.ServerPersister(ServerManager.GetServerDataFolder());
             var allServers = persister.GetWildWestServerList();
             foreach (var serverName in GetAllProfileServerNames())
             {
                 var existingServer = ServerManager.ServerList.FirstOrDefault(qq => streqi(qq.ServerName, serverName));
                 if (existingServer == null)
                 {
                     var servData = allServers.FirstOrDefault(qq => streqi(qq.ServerName, serverName));
                     if (servData != null)
                     {
                         var model = ServerModel.Create(servData);
                         ServerManager.ServerList.Add(model);
                     }
                     else
                     {
                         Logger.WriteInfo($"Ignoring unknown server '{serverName}'");
                     }
                 }
             }
             Properties.Settings.Default.HaveImportedProfileServers = true;
             Properties.Settings.Default.Save();
         }
     }
     catch (Exception exc)
     {
         Logger.WriteError("Failed to import profile servers: " + exc.ToString());
     }
 }
Ejemplo n.º 5
0
 public Server(UserAccount acct, ServerModel serverItem)
 {
     _myAccount = acct;
     _myServer  = serverItem;
     _myServer.PropertyChanged += ServerItemPropertyChanged;
     AvailableCharacters        = new ObservableCollection <AccountCharacter>();
     ServerStatusSymbol         = "";
 }
Ejemplo n.º 6
0
        private void Import(object parameter)
        {
            ServerModel server = parameter as ServerModel;

            if (IsModelInOurServers(server))
            {
                return;
            }
            ServerManager.ServerList.Add(server);
            LoadServers();
        }
Ejemplo n.º 7
0
 private void CallToUpdate(ServerModel server, string status)
 {
     if (System.Windows.Application.Current == null)
     {
         return;
     }
     System.Windows.Application.Current.Dispatcher.BeginInvoke(
         DispatcherPriority.Normal, new Action(() =>
     {
         PerformUpdate(server, status);
     }));
 }
Ejemplo n.º 8
0
        private void LoadServers()
        {
            _serverModels.Clear();
            var persister = new GameManagement.ServerPersister(ServerManager.GetServerDataFolder());

            var allServers       = persister.GetWildWestServerList();
            var availableServers = allServers.Where(q => !IsInOurServers(q));

            foreach (var servdata in availableServers)
            {
                ServerModel model = ServerModel.Create(servdata);
                _serverModels.Add(model);
            }
        }
Ejemplo n.º 9
0
        private static void AddOrUpdateServer(GameManagement.ServerPersister.ServerData servdata)
        {
            var existing = ServerList.FirstOrDefault(s => s.IsEqual(servdata));

            if (existing != null)
            {
                existing.ServerName        = servdata.ServerName;
                existing.ServerDescription = servdata.ServerDesc;
                existing.ServerIpAndPort   = servdata.ConnectionString;
                existing.RodatSetting      = servdata.RodatSetting;
                existing.VisibilitySetting = servdata.VisibilitySetting;
                existing.EMU = servdata.EMU;
            }
            else
            {
                ServerModel model = ServerModel.Create(servdata);
                ServerList.Add(model);
            }
        }
Ejemplo n.º 10
0
        public override bool Equals(object obj)
        {
            ServerModel ob2 = (obj as ServerModel);

            if (ob2 == null)
            {
                return(false);
            }
            if (this.ServerId == ob2.ServerId)
            {
                return(true);
            }

            /*
             * We are now using exact id match, not equivalent data
             * if (GetHashCode() != ob2.GetHashCode()) { return false; }
             * if (ServerName != ob2.ServerName) { return false; }
             * if (ServerIpAndPort != ob2.ServerIpAndPort) { return false; }
             * */
            return(true);
        }
        private void LaunchSimpleGame(string path, ServerModel server, string account, string pwd)
        {
            SaveToSettings();
            var launchItem = new LaunchItem();

            launchItem.CustomLaunchPath = path;
            launchItem.ServerName       = server.ServerName;
            launchItem.AccountName      = account;
            launchItem.Password         = pwd;
            launchItem.IpAndPort        = server.ServerIpAndPort;
            launchItem.EMU = server.EMU;
            launchItem.CharacterSelected = null; // no character choices for SimpleLaunch, b/c that requires MagFilter
            launchItem.RodatSetting      = server.RodatSetting;
            launchItem.IsSimpleLaunch    = true;

            if (LaunchingEvent == null)
            {
                throw new Exception("SimpleLaunchWindowViewModel.LaunchingEvent null");
            }
            LaunchingEvent(launchItem);
        }
Ejemplo n.º 12
0
 public SimpleServerItem(ServerModel server)
 {
     _item = server;
     _item.PropertyChanged += OnItemPropertyChanged;
 }
Ejemplo n.º 13
0
 private bool IsModelInOurServers(ServerModel server)
 {
     return(ServerManager.ServerList.Contains(server));
 }