mission handlers and attempt to create player db

This commit is contained in:
raphaeIl 2024-04-26 11:50:30 -04:00
parent 14e13bc9d7
commit f2d6b6d547
12 changed files with 548 additions and 17 deletions

View File

@ -11,7 +11,7 @@ namespace SCHALE.Common.Database.Models.Game
{
[Key]
[Column("_id")]
public uint ServerId { get; set; }
public required uint ServerId { get; set; }
public AccountDB AccountDB { get; set; }

View File

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace SCHALE.Common.Database.Models.Game
{
public class Player
{
[Key]
[Column("_id")]
public required uint ServerId { get; set; }
public List<MissionProgressDB> MissionProgressDBs { get; set; }
}
}

View File

@ -12,6 +12,9 @@ namespace SCHALE.Common.Database
public DbSet<GuestAccount> GuestAccounts { get; set; }
public DbSet<Account> Accounts { get; set; }
public DbSet<Counter> Counters { get; set; }
public DbSet<Player> Players { get; set; }
public Player CurrentPlayer { get { return Players.FirstOrDefault();} } // temp
public SCHALEContext(DbContextOptions<SCHALEContext> options) : base(options)
{
@ -25,6 +28,10 @@ namespace SCHALE.Common.Database
modelBuilder.Entity<GuestAccount>().ToCollection("guest_accounts");
modelBuilder.Entity<Account>().ToCollection("accounts");
modelBuilder.Entity<Player>().ToCollection("players");
// attempt to fix MissionProgressDB.Dictionary<long, long> ProgressParameters serialization
modelBuilder.Entity<Player>().Property(e => e.MissionProgressDBs).HasJsonConversion<List<MissionProgressDB>>();
modelBuilder.Entity<Counter>().ToCollection("counters");
}

View File

@ -1,5 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
namespace SCHALE.Common.Database
{
@ -13,4 +17,29 @@ namespace SCHALE.Common.Database
});
}
}
public static class ValueConversionExtensions
{
public static PropertyBuilder<T> HasJsonConversion<T>(this PropertyBuilder<T> propertyBuilder) where T : class, new()
{
ValueConverter<T, string> converter = new ValueConverter<T, string>
(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<T>(v) ?? new T()
);
ValueComparer<T> comparer = new ValueComparer<T>
(
(l, r) => JsonConvert.SerializeObject(l) == JsonConvert.SerializeObject(r),
v => v == null ? 0 : JsonConvert.SerializeObject(v).GetHashCode(),
v => JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(v))
);
propertyBuilder.HasConversion(converter);
propertyBuilder.Metadata.SetValueConverter(converter);
propertyBuilder.Metadata.SetValueComparer(comparer);
return propertyBuilder;
}
}
}

View File

@ -1,6 +1,9 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Options;
using SCHALE.Common.FlatData;
using SCHALE.Common.NetworkProtocol;
using SCHALE.Common.Parcel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace SCHALE.Common.Database
@ -1528,9 +1531,12 @@ namespace SCHALE.Common.Database
[JsonIgnore]
public long AccountServerId { get; set; }
public long MissionUniqueId { get; set; }
public bool Complete { get; set; }
public DateTime StartTime { get; set; }
[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)]
public Dictionary<long, long> ProgressParameters { get; set; }
}

View File

@ -1,4 +1,5 @@
using SCHALE.Common.Database;
using SCHALE.Common.FlatData;
using System.Text.Json.Serialization;
namespace SCHALE.Common.NetworkProtocol
@ -39,7 +40,7 @@ namespace SCHALE.Common.NetworkProtocol
public ServerNotificationFlag ServerNotification { get; set; }
public List<MissionProgressDB> MissionProgressDBs { get; set; }
public Dictionary<long, List<MissionProgressDB>> EventMissionProgressDBDict { get; set; }
// public Dictionary<OpenConditionContent, OpenConditionLockReason> StaticOpenConditions { get; set; }
public Dictionary<OpenConditionContent, OpenConditionLockReason> StaticOpenConditions { get; set; }
}
[Flags]

View File

@ -11,6 +11,7 @@
<PackageReference Include="Google.FlatBuffers" Version="24.3.25" />
<PackageReference Include="MersenneTwister" Version="1.0.6" />
<PackageReference Include="MongoDB.EntityFrameworkCore" Version="7.0.0-preview.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

View File

@ -6,6 +6,7 @@ using System.IO.Compression;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using Serilog;
namespace SCHALE.GameServer.Controllers.Api
{
@ -45,6 +46,9 @@ namespace SCHALE.GameServer.Controllers.Api
var jsonNode = JsonSerializer.Deserialize<JsonNode>(payloadStr);
var protocol = (Protocol?)jsonNode?["Protocol"]?.GetValue<int?>() ?? Protocol.None;
logger.LogDebug("Protocol: {Protocol}", protocol.ToString());
logger.LogDebug("Protocol: {Protocol}", (int)protocol);
if (protocol == Protocol.None)
{
logger.LogWarning("Failed to read protocol from JsonNode, {Payload:j}", payloadStr);
@ -58,6 +62,9 @@ namespace SCHALE.GameServer.Controllers.Api
goto protocolErrorRet;
}
logger.LogDebug(Encoding.ASCII.GetString(payloadMs.ToArray()));
var payload = (JsonSerializer.Deserialize(payloadStr, requestType) as RequestPacket)!;
var rsp = protocolHandlerFactory.Invoke(protocol, payload);
@ -77,14 +84,13 @@ namespace SCHALE.GameServer.Controllers.Api
protocol = ((BasePacket)rsp).Protocol.ToString()
});
protocolErrorRet:
protocolErrorRet:
return Results.Json(new
{
packet = JsonSerializer.Serialize(new ErrorPacket() { Reason = "Protocol not implemented (Server Error)", ErrorCode = WebAPIErrorCode.InternalServerError }),
protocol = Protocol.Error.ToString()
});
}
catch (Exception)
} catch (Exception)
{
throw;
}

View File

@ -1,4 +1,5 @@
using SCHALE.Common.NetworkProtocol;
using SCHALE.Common.Database;
using SCHALE.Common.NetworkProtocol;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
@ -9,13 +10,28 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
[ProtocolHandler(Protocol.Academy_GetInfo)]
public ResponsePacket GetInfoHandler(AcademyGetInfoRequest req)
{
//Context.CurrentPlayer.MissionProgressDBs
var MissionProgressDBs = new List<MissionProgressDB> {
new MissionProgressDB() {
MissionUniqueId = 1700,
Complete = false,
StartTime = DateTime.UtcNow,
ProgressParameters = new Dictionary<long, long>
{
{ 0, 2 }
}
}
};
return new AcademyGetInfoResponse()
{
AcademyDB = new()
{
AccountId = 1
AccountId = Context.CurrentPlayer.ServerId,
},
AcademyLocationDBs = [],
MissionProgressDBs = MissionProgressDBs,
//MissionProgressDBs = Context.CurrentPlayer.MissionProgressDBs,
};
}
}

View File

@ -2,6 +2,7 @@
using SCHALE.Common.FlatData;
using SCHALE.Common.NetworkProtocol;
using SCHALE.Common.Parcel;
using SCHALE.Common.Database.Models.Game;
using Serilog;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
@ -49,8 +50,7 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
ErrorCode = WebAPIErrorCode.AccountAuthNotCreated
};
}
else
} else
{
return new AccountAuthResponse()
{
@ -61,8 +61,111 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
AccountServerId = account.ServerId,
MxToken = req.SessionKey.MxToken,
},
MissionProgressDBs = new List<MissionProgressDB>
{
new MissionProgressDB
{
MissionUniqueId = 1501,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44") },
new MissionProgressDB
{
MissionUniqueId = 1700,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1500,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44") },
new MissionProgressDB
{
MissionUniqueId = 2200,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 }, { 1, 5 } }
},
new MissionProgressDB
{
MissionUniqueId = 300000,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000210,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000220,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000230,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000240,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000250,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000260,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000270,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001327,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001357,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001377,
Complete = true,
StartTime = DateTime.Parse("2024-04-26T20:46:44"),
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
}
};
}
}
@ -72,6 +175,9 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
var account = Common.Database.Models.Game.Account.Create((uint)req.AccountId);
Context.Accounts.Add(account);
Context.Players.Add(new Player() { ServerId = (uint)req.AccountId });
Context.SaveChanges();
Log.Information("Account Created " + Context.Accounts.Count());
@ -169,7 +275,7 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
return new ShopBeforehandGachaGetResponse()
{
SessionKey = new ()
SessionKey = new()
{
MxToken = req.SessionKey.MxToken,
AccountServerId = req.SessionKey.AccountServerId,
@ -186,6 +292,16 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
};
}
[ProtocolHandler(Protocol.EventContent_CollectionList)]
public ResponsePacket EventContent_CollectionListHandler(EventContentCollectionListRequest req)
{
return new EventContentCollectionListResponse()
{
};
}
}
}

View File

@ -1,4 +1,6 @@
using SCHALE.Common.NetworkProtocol;
using SCHALE.Common.Database;
using SCHALE.Common.NetworkProtocol;
using Serilog;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
@ -9,9 +11,338 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
[ProtocolHandler(Protocol.Mission_List)]
public ResponsePacket ListHandler(MissionListRequest req)
{
return new MissionListResponse()
{
var player = Context.Players.SingleOrDefault(x => x.ServerId == req.AccountId);
Log.Information($"MissionListRequest EventContentId: {req.EventContentId}");
Context.CurrentPlayer.MissionProgressDBs = new List<MissionProgressDB>
{
new MissionProgressDB
{
MissionUniqueId = 1501,
Complete = true,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 1700,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 2 } }
},
new MissionProgressDB
{
MissionUniqueId = 1500,
Complete = true,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 2200,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 }, { 1, 5 } }
},
new MissionProgressDB
{
MissionUniqueId = 300000,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000210,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000220,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000230,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000240,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000250,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000260,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1000270,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001327,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001357,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001377,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001011,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001014,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001015,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001016,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001019,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 4 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001020,
Complete = true,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001021,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001025,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001026,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001028,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001030,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 1, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001031,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001036,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001037,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001039,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001041,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001046,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001050,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001051,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001055,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 1, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001056,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001057,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001059,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001060,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001061,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001065,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001067,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001069,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001070,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001071,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001075,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 13003, 1 }, { 13010, 1 }, { 16003, 1 }, { 26000, 1 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001079,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 7, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001080,
StartTime = DateTime.Now,
ProgressParameters = new Dictionary<long, long> { { 0, 0 } }
},
new MissionProgressDB
{
MissionUniqueId = 1001013,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 1001023,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 1001034,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 1001044,
StartTime = DateTime.Now },
new MissionProgressDB
{
MissionUniqueId = 1001054,
StartTime = DateTime.Now },
};
//Context.CurrentPlayer.MissionProgressDBs = [];
Context.SaveChanges();
return new MissionListResponse
{
//ProgressDBs = Context.CurrentPlayer.MissionProgressDBs
ProgressDBs = Context.CurrentPlayer.MissionProgressDBs
};
}

View File

@ -1,4 +1,5 @@
using SCHALE.Common.NetworkProtocol;
using Serilog;
namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
{
@ -9,6 +10,9 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
[ProtocolHandler(Protocol.Scenario_Skip)]
public ResponsePacket SkipHandler(ScenarioSkipRequest req)
{
Log.Information($"ScenarioSkipRequest ScriptGroupId:" + req.ScriptGroupId);
Log.Information($"ScenarioSkipRequest SkipPointScriptCount: " + req.SkipPointScriptCount);
// skip story doesn't work yet, probably need to implement missiondb
return new ScenarioSkipResponse()
{