forked from SoDOff-Project/sodoff
Player Invites #10
@ -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")]
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1326
src/Migrations/20250318195040_Viking_CurrentRoomId.Designer.cs
generated
Normal file
1326
src/Migrations/20250318195040_Viking_CurrentRoomId.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
src/Migrations/20250318195040_Viking_CurrentRoomId.cs
Normal file
28
src/Migrations/20250318195040_Viking_CurrentRoomId.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1329
src/Migrations/20250318223639_Viking_CurrentZone.Designer.cs
generated
Normal file
1329
src/Migrations/20250318223639_Viking_CurrentZone.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
src/Migrations/20250318223639_Viking_CurrentZone.cs
Normal file
28
src/Migrations/20250318223639_Viking_CurrentZone.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -823,6 +823,12 @@ namespace sodoff.Migrations
|
|||||||
b.Property<DateTime?>("CreationDate")
|
b.Property<DateTime?>("CreationDate")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<int?>("CurrentRoomId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("CurrentZone")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<uint?>("GameVersion")
|
b.Property<uint?>("GameVersion")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ public class Viking {
|
|||||||
public int? SelectedDragonId { get; set; }
|
public int? SelectedDragonId { get; set; }
|
||||||
|
|
||||||
public bool? Online { 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 ICollection<Session> Sessions { get; set; } = null!;
|
||||||
public virtual User User { get; set; } = null!;
|
public virtual User User { get; set; } = null!;
|
||||||
|
33
src/Schema/BuddyLocation.cs
Normal file
33
src/Schema/BuddyLocation.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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,31 @@ 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 = 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)
|
public BuddyList ConstructBuddyList(Viking viking)
|
||||||
{
|
{
|
||||||
// get all relationships viking has made
|
// get all relationships viking has made
|
||||||
|
@ -45,12 +45,14 @@ public class MMOClientService : IHostedService
|
|||||||
SFSClient.Connect(SFSConfig);
|
SFSClient.Connect(SFSConfig);
|
||||||
|
|
||||||
SFSClient.AddEventListener(SFSEvent.CONNECTION, OnConnectionEstablished);
|
SFSClient.AddEventListener(SFSEvent.CONNECTION, OnConnectionEstablished);
|
||||||
|
SFSClient.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
|
||||||
SFSClient.AddEventListener(SFSEvent.LOGIN, OnLogin);
|
SFSClient.AddEventListener(SFSEvent.LOGIN, OnLogin);
|
||||||
|
|
||||||
// return completed task (SmartFox seems to be completely synchronous)
|
// return completed task (SmartFox seems to be completely synchronous)
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Task SetRoomVarForRoom(int roomId, RoomVariable var)
|
public Task SetRoomVarForRoom(int roomId, RoomVariable var)
|
||||||
{
|
{
|
||||||
if (IsLoggedIn)
|
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)
|
private void OnLogin(BaseEvent evt)
|
||||||
{
|
{
|
||||||
CurrentUser = (User)evt.Params["user"];
|
CurrentUser = (User)evt.Params["user"];
|
||||||
|
@ -68,7 +68,7 @@ public class MessagingService
|
|||||||
message.ConversationID = messageToReplyTo.ConversationID;
|
message.ConversationID = messageToReplyTo.ConversationID;
|
||||||
|
|
||||||
// add a message to the replier's board saying a thread update has occured (if reply isn't to self)
|
// add a message to the replier's board saying a thread update has occured (if reply isn't to self)
|
||||||
if (message.VikingId != message.ToVikingId) AddMessageToViking(message.Viking, message.ToViking, MessageType.Data, MessageTypeID.ThreadUpdate, MessageLevel.WhiteList, "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{BuddyUserName}}'s Message Board!]]", isPrivate: true);
|
if (message.VikingId != message.ToVikingId) AddMessageToViking(message.Viking, message.ToViking, MessageType.Data, MessageTypeID.ThreadUpdate, MessageLevel.WhiteList, "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{OwnerUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{OwnerUserName}}'s Message Board!]]", "[[Line1]]=[[{{BuddyUserName}} Replied To Your Message In {{OwnerUserName}}'s Message Board!]]", isPrivate: true);
|
||||||
} else throw new InvalidOperationException("Tried To Reply To A Message That Doesn't Exist");
|
} else throw new InvalidOperationException("Tried To Reply To A Message That Doesn't Exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -269,7 +277,7 @@ public class MessagingService
|
|||||||
Viking? msgAuthor = ctx.Vikings.FirstOrDefault(e => e.Id == message.VikingId) ?? new Viking();
|
Viking? msgAuthor = ctx.Vikings.FirstOrDefault(e => e.Id == message.VikingId) ?? new Viking();
|
||||||
|
|
||||||
if(message.IsDeleted && !showDeletedMessages) { ctx.Messages.Remove(message); continue; }
|
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;
|
if(!message.IsNew && !showOldMessages) continue;
|
||||||
|
|
||||||
MessageInfo messageInfo = new MessageInfo
|
MessageInfo messageInfo = new MessageInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user