Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Various bug fixes
  • Loading branch information
ThorConzales authored and ThorConzales committed Aug 27, 2017
1 parent 6167865 commit 06e7fdf
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Backend/Controllers/LobbyController.cs
Expand Up @@ -64,7 +64,7 @@ public class LobbyController : Controller, IDisposable {
NegativeReputation = p.User.NegativeReputation NegativeReputation = p.User.NegativeReputation
} : null, } : null,
GameStats = p.User != null ? UserUtils.GetGameStats(p.GamesStartedRM, p.GamesStartedDM, p.GamesWonRM, p.GamesWonDM, p.GamesEndedRM, p.GamesEndedDM) : null, GameStats = p.User != null ? UserUtils.GetGameStats(p.GamesStartedRM, p.GamesStartedDM, p.GamesWonRM, p.GamesWonDM, p.GamesEndedRM, p.GamesEndedDM) : null,
}) }).ToList()
}; };
foreach (var player in lobby.Players) { foreach (var player in lobby.Players) {
LobbyUtils.CalculateUserFieldColors(player, lobby.Ranked); LobbyUtils.CalculateUserFieldColors(player, lobby.Ranked);
Expand Down
10 changes: 4 additions & 6 deletions Backend/Controllers/UserProfileController.cs
Expand Up @@ -20,8 +20,8 @@ public class UserProfileController : IDisposable {
_repository = repository; _repository = repository;
} }


[HttpGet("{id}/{lobbyId}")] [HttpGet("{id}")]
public User Get(string id, string lobbyId) { public User Get(string id) {
var user = _repository.Users.Include(u => u.LobbySlots).Include(u => u.Reputations).ThenInclude(ur => ur.Reputation).Include(u => u.Reputations).ThenInclude(u => u.Lobby).Select(u => new User { var user = _repository.Users.Include(u => u.LobbySlots).Include(u => u.Reputations).ThenInclude(ur => ur.Reputation).Include(u => u.Reputations).ThenInclude(u => u.Lobby).Select(u => new User {
Id = u.Id, Id = u.Id,
SSteamId = u.SteamId.ToString(), SSteamId = u.SteamId.ToString(),
Expand Down Expand Up @@ -61,10 +61,8 @@ public class UserProfileController : IDisposable {
} : null } : null
}).ToList() }).ToList()
}).FirstOrDefault(u => u.SSteamId == id); }).FirstOrDefault(u => u.SSteamId == id);
user.GameStats = UserUtils.GetGameStats(user.GamesStartedRM, user.GamesStartedDM, user.GamesWonRM, user.GamesWonRM, user.GamesEndedRM, user.GamesEndedDM); user.GameStats = UserUtils.GetGameStats(user.GamesStartedRM, user.GamesStartedDM, user.GamesWonRM, user.GamesWonDM, user.GamesEndedRM, user.GamesEndedDM);
var longLobbyId = ulong.Parse(lobbyId); LobbyUtils.CalculateUserFieldColors(user, 0);
var lobby = _repository.Lobbies.FirstOrDefault(l => l.LobbyId == longLobbyId);
LobbyUtils.CalculateUserFieldColors(user, lobby.Ranked);
return user; return user;
} }


Expand Down
28 changes: 28 additions & 0 deletions Backend/Jobs/NetHookDumpReaderJob.cs
Expand Up @@ -113,11 +113,39 @@ public class NetHookDumpReaderJob {
private void ProcessCreateLobbyResponse(NetHookItem item) { private void ProcessCreateLobbyResponse(NetHookItem item) {
var msg = item.ReadAsProtobufMsg<CMsgClientMMSCreateLobbyResponse>(); var msg = item.ReadAsProtobufMsg<CMsgClientMMSCreateLobbyResponse>();
Variables.Lobby.LobbyId = msg.Body.steam_id_lobby; Variables.Lobby.LobbyId = msg.Body.steam_id_lobby;
CheckIfReJoiningStartedLobby();
} }


private void ProcessJoinLobbyResponse(NetHookItem item) { private void ProcessJoinLobbyResponse(NetHookItem item) {
var msg = item.ReadAsProtobufMsg<CMsgClientMMSJoinLobbyResponse>(); var msg = item.ReadAsProtobufMsg<CMsgClientMMSJoinLobbyResponse>();
Variables.Lobby.LobbyId = msg.Body.steam_id_lobby; Variables.Lobby.LobbyId = msg.Body.steam_id_lobby;
CheckIfReJoiningStartedLobby();
}

private void CheckIfReJoiningStartedLobby() {
try {
using (IRepository repository = new Repository()) {
var lobby = repository.Lobbies.Include(l => l.Players).ThenInclude(p => p.User).FirstOrDefault(l => l.LobbyId == Variables.Lobby.LobbyId && l.Started.HasValue);
if (lobby != null) {
lobby.Joined = DateTime.UtcNow;
lobby.Started = null;
lobby.Sealed = false;
repository.SetModified(lobby);
repository.SaveChanges();
foreach (var player in lobby.Players.Where(p => p.Position > 0 && p.User != null)) {
try {
player.User.Games--;
repository.SetModified(player.User);
repository.SaveChanges();
} catch (Exception e) {
LogUtils.Error("Error while modifing user for re-joined lobby: "+player.User.Name, e);
}
}
}
}
} catch (Exception e) {
LogUtils.Error("Error while checking if re-joining started lobby", e);
}
} }


private void ProcessLeaderBoardUpdate(NetHookItem item) { private void ProcessLeaderBoardUpdate(NetHookItem item) {
Expand Down
3 changes: 2 additions & 1 deletion Backend/Startup.cs
Expand Up @@ -51,7 +51,8 @@ public class Startup {
app.UseMvc(); app.UseMvc();


if (Variables.ReplayMode) { if (Variables.ReplayMode) {
Variables.NethookDumpDir = @"C:\Program Files (x86)\Steam\nethook\_Aoe2HostLobby2"; //Variables.NethookDumpDir = @"C:\Program Files (x86)\Steam\nethook\_Aoe2HostLobby2";
Variables.NethookDumpDir = @"C:\Program Files (x86)\Steam\nethook\_Aoe2JoinLobby";
} else { } else {
_netHookDumpReaderJob = new NetHookDumpReaderJob(); _netHookDumpReaderJob = new NetHookDumpReaderJob();
} }
Expand Down
2 changes: 1 addition & 1 deletion Backend/Utils/UserUtils.cs
Expand Up @@ -212,7 +212,7 @@ public class UserUtils {
throw new Exception("User not found in database"); throw new Exception("User not found in database");
} }
player.ReputationStats = new PlayerReputationStats() { player.ReputationStats = new PlayerReputationStats() {
Games = 0, Games = user.Games,
PositiveReputation = user.PositiveReputation, PositiveReputation = user.PositiveReputation,
NegativeReputation = user.NegativeReputation NegativeReputation = user.NegativeReputation
}; };
Expand Down
Expand Up @@ -34,6 +34,7 @@ export class RunningSessionPageComponent implements OnInit, OnDestroy {
this.startLobbyFetcherTimer(); this.startLobbyFetcherTimer();
if (this.lobbyId == "0") { if (this.lobbyId == "0") {
this.subscriptions.push(this.appService.Events.gameStarted.subscribe(() => { this.subscriptions.push(this.appService.Events.gameStarted.subscribe(() => {
this.lobbyId = this.lobby.sLobbyId;
this.lobbyStarted = true; this.lobbyStarted = true;
this.appService.stopNethook(() => { }); this.appService.stopNethook(() => { });
this.appService.toastInfo("Lobby started!"); this.appService.toastInfo("Lobby started!");
Expand Down
Expand Up @@ -12,7 +12,7 @@
<span style="margin-right: 10px;">Location <strong>{{profile.location}}</strong></span> <span style="margin-right: 10px;">Location <strong>{{profile.location}}</strong></span>
</td> </td>
<td> <td>
<span style="margin-right: 10px;" [ngClass]="{cellColorSafe: profile.fieldColors?.Games == 1, cellColorDanger: profile.fieldColors?.Games == 2}">Shared Games <strong>{{profile.games}}</strong></span> <span style="margin-right: 10px;">Shared Games <span [ngClass]="{cellColorSafe: profile.fieldColors?.Games == 1, cellColorDanger: profile.fieldColors?.Games == 2}" style="font-weight: bold;">{{profile.games}}</span></span>
</td> </td>
<td> <td>
<i class="material-icons md-24" style="margin-right: 5px; margin-top: 7px; color: red;">thumb_down</i> <i class="material-icons md-24" style="margin-right: 5px; margin-top: 7px; color: red;">thumb_down</i>
Expand Down
Expand Up @@ -55,7 +55,7 @@ export class UserProfileDialogComponent implements OnInit {
} }


private fetchProfile() { private fetchProfile() {
this.httpService.get<UserProfile>("/api/userProfile/" + this.data.steamId + "/" + this.data.lobbyId).subscribe(response => { this.httpService.get<UserProfile>("/api/userProfile/" + this.data.steamId).subscribe(response => {
this.profile = response; this.profile = response;
this.userReputationsDataSource = new UserReputationsDataSource(response.reputations); this.userReputationsDataSource = new UserReputationsDataSource(response.reputations);
if (this.profile.knownNames.length > 1) { if (this.profile.knownNames.length > 1) {
Expand Down
6 changes: 5 additions & 1 deletion Database/Repository.cs
Expand Up @@ -71,7 +71,11 @@ public class Repository : DbContext, IRepository {
} }


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
var path = Path.Combine(Environment.GetEnvironmentVariable("AppData"), "AoE2HDLobbyCompanion\\database.db"); var databaseName = "AoE2HDLobbyCompanion\\database.db";
#if DEBUG
databaseName = "AoE2HDLobbyCompanion\\database_test.db";
#endif
var path = Path.Combine(Environment.GetEnvironmentVariable("AppData"), databaseName);
optionsBuilder.UseSqlite("Data Source=" + path); optionsBuilder.UseSqlite("Data Source=" + path);
} }
} }
Expand Down

0 comments on commit 06e7fdf

Please sign in to comment.