Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Application/GunGames/Results/PlayerLeveledDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void Handle(KillContext context)
Level = victimProgression.WeaponLevel,
Weapon = newWeapon.Name
});

worldService.SendClientMessage(Color.Yellow, message);
}
}
1 change: 1 addition & 0 deletions src/Application/GunGames/Results/PlayerLeveledUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Handle(KillContext context)
Level = killerProgression.WeaponLevel,
Weapon = newWeapon.Name
});

worldService.SendClientMessage(Color.Yellow, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void Handle(KillContext context)
Killer = context.Killer.Name,
Weapon = newWeapon.Name
});

worldService.SendClientMessage(Color.Yellow, message);
}
}
8 changes: 7 additions & 1 deletion src/Application/GunGames/Results/PlayerScoredFinalKill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
/// Handles the <see cref="GunGameResult.ScoredFinalKill"/> result.
/// </summary>
public class PlayerScoredFinalKill(
IWorldService worldService) : IGunGameResultHandler
IWorldService worldService,
IPlayerRepository playerRepository) : IGunGameResultHandler
{
public GunGameResult Result => GunGameResult.ScoredFinalKill;

public void Handle(KillContext context)
{
PlayerInfo killerInfo = context.Killer.GetRequiredInfo();
killerInfo.AddGunGameWins();
playerRepository.UpdateGunGameWins(killerInfo);

var message = Smart.Format(GunGameMessages.PlayerScoredFinalKill, new
{
Killer = context.Killer.Name
});

worldService.SendClientMessage(Color.Gold, message);
}
}
1 change: 1 addition & 0 deletions src/Application/Players/Accounts/IPlayerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IPlayerRepository
void UpdateDroppedFlags(PlayerInfo player);
void UpdateReturnedFlags(PlayerInfo player);
void UpdateHeadShots(PlayerInfo player);
void UpdateGunGameWins(PlayerInfo player);
void UpdateRole(PlayerInfo player);
void UpdateSkin(PlayerInfo player);
void UpdateRank(PlayerInfo player);
Expand Down
7 changes: 7 additions & 0 deletions src/Application/Players/Accounts/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public PlayerInfo() { }
/// Indicates the number of shots that the player has made at the heads of other players.
/// </summary>
public int HeadShots { get; private set; }

/// <summary>
/// Indicates the number of times the player has won a GunGame match.
/// </summary>
public int GunGameWins { get; private set; }

public RoleId RoleId { get; private set; } = RoleId.Basic;
public int SkinId { get; private set; } = NoSkin;
public RankId RankId { get; private set; } = RankId.Noob;
Expand Down Expand Up @@ -80,6 +86,7 @@ public PlayerInfo() { }
public void AddDroppedFlags() => DroppedFlags++;
public void AddReturnedFlags() => ReturnedFlags++;
public void AddHeadShots() => HeadShots++;
public void AddGunGameWins() => GunGameWins++;

public Result SetName(string value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private static string GetPlayerContent(Player player)
Dropped Flags: {playerInfo.DroppedFlags}
Returned Flags: {playerInfo.ReturnedFlags}
HeadShots: {playerInfo.HeadShots}
GunGame Wins: {playerInfo.GunGameWins}
Role: {playerInfo.RoleId}
Rank: {playerInfo.RankId}
Registration Date: {createdAt}
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/Persistence.InMemory/FakePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public FakePlayer(string name, string passwordHash)
public int DroppedFlags { get; set; }
public int ReturnedFlags { get; set; }
public int HeadShots { get; set; }
public int GunGameWins { get; set; }
public int SkinId { get; set; } = NoSkin;
public RoleId RoleId { get; set; } = RoleId.Basic;
public RankId RankId { get; set; } = RankId.Noob;
Expand Down
22 changes: 21 additions & 1 deletion src/Persistence/Persistence.InMemory/FakePlayerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ internal class FakePlayerRepository(
public void Create(PlayerInfo player)
{
var passwordHash = passwordHasher.HashPassword(player.Password);
var fakePlayer = new FakePlayer(player.Name, passwordHash);
var fakePlayer = new FakePlayer(player.Name, passwordHash)
{
TotalKills = player.TotalKills,
TotalDeaths = player.TotalDeaths,
MaxKillingSpree = player.MaxKillingSpree,
BroughtFlags = player.BroughtFlags,
CapturedFlags = player.CapturedFlags,
DroppedFlags = player.DroppedFlags,
ReturnedFlags = player.ReturnedFlags,
HeadShots = player.HeadShots,
GunGameWins = player.GunGameWins,
SkinId = player.SkinId,
RoleId = player.RoleId,
RankId = player.RankId,
CreatedAt = player.CreatedAt,
LastConnection = player.LastConnection
};
players.Add(fakePlayer.Id, fakePlayer);
// The Account ID is immutable and lacks a public setter; Reflection is used to modify it.
player.SetValue(value: fakePlayer.Id, propertyName: nameof(PlayerInfo.AccountId));
Expand Down Expand Up @@ -47,6 +63,7 @@ public PlayerInfo GetOrDefault(string name)
playerInfo.SetValue(value: fakePlayer.DroppedFlags, propertyName: nameof(PlayerInfo.DroppedFlags));
playerInfo.SetValue(value: fakePlayer.ReturnedFlags, propertyName: nameof(PlayerInfo.ReturnedFlags));
playerInfo.SetValue(value: fakePlayer.HeadShots, propertyName: nameof(PlayerInfo.HeadShots));
playerInfo.SetValue(value: fakePlayer.GunGameWins, propertyName: nameof(PlayerInfo.GunGameWins));
playerInfo.SetValue(value: fakePlayer.CreatedAt, propertyName: nameof(PlayerInfo.CreatedAt));
playerInfo.SetValue(value: fakePlayer.LastConnection, propertyName: nameof(PlayerInfo.LastConnection));
return playerInfo;
Expand All @@ -67,6 +84,9 @@ public void UpdateReturnedFlags(PlayerInfo player)
public void UpdateHeadShots(PlayerInfo player)
=> players[player.AccountId].HeadShots = player.HeadShots;

public void UpdateGunGameWins(PlayerInfo player)
=> players[player.AccountId].GunGameWins = player.GunGameWins;

public void UpdateLastConnection(PlayerInfo player)
=> players[player.AccountId].LastConnection = player.LastConnection;

Expand Down
5 changes: 5 additions & 0 deletions src/Persistence/Persistence.MariaDB/PlayerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void Create(PlayerInfo player)
command.Parameters.AddWithValue("@dropped_flags", player.DroppedFlags);
command.Parameters.AddWithValue("@returned_flags", player.ReturnedFlags);
command.Parameters.AddWithValue("@head_shots", player.HeadShots);
command.Parameters.AddWithValue("@gungame_wins", player.GunGameWins);
command.Parameters.AddWithValue("@role_id", player.RoleId.ToString());
command.Parameters.AddWithValue("@skin_id", player.SkinId);
command.Parameters.AddWithValue("@rank_id", player.RankId);
Expand Down Expand Up @@ -81,6 +82,7 @@ public PlayerInfo GetOrDefault(string name)
playerInfo.SetValue(value: reader.GetInt32("dropped_flags"), propertyName: nameof(PlayerInfo.DroppedFlags));
playerInfo.SetValue(value: reader.GetInt32("returned_flags"), propertyName: nameof(PlayerInfo.ReturnedFlags));
playerInfo.SetValue(value: reader.GetInt32("head_shots"), propertyName: nameof(PlayerInfo.HeadShots));
playerInfo.SetValue(value: reader.GetInt32("gungame_wins"), propertyName: nameof(PlayerInfo.GunGameWins));
playerInfo.SetValue(value: reader.GetDateTime("created_at"), propertyName: nameof(PlayerInfo.CreatedAt));
playerInfo.SetValue(value: reader.GetDateTime("last_connection"), propertyName: nameof(PlayerInfo.LastConnection));
return playerInfo;
Expand All @@ -101,6 +103,9 @@ public void UpdateReturnedFlags(PlayerInfo player)
public void UpdateHeadShots(PlayerInfo player)
=> Update(player.AccountId, "head_shots", player.HeadShots);

public void UpdateGunGameWins(PlayerInfo player)
=> Update(player.AccountId, "gungame_wins", player.GunGameWins);

public void UpdateLastConnection(PlayerInfo player)
=> Update(player.AccountId, "last_connection", player.LastConnection);

Expand Down
2 changes: 2 additions & 0 deletions src/Persistence/Persistence.MariaDB/sql/players.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ INSERT INTO players
dropped_flags,
returned_flags,
head_shots,
gungame_wins,
role_id,
skin_id,
rank_id,
Expand All @@ -28,6 +29,7 @@ VALUES (
@dropped_flags,
@returned_flags,
@head_shots,
@gungame_wins,
@role_id,
@skin_id,
@rank_id,
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/Persistence.MariaDB/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS players (
dropped_flags int(11) NOT NULL CHECK(dropped_flags >= 0),
returned_flags int(11) NOT NULL CHECK(returned_flags >= 0),
head_shots int(11) NOT NULL CHECK(head_shots >= 0),
gungame_wins int(11) NOT NULL CHECK(gungame_wins >= 0),
role_id enum('Basic','VIP','Moderator','Admin') NOT NULL,
skin_id int(11) NOT NULL CHECK(skin_id >= -1 AND skin_id <= 311),
rank_id int(11) NOT NULL CHECK(rank_id >= 0 AND rank_id <= 14),
Expand Down
128 changes: 99 additions & 29 deletions src/Persistence/Persistence.MariaDB/sql/seed_data.sql
Original file line number Diff line number Diff line change
@@ -1,36 +1,106 @@
-- name: InitializeSeedData
DELETE FROM players;
ALTER TABLE players AUTO_INCREMENT = 1;
INSERT INTO players
(
name,
password,
total_kills,
total_deaths,
max_killing_spree,
brought_flags,
captured_flags,
dropped_flags,
returned_flags,
head_shots,
role_id,
skin_id,
rank_id,
created_at,
last_connection
INSERT INTO players
(
name,
password,
total_kills,
total_deaths,
max_killing_spree,
brought_flags,
captured_flags,
dropped_flags,
returned_flags,
head_shots,
gungame_wins,
role_id,
skin_id,
rank_id,
created_at,
last_connection
)
VALUES
('Admin_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,'Admin',146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Moderator_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,'Moderator',146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('VIP_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,'VIP',146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',0,0,0,0,0,0,0,0,'Basic',146,0,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(2)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',150,0,10,0,0,0,0,0,'Basic',131,3,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(3)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',160,0,15,0,0,0,0,0,'Basic',140,3,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(4)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',170,0,20,0,0,0,0,0,'Basic',137,3,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(5)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',200,0,25,0,0,0,0,0,'Basic',100,4,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(6)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',251,0,50,0,0,0,0,0,'Basic',98,5,'2023-10-12 12:19:24','2023-10-13 12:19:24'),
('Basic_Player(7)','$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',200,0,30,0,0,0,0,0,'Basic',150,4,'2023-10-12 12:19:24','2023-10-13 12:19:24')
;
VALUES
(
'Admin_Player',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
0, 0, 0, 0, 0, 0, 0, 0, 0,
'Admin', 146, 0,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Moderator_Player',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
0, 0, 0, 0, 0, 0, 0, 0, 0,
'Moderator', 146, 0,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'VIP_Player',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
0, 0, 0, 0, 0, 0, 0, 0, 0,
'VIP', 146, 0,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
0, 0, 0, 0, 0, 0, 0, 0, 0,
'Basic', 146, 0,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(2)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
150, 0, 10, 0, 0, 0, 0, 0, 0,
'Basic', 131, 3,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(3)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
160, 0, 15, 0, 0, 0, 0, 0, 0,
'Basic', 140, 3,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(4)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
170, 0, 20, 0, 0, 0, 0, 0, 0,
'Basic', 137, 3,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(5)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
200, 0, 25, 0, 0, 0, 0, 0, 0,
'Basic', 100, 4,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(6)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
251, 0, 50, 0, 0, 0, 0, 0, 0,
'Basic', 98, 5,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
),
(
'Basic_Player(7)',
'$2a$10$60QnEiafBCLfVBMfQkExVeolyBxVHWcSQKTvkxVJj9FUozRpRP/GW',
200, 0, 30, 0, 0, 0, 0, 0, 0,
'Basic', 150, 4,
'2023-10-12 12:19:24',
'2023-10-13 12:19:24'
);

-- name: RemoveSeedData
DELETE FROM players;
5 changes: 5 additions & 0 deletions src/Persistence/Persistence.SQLite/PlayerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void Create(PlayerInfo player)
command.Parameters.AddWithValue("$dropped_flags", player.DroppedFlags);
command.Parameters.AddWithValue("$returned_flags", player.ReturnedFlags);
command.Parameters.AddWithValue("$head_shots", player.HeadShots);
command.Parameters.AddWithValue("$gungame_wins", player.GunGameWins);
command.Parameters.AddWithValue("$role_id", player.RoleId);
command.Parameters.AddWithValue("$skin_id", player.SkinId);
command.Parameters.AddWithValue("$rank_id", player.RankId);
Expand Down Expand Up @@ -81,6 +82,7 @@ public PlayerInfo GetOrDefault(string name)
playerInfo.SetValue(value: reader.GetInt32("dropped_flags"), propertyName: nameof(PlayerInfo.DroppedFlags));
playerInfo.SetValue(value: reader.GetInt32("returned_flags"), propertyName: nameof(PlayerInfo.ReturnedFlags));
playerInfo.SetValue(value: reader.GetInt32("head_shots"), propertyName: nameof(PlayerInfo.HeadShots));
playerInfo.SetValue(value: reader.GetInt32("gungame_wins"), propertyName: nameof(PlayerInfo.GunGameWins));
playerInfo.SetValue(value: reader.GetDateTime("created_at"), propertyName: nameof(PlayerInfo.CreatedAt));
playerInfo.SetValue(value: reader.GetDateTime("last_connection"), propertyName: nameof(PlayerInfo.LastConnection));
return playerInfo;
Expand All @@ -101,6 +103,9 @@ public void UpdateReturnedFlags(PlayerInfo player)
public void UpdateHeadShots(PlayerInfo player)
=> Update(player.AccountId, "head_shots", player.HeadShots);

public void UpdateGunGameWins(PlayerInfo player)
=> Update(player.AccountId, "gungame_wins", player.GunGameWins);

public void UpdateLastConnection(PlayerInfo player)
=> Update(player.AccountId, "last_connection", player.LastConnection);

Expand Down
2 changes: 2 additions & 0 deletions src/Persistence/Persistence.SQLite/sql/players.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ INSERT INTO players
dropped_flags,
returned_flags,
head_shots,
gungame_wins,
role_id,
skin_id,
rank_id,
Expand All @@ -28,6 +29,7 @@ VALUES (
$dropped_flags,
$returned_flags,
$head_shots,
$gungame_wins,
$role_id,
$skin_id,
$rank_id,
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/Persistence.SQLite/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS players (
dropped_flags INTEGER NOT NULL CHECK(dropped_flags >= 0),
returned_flags INTEGER NOT NULL CHECK(returned_flags >= 0),
head_shots INTEGER NOT NULL CHECK(head_shots >= 0),
gungame_wins INTEGER NOT NULL CHECK(gungame_wins >= 0),
role_id INTEGER NOT NULL CHECK(role_id >= 0 AND role_id <= 3),
skin_id INTEGER NOT NULL CHECK(skin_id >= -1 AND skin_id <= 311),
rank_id INTEGER NOT NULL CHECK(rank_id >= 0 AND rank_id <= 14),
Expand Down
Loading
Loading