Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Server.Remote
- {
- public class Accounts : MarshalByRefObject, IAccounts
- {
- private List<User> list;
- public Accounts()
- {
- list = new List<User>();
- }
- /** Login
- * Check if there's an User with the same username/password combo in the list
- * If so, return it's ID, otherwise, return -1
- */
- public int Login(String username, String password)
- {
- foreach (User u in list)
- {
- if (u.GetUsername() == username && u.GetPassword() == password)
- {
- Console.WriteLine("Sucessfull login attempt by: " + username);
- return u.GetID();
- }
- }
- Console.WriteLine("Failed login attempt to account: " + username);
- return -1;
- }
- /** Register
- * Check if there's an user with the same username in the database
- * if not, create a new one and assign it an ID (List Count Works) and return true
- * return false if creation failed
- */
- public Boolean Register(String username, String password)
- {
- foreach (User u in list)
- {
- if (u.GetUsername() == username)
- {
- Console.WriteLine("Registration failed, existing user: " + username);
- return false;
- }
- }
- Console.WriteLine("Registered a new user: " + username);
- list.Add(new User(username, password, list.Count));
- return true;
- }
- public double GetUserBalance(int user_id)
- {
- foreach (User u in list)
- {
- if (u.GetID() == user_id)
- {
- return u.GetBalance();
- }
- }
- return 0.0;
- }
- }
- /** User Class
- * Simple structure containing an user's information
- */
- class User
- {
- private String username, password;
- private int id;
- private double balance = 0;
- public User(String _username, String _password, int _id)
- {
- username = _username;
- password = _password;
- id = _id;
- }
- public String GetUsername()
- {
- return username;
- }
- public String GetPassword()
- {
- return password;
- }
- public int GetID()
- {
- return id;
- }
- public double GetBalance()
- {
- return balance;
- }
- public double SetBalance(double delta)
- {
- balance += delta;
- return balance;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- namespace Server.Remote
- {
- class TransactionCenter
- {
- private List<TransactionItem> queue_buy;
- private List<TransactionItem> queue_sell;
- public TransactionCenter()
- {
- queue_buy = new List<TransactionItem>();
- queue_sell = new List<TransactionItem>();
- }
- }
- class TransactionItem
- {
- private int user_id;
- private double amount, price;
- public TransactionItem(int _user_id, double _amount, double _price)
- {
- user_id = _user_id;
- amount = _amount;
- price = _price;
- }
- }
- }
Add Comment
Please, Sign In to add comment