mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-23 13:41:31 +00:00
More match progress
This commit is contained in:
parent
20316be3c6
commit
e7d3d6bd02
5 changed files with 83 additions and 28 deletions
|
@ -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>
|
||||
|
|
|
@ -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}]");
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
9
ProjectLighthouse/Types/Match/RoomState.cs
Normal file
9
ProjectLighthouse/Types/Match/RoomState.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace LBPUnion.ProjectLighthouse.Types.Match {
|
||||
public enum RoomState {
|
||||
Idle = 0,
|
||||
LookingForPlayersForLevel = 1,
|
||||
Unknown = 2,
|
||||
DivingIn = 3,
|
||||
DivingInWaiting = 4,
|
||||
}
|
||||
}
|
8
ProjectLighthouse/Types/Match/UpdatePlayersInRoom.cs
Normal file
8
ProjectLighthouse/Types/Match/UpdatePlayersInRoom.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue