private static void SetupTelegramConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean( translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramPrompt, "Y", "N") ) ) { return; } settings.TelegramConfig.UseTelegramAPI = true; string strInput = PromptForString( translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodePrompt) ); settings.TelegramConfig.TelegramAPIKey = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodeConfirm, strInput)); strInput = PromptForString( translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordPrompt) ); settings.TelegramConfig.TelegramPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordConfirm, strInput)); }
private static void SetupAccountType(ITranslation translator, GlobalSettings settings) { string strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAccount), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePrompt, "google", "ptc")); while (true) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "google": settings.Auth.AuthConfig.AuthType = AuthType.Google; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "GOOGLE")); return; case "ptc": settings.Auth.AuthConfig.AuthType = AuthType.Ptc; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "PTC")); return; default: Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePromptError, "google", "ptc"), LogLevel.Error); break; } } }
private static void SetupAccountType(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAccount), LogLevel.Info); string accountType = PromptForString( translator, translator.GetTranslation(TranslationString.FirstStartSetupTypePrompt, "google", "ptc"), new string[] { "google", "ptc" }, translator.GetTranslation(TranslationString.FirstStartSetupTypePromptError, "google", "ptc"), false ); switch (accountType) { case "google": settings.Auth.AuthConfig.AuthType = AuthType.Google; break; case "ptc": settings.Auth.AuthConfig.AuthType = AuthType.Ptc; break; } Logger.Write( translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, accountType.ToUpper() ) ); }
private static void SetupWebSocketConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } settings.WebsocketsConfig.UseWebsocket = true; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPortPrompt)); strInput = Console.ReadLine(); settings.WebsocketsConfig.WebSocketPort = int.Parse(strInput); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPortConfirm, strInput)); }
private static void SetupProxyConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyPrompt, "Y", "N"))) { return; } settings.Auth.ProxyConfig.UseProxy = true; string strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyHostPrompt)); settings.Auth.ProxyConfig.UseProxyHost = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupProxyHostConfirm, strInput)); strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyPortPrompt)); settings.Auth.ProxyConfig.UseProxyPort = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupProxyPortConfirm, strInput)); if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyAuthPrompt, "Y", "N"))) { return; } settings.Auth.ProxyConfig.UseProxyAuthentication = true; strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyUsernamePrompt)); settings.Auth.ProxyConfig.UseProxyUsername = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupProxyUsernameConfirm, strInput)); strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupProxyPasswordPrompt)); settings.Auth.ProxyConfig.UseProxyPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupProxyPasswordConfirm, strInput)); }
private static void SetupAutoCompleteTutConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } settings.PlayerConfig.AutoCompleteTutorial = true; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt)); strInput = Console.ReadLine(); settings.PlayerConfig.DesiredNickname = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, strInput)); }
private static void SetupUserAccount(ITranslation translator, GlobalSettings settings) { Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernamePrompt), LogLevel.None); string strInput = Console.ReadLine(); if (settings.Auth.AuthConfig.AuthType == AuthType.Google) { settings.Auth.AuthConfig.GoogleUsername = strInput; } else { settings.Auth.AuthConfig.PtcUsername = strInput; } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernameConfirm, strInput)); Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordPrompt), LogLevel.None); strInput = Console.ReadLine(); if (settings.Auth.AuthConfig.AuthType == AuthType.Google) { settings.Auth.AuthConfig.GooglePassword = strInput; } else { settings.Auth.AuthConfig.PtcPassword = strInput; } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartAccountCompleted), LogLevel.None); }
private static Session SetupTranslationCode(Session session, IElevationService elevationService, ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean( translator, translator.GetTranslation(TranslationString.FirstStartLanguagePrompt, "Y", "N") ) ) { return(session); } string strInput = PromptForString( translator, translator.GetTranslation(TranslationString.FirstStartLanguageCodePrompt) ); settings.ConsoleConfig.TranslationLanguageCode = strInput; session = new Session( new ClientSettings(settings, elevationService), new LogicSettings(settings), elevationService ); translator = session.Translation; Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageConfirm, strInput)); return(session); }
public void CheckProxy(ITranslation translator) { using (var tempWebClient = new NecroWebClient()) { var unproxiedIp = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); if (ProxyConfig.UseProxy) { tempWebClient.Proxy = InitProxy(); var proxiedIPres = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); var proxiedIp = proxiedIPres == null ? "INVALID PROXY" : proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIp, proxiedIp), LogLevel.Info, unproxiedIp == proxiedIp ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIp != proxiedIp && proxiedIPres != null) { return; } Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIp), LogLevel.Info, ConsoleColor.Red); } } }
public static bool PromptForSetup(ITranslation translator) { bool promptForSetup = PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartPrompt, "Y", "N")); if (!promptForSetup) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartAutoGenSettings)); } return(promptForSetup); }
private static void SetupWebSocketConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPrompt, "Y", "N"))) { return; } settings.WebsocketsConfig.UseWebsocket = true; settings.WebsocketsConfig.WebSocketPort = PromptForInteger(translator, translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPortPrompt)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPortConfirm, settings.WebsocketsConfig.WebSocketPort.ToString())); }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"), LogLevel.None); bool boolBreak = false; while (!boolBreak) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; default: // PROMPT ERROR \\ Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongPrompt)); while (true) { try { string strInput = Console.ReadLine(); string[] strSplit = strInput.Split(','); if (strSplit.Length > 1) { double dblLat = double.Parse(strSplit[0].Trim(' ')); double dblLong = double.Parse(strSplit[1].Trim(' ')); settings.LocationConfig.DefaultLatitude = dblLat; settings.LocationConfig.DefaultLongitude = dblLong; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongConfirm, $"{dblLat}, {dblLong}")); } else { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); continue; } break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); } } }
private static void SetupWalkingConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedPrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedKmHPrompt)); strInput = Console.ReadLine(); settings.LocationConfig.WalkingSpeedInKilometerPerHour = Double.Parse(strInput); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedKmHConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUseWalkingSpeedVariantPrompt, "Y", "N"), LogLevel.None); boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; settings.LocationConfig.UseWalkingSpeedVariant = true; break; case "n": settings.LocationConfig.UseWalkingSpeedVariant = false; return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantPrompt)); strInput = Console.ReadLine(); settings.LocationConfig.WalkingSpeedVariant = Double.Parse(strInput); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantConfirm, strInput)); }
private static Session SetupTranslationCode(Session session, ITranslation translator, GlobalSettings globalSettings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguagePrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine(); if (string.IsNullOrWhiteSpace(strInput)) { Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } switch (strInput.ToLowerInvariant()) { case "y": boolBreak = true; break; case "n": return(session); default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageCodePrompt)); strInput = Console.ReadLine(); globalSettings.ConsoleConfig.TranslationLanguageCode = strInput; // create new session ClientSettings clientSettings = new ClientSettings(globalSettings); LogicSettings logicSettings = new LogicSettings(globalSettings); Translation translation = Translation.Load(logicSettings); session = new Session(clientSettings, logicSettings, translation); translator = session.Translation; // TODO: I've never seen this before. Ommit? Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageConfirm, strInput)); return(session); }
private static void SetupWalkingConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedPrompt, "Y", "N"))) { return; } settings.LocationConfig.WalkingSpeedInKilometerPerHour = PromptForDouble(translator, translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedKmHPrompt)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedKmHConfirm, settings.LocationConfig.WalkingSpeedInKilometerPerHour.ToString())); settings.LocationConfig.UseWalkingSpeedVariant = PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupUseWalkingSpeedVariantPrompt, "Y", "N")); settings.LocationConfig.WalkingSpeedVariant = PromptForDouble(translator, translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantPrompt)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantConfirm, settings.LocationConfig.WalkingSpeedVariant.ToString())); }
public WebSocketInterface(int port, ITranslation translations) { _server = new WebSocketServer(); var setupComplete = _server.Setup(new ServerConfig { Name = "NecroWebSocket", Ip = "Any", Port = port, Mode = SocketMode.Tcp, Security = "tls", Certificate = new CertificateConfig { FilePath = @"cert.pfx", Password = "******" } }); if (setupComplete == false) { Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error); return; } _server.NewMessageReceived += HandleMessage; _server.NewSessionConnected += HandleSession; _server.Start(); }
public WebSocketInterface(int port, ITranslation translations) { _server = new WebSocketServer(); var setupComplete = _server.Setup(new ServerConfig { Name = "NecroWebSocket", Ip = "Any", Port = port, Mode = SocketMode.Tcp, Security = "tls", Certificate = new CertificateConfig { FilePath = @"cert.pfx", Password = "******" } }); if (setupComplete == false) { Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error); return; } _server.NewMessageReceived += HandleMessage; _server.NewSessionConnected += HandleSession; _server.Start(); }
public static void CheckGoogleAPI(ITranslation translator, GlobalSettings settings) { if (settings.GoogleWalkConfig.UseGoogleWalk && !settings.GPXSettings.UseGpxPathing) { Logger.Write(translator.GetTranslation(TranslationString.GoogleAPIFailed), LogLevel.Info, ConsoleColor.Red); } }
public static bool PromptForBoolean(ITranslation translator, string initialPrompt, string errorPrompt = null) { while (true) { Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": return(true); case "n": return(false); default: if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation(TranslationString.PromptError, "y", "n"); } Logger.Write(errorPrompt, LogLevel.Error); continue; } } }
private static void SetupAutoCompleteTutConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Y", "N"))) { return; } settings.PlayerConfig.AutoCompleteTutorial = true; string strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt)); settings.PlayerConfig.DesiredNickname = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, strInput)); strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderPrompt)); settings.PlayerConfig.DesiredGender = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderConfirm, strInput)); strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterPrompt)); settings.PlayerConfig.DesiredStarter = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterConfirm, strInput)); }
public void CheckProxy(ITranslation translator) { string unproxiedIp; using (HttpClient client = new HttpClient()) { var responseContent = client.GetAsync("https://api.ipify.org/?format=text").Result; unproxiedIp = responseContent.Content.ReadAsStringAsync().Result; } if (ProxyConfig.UseProxy) { var httpClientHandler = new HttpClientHandler { Proxy = InitProxy(), UseProxy = true }; using (HttpClient client = new HttpClient(httpClientHandler)) { var responseContent = client.GetAsync("https://api.ipify.org/?format=text").Result; var proxiedIPres = responseContent.Content.ReadAsStringAsync().Result; var proxiedIp = proxiedIPres == null ? "INVALID PROXY" : proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIp, proxiedIp), LogLevel.Info, unproxiedIp == proxiedIp ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIp != proxiedIp && proxiedIPres != null) { return; } Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIp), LogLevel.Info, ConsoleColor.Red); } }
public static bool PromptForSetup(ITranslation translator) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartPrompt, "Y", "N"), LogLevel.Warning); while (true) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": return(true); case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartAutoGenSettings)); return(false); default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "Y", "N"), LogLevel.Error); continue; } } }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean( translator, translator.GetTranslation( TranslationString.FirstStartDefaultLocationPrompt, "Y", "N") ) ) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.Info); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongPrompt)); while (true) { try { var strInput = Console.ReadLine(); var strSplit = strInput.Split(','); if (strSplit.Length > 1) { var dblLat = double.Parse(strSplit[0].Trim(' ')); var dblLong = double.Parse(strSplit[1].Trim(' ')); settings.LocationConfig.DefaultLatitude = dblLat; settings.LocationConfig.DefaultLongitude = dblLong; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongConfirm, $"{dblLat}, {dblLong}")); } else { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); continue; } break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); } } }
public void checkProxy(ITranslation translator) { using (var tempWebClient = new NecroWebClient()) { string unproxiedIP = tempWebClient.DownloadString(new Uri("https://api.ipify.org/?format=text")); if (ProxyConfig.UseProxy) { string proxiedIPres = tempWebClient.DownloadString(new Uri("https://api.ipify.org/?format=text")); string proxiedIP = proxiedIPres == null?"INVALID PROXY": proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIP, proxiedIP), LogLevel.Info, (unproxiedIP == proxiedIP) ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIP == proxiedIP || proxiedIPres == null) { Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIP), LogLevel.Info, ConsoleColor.Red); } } }
private static Session SetupTranslationCode(Session session, ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguagePrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return(session); default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageCodePrompt)); strInput = Console.ReadLine(); settings.ConsoleConfig.TranslationLanguageCode = strInput; session = new Session(new ClientSettings(settings), new LogicSettings(settings)); translator = session.Translation; Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageConfirm, strInput)); return(session); }
public WebSocketInterface(string ipAddress, int port, Session session) { _session = session; _server = new WebSocketServer(); _websocketHandler = WebSocketEventManager.CreateInstance(); // Add custom seriaizer to convert ulong to string (ulong shoud not appear to json according to json specs) _jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; _jsonSerializerSettings.Converters.Add(new LongToStringJsonConverter()); ITranslation translations = session.Translation; ServerConfig config = new ServerConfig { Name = "NecroWebSocket", Mode = SocketMode.Tcp, Certificate = new CertificateConfig { FilePath = @"cert.pfx", Password = "******" }, Listeners = new List <ListenerConfig> { new ListenerConfig { Ip = ipAddress, Port = port, Security = "tls" }, new ListenerConfig { Ip = ipAddress, Port = port + 1, Security = "none" } }, }; bool setupComplete = _server.Setup(config); if (setupComplete == false) { Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error); return; } _server.NewMessageReceived += HandleMessage; _server.NewSessionConnected += HandleSession; _server.Start(); }
public static string PromptForString(ITranslation translator, string initialPrompt, string[] validStrings = null, string errorPrompt = null, bool caseSensitive = true) { while (true) { Logger.Write(initialPrompt, LogLevel.Info); // For now this just reads from the console, but in the future, we may change this to read from the GUI. string strInput = Console.ReadLine(); if (!caseSensitive) { strInput = strInput.ToLower(); } // If no valid strings to validate, then return immediately. if (validStrings == null) { return(strInput); } // Validate string foreach (string validString in validStrings) { if (String.Equals(strInput, validString, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { return(strInput); } } // If we got here, no valid strings. if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation( TranslationString.PromptErrorString, string.Join(",", validStrings) ); } Logger.Write(errorPrompt, LogLevel.Error); } }
private static double PromptForDouble(ITranslation translator, string initialPrompt, string errorPrompt = null) { Logger.Write(initialPrompt, LogLevel.None); while (true) { var strInput = Console.ReadLine(); double doubleVal; if (double.TryParse(strInput, out doubleVal)) { return(doubleVal); } else { if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation(TranslationString.PromptErrorDouble); } Logger.Write(errorPrompt, LogLevel.Error); } } }
public static int PromptForInteger(ITranslation translator, string initialPrompt, string errorPrompt = null) { while (true) { Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine(); int intVal; if (int.TryParse(strInput, out intVal)) { return(intVal); } else { if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation(TranslationString.PromptErrorInteger); } Logger.Write(errorPrompt, LogLevel.Error); } } }
private static void SetupTelegramConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPrompt, "Y", "N"), LogLevel.None); string strInput; var boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } settings.TelegramConfig.UseTelegramAPI = true; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodePrompt)); strInput = Console.ReadLine(); settings.TelegramConfig.TelegramAPIKey = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodeConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordPrompt)); strInput = Console.ReadLine(); settings.TelegramConfig.TelegramPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordConfirm, strInput)); }
public void checkProxy(ITranslation translator) { using (var tempWebClient = new NecroWebClient()) { string unproxiedIP = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); if (UseProxy) { tempWebClient.Proxy = this.InitProxy(); string proxiedIPres = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); string proxiedIP = proxiedIPres == null?"INVALID PROXY": proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIP, proxiedIP), LogLevel.Info, (unproxiedIP == proxiedIP) ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIP == proxiedIP || proxiedIPres == null) { Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIP), LogLevel.Info, ConsoleColor.Red); } } }
private static void SetupUserAccount(ITranslation translator, GlobalSettings settings) { Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernamePrompt), LogLevel.None); string strInput = Console.ReadLine(); if (settings.Auth.AuthType == AuthType.Google) settings.Auth.GoogleUsername = strInput; else settings.Auth.PtcUsername = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernameConfirm, strInput)); Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordPrompt), LogLevel.None); strInput = Console.ReadLine(); if (settings.Auth.AuthType == AuthType.Google) settings.Auth.GooglePassword = strInput; else settings.Auth.PtcPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartAccountCompleted), LogLevel.None); }
private static Session SetupTranslationCode(Session session, ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguagePrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return session; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageCodePrompt)); strInput = Console.ReadLine(); settings.TranslationLanguageCode = strInput; session = new Session(new ClientSettings(settings), new LogicSettings(settings)); translator = session.Translation; Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageConfirm, strInput)); return session; }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"), LogLevel.None); bool boolBreak = false; while (!boolBreak) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; default: // PROMPT ERROR \\ Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongPrompt)); while (true) { try { string strInput = Console.ReadLine(); string[] strSplit = strInput.Split( ',' ); if( strSplit.Length > 1 ) { double dblLat = double.Parse( strSplit[ 0 ].Trim( ' ' ) ); double dblLong = double.Parse( strSplit[ 1 ].Trim( ' ' ) ); settings.DefaultLatitude = dblLat; settings.DefaultLongitude = dblLong; Logger.Write( translator.GetTranslation( TranslationString.FirstStartSetupDefaultLatLongConfirm, $"{dblLat}, {dblLong}" ) ); } else { Logger.Write( translator.GetTranslation( TranslationString.FirstStartSetupDefaultLocationError, $"{settings.DefaultLatitude}, {settings.DefaultLongitude}", LogLevel.Error ) ); continue; } break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.DefaultLatitude}, {settings.DefaultLongitude}", LogLevel.Error)); continue; } } }
private static void SetupAccountType(ITranslation translator, GlobalSettings settings) { string strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAccount), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePrompt, "google", "ptc")); while (true) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "google": settings.Auth.AuthType = AuthType.Google; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "GOOGLE")); return; case "ptc": settings.Auth.AuthType = AuthType.Ptc; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "PTC")); return; default: Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePromptError, "google", "ptc"), LogLevel.Error); break; } } }
public static bool PromptForSetup(ITranslation translator) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartPrompt, "Y", "N"), LogLevel.Warning); while (true) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": return true; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartAutoGenSettings)); return false; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "Y", "N"), LogLevel.Error); continue; } } }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"), LogLevel.None); bool boolBreak = false; while (!boolBreak) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; default: // PROMPT ERROR \\ Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatPrompt)); while (true) { try { double dblInput = double.Parse(Console.ReadLine()); settings.DefaultLatitude = dblInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatConfirm, dblInput)); break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, settings.DefaultLatitude, LogLevel.Error)); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLongPrompt)); while (true) { try { double dblInput = double.Parse(Console.ReadLine()); settings.DefaultLongitude = dblInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLongConfirm, dblInput)); break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, settings.DefaultLongitude, LogLevel.Error)); continue; } } }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"), LogLevel.None); bool boolBreak = false; while (!boolBreak) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; default: // PROMPT ERROR \\ Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatPrompt)); while (true) { try { double dblInput = double.Parse(Console.ReadLine()); settings.DefaultLatitude = dblInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatConfirm, dblInput)); break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, settings.DefaultLatitude, LogLevel.Error)); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLongPrompt)); while (true) { try { double dblInput = double.Parse(Console.ReadLine()); settings.DefaultLongitude = dblInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLongConfirm, dblInput)); break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, settings.DefaultLongitude, LogLevel.Error)); continue; } } }