backend
This commit is contained in:
parent
24b773d845
commit
d3f8fd23f4
21 changed files with 297 additions and 49 deletions
|
@ -46,6 +46,16 @@ namespace Sledgemapper.Api.Hubs
|
|||
await Clients.Group(sessionName).NewTile(tile);
|
||||
}
|
||||
|
||||
public async Task NewRoom(string sessionName, Room room)
|
||||
{
|
||||
await Clients.Group(sessionName).NewRoom(room);
|
||||
}
|
||||
|
||||
public async Task NewLine(string sessionName, Line line)
|
||||
{
|
||||
await Clients.Group(sessionName).NewLine(line);
|
||||
}
|
||||
|
||||
public async Task NewWall(string sessionName, Wall tile)
|
||||
{
|
||||
await Clients.Group(sessionName).NewWall(tile);
|
||||
|
@ -113,7 +123,7 @@ namespace Sledgemapper.Api.Hubs
|
|||
var userId = int.Parse(Context.User.Identity.Name);
|
||||
var SessionUsers = _dbContext.SessionUsers.Where(m => m.SessionId == sessionId).OrderBy(m => m.UserId).ToList();
|
||||
var user = _datacontext.Users.First(u => u.Id == userId);
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId]};
|
||||
var player = new Player { UserId = userId, Initials = user.Initials, Position = tile, Color = UserColors[userId] };
|
||||
await Clients.Group(sessionName).PlayerUpdate(player);
|
||||
}
|
||||
|
||||
|
@ -131,7 +141,7 @@ namespace Sledgemapper.Api.Hubs
|
|||
public override async Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
var userConnection = _dbContext.UserConnections.FirstOrDefault(m => m.ConnectionId == Context.ConnectionId);
|
||||
var userId=userConnection.UserId;
|
||||
var userId = userConnection.UserId;
|
||||
if (userConnection != null)
|
||||
{
|
||||
_dbContext.UserConnections.Remove(userConnection);
|
||||
|
@ -142,8 +152,8 @@ namespace Sledgemapper.Api.Hubs
|
|||
foreach (var userSession in userSessions)
|
||||
{
|
||||
var session = _dbContext.Sessions.FirstOrDefault(m => m.SessionId == userSession.SessionId);
|
||||
|
||||
await Clients.Group(session.SessionName).RemovePlayer(new Player{UserId=userId}); //send remove player
|
||||
|
||||
await Clients.Group(session.SessionName).RemovePlayer(new Player { UserId = userId }); //send remove player
|
||||
_dbContext.SessionUsers.Remove(userSession);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue