Add remaining project files
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
using DeluxeBackend.Models;
|
||||
using DeluxeBackend.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using static DeluxeBackend.Enums;
|
||||
|
||||
namespace DeluxeBackend.Controllers.Matchmaking
|
||||
{
|
||||
[Route("Matchmaking/player")]
|
||||
[ApiController]
|
||||
public class PlayerController : ControllerBase
|
||||
{
|
||||
private readonly IJwtService jwt;
|
||||
private readonly ILiteDbService db;
|
||||
private readonly INotificationService ws;
|
||||
|
||||
public PlayerController(IJwtService _jwt, ILiteDbService _db, INotificationService _ws) {
|
||||
jwt = _jwt;
|
||||
db = _db;
|
||||
ws = _ws;
|
||||
}
|
||||
[HttpPost("login")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> Login()
|
||||
{
|
||||
return Ok("");
|
||||
}
|
||||
[HttpPost("exclusivelogin")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> ExclusiveLogin()
|
||||
{
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return NotFound("User not found in database");
|
||||
}
|
||||
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
}
|
||||
presence.Instance = null;
|
||||
presence.LastOnline = DateTime.UtcNow;
|
||||
presence.IsOnline = true;
|
||||
db.Presences.Upsert(presence);
|
||||
await ws.SendToAllPlayer("PresenceUpdate", presence.ToDictionary());
|
||||
return Ok("");
|
||||
}
|
||||
[HttpGet("connection-info")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> ConnectioniInfo([FromQuery(Name ="roomInstanceId")] long? roomInstanceId = null)
|
||||
{
|
||||
//return Ok(new { success = false });
|
||||
string? photonRegion = null;
|
||||
string? photonRoomId = null;
|
||||
if (roomInstanceId.HasValue)
|
||||
{
|
||||
RoomInstance? roomInstance = db.RoomInstances.Include(x => x.SubRoom).Include(x => x.SubRoom!.Room).FindById(roomInstanceId.Value);
|
||||
if (roomInstance != null)
|
||||
{
|
||||
photonRegion = roomInstance.PhotonRegion;
|
||||
photonRoomId = roomInstance.PhotonRoom;
|
||||
}
|
||||
}
|
||||
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
return Ok(new { success =true, value = new Dictionary<string, object>() {
|
||||
|
||||
["photonAuthToken"] = "Meow",
|
||||
["photonRealtimeAppId"] = "1b822489-5923-4d99-a0c9-7ca8b39e3481",
|
||||
["photonVoiceAppId"] = "5e54ba56-1c6d-4d7d-95b3-000c1b4f1d82",
|
||||
["photonChatAppId"] = "df1cd903-1d6a-4d74-ab85-19cb5ba38760",
|
||||
["photonRegion"] = photonRegion,
|
||||
["photonRoomId"] = photonRoomId,
|
||||
//["VoiceServerId"] = "test-voice-5",
|
||||
//["VoiceConnectionInfo"] = "192.168.1.171:6791"
|
||||
|
||||
} });
|
||||
#pragma warning restore CS8601
|
||||
#pragma warning restore CS8625
|
||||
}
|
||||
|
||||
[HttpPost("heartbeat")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> Heartbeat()
|
||||
{
|
||||
LoginWithInfoResult? login = await jwt.GetLoginWithInfo(User);
|
||||
if (login == null) return Unauthorized();
|
||||
|
||||
Account account = login.Account;
|
||||
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
}
|
||||
presence.LastOnline = DateTime.UtcNow;
|
||||
presence.IsOnline = true;
|
||||
presence.AppVersion = login.AppVersion;
|
||||
db.Presences.Upsert(presence);
|
||||
await ws.SendToAllPlayer("PresenceUpdate", presence.ToDictionary());
|
||||
return Ok(presence.ToDictionary());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Player([FromQuery(Name = "id")] List<long> accountIds)
|
||||
{
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return NotFound("User not found in database");
|
||||
}
|
||||
List<Dictionary<string, object>> presences = new List<Dictionary<string, object>>();
|
||||
foreach (var accountId in accountIds)
|
||||
{
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == accountId);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence { Account = db.Accounts.FindById(accountId) };
|
||||
}
|
||||
presences.Add(presence.ToDictionary());
|
||||
|
||||
}
|
||||
return Ok(presences);
|
||||
}
|
||||
[HttpPut("gameserverregionpings")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> gameserverregionpings()
|
||||
{
|
||||
return Ok(new { Success = true });
|
||||
}
|
||||
|
||||
[HttpPut("statusvisibility")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> StatusVisibility([FromForm] StatusVisibilityType statusVisibility)
|
||||
{
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return NotFound("User not found in database");
|
||||
}
|
||||
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
}
|
||||
presence.StatusVisibility = statusVisibility;
|
||||
db.Presences.Upsert(presence);
|
||||
await ws.SendToAllPlayer("PresenceUpdate", presence.ToDictionary());
|
||||
return Ok(presence.ToDictionary());
|
||||
}
|
||||
[HttpPut("vrmovementmode")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> VrMovementMode([FromForm] VrMovementModeType vrMovementMode)
|
||||
{
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return NotFound("User not found in database");
|
||||
}
|
||||
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
}
|
||||
presence.VrMovementMode = vrMovementMode;
|
||||
db.Presences.Upsert(presence);
|
||||
await ws.SendToPlayerSubs(account.Id, "PresenceUpdate", presence.ToDictionary());
|
||||
return Ok(presence.ToDictionary());
|
||||
}
|
||||
|
||||
[HttpPost("logout")]
|
||||
[Authorize(Roles = "gameClient")]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
Account? account = await jwt.GetLogin(User);
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return NotFound("User not found in database");
|
||||
}
|
||||
|
||||
AccountPresence presence = db.Presences.Include(x => x.Account).Include(x => x.Instance).Include(x => x.Instance!.SubRoom).Include(x => x.Instance!.SubRoom!.Room).Include(x => x.Instance!.SubRoom!.Room!.Creator).FindOne(x => x.Account.Id == account.Id);
|
||||
if (presence == null)
|
||||
{
|
||||
presence = new AccountPresence
|
||||
{
|
||||
Account = account,
|
||||
};
|
||||
}
|
||||
presence.Instance = null;
|
||||
presence.LastOnline = DateTime.UtcNow;
|
||||
presence.IsOnline = false;
|
||||
db.Presences.Upsert(presence);
|
||||
await ws.SendToAllPlayer("PresenceUpdate", presence.ToDictionary());
|
||||
return Ok("");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user