Player Invites #10

Merged
Moonbase merged 7 commits from invites into master 2025-03-18 16:25:23 -07:00
9 changed files with 1482 additions and 1 deletions
Showing only changes of commit 8abf75a3e9 - Show all commits

View File

@ -25,6 +25,7 @@ public class ContentController : Controller {
private NeighborhoodService neighborhoodService; private NeighborhoodService neighborhoodService;
private WorldIdService worldIdService; private WorldIdService worldIdService;
private BuddyService buddyService; private BuddyService buddyService;
private MessagingService messagingService;
private Random random = new Random(); private Random random = new Random();
private readonly IOptions<ApiServerConfig> config; private readonly IOptions<ApiServerConfig> config;
@ -42,6 +43,7 @@ public class ContentController : Controller {
NeighborhoodService neighborhoodService, NeighborhoodService neighborhoodService,
WorldIdService worldIdService, WorldIdService worldIdService,
BuddyService buddyService, BuddyService buddyService,
MessagingService messagingService,
IOptions<ApiServerConfig> config IOptions<ApiServerConfig> config
) { ) {
this.ctx = ctx; this.ctx = ctx;
@ -57,6 +59,7 @@ public class ContentController : Controller {
this.neighborhoodService = neighborhoodService; this.neighborhoodService = neighborhoodService;
this.worldIdService = worldIdService; this.worldIdService = worldIdService;
this.buddyService = buddyService; this.buddyService = buddyService;
this.messagingService = messagingService;
this.config = config; this.config = config;
} }
@ -1264,6 +1267,28 @@ public class ContentController : Controller {
else return Ok(false); 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] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ContentWebService.asmx/GetBuddyList")] [Route("ContentWebService.asmx/GetBuddyList")]

View File

@ -26,5 +26,31 @@ namespace sodoff.Controllers.Common
return Ok(viking.Online); return Ok(viking.Online);
} else return Ok(false); } 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_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

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

View File

@ -25,6 +25,7 @@ public class Viking {
public bool? Online { get; set; } public bool? Online { get; set; }
public int? CurrentRoomId { get; set; } public int? CurrentRoomId { get; set; }
public string? CurrentZone { get; set; }
public virtual ICollection<Session> Sessions { get; set; } = null!; public virtual ICollection<Session> Sessions { get; set; } = null!;
public virtual User User { 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;
using System.Data; using System.Data;
using System.Security; using System.Security;
using Microsoft.Extensions.Options;
using sodoff.Configuration;
using sodoff.Model; using sodoff.Model;
using sodoff.Schema; using sodoff.Schema;
using sodoff.Util; using sodoff.Util;
@ -15,12 +17,14 @@ public class BuddyService
private readonly DBContext ctx; private readonly DBContext ctx;
private readonly MessagingService messagingService; private readonly MessagingService messagingService;
private readonly MMOClientService mMOClientService; 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.ctx = ctx;
this.messagingService = messagingService; this.messagingService = messagingService;
this.mMOClientService = mMOClientService; this.mMOClientService = mMOClientService;
this.config = config;
} }
public BuddyActionResult CreateBuddyRelation(Viking viking1, Viking viking2, BuddyStatus buddyStatus1 = BuddyStatus.PendingApprovalFromOther, BuddyStatus buddyStatus2 = BuddyStatus.PendingApprovalFromSelf) public BuddyActionResult CreateBuddyRelation(Viking viking1, Viking viking2, BuddyStatus buddyStatus1 = BuddyStatus.PendingApprovalFromOther, BuddyStatus buddyStatus2 = BuddyStatus.PendingApprovalFromSelf)
@ -176,6 +180,30 @@ public class BuddyService
else return false; 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 = 0
};
if (viking.GameVersion <= ClientVersion.WoJS) buddyLocation.AppName = "JSMain";
// return
return buddyLocation;
}
else return new BuddyLocation();
}
public BuddyList ConstructBuddyList(Viking viking) public BuddyList ConstructBuddyList(Viking viking)
{ {
// get all relationships viking has made // get all relationships viking has made

View File

@ -87,6 +87,14 @@ public class MessagingService
return message; 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) public void RemoveMessage(int id)
{ {
// find message // find message