static void Main(string[] args) { //Account acc = Account.CreateNew(101, "Sample", AccountType.Savings, 1000); IAccount acc = AccountServer.Get(101, "Sample", AccountType.Savings, 1000); if (acc == null) { Console.WriteLine("Error creating account object.Terminating code"); } Console.WriteLine($"1.{acc}"); acc.Deposit(5000); Console.WriteLine($"2.Deposited 5000, \n\t{acc}"); try { acc.Withdraw(2500); } catch (MinimumBalanceException me) { Console.WriteLine(me.Message); } Console.WriteLine($"3.Withdrew 4500, \n\t{acc}"); //create another account // Account acc2 = Account.CreateNew(102, "Jumble", AccountType.Current, 5000); IAccount acc2 = AccountServer.Get(101, "Sample", AccountType.Savings, 1500); if (acc2 == null) { Console.WriteLine("Error creating account object.Terminating code"); } Console.WriteLine($"4.Another account, \n\t{acc2}"); //acc.FundTransfer(acc2, 1000); Console.WriteLine($"5.After fund transfer:, \n\t{acc}\n\t{acc2}"); Console.WriteLine("".PadLeft(45, '-')); }
/// <summary> /// Pings the server, checking for activity /// </summary> /// <remarks>Sets the ping type to status(0)</remarks> public static bool PingServer(string Url) { if (string.IsNullOrEmpty(Url)) { return(false); } IStatus.PingRequestStatusCode ping = AccountServer.PingAccount(Url); return(ping == IStatus.PingRequestStatusCode.Ok ? true : false); }
/// <summary> /// Sends a login request to the server /// </summary> public static string[] LoginServer(string Username, string Password) { string url = CurrentUrl; IStatus.LoginResponseObject payload; IStatus.LoginRequestObject request = new IStatus.LoginRequestObject(); request.Username = Username; request.PasswordHash = Password; string msg; switch (AccountServer.LoginAccount(request, CurrentUrl, out payload)) { case IStatus.LoginStatusCode.Ok: string[] getPayload = { payload.TicketId.ToString(), payload.Username }; return(getPayload); case IStatus.LoginStatusCode.InvalidCredentials: msg = "Error: Invalid username/password"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Login Request"); if (passwordCount++ >= 3) { if (ShowReminder != null) { ShowReminder(passwordCount); } } break; case IStatus.LoginStatusCode.MalformedData: msg = "Error: malformed username/password"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Login Request"); if (passwordCount++ >= 3) { if (ShowReminder != null) { ShowReminder(passwordCount); } } break; case IStatus.LoginStatusCode.ServerError: msg = "Server error, could not connect.\r\n Is your firewall enabled?"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : AccountServer.Reason, "Login Request"); break; case IStatus.LoginStatusCode.NoResponse: msg = "Server error, received no response from the server."; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : AccountServer.Reason, "Login Request"); break; } return(null); }
internal void UpdateAccountStatus(string serverName, string accountName, ServerAccountStatusEnum status) { AccountServer acctServer = FindServer(serverName, accountName); if (acctServer != null) { string symbol = GetStatusSymbol(status); acctServer.tServer.SetAccountServerStatus(status, symbol); acctServer.tAccount.NotifyAccountSummaryChanged(); } }
private AccountServer.PingRequestStatusCode PingServer(string url) { switch (AccountServer.PingAccount(url)) { default: case AccountServer.PingRequestStatusCode.NotFound: return(AccountServer.PingRequestStatusCode.NotFound); case AccountServer.PingRequestStatusCode.Ok: return(AccountServer.PingRequestStatusCode.Ok); } }
private void btnRegister_Click(object sender, EventArgs e) { this.accountServer = this.settings["Launcher"]["Accounts"]; //Lets ping first AccountServer.PingRequestStatusCode ping = PingServer(this.settings["Launcher"]["Accounts"]); if (ping != AccountServer.PingRequestStatusCode.Ok) { //Try the backup if ((ping = PingServer(this.settings["Launcher"]["AccountsBackup"])) != AccountServer.PingRequestStatusCode.Ok) { int num3 = (int)MessageBox.Show("Server error, could not connect. Is your firewall enabled?"); return; } this.accountServer = this.settings["Launcher"]["AccountsBackup"]; } switch (AccountServer.RegisterAccount(new AccountServer.RegisterRequestObject() { Username = this.txtUsername.Text.Trim(), PasswordHash = Md5.Hash(this.txtPassword.Text.Trim()), Email = this.txtEmail.Text.Trim() }, this.accountServer)) { case AccountServer.RegistrationStatusCode.Ok: int num1 = (int)MessageBox.Show("Account created!"); break; case AccountServer.RegistrationStatusCode.MalformedData: int num2 = (int)MessageBox.Show("Error: malformed username/password"); break; case AccountServer.RegistrationStatusCode.UsernameTaken: int num3 = (int)MessageBox.Show("Username is taken"); break; case AccountServer.RegistrationStatusCode.EmailTaken: int num4 = (int)MessageBox.Show("Email is already used"); break; case AccountServer.RegistrationStatusCode.WeakCredentials: string msg = "(too short/invalid characters/invalid email)"; int num5 = (int)MessageBox.Show("Credentials are invalid: " + (AccountServer.Reason != null ? AccountServer.Reason : msg)); break; case AccountServer.RegistrationStatusCode.ServerError: string defaultMsg = "Server error, could not connect. Is your firewall enabled?"; int num6 = (int)MessageBox.Show((AccountServer.Reason != null ? AccountServer.Reason : defaultMsg)); break; } }
ICollection IManager.GetByParentKey(int key) { ArrayList accounts = new ArrayList(); DataSet ds = AccountServer.GetByCustomerID(key); foreach (DataRow row in ds.Tables["tblAccount"].Rows) { accounts.Add(new AccountBase(row)); } return(accounts); }
/// <summary> /// Registers a new account /// </summary> public static bool RegisterAccount(string Username, string Password, string Email) { string msg; IStatus.RegisterRequestObject request = new IStatus.RegisterRequestObject(); request.Username = Username; request.PasswordHash = Helpers.Md5.Hash(Password); request.Email = Email; switch (AccountServer.RegisterAccount(request, CurrentUrl)) { case IStatus.RegistrationStatusCode.Ok: MessageBox.Show("Account created!", "Register Request"); return(true); case IStatus.RegistrationStatusCode.MalformedData: msg = "Error: malformed username/password"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Register Request"); break; case IStatus.RegistrationStatusCode.UsernameTaken: msg = "Error: Username is taken."; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Register Request"); break; case IStatus.RegistrationStatusCode.EmailTaken: msg = "Error: Email is already used."; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Register Request"); break; case IStatus.RegistrationStatusCode.WeakCredentials: msg = "too short/invalid characters/invalid email"; MessageBox.Show("Error: Credentials are invalid.\n\r(" + (string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : AccountServer.Reason) + ")", "Register Request"); break; case IStatus.RegistrationStatusCode.ServerError: msg = "Server error, could not connect. Is your firewall enabled?"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Register Request"); break; case IStatus.RegistrationStatusCode.NoResponse: msg = "Server error, received no response from the server."; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Register Request"); break; } return(false); }
internal void UpdateAccountStatus(string serverName, string accountName, ServerAccountStatusEnum status) { AccountServer acctServer = FindServer(serverName, accountName); if (acctServer != null) { string symbol = GetStatusSymbol(status); Server server = acctServer.tServer; server.SetAccountServerStatus(status, symbol); if (DateTime.UtcNow - server.LastStatusSummaryChangedNoticeUtc > TimeSpan.FromSeconds(2.0)) { server.NotifyOfStatusSummaryChanged(); } acctServer.tAccount.NotifyAccountSummaryChanged(); } }
private void btnPlay_Click(object sender, EventArgs e) { this.accountServer = this.settings["Launcher"]["Accounts"]; this.SetCurrentTask("Checking server status..."); //Lets ping first AccountServer.PingRequestStatusCode ping = PingServer(this.settings["Launcher"]["Accounts"]); if (ping != AccountServer.PingRequestStatusCode.Ok) { //Try the backup if ((ping = PingServer(this.settings["Launcher"]["AccountsBackup"])) != AccountServer.PingRequestStatusCode.Ok) { int num3 = (int)MessageBox.Show("Server error, could not connect. Is your firewall enabled?"); return; } this.accountServer = this.settings["Launcher"]["AccountsBackup"]; } this.SetCurrentTask("Trying credentials..."); AccountServer.LoginResponseObject payload; switch (AccountServer.LoginAccount(new AccountServer.LoginRequestObject() { Username = this.txtUsername.Text.Trim(), PasswordHash = this.txtPassword.Text == "*****" ? this.settings["Credentials"]["Password"] : Md5.Hash(this.txtPassword.Text.Trim()) }, this.accountServer, out payload)) { case AccountServer.LoginStatusCode.Ok: this.LaunchGame(payload.TicketId.ToString(), ((object)payload.Username).ToString()); break; case AccountServer.LoginStatusCode.MalformedData: string msg = "Error: malformed username/password"; int num1 = (int)MessageBox.Show((AccountServer.Reason != null ? "Error: " + AccountServer.Reason : msg)); break; case AccountServer.LoginStatusCode.InvalidCredentials: int num2 = (int)MessageBox.Show("Invalid username/password"); break; case AccountServer.LoginStatusCode.ServerError: int num3 = (int)MessageBox.Show("Server error, could not connect. Is your firewall enabled?"); break; } }
public void Setup() { MaxCups = 25; softdrink = new Drink(0.50m, "Soft drink"); accountServer = AccountServer.GetAccountServerInstance as AccountServer; card1 = new CashCard("12345", 1001); card2 = new CashCard("67890", 1002); card3 = new CashCard("11111", 2001); card4 = new CashCard("22222", 2002); accountWithBalance = new JointAccount("101", 20m, card1, card2); accountWithInsufficientBalance = new JointAccount("102", 0.45m, card3, card4); //add some test accounts accountServer.AddAccount(accountWithBalance); accountServer.AddAccount(accountWithInsufficientBalance); }
/// <summary> /// Sends a recovery request to the server /// </summary> public static bool RecoveryRequest(string Username, string Email, bool Reset) { string url = CurrentUrl + @"/recover"; string payload; IStatus.RecoverRequestObject request = new IStatus.RecoverRequestObject(); request.Username = Username; request.Email = Email; request.Reset = Reset; string msg; switch (AccountServer.RecoverAccount(request, url, out payload)) { case IStatus.RecoverStatusCode.Ok: MessageBox.Show("Recovery Successful!\n\rCheck your email at " + payload, "Recovery Request"); return(true); case IStatus.RecoverStatusCode.InvalidCredentials: msg = "Error: Invalid username/email"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Recovery Request"); break; case IStatus.RecoverStatusCode.MalformedData: msg = "Error: malformed username/email"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Recovery Request"); break; case IStatus.RecoverStatusCode.ServerError: msg = "Server error, could not connect.\r\n Is your firewall enabled?"; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Recovery Request"); break; case IStatus.RecoverStatusCode.NoResponse: msg = "Server error, received no response from the server."; MessageBox.Show(string.IsNullOrWhiteSpace(AccountServer.Reason) ? msg : "Error: " + AccountServer.Reason, "Recovery Request"); break; } return(false); }
private AccountServer FindServer(string serverName, string accountName) { var account = KnownUserAccounts.FirstOrDefault(x => x.AccountName == accountName); if (account == null) { return(null); } var server = account.Servers.FirstOrDefault(x => x.ServerName == serverName); if (server == null) { return(null); } AccountServer acctServer = new AccountServer() { tAccount = account.Account, tServer = server }; return(acctServer); }
internal void ExecuteGameCommand(string serverName, string accountName, string command) { AccountServer acctServer = FindServer(serverName, accountName); if (acctServer == null) { return; } Logger.WriteInfo(string.Format( "QQQ - not currently invoked -- Command received from server='{0}', account='{1}': {2}", serverName, accountName, command)); // TODO // write code to implement commands from game to launcher if (acctServer != null) { } else { Logger.WriteError("Command received from unknown server/account"); } }
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext .Get <ApplicationUserManager>("AspNet.Identity.Owin:" + typeof(ApplicationUserManager).AssemblyQualifiedName); if (userManager != null) { AccountServer acc = new AccountServer(); var user = acc.ValidUserByUserNameAndPwd(context.UserName, context.Password); if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect"); //return; return(Task.FromResult <object>(null)); } var identity = new ClaimsIdentity( new GenericIdentity(context.UserName, OAuthDefaults.AuthenticationType), context.Scope.Select(x => new Claim("urn:oauth:scope", x))); context.Validated(identity); } return(Task.FromResult(0)); }
private static Task RunServers(CancellationToken token) { var webServer = AccountServer.CreateWebServer($"http://*:{Configuration.Global.WebPort}/"); var webTask = webServer.RunAsync(token); var gameServer = new GameServer(IPAddress.Any, Convert.ToInt32(Configuration.Global.GamePort)); gameServer.OptionNoDelay = true; var gameTask = Task.Run(async() => { gameServer.Start(); while (!token.IsCancellationRequested) { // Wait await Task.Delay(10, token); } // Calling stop gameServer.Stop(); }, token); return(Task.WhenAll(webTask, gameTask)); }
public async void UpdateAccountsDBAsync(string path) { try { GetToken(User); bool isAccounts = true; if (path != "accounts/") { isAccounts = false; } var fromServer = await AccountServer.Get(path, User.Token); foreach (Account newItem in fromServer) { Account item = db.Accounts.SingleOrDefault(it => it.Id2 == newItem.Id); if (item == null) { newItem.IsAccount = isAccounts; newItem.User = User; await AddItemAsync(newItem); } else { if (item.UpdateTime < newItem.UpdateTime) { if (item.Title != newItem.Title) { item.Title = newItem.Title; } if (item.Balance != newItem.Balance) { item.Balance = newItem.Balance; } if (item.TotalSum != newItem.TotalSum) { item.TotalSum = newItem.TotalSum; } await UpdateItemAsync(item); } else { if (item.Title != newItem.Title) { newItem.Title = item.Title; } if (item.Balance != newItem.Balance) { newItem.Balance = item.Balance; } if (item.TotalSum != newItem.TotalSum) { newItem.TotalSum = item.TotalSum; } AccountServer.Update(newItem, User.Token); } } } var fromLocal = db.Accounts.Where(item => item.User.Id == User.Id && item.IsAccount == isAccounts).Include(i => i.User).ToList(); foreach (Account newItem in fromLocal) { Account itemFromServer = fromServer.SingleOrDefault(item => item.Id == newItem.Id2); if (itemFromServer == null) { newItem.Id2 = AccountServer.Add(newItem, User.Token).Id; try { await UpdateItemAsync(newItem); } catch (Exception e) { Console.WriteLine(e); } } else { if (newItem.UpdateTime < itemFromServer.UpdateTime) { if (newItem.Title != itemFromServer.Title) { newItem.Title = itemFromServer.Title; } if (newItem.Balance != itemFromServer.Balance) { newItem.Balance = itemFromServer.Balance; } if (newItem.TotalSum != itemFromServer.TotalSum) { newItem.TotalSum = itemFromServer.TotalSum; } try { await UpdateItemAsync(newItem); } catch (Exception e) { Console.WriteLine(e); } } else { if (itemFromServer.Title != newItem.Title) { itemFromServer.Title = newItem.Title; } if (itemFromServer.Balance != newItem.Balance) { itemFromServer.Balance = newItem.Balance; } if (itemFromServer.TotalSum != newItem.TotalSum) { itemFromServer.TotalSum = newItem.TotalSum; } AccountServer.Update(itemFromServer, User.Token); } } } } catch (Exception e) { Console.WriteLine(e); } }
/// <summary> /// /// </summary> /// <param name="plexServerClient">Plex Server Client</param> /// <param name="plexLibraryClient">Plex Library Client</param> /// <param name="accountServer">Account Server Object</param> /// <exception cref="ArgumentNullException">Invalid Account Server</exception> public Server(IPlexServerClient plexServerClient, IPlexLibraryClient plexLibraryClient, AccountServer accountServer) { this.plexServerClient = plexServerClient ?? throw new ArgumentNullException(nameof(plexServerClient)); this.plexLibraryClient = plexLibraryClient ?? throw new ArgumentNullException(nameof(plexLibraryClient)); if (accountServer == null) { throw new ArgumentNullException(nameof(accountServer)); } // Map AccountServer to this Server Object (Mainly to get Access Token and Host) ObjectMapper.Mapper.Map(accountServer, this); var serverModel = plexServerClient.GetPlexServerInfo(this.AccessToken, this.Uri.ToString()).Result; ObjectMapper.Mapper.Map(serverModel, this); }
private Account login(string user, string pass) { return(AccountServer.processLogin(user, pass)); }