Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mods] Captain #384

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reporting a Vulnerability

Contact a @Mod Developer on [Discord](https://discord.gg/c-rpg) or send an
email to [hello@c-rpg.eu](mailto:hello@c-rpg.eu).
email to [hello@namidaka.fr](mailto:hello@namidaka.fr).
36 changes: 16 additions & 20 deletions deploy/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,24 @@ steam_api_key: !vault |

epic_games_client_secret: !vault |
$ANSIBLE_VAULT;1.1;AES256
30633266323035383864653436643932396433663739313636613531313732623064643462636161
6330386538663935316566343730343130663662396130610a643363666138316337356164303234
64343039343232346562363162653934626562376631316563613565396163356264356636313663
6236383639633361380a373535306563326538643638376463363630323930326235643837373165
35303537386133376264663038626164373164373666383866633332333163643835373734306532
6333353234666531373062623732323437393337633037303435

61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434
microsoft_client_secret: !vault |
$ANSIBLE_VAULT;1.1;AES256
65336566656238663362376330353964333330303266663633616635326333363437653539333737
3439333666343931353632636334666466323431373964350a663864376464326137323932313666
34373462353133626337353134333064346538326636336632393266306339616131353835303133
6631663465353164350a633961323336356338373835613662376263333533613839313332306231
61626232356330653561626130313136393361373464353863663635353830396135643537303030
3563386630386336353465376130643462383132343063383131

61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434
crpg_game_server_api_secret: !vault |
$ANSIBLE_VAULT;1.1;AES256
32326433613332653435346566636265643466643030643234383735333663383433663836656334
6263343930313465663436303339343262633130653864340a306439393363616435613732323437
31643762313537653230353636346363383430393765653933303665336339616264316138663038
3435316531373164640a616437393663666161653465303461306334623362343034386637356162
62353136616336613035623733333161333235366361643733336534343564643065
37326237663864613932666364383863373430303930353934326662313034306137306432303531
3830373066613633333165356230626163613233383937300a613736646331303631333536643163
37363938643363346530346166653733396264313036343238636536653837646564326132353936
3836613332616234360a383330306238386639653539333732663439353438306437643636313539
63383937363866363633653933623336613564616339303832303637633065393233

crpg_api_domain_name: api.c-rpg.eu
crpg_api_domain_name: api.namidaka.fr
76 changes: 38 additions & 38 deletions deploy/group_vars/centralservers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

ansible_sudo_pass: !vault |
$ANSIBLE_VAULT;1.1;AES256
66323536646461616430383436323736313532653037363330346537336431666432366361653438
3332333437643932353834383338336363616635306362610a623032656162623466653239613437
39393333333334613531333930336562323637643135303338363365653837643634366131646163
6464396461366162300a383766366539633839393539346439653662313334363565333731353236
32393961366339366233393731383165373039346638313661323864353130363835
32326165616133323332366631633136663436323037633536643730363333313234356538303437
3036326266636130353664326263313165333036313034330a306537376130376636323062303863
30666637363636626236393832333163653162666337343137326339666232663434626532343539
3733376466396562650a633061383938306533316235366163356239356666656166396334663137
3439

crpg_reverse_proxy_service_name: crpg-reverse-proxy

Expand All @@ -18,18 +18,18 @@ crpg_api_log_file: "/var/log/crpg/{{ crpg_api_service_name }}.log"

crpg_ui_path: "/var/www/{{ crpg_domain_name }}"

crpg_domain_name: c-rpg.eu
crpg_domain_name: namidaka.fr

crpg_db_service_name: crpg-db
crpg_db: crpg
crpg_db_user: crpg
crpg_db_user_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
38303737393930623462303066366563363435616265376637656538383336373931333532326362
3364653166383839383735346266336661613566373265650a613637626666656635653134623165
38626562646536376361343732396539373764663132663262333566326339383239653065356138
3434356465313665390a643036346635343562646136653063646166366264396664313530326334
3163
36666130613663333435323864656237653566383531326463383433343831363038303732656131
3662643863663838396534643766616262626365346563650a623136393037343630313063653561
31363665626230626535323437623461323037656631303564323864643265616461613963333263
6338623462376663340a313138616563353562313738643862343533396563646431363639616563
32666435623364313032643564306565646131346430336134613032393033336436

datadog_db_user: dd-agent # Same username as Datadog agent so ident authentication can be used

Expand All @@ -40,21 +40,19 @@ datadog_opentracing_version: 1.3.5

datadog_api_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
63336331303239353839636366306365663262326338343831616564396133386631616539386636
6436303036373834386662363836623266336536376365330a653532333535666436353230623332
34386236323063306233383730343034333632643532396532353962653335393863653139653336
3730653536623865660a356565313035373337313030613966646164623736623937626464373966
66663735636134326334333164343430616634623761326163316434306530363833626236633430
6537393033613533636438646634643235666337383030336130
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434

datadog_application_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
33323830303038316239393336613633303062613765303737343364663533393462396439353865
6232646534353762356632656436653863383661643961620a366337396531313032636665646331
65373062643737353431656238623264613239326364623939623566393631373035386364383363
6330363838333033390a366637373134626562373132333938613630653036313738636531666337
65346338633837646361386362393363336461383065346338353530623461643930326632326565
3239616561353364363634616233333934633865633262393137
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434

datadog_checks:
nginx:
Expand Down Expand Up @@ -192,21 +190,23 @@ patreon_access_token: !vault |

afdian_access_token: !vault |
$ANSIBLE_VAULT;1.1;AES256
39343663386135383239343237633366373636376337643731376638306231376163626238643838
3861323337343066623666373761643837313838313763340a333364353066303366643331626232
32616234373235663231393462636664396263623361646564616431663961616465383035383734
6665353666386261620a383036633833303030623837366330333938613265373563663639316639
62623365356162663637343239306532623761326334636132613339323736323062666332623766
6237373533363461343439303630356438376337343765386232
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434

github_access_token: !vault |
$ANSIBLE_VAULT;1.1;AES256
37396232626466353962303235373030326335363866303362643234616461663830646530363565
3038346164373634623838313365313639376133313331390a663064393837323239326662393635
63373237626336616634313132343231303161633131653461393366303762393737653139613234
6166363334326462320a346637383135343666653636326439386138303536396562353232663439
63356232643334373836376131656334626661383363376132626461663130376233343038326138
32373966363261303935383465323834386131626138326235623363623661323430666238623730
62376330336330653737353036346237306539623233333731363463313531336433623338373332
63353162313034363131376130366565646565613533626631383337663834626331396235626131
3263
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434
afdian_access_token: !vault |
$ANSIBLE_VAULT;1.1;AES256
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434
8 changes: 8 additions & 0 deletions deploy/group_vars/gameservers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ bannerlord_server_bin_path: "{{ bannerlord_server_path }}/bin/Linux64_Shipping_S
crpg_module_path: "{{ bannerlord_server_path }}/Modules/cRPG"

crpg_game_server_id: "{{ ansible_hostname | regex_replace('^crpg(\\d\\d)$', '\\1') }}"

steam_user_name: !vault |
$ANSIBLE_VAULT;1.1;AES256
61353865653665623739633563633933626564623130343662643336363134343166313135663863
6565313738343862346631353435373432313062646330350a343836326233353239663739336331
34393762366338333333343635316562633162653932663138306432376431643363323762633430
6465316635666365610a336564363433646161363632646665363236383936636134613164323462
6434
41 changes: 0 additions & 41 deletions deploy/host_vars/crpg02.c-rpg.eu.yml

This file was deleted.

4 changes: 2 additions & 2 deletions deploy/hosts.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[centralservers]
c-rpg.eu
namidaka.fr

[gameservers]
crpg03.c-rpg.eu
crpg03.namidaka.fr
11 changes: 6 additions & 5 deletions deploy/roles/geoip/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ geoip_path: /usr/share/geoip

maxmind_license_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
62613238363266343034336663373161383734336665303730663639373362306166623734303231
3636373937376336363763396635323562393861653939610a313565366163313731303562623430
63363564366133303330376462333361353164363731633261313931326162613238343635636266
3861643032326339660a646463363936333862303361626133333039303737306462366430316331
31373738653833333463373465333337646236393233623563336133616532396638
34633832353166333731333634653537373538613431313135333839353633323235653434326131
6165653032383033333839326365623731363663663765610a396265623834623331386438623330
62373939383566356565393763373637663962363531346164306164663363343435623037303935
3365333665343831660a383333353734653030383035613834353737623639336163616462306662
38643836316462336435316466653333326361343833643865393061656466353963623364356638
3664376239346334303934353962666161373731313965656632
75 changes: 75 additions & 0 deletions src/Application/Captains/Commands/GetUserCaptainCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using AutoMapper;
using Crpg.Application.Captains.Models;
using Crpg.Application.Common.Interfaces;
using Crpg.Application.Common.Mediator;
using Crpg.Application.Common.Results;
using Crpg.Domain.Entities.Captains;
using FluentValidation;
using Microsoft.EntityFrameworkCore;

namespace Crpg.Application.Captains.Commands;

/// <summary>
/// Get or create a user with its character.
/// </summary>
public record GetUserCaptainCommand : IMediatorRequest<CaptainViewModel>
{
public int UserId { get; init; }
public class Validator : AbstractValidator<CaptainViewModel>
{
public Validator()
{
}
}

internal class Handler : IMediatorRequestHandler<GetUserCaptainCommand, CaptainViewModel>
{
private readonly ICrpgDbContext _db;
private readonly IMapper _mapper;

public Handler(ICrpgDbContext db, IMapper mapper)
{
_db = db;
_mapper = mapper;
}

public async Task<Result<CaptainViewModel>> Handle(GetUserCaptainCommand req, CancellationToken cancellationToken)
{
var user = await _db.Users
.Where(u => u.Id == req.UserId)
.Include(u => u.Captain)
.FirstOrDefaultAsync(cancellationToken);
if (user == null)
{
return new(CommonErrors.UserNotFound(req.UserId));
}

if (user.Captain == null)
{
user.Captain = CreateCaptain(req.UserId);
_db.Captains.Add(user.Captain);

await _db.SaveChangesAsync(cancellationToken);
}

var gameUser = _mapper.Map<CaptainViewModel>(user.Captain);
return new(gameUser);
}

private Captain CreateCaptain(int userId)
{
Captain captain = new()
{
UserId = userId,
Formations = new List<CaptainFormation>()
{
new() { Number = 1, Weight = 33 },
new() { Number = 2, Weight = 33 },
new() { Number = 3, Weight = 33 },
},
};

return captain;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using AutoMapper;
using Crpg.Application.Captains.Models;
using Crpg.Application.Common.Interfaces;
using Crpg.Application.Common.Mediator;
using Crpg.Application.Common.Results;
using Microsoft.EntityFrameworkCore;

namespace Crpg.Application.Captains.Commands;

public record UpdateFormationCharacterCommand : IMediatorRequest<CaptainFormationViewModel>
{
public int? CharacterId { get; init; }
public int UserId { get; init; }
public int Number { get; init; }

internal class Handler : IMediatorRequestHandler<UpdateFormationCharacterCommand, CaptainFormationViewModel>
{
private readonly ICrpgDbContext _db;

private readonly IMapper _mapper;

public Handler(ICrpgDbContext db, IMapper mapper)
{
_db = db;
_mapper = mapper;
}

public async Task<Result<CaptainFormationViewModel>> Handle(UpdateFormationCharacterCommand req, CancellationToken cancellationToken)
{
var captain = await _db.Captains
.Where(c => c.UserId == req.UserId)
.Select(c => new
{
Formation = c.Formations.FirstOrDefault(f => f.Number == req.Number),
})
.FirstOrDefaultAsync(cancellationToken);

if (captain?.Formation == null)
{
return new(CommonErrors.CaptainFormationNotFound(req.Number, req.UserId));
}

if (req.CharacterId == null) {

Check warning on line 43 in src/Application/Captains/Commands/UpdateFormationCharacterCommand.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 43 in src/Application/Captains/Commands/UpdateFormationCharacterCommand.cs

View workflow job for this annotation

GitHub Actions / build

captain.Formation.CharacterId = null;
await _db.SaveChangesAsync(cancellationToken);
return new(_mapper.Map<CaptainFormationViewModel>(captain.Formation));
}

var character = await _db.Characters
.FirstOrDefaultAsync(c => c.UserId == req.UserId && c.Id == req.CharacterId.Value, cancellationToken);
if (character == null)
{
return new(CommonErrors.CharacterNotFound(req.CharacterId.Value, req.UserId));
}

if (character.ForTournament)
{
return new(CommonErrors.CharacterForTournament(req.CharacterId.Value));
}

captain.Formation.CharacterId = req.CharacterId.Value;

await _db.SaveChangesAsync(cancellationToken);
return new(_mapper.Map<CaptainFormationViewModel>(captain.Formation));
}
}
}
Loading
Loading