mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
rework GetMMOServerInfoWithZone
add MMOSupportMinVersion configure setting
This commit is contained in:
parent
f768020ede
commit
9d89a6b6da
@ -2,6 +2,10 @@
|
||||
public class ApiServerConfig {
|
||||
public string ResponseURL { get; set; } = string.Empty;
|
||||
|
||||
public string MMOAdress { get; set; } = "127.0.0.1";
|
||||
public int MMOPort { get; set; } = 9933;
|
||||
public uint MMOSupportMinVersion { get; set; } = 0;
|
||||
|
||||
public DbProviders DbProvider { get; set; } = DbProviders.SQLite;
|
||||
public string DbPath { get; set; } = string.Empty;
|
||||
public string DbConnection { get; set; } = string.Empty;
|
||||
|
@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using sodoff.Attributes;
|
||||
using sodoff.Model;
|
||||
using sodoff.Schema;
|
||||
using sodoff.Util;
|
||||
using sodoff.Configuration;
|
||||
|
||||
namespace sodoff.Controllers.Common;
|
||||
|
||||
@ -11,9 +13,11 @@ namespace sodoff.Controllers.Common;
|
||||
public class AuthenticationController : Controller {
|
||||
|
||||
private readonly DBContext ctx;
|
||||
private readonly IOptions<ApiServerConfig> config;
|
||||
|
||||
public AuthenticationController(DBContext ctx) {
|
||||
public AuthenticationController(DBContext ctx, IOptions<ApiServerConfig> config) {
|
||||
this.ctx = ctx;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -108,7 +112,7 @@ public class AuthenticationController : Controller {
|
||||
Username = user.Username,
|
||||
MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder
|
||||
FacebookUserID = 0,
|
||||
MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey),
|
||||
MultiplayerEnabled = ClientVersion.GetVersion(apiKey) >= config.Value.MMOSupportMinVersion,
|
||||
IsApproved = true,
|
||||
Age = 24,
|
||||
OpenChatEnabled = true
|
||||
@ -123,7 +127,7 @@ public class AuthenticationController : Controller {
|
||||
UserID = viking.Uid.ToString(),
|
||||
Username = viking.Name,
|
||||
FacebookUserID = 0,
|
||||
MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey),
|
||||
MultiplayerEnabled = ClientVersion.GetVersion(apiKey) >= config.Value.MMOSupportMinVersion,
|
||||
IsApproved = true,
|
||||
Age = 24,
|
||||
OpenChatEnabled = true
|
||||
|
@ -1,21 +1,24 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using sodoff.Schema;
|
||||
using sodoff.Services;
|
||||
using sodoff.Util;
|
||||
|
||||
namespace sodoff.Controllers.Common;
|
||||
|
||||
public class ConfigurationController : Controller {
|
||||
private MMOConfigService mmoConfigService;
|
||||
|
||||
public ConfigurationController(MMOConfigService mmoConfigService) {
|
||||
this.mmoConfigService = mmoConfigService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
//[Produces("application/xml")]
|
||||
[Produces("application/xml")]
|
||||
[Route("ConfigurationWebService.asmx/GetMMOServerInfoWithZone")]
|
||||
public IActionResult GetMMOServerInfoWithZone([FromForm] string apiKey) {
|
||||
// TODO: this is a placeholder
|
||||
if (apiKey == "A1A13A0A-7C6E-4E9B-B0F7-22034D799013" || apiKey == "A2A09A0A-7C6E-4E9B-B0F7-22034D799013" || apiKey == "A3A12A0A-7C6E-4E9B-B0F7-22034D799013") { // NOTE: in this request apiKey is send uppercase
|
||||
// do not send MMO servers to old (incompatibility with MMO server) client
|
||||
return Ok(XmlUtil.SerializeXml(new MMOServerInformation[0]));
|
||||
}
|
||||
return Ok(XmlUtil.ReadResourceXmlString("mmo"));
|
||||
return Ok(mmoConfigService.GetMMOServerInformation(
|
||||
ClientVersion.GetVersion(apiKey.ToLower()) // NOTE: in this request apiKey is send uppercase
|
||||
));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -1,10 +1,12 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using sodoff.Attributes;
|
||||
using sodoff.Model;
|
||||
using sodoff.Schema;
|
||||
using sodoff.Services;
|
||||
using sodoff.Util;
|
||||
using sodoff.Configuration;
|
||||
|
||||
namespace sodoff.Controllers.Common;
|
||||
public class ProfileController : Controller {
|
||||
@ -12,10 +14,13 @@ public class ProfileController : Controller {
|
||||
private readonly DBContext ctx;
|
||||
private AchievementService achievementService;
|
||||
private ProfileService profileService;
|
||||
public ProfileController(DBContext ctx, AchievementService achievementService, ProfileService profileService) {
|
||||
private readonly IOptions<ApiServerConfig> config;
|
||||
|
||||
public ProfileController(DBContext ctx, AchievementService achievementService, ProfileService profileService, IOptions<ApiServerConfig> config) {
|
||||
this.ctx = ctx;
|
||||
this.achievementService = achievementService;
|
||||
this.profileService = profileService;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -116,7 +121,7 @@ public class ProfileController : Controller {
|
||||
ParentUserID = viking.UserId.ToString(),
|
||||
Username = viking.Name,
|
||||
FirstName = viking.Name,
|
||||
MultiplayerEnabled = ClientVersion.IsMultiplayerSupported(apiKey),
|
||||
MultiplayerEnabled = ClientVersion.GetVersion(apiKey) >= config.Value.MMOSupportMinVersion,
|
||||
Locale = "en-US", // placeholder
|
||||
GenderID = gender,
|
||||
OpenChatEnabled = true,
|
||||
|
@ -29,6 +29,7 @@ builder.Services.AddSingleton<AchievementStoreSingleton>();
|
||||
builder.Services.AddSingleton<ItemService>();
|
||||
builder.Services.AddSingleton<StoreService>();
|
||||
builder.Services.AddSingleton<DisplayNamesService>();
|
||||
builder.Services.AddSingleton<MMOConfigService>();
|
||||
|
||||
builder.Services.AddScoped<KeyValueService>();
|
||||
builder.Services.AddScoped<MissionService>();
|
||||
|
@ -1,22 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ArrayOfMMOServerInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://api.jumpstart.com/">
|
||||
<!--
|
||||
This file can be used to provide different mmo servers for different zones (<ZN> tag in <MMOServerInfo>).
|
||||
This configuration is optional. For zones not specified in this file default entry from DWADragonsMain.xml will be used.
|
||||
<MMOConfig>
|
||||
<!-- For version doesn't match to entries in this file default (empty <ArrayOfMMOServerInfo>) will be send. -->
|
||||
|
||||
For each zone that is to use a different server, an entry should be created `<MMOServerInfo>` node:
|
||||
<Version>
|
||||
<!-- SoD <= 2.3 -->
|
||||
<VersionMin>0xa0000000</VersionMin>
|
||||
<VersionMax>0xa2a03a0a</VersionMax>
|
||||
<ZoneList>ArenaFrenzyDO ArmorWingIslandDO BerkCloudsDO BerkDocksDO BerkFarmDO CreditsDO DEClubhouseINTDO DarkDeepDO DragonRacingDO FarmingDO FarmingOceanDO GauntletDO GlacierIslandDO GreatHallSchoolIntDO HatcheryINT02DO HatcheryINTDO HelheimsGateDO HobblegruntIslandDO HubArctic01DO HubArcticINTDO HubAuctionIslandDO HubBerkDO HubDeathsongIslandDO HubDragonIslandDO HubDragonIslandINTDO HubDragonsEdgeDO HubEruptodonIslandDO HubLookoutDO HubSchoolDO HubTrainingDO HubWilderness01DO MudrakerIslandDO MyRoomINTDO OpenOceanDO RacingDragon ScuttleclawIslandDO ShipGraveyardDO TargetPracticeDO TitanIslandDO ZipplebackIslandDO</ZoneList>
|
||||
</Version>
|
||||
|
||||
<Version>
|
||||
<!-- Math Blaster -->
|
||||
<VersionMin>0x00700000</VersionMin>
|
||||
<VersionMax>0x00700000</VersionMax>
|
||||
<ZoneList>DNAMorph AlienWorldJungle GauntletShooter AlienRace Spaceport ReadyRoom AlienBattleGame TrainingRoom FaceOffGame AlienWorldIce AlienAdult SnatchItMB AlienRiderGame AlienBaby AlienBattleArena SpaceRacing Academy AlienRider Hangar AlienLarvaRoom MyPodInt DNAMorph AlienWorldJungle GauntletShooter AlienRace Spaceport ReadyRoom AlienBattleGame TrainingRoom FaceOffGame AlienWorldIce AlienAdult SnatchItMB AlienRiderGame AlienBaby AlienBattleArena SpaceRacing Academy AlienRider Hangar AlienLarvaRoom MyPodInt DNAMorph AlienWorldJungle GauntletShooter AlienRace Spaceport ReadyRoom AlienBattleGame TrainingRoom FaceOffGame AlienWorldIce AlienAdult SnatchItMB AlienRiderGame AlienBaby AlienBattleArena SpaceRacing Academy AlienRider Hangar AlienLarvaRoom MyPodInt DNAMorph AlienWorldJungle GauntletShooter AlienRace Spaceport ReadyRoom AlienBattleGame TrainingRoom FaceOffGame AlienWorldIce AlienAdult SnatchItMB AlienRiderGame AlienBaby AlienBattleArena SpaceRacing Academy AlienRider Hangar AlienLarvaRoom MyPodInt DNAMorph AlienWorldJungle GauntletShooter AlienRace Spaceport ReadyRoom AlienBattleGame TrainingRoom FaceOffGame AlienWorldIce AlienAdult SnatchItMB AlienRiderGame AlienBaby AlienBattleArena SpaceRacing Academy AlienRider Hangar AlienLarvaRoom MyPodInt</ZoneList>
|
||||
</Version>
|
||||
|
||||
<Version>
|
||||
<!-- World of JumpStart -->
|
||||
<VersionMin>0x00600000</VersionMin>
|
||||
<VersionMax>0x00600000</VersionMax>
|
||||
<ZoneList>DWMadPenguinHQINT UncleMilton EnemyValley LoungeIntUpper UncleMiltonBounceHouse Boardwalk MyRoomsInt DWMadEuropeAlps SpeedDrome WinterWonderland GemMineInt Beach TrainingIsland * IslandX SanctuaryBaby DWMadEuropeParis AdventureCanyon DWMadNYHarbor JumpStartBowlInt TownCenter SanctuaryFlying MultiplayerSystem DWMadNYCentralParkFunZone MainStreet LearningInt HomeBase Hollows FreeFallMtn ArcadeInt ShipWreckLagoon DWMadEuropeItaly MummyMazeInt EnchantedSanctuary MyVIPRoomInt DownTown DWMadNYCentralPark MyNeighborhood MountainJetpack DWMadNYTimesSquare MainStreetFunZone DuneBuggyZone LoungeInt JSStadiumInt SanctuaryAdult BroomStickArena RabbitHoleInt CoconutMall Lobby </ZoneList>
|
||||
</Version>
|
||||
|
||||
<!-- Multiple <MMOServerInfo> child can be used instead of <ZoneList>
|
||||
to provide different MMO servers for different zones (<ZN> tag in <MMOServerInfo>).
|
||||
|
||||
For zones not specified in this config, default entry from DWADragonsMain.xml will be used.
|
||||
|
||||
It's possible provide multiple servers (multiple <MMOServerInfo> nodes) per zone.
|
||||
<DF> can be used to indicated default server(s).
|
||||
|
||||
<ZN> values for SoD 3.31: ArenaFrenzyDO ArmorWingIslandDO BerkCloudsDO BerkDocksDO BerkFarmDO CreditsDO DEClubhouseINTDO DarkDeepCavesDO DarkDeepDO DragonRacingDO FarmingDO FarmingDreadfallDO FarmingOceanDO FarmingThawfestDO GauntletDO GlacierIslandDO GreatHallBerkIntDO GreatHallSchoolIntDO HatcheryINT02DO HatcheryINTDO HelheimsGateDO HobblegruntIslandDO HubArctic01DO HubArcticINTDO HubAuctionIslandDO HubBerkDO HubBerkNewDO HubCenoteDO HubDeathsongIslandDO HubDragonIslandDO HubDragonIslandINTDO HubDragonsEdgeDO HubEruptodonIslandDO HubHiddenWorldDO HubHiddenWorldNBDO HubLookoutDO HubSchoolDO HubTradewindIslandDO HubTrainingDO HubVanaheimDO HubWarlordIslandDO HubWilderness01DO MudrakerIslandDO MyRoomINTDO OpenOceanDO PirateQueenShipDO RacingDragon ScuttleclawIslandDO ShipGraveyardDO TargetPracticeDO TitanIslandDO ZipplebackIslandDO
|
||||
|
||||
Example:
|
||||
|
||||
<Version>
|
||||
<VersionMin>0x0000</VersionMin>
|
||||
<VersionMax>0x0010</VersionMax>
|
||||
<MMOServerInfo>
|
||||
<IP xmlns="">127.0.0.1</IP>
|
||||
<PN xmlns="">9933</PN>
|
||||
<VR xmlns="">S2X</VR>
|
||||
<DF xmlns="">true</DF>
|
||||
<ZN xmlns="">HubSchoolDO</ZN>
|
||||
<RZN xmlns="">JumpStart</RZN>
|
||||
</MMOServerInfo>
|
||||
<MMOServerInfo>
|
||||
<IP xmlns="">127.0.0.2</IP>
|
||||
<PN xmlns="">9933</PN>
|
||||
<VR xmlns="">S2X</VR>
|
||||
<DF xmlns="">false</DF>
|
||||
<ZN xmlns="">HubSchoolDO</ZN>
|
||||
<RZN xmlns="">JumpStart</RZN>
|
||||
</MMOServerInfo>
|
||||
|
||||
<ZN> values for SoD 3.31: ArenaFrenzyDO ArmorWingIslandDO BerkCloudsDO BerkDocksDO BerkFarmDO CreditsDO DEClubhouseINTDO DarkDeepCavesDO DarkDeepDO DragonRacingDO FarmingDO FarmingDreadfallDO FarmingOceanDO FarmingThawfestDO GauntletDO GlacierIslandDO GreatHallBerkIntDO GreatHallSchoolIntDO HatcheryINT02DO HatcheryINTDO HelheimsGateDO HobblegruntIslandDO HubArctic01DO HubArcticINTDO HubAuctionIslandDO HubBerkDO HubBerkNewDO HubCenoteDO HubDeathsongIslandDO HubDragonIslandDO HubDragonIslandINTDO HubDragonsEdgeDO HubEruptodonIslandDO HubHiddenWorldDO HubHiddenWorldNBDO HubLookoutDO HubSchoolDO HubTradewindIslandDO HubTrainingDO HubVanaheimDO HubWarlordIslandDO HubWilderness01DO MudrakerIslandDO MyRoomINTDO OpenOceanDO PirateQueenShipDO RacingDragon ScuttleclawIslandDO ShipGraveyardDO TargetPracticeDO TitanIslandDO ZipplebackIslandDO
|
||||
|
||||
It's possible provide multiple servers (multiple <MMOServerInfo> nodes) per zone ... <DF> can be used to indicated default server(s).
|
||||
-->
|
||||
</ArrayOfMMOServerInfo>
|
||||
</Version>
|
||||
-->
|
||||
</MMOConfig>
|
||||
|
10
src/Schema/MMOConfig.cs
Normal file
10
src/Schema/MMOConfig.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace sodoff.Schema;
|
||||
|
||||
[XmlRoot(ElementName = "MMOConfig", Namespace = "")]
|
||||
[Serializable]
|
||||
public class MMOConfig {
|
||||
[XmlElement(ElementName = "Version")]
|
||||
public MMOConfigEntry[] Versions;
|
||||
}
|
32
src/Schema/MMOConfigEntry.cs
Normal file
32
src/Schema/MMOConfigEntry.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Xml.Serialization;
|
||||
using sodoff.Util;
|
||||
|
||||
namespace sodoff.Schema;
|
||||
|
||||
[XmlRoot(ElementName = "MMOConfigEntry", Namespace = "")]
|
||||
[Serializable]
|
||||
public class MMOConfigEntry {
|
||||
[XmlElement(ElementName = "VersionMin")]
|
||||
public string VersionMin {
|
||||
get { return VersionFirst.ToString("X"); }
|
||||
set { VersionFirst = XmlUtil.HexToUint(value); }
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public uint VersionFirst;
|
||||
|
||||
[XmlElement(ElementName = "VersionMax")]
|
||||
public string VersionMax {
|
||||
get { return VersionLast.ToString("X"); }
|
||||
set { VersionLast = XmlUtil.HexToUint(value); }
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public uint VersionLast;
|
||||
|
||||
[XmlElement(ElementName = "ZoneList")]
|
||||
public string ZoneList;
|
||||
|
||||
[XmlElement(ElementName = "MMOServerInfo")]
|
||||
public MMOServerData[] MMOServerDataArray;
|
||||
}
|
47
src/Services/MMOConfigService.cs
Normal file
47
src/Services/MMOConfigService.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using sodoff.Schema;
|
||||
using sodoff.Util;
|
||||
using sodoff.Configuration;
|
||||
|
||||
namespace sodoff.Services;
|
||||
|
||||
public class MMOConfigService {
|
||||
MMOConfig mmoconfig;
|
||||
private readonly IOptions<ApiServerConfig> config;
|
||||
|
||||
public MMOConfigService(IOptions<ApiServerConfig> config) {
|
||||
this.config = config;
|
||||
this.mmoconfig = XmlUtil.DeserializeXml<MMOConfig>(XmlUtil.ReadResourceXmlString("mmo"));
|
||||
|
||||
char[] delimiterChars = { ' ', ',', '\t', '\n' };
|
||||
foreach (var v in mmoconfig.Versions) {
|
||||
if (!String.IsNullOrEmpty(v.ZoneList)) {
|
||||
List<MMOServerData> MMOServerDataList = new();
|
||||
foreach (var ZoneName in v.ZoneList.Split(delimiterChars)) {
|
||||
if (!String.IsNullOrWhiteSpace(ZoneName)) {
|
||||
MMOServerDataList.Add(new MMOServerData {
|
||||
IPAddress = config.Value.MMOAdress,
|
||||
Port = config.Value.MMOPort,
|
||||
Version = "S2X",
|
||||
isDefault = true,
|
||||
ZoneName = ZoneName.Trim(),
|
||||
RootZone = "JumpStart"
|
||||
} );
|
||||
}
|
||||
}
|
||||
v.MMOServerDataArray = MMOServerDataList.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MMOServerInformation GetMMOServerInformation(uint version) {
|
||||
if (version >= config.Value.MMOSupportMinVersion) {
|
||||
return new MMOServerInformation {
|
||||
MMOServerDataArray = mmoconfig.Versions.FirstOrDefault(c => c.VersionFirst >= version && c.VersionLast <= version)?.MMOServerDataArray
|
||||
};
|
||||
} else {
|
||||
return new MMOServerInformation();
|
||||
}
|
||||
}
|
||||
}
|
@ -35,8 +35,4 @@ public class ClientVersion {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static bool IsMultiplayerSupported(string apiKey) {
|
||||
return GetVersion(apiKey) >= 0xa3a19a0a;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,10 @@ public class XmlUtil {
|
||||
result = reader.ReadToEnd();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static uint HexToUint(string hex) {
|
||||
if (hex.StartsWith("0x", StringComparison.CurrentCultureIgnoreCase))
|
||||
hex = hex.Substring(2);
|
||||
return Convert.ToUInt32(hex, 16);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,15 @@
|
||||
"// ResponseURL": "When not empty is used as server url in some responses. Otherwise will be auto detected.",
|
||||
"ResponseURL": "",
|
||||
|
||||
"// MMOAdress": "MMO server address (IP or domain) to use in GetMMOServerInfo* responses.",
|
||||
"MMOAdress": "127.0.0.1",
|
||||
|
||||
"// MMOPort": "MMO server port to use in GetMMOServerInfo* responses.",
|
||||
"MMOPort": 9933,
|
||||
|
||||
"// MMOSupportMinVersion": "Minimum client version allowed to use MMO. For example: '0xa3a31a0a' mean SoD 3.31, '0xa0000000' mean all SoD version, 0 mean all games.",
|
||||
"MMOSupportMinVersion": "0xa3a31a0a",
|
||||
|
||||
"// DbProvider": "Select database backend to use: SQLite, PostgreSQL, MySQL (availability may depend on build options)",
|
||||
"DbProvider": "SQLite",
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user