More match progress

This commit is contained in:
jvyden 2021-10-25 02:38:03 -04:00
parent 20316be3c6
commit e7d3d6bd02
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
5 changed files with 83 additions and 28 deletions

View file

@ -9,6 +9,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=farc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kettu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lbpme/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=LBPU/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lolcatftw/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Swingy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=thumbsup/@EntryIndexedValue">True</s:Boolean>

View file

@ -1,4 +1,5 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -23,45 +24,52 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
[HttpPost("match")]
[Produces("text/json")]
public async Task<IActionResult> Match() {
// User? user = await this.database.UserFromRequest(this.Request);
//
// if(user == null) return this.StatusCode(403, "");
User? user = await this.database.UserFromRequest(this.Request);
if(user == null) return this.StatusCode(403, "");
#region Parse match data
// Example POST /match: [UpdateMyPlayerData,["Player":"FireGamer9872"]]
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
if(bodyString.Contains("FindBestRoom")) {
return this.Ok("[{\"StatusCode\":200},{\"Players\":[{\"PlayerId\":\"literally1984\",\"matching_res\":0},{\"PlayerId\":\"jvyden\",\"matching_res\":1}],\"Slots\":[[5,0]],\"RoomState\":\"E_ROOM_IN_POD\",\"HostMood\":\"E_MOOD_EVERYONE\",\"LevelCompletionEstimate\":0,\"PassedNoJoinPoint\":0,\"MoveConnected\":false,\"Location\":[\"127.0.0.1\"],\"BuildVersion\":289,\"Language\":1,\"FirstSeenTimestamp\":1427331263756,\"LastSeenTimestamp\":1635112546000,\"GameId\":1,\"NatType\":2,\"Friends\":[],\"Blocked\":[],\"RecentlyLeft\":[],\"FailedJoin\":[]}]");
}
if(bodyString[0] != '[') return this.BadRequest();
string matchType = "";
IMatchData? matchData;
try {
matchData = MatchHelper.Deserialize(bodyString);
}
catch(Exception e) {
Logger.Log("Exception while parsing MatchData: " + e);
Logger.Log("Data: " + bodyString);
int i = 1;
while(true) {
if(bodyString[i] == ',') break;
matchType += bodyString[i];
i++;
return this.BadRequest();
}
string matchString = string.Concat(bodyString.Skip(matchType.Length + 2).SkipLast(1));
if(matchData == null) return this.BadRequest();
#endregion
#region Update LastMatch
// LastMatch? lastMatch = await this.database.LastMatches
// .Where(l => l.UserId == user.UserId).FirstOrDefaultAsync();
//
// // below makes it not look like trash
// // ReSharper disable once ConvertIfStatementToNullCoalescingExpression
// if(lastMatch == null) {
// lastMatch = new LastMatch {
// UserId = user.UserId,
// };
// this.database.LastMatches.Add(lastMatch);
// }
//
// lastMatch.Timestamp = TimestampHelper.Timestamp;
//
// await this.database.SaveChangesAsync();
LastMatch? lastMatch = await this.database.LastMatches
.Where(l => l.UserId == user.UserId).FirstOrDefaultAsync();
// below makes it not look like trash
// ReSharper disable once ConvertIfStatementToNullCoalescingExpression
if(lastMatch == null) {
lastMatch = new LastMatch {
UserId = user.UserId,
};
this.database.LastMatches.Add(lastMatch);
}
lastMatch.Timestamp = TimestampHelper.Timestamp;
await this.database.SaveChangesAsync();
#endregion
return this.Ok("[{\"StatusCode\":200}]");

View file

@ -1,5 +1,34 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using LBPUnion.ProjectLighthouse.Types.Match;
namespace LBPUnion.ProjectLighthouse.Helpers {
public class MatchHelper {
public static class MatchHelper {
public static IMatchData? Deserialize(string data) {
string matchType = "";
int i = 1;
while(true) {
if(data[i] == ',') break;
matchType += data[i];
i++;
}
string matchData = $"{{{string.Concat(data.Skip(matchType.Length + 3).SkipLast(2))}}}";
return Deserialize(matchType, matchData);
}
public static IMatchData? Deserialize(string matchType, string matchData) {
return matchType switch {
"UpdateMyPlayerData" => JsonSerializer.Deserialize<UpdateMyPlayerData>(matchData),
"UpdatePlayersInRoom" => JsonSerializer.Deserialize<UpdatePlayersInRoom>(matchData),
_ => null,
};
}
}
}

View file

@ -0,0 +1,9 @@
namespace LBPUnion.ProjectLighthouse.Types.Match {
public enum RoomState {
Idle = 0,
LookingForPlayersForLevel = 1,
Unknown = 2,
DivingIn = 3,
DivingInWaiting = 4,
}
}

View file

@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace LBPUnion.ProjectLighthouse.Types.Match {
public class UpdatePlayersInRoom : IMatchData {
public List<string> Players;
public List<string> Reservations;
}
}