This commit is contained in:
Alan Moon 2025-03-18 16:34:02 -07:00
commit 28adf1b3f1
12 changed files with 2850 additions and 2 deletions

View File

@ -25,6 +25,7 @@ public class ContentController : Controller {
private NeighborhoodService neighborhoodService;
private WorldIdService worldIdService;
private BuddyService buddyService;
private MessagingService messagingService;
private Random random = new Random();
private readonly IOptions<ApiServerConfig> config;
@ -42,6 +43,7 @@ public class ContentController : Controller {
NeighborhoodService neighborhoodService,
WorldIdService worldIdService,
BuddyService buddyService,
MessagingService messagingService,
IOptions<ApiServerConfig> config
) {
this.ctx = ctx;
@ -57,6 +59,7 @@ public class ContentController : Controller {
this.neighborhoodService = neighborhoodService;
this.worldIdService = worldIdService;
this.buddyService = buddyService;
this.messagingService = messagingService;
this.config = config;
}
@ -1264,6 +1267,28 @@ public class ContentController : Controller {
else return Ok(false);
}
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/InviteBuddy")]
[VikingSession]
public IActionResult InviteBuddy(Viking viking, [FromForm] Guid buddyUserId)
{
Viking? viking1 = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserId);
if (viking1 != null) messagingService.SendInvite(viking, viking1);
return Ok(true);
}
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/GetBuddyLocation")]
public IActionResult GetBuddyLocation([FromForm] Guid buddyUserID)
{
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Uid == buddyUserID);
if (viking != null) return Ok(buddyService.GetLocationOfBuddy(viking));
else return Ok(new BuddyLocation());
}
[HttpPost]
[Produces("application/xml")]
[Route("ContentWebService.asmx/GetBuddyList")]

View File

@ -26,5 +26,31 @@ namespace sodoff.Controllers.Common
return Ok(viking.Online);
} else return Ok(false);
}
[HttpPost]
[Produces("application/json")]
[Route("Precense/SetVikingRoom")]
public IActionResult SetVikingRoom([FromForm] Guid token, [FromForm] int roomId, [FromForm] string zoneName)
{
// get viking from session
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == token)?.Viking;
if (viking != null)
{
if (roomId <= 0 && string.IsNullOrEmpty(zoneName))
{
viking.CurrentRoomId = null;
viking.CurrentZone = null;
ctx.SaveChanges();
return Ok(true);
}
viking.CurrentRoomId = roomId;
viking.CurrentZone = zoneName;
ctx.SaveChanges();
return Ok(true);
}
else return Ok(false);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace sodoff.Migrations
{
/// <inheritdoc />
public partial class Viking_CurrentRoomId : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "CurrentRoomId",
table: "Vikings",
type: "INTEGER",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CurrentRoomId",
table: "Vikings");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace sodoff.Migrations
{
/// <inheritdoc />
public partial class Viking_CurrentZone : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CurrentZone",
table: "Vikings",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CurrentZone",
table: "Vikings");
}
}
}

View File

@ -823,6 +823,12 @@ namespace sodoff.Migrations
b.Property<DateTime?>("CreationDate")
.HasColumnType("TEXT");
b.Property<int?>("CurrentRoomId")
.HasColumnType("INTEGER");
b.Property<string>("CurrentZone")
.HasColumnType("TEXT");
b.Property<uint?>("GameVersion")
.HasColumnType("INTEGER");

View File

@ -24,6 +24,8 @@ public class Viking {
public int? SelectedDragonId { get; set; }
public bool? Online { get; set; }
public int? CurrentRoomId { get; set; }
public string? CurrentZone { get; set; }
public virtual ICollection<Session> Sessions { get; set; } = null!;
public virtual User User { get; set; } = null!;

View File

@ -0,0 +1,33 @@
using System.Xml.Serialization;
namespace sodoff.Schema
{
[XmlRoot(ElementName = "BuddyLocation", Namespace = "")]
[Serializable]
public class BuddyLocation
{
[XmlElement(ElementName = "UserID")]
public string UserID;
[XmlElement(ElementName = "Server")]
public string Server;
[XmlElement(ElementName = "Zone")]
public string Zone;
[XmlElement(ElementName = "Room")]
public string Room;
[XmlElement(ElementName = "MultiplayerID")]
public int MultiplayerID;
[XmlElement(ElementName = "ServerVersion")]
public string ServerVersion;
[XmlElement(ElementName = "AppName")]
public string AppName;
[XmlElement(ElementName = "ServerPort")]
public int ServerPort;
}
}

View File

@ -1,6 +1,8 @@
using System;
using System.Data;
using System.Security;
using Microsoft.Extensions.Options;
using sodoff.Configuration;
using sodoff.Model;
using sodoff.Schema;
using sodoff.Util;
@ -15,12 +17,14 @@ public class BuddyService
private readonly DBContext ctx;
private readonly MessagingService messagingService;
private readonly MMOClientService mMOClientService;
private readonly IOptions<ApiServerConfig> config;
public BuddyService(DBContext ctx, MessagingService messagingService, MMOClientService mMOClientService)
public BuddyService(DBContext ctx, MessagingService messagingService, MMOClientService mMOClientService, IOptions<ApiServerConfig> config)
{
this.ctx = ctx;
this.messagingService = messagingService;
this.mMOClientService = mMOClientService;
this.config = config;
}
public BuddyActionResult CreateBuddyRelation(Viking viking1, Viking viking2, BuddyStatus buddyStatus1 = BuddyStatus.PendingApprovalFromOther, BuddyStatus buddyStatus2 = BuddyStatus.PendingApprovalFromSelf)
@ -176,6 +180,31 @@ public class BuddyService
else return false;
}
public BuddyLocation GetLocationOfBuddy(Viking viking)
{
if (viking.CurrentRoomId != null && viking.CurrentZone != null)
{
// construct
BuddyLocation buddyLocation = new()
{
UserID = viking.Uid.ToString(),
Room = viking.CurrentRoomId.Value.ToString(),
Server = config.Value.MMOAdress,
ServerPort = config.Value.MMOPort,
ServerVersion = "S2X",
Zone = viking.CurrentZone,
MultiplayerID = viking.CurrentRoomId.Value
};
if (viking.GameVersion <= ClientVersion.WoJS) buddyLocation.AppName = "JSMain";
else if (viking.GameVersion <= ClientVersion.MB) buddyLocation.AppName = "MBMain";
// return
return buddyLocation;
}
else return new BuddyLocation();
}
public BuddyList ConstructBuddyList(Viking viking)
{
// get all relationships viking has made

View File

@ -45,12 +45,14 @@ public class MMOClientService : IHostedService
SFSClient.Connect(SFSConfig);
SFSClient.AddEventListener(SFSEvent.CONNECTION, OnConnectionEstablished);
SFSClient.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
SFSClient.AddEventListener(SFSEvent.LOGIN, OnLogin);
// return completed task (SmartFox seems to be completely synchronous)
return Task.CompletedTask;
}
public Task SetRoomVarForRoom(int roomId, RoomVariable var)
{
if (IsLoggedIn)
@ -100,6 +102,12 @@ public class MMOClientService : IHostedService
}
}
private void OnConnectionLost(BaseEvent evt)
{
Console.WriteLine($"Connection To The MMO Server Was Lost. Reason - {(string)evt.Params["reason"]}");
Console.WriteLine("MMO Service Currently Not Ready.\nThis Required A Full API Restart For Realtime Communication To Be Reestablished.");
}
private void OnLogin(BaseEvent evt)
{
CurrentUser = (User)evt.Params["user"];

View File

@ -87,6 +87,14 @@ public class MessagingService
return message;
}
public void SendInvite(Viking viking, Viking buddyViking)
{
if(buddyViking.Online ?? false) // TODO - also account for LIMBO
{
mMOClientService.SendCommandToUser(buddyViking.Uid.ToString(), "SPI", new string[] { "SPI", "-1", viking.Uid.ToString(), "1", "5" });
}
}
public void RemoveMessage(int id)
{
// find message
@ -269,7 +277,7 @@ public class MessagingService
Viking? msgAuthor = ctx.Vikings.FirstOrDefault(e => e.Id == message.VikingId) ?? new Viking();
if(message.IsDeleted && !showDeletedMessages) { ctx.Messages.Remove(message); continue; }
if(DateTime.Compare(now, message.CreatedAt.AddMinutes(30)) > 0 && !showOldMessages) { message.IsNew = false; continue; } // sometimes clients won't set IsNew flag when updating messages, so do not add messages more than 30 minutes old to response
if(DateTime.Compare(now, message.CreatedAt.AddMinutes(5)) > 0 && !showOldMessages) { message.IsNew = false; continue; } // sometimes clients won't set IsNew flag when updating messages, so do not add messages more than 30 minutes old to response
if(!message.IsNew && !showOldMessages) continue;
MessageInfo messageInfo = new MessageInfo