Guest User

Untitled

a guest
Apr 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Server.Remote
  5. {
  6. public class Accounts : MarshalByRefObject, IAccounts
  7. {
  8. private List<User> list;
  9.  
  10. public Accounts()
  11. {
  12. list = new List<User>();
  13. }
  14.  
  15. /** Login
  16. * Check if there's an User with the same username/password combo in the list
  17. * If so, return it's ID, otherwise, return -1
  18. */
  19. public int Login(String username, String password)
  20. {
  21. foreach (User u in list)
  22. {
  23. if (u.GetUsername() == username && u.GetPassword() == password)
  24. {
  25. Console.WriteLine("Sucessfull login attempt by: " + username);
  26. return u.GetID();
  27. }
  28. }
  29.  
  30. Console.WriteLine("Failed login attempt to account: " + username);
  31. return -1;
  32. }
  33.  
  34. /** Register
  35. * Check if there's an user with the same username in the database
  36. * if not, create a new one and assign it an ID (List Count Works) and return true
  37. * return false if creation failed
  38. */
  39. public Boolean Register(String username, String password)
  40. {
  41. foreach (User u in list)
  42. {
  43. if (u.GetUsername() == username)
  44. {
  45. Console.WriteLine("Registration failed, existing user: " + username);
  46. return false;
  47. }
  48. }
  49.  
  50. Console.WriteLine("Registered a new user: " + username);
  51. list.Add(new User(username, password, list.Count));
  52. return true;
  53. }
  54.  
  55. public double GetUserBalance(int user_id)
  56. {
  57. foreach (User u in list)
  58. {
  59. if (u.GetID() == user_id)
  60. {
  61. return u.GetBalance();
  62. }
  63. }
  64. return 0.0;
  65. }
  66. }
  67.  
  68. /** User Class
  69. * Simple structure containing an user's information
  70. */
  71. class User
  72. {
  73. private String username, password;
  74. private int id;
  75. private double balance = 0;
  76.  
  77. public User(String _username, String _password, int _id)
  78. {
  79. username = _username;
  80. password = _password;
  81. id = _id;
  82. }
  83.  
  84. public String GetUsername()
  85. {
  86. return username;
  87. }
  88.  
  89. public String GetPassword()
  90. {
  91. return password;
  92. }
  93.  
  94. public int GetID()
  95. {
  96. return id;
  97. }
  98.  
  99. public double GetBalance()
  100. {
  101. return balance;
  102. }
  103.  
  104. public double SetBalance(double delta)
  105. {
  106. balance += delta;
  107. return balance;
  108. }
  109. }
  110. }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123. using System;
  124. using System.Collections.Generic;
  125.  
  126. namespace Server.Remote
  127. {
  128. class TransactionCenter
  129. {
  130. private List<TransactionItem> queue_buy;
  131. private List<TransactionItem> queue_sell;
  132.  
  133. public TransactionCenter()
  134. {
  135. queue_buy = new List<TransactionItem>();
  136. queue_sell = new List<TransactionItem>();
  137. }
  138. }
  139.  
  140. class TransactionItem
  141. {
  142. private int user_id;
  143. private double amount, price;
  144.  
  145. public TransactionItem(int _user_id, double _amount, double _price)
  146. {
  147. user_id = _user_id;
  148. amount = _amount;
  149. price = _price;
  150. }
  151. }
  152. }
Add Comment
Please, Sign In to add comment