public void DeliverPoints(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); if (!ServiceProvider.GetPlayerService().Exists(user.SignalRId)) throw new ArgumentException("parameter user is not connected"); int currentPlayerPoints = GetUserPoints(user); int points = ServiceProvider.GetJobService().GetUserJobInfos(user).EarningPoints; SetUserPoints(user, points + currentPlayerPoints); }
public void DeliverPay(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); if (!ServiceProvider.GetPlayerService().Exists(user.SignalRId)) throw new ArgumentException("parameter user is not connected"); int currentPlayerAccount = GetUserBankAccount(user); int salary = ServiceProvider.GetJobService().GetUserJobInfos(user).Salary; int newAccount = currentPlayerAccount + salary; SetUserBankAccount(user, newAccount); }
public bool GetUserActivatedStatus(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return Convert.ToBoolean(ExecuteQueryInt("Activated", user)); }
private bool ExecuteUpdate(string field, string value, ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); using (SqlConnection conn = SqlConnectionService.GetConnection()) { string query = string.Format("UPDATE dbo.Users SET {0} = {1} WHERE UserId = @ConnectionId", field, value); using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@ConnectionId", user.UserId); int lines = cmd.ExecuteNonQuery(); conn.Close(); return lines != 0; } } }
private int ExecuteQueryInt(string value, ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); using (SqlConnection conn = SqlConnectionService.GetConnection()) { string query = string.Format("SELECT {0} from dbo.Users WHERE UserId = @ConnectionId", value); using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@ConnectionId", user.UserId); int data = Convert.ToInt32(cmd.ExecuteScalar()); conn.Close(); return data; } } }
public bool SetUserPoints(ServerPlayerModel user, int ammount) { if (user == null) throw new ArgumentException("parameter user is null"); return ExecuteUpdate("Points", ammount < 0 ? "0" : ammount.ToString(), user); }
public bool SetUserBankAccount(ServerPlayerModel user, int ammount) { if (user == null) throw new ArgumentException("parameter user is null"); int newAmmount = ammount; if ((ammount) <= 0) { newAmmount = 0; } return ExecuteUpdate("Account", newAmmount.ToString(), user); }
/// <summary> /// Gets all the info relating the job of the User corresponding to the provided ServerPlayerModel /// </summary> /// <param name="connectionId"></param> /// <returns>Returns a job model containing all the infos</returns> public JobModel GetUserJobInfos(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return GetUserJobInfos(user.SignalRId); }
public bool SetBan(ServerPlayerModel user, bool value) { if (user == null) throw new ArgumentException("parameter user is null"); return ExecuteUpdate("Banned", (value ? "1" : "0"), user); }
public bool IsBanned(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return Convert.ToBoolean(this.ExecuteQueryInt("Banned", user)); }
public string GetUserLogin(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return ExecuteQuery("UserLogin", user); }
public void UserLogoutSetConnectedToFalseWithPlayerModel() { TestEnvironment.DeleteTestUser(); UserModel user = TestEnvironment.GetTestUserModel(); IUserRegistrationService registrationService = TestEnvironment.GetUserRegistrationService(); registrationService.Register(user); int userId = registrationService.Connect(user); ServerPlayerModel serverPlayer = new ServerPlayerModel() { UserId = userId }; registrationService.LogOut(serverPlayer); string query = "select * from dbo.Users where UserId = @Id"; using (SqlConnection conn = SqlConnectionService.GetConnection()) { using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@Id", serverPlayer.UserId); var data = cmd.ExecuteReader(); while (data.Read()) { Assert.AreEqual(data["Connected"], false); } conn.Close(); } } TestEnvironment.DeleteTestUser(); }
/// <summary> /// Try to move a player to a specified location /// </summary> /// <param name="player"></param> /// <param name="to"></param> /// <param name="direction"></param> /// <returns></returns> public bool TryMovePlayerTo(ServerPlayerModel player, Vector2 to, EPlayerDirection direction) { return MovePlayerTo(player, to, direction); }
/// <summary> /// Move a given user to the specified destination /// </summary> /// <param name="player"></param> /// <param name="to"></param> public bool MovePlayerTo(ServerPlayerModel player, Vector2 to, EPlayerDirection direction) { return MovePlayerTo(player.SignalRId, to, direction); }
public int GetUserBankAccount(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return (ExecuteQueryInt("Account", user)); }
public bool SetUserActivatedStatus(ServerPlayerModel user, bool value) { if (user == null) throw new ArgumentException("parameter user is null"); return ExecuteUpdate("Activated", (value ? 1 : 0).ToString(), user); }
public List<ServerPropertyModel> GetUserProperties(ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); using (SqlConnection conn = SqlConnectionService.GetConnection()) { string query = ("SELECT l.ListPropertyId, l.NameProperty, l.PropertyDescription, l.Threshold, l.Price from dbo.UserProperties p JOIN dbo.Users u on p.UserId = u.UserId JOIN dbo.ListProperties l ON l.ListPropertyId = p.ListPropertyId WHERE p.UserId = @id"); using (SqlCommand cmd = new SqlCommand(query, conn)) { List<ServerPropertyModel> Properties = new List<ServerPropertyModel>(); conn.Open(); cmd.Parameters.AddWithValue("@id", user.UserId); var reader = cmd.ExecuteReader(); while (reader.Read()) { ServerPropertyModel propertyModel = new ServerPropertyModel(); propertyModel.PropertyId = Convert.ToInt32(reader["ListPropertyId"]); propertyModel.PropertyName = (reader["NameProperty"]).ToString(); propertyModel.PropertyDescription = (reader["PropertyDescription"]).ToString(); propertyModel.Threshold = Convert.ToInt32(reader["Threshold"]); propertyModel.Price = Convert.ToInt32(reader["Price"]); Properties.Add(propertyModel); } conn.Close(); return Properties; } } }
/// <summary> /// Change the Job of a User /// </summary> /// <param name="jobId">The new job Id</param> /// <param name="user">The user</param> /// <returns>True if success, else false</returns> public bool ChangeUserJob(int jobId, ServerPlayerModel user) { if (user == null) throw new ArgumentException("parameter user is null"); return ChangeUserJob(jobId, user.SignalRId); }