Merge pull request 'SES-106 Added new mwthod and changed static fields in Hub to be able to share them in other classes' (#31) from SES-106 into dev
Reviewed-on: #31
This commit is contained in:
commit
a37ebe0e98
@ -6,8 +6,12 @@ using System.Threading.Tasks;
|
|||||||
namespace SessionCompanion.Controllers
|
namespace SessionCompanion.Controllers
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
|
using System.Security.Policy;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
using SessionCompanion.Extensions.EitherType;
|
using SessionCompanion.Extensions.EitherType;
|
||||||
|
using SessionCompanion.Hubs;
|
||||||
using SessionCompanion.ViewModels.ApiResponses;
|
using SessionCompanion.ViewModels.ApiResponses;
|
||||||
using SessionCompanion.ViewModels.UserViewModels;
|
using SessionCompanion.ViewModels.UserViewModels;
|
||||||
|
|
||||||
@ -17,9 +21,12 @@ namespace SessionCompanion.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IUserService _service;
|
private readonly IUserService _service;
|
||||||
|
|
||||||
|
private SessionHubData _sessionHubData;
|
||||||
|
|
||||||
public UserController(IUserService service)
|
public UserController(IUserService service)
|
||||||
{
|
{
|
||||||
this._service = service;
|
this._service = service;
|
||||||
|
this._sessionHubData = new SessionHubData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -69,5 +76,15 @@ namespace SessionCompanion.Controllers
|
|||||||
|
|
||||||
return new SuccessResponse("User created");
|
return new SuccessResponse("User created");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Metoda sprawdza czy ktoś jest już zalogowany jako Game Master
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true jesli ktoś jest już zalogowany i false jeśli nie</returns>
|
||||||
|
[HttpGet("IsGMLogged")]
|
||||||
|
public Either<bool, ErrorResponse> IsGameMasterAllreadyLogged()
|
||||||
|
{
|
||||||
|
return this._sessionHubData.GameMasterConnected_Prop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SessionCompanion.Hubs
|
namespace SessionCompanion.Hubs
|
||||||
@ -9,17 +7,13 @@ namespace SessionCompanion.Hubs
|
|||||||
public class SessionHub : Hub
|
public class SessionHub : Hub
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lista zalogowanych graczy i identyfikator wybranej postaci
|
/// Klasa zawierająca wszystkie dane potrzebne w SignalR odnośnie aktualnej sesji
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static Dictionary<string, int> ConnectedCharacters = new Dictionary<string, int>();
|
private SessionHubData sessionHubData;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Status, czy GM został już zalogowany
|
|
||||||
/// </summary>
|
|
||||||
private static bool GameMasterConnected = new bool();
|
|
||||||
|
|
||||||
public SessionHub()
|
public SessionHub()
|
||||||
{
|
{
|
||||||
|
this.sessionHubData = new SessionHubData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,16 +25,17 @@ namespace SessionCompanion.Hubs
|
|||||||
public override Task OnDisconnectedAsync(Exception exception)
|
public override Task OnDisconnectedAsync(Exception exception)
|
||||||
{
|
{
|
||||||
// if true then it is character, if false it is GM
|
// if true then it is character, if false it is GM
|
||||||
if (ConnectedCharacters.ContainsKey(Context.ConnectionId))
|
if (this.sessionHubData.ConnectedCharacters_Prop.ContainsKey(Context.ConnectionId))
|
||||||
{
|
{
|
||||||
Groups.RemoveFromGroupAsync(Context.ConnectionId, "Players");
|
Groups.RemoveFromGroupAsync(Context.ConnectionId, "Players");
|
||||||
ConnectedCharacters.Remove(Context.ConnectionId);
|
this.sessionHubData.ConnectedCharacters_Prop.Remove(Context.ConnectionId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Groups.RemoveFromGroupAsync(Context.ConnectionId, "GameMaster");
|
Groups.RemoveFromGroupAsync(Context.ConnectionId, "GameMaster");
|
||||||
GameMasterConnected = false;
|
this.sessionHubData.GameMasterConnected_Prop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clients.All.SendAsync("GoodBye", "Player has left the game");
|
Clients.All.SendAsync("GoodBye", "Player has left the game");
|
||||||
return base.OnDisconnectedAsync(exception);
|
return base.OnDisconnectedAsync(exception);
|
||||||
}
|
}
|
||||||
@ -54,10 +49,10 @@ namespace SessionCompanion.Hubs
|
|||||||
/// <returns>Zwraca true - jeśli udało się zalogować, false - jesli ktoś zalogował się już jako GM</returns>
|
/// <returns>Zwraca true - jeśli udało się zalogować, false - jesli ktoś zalogował się już jako GM</returns>
|
||||||
public bool GameMasterLogin()
|
public bool GameMasterLogin()
|
||||||
{
|
{
|
||||||
if (!GameMasterConnected)
|
if (!this.sessionHubData.GameMasterConnected_Prop)
|
||||||
{
|
{
|
||||||
Groups.AddToGroupAsync(Context.ConnectionId, "GameMaster");
|
Groups.AddToGroupAsync(Context.ConnectionId, "GameMaster");
|
||||||
GameMasterConnected = true;
|
this.sessionHubData.GameMasterConnected_Prop = true;
|
||||||
Clients.All.SendAsync("Welcome", "Welcome new Game Master");
|
Clients.All.SendAsync("Welcome", "Welcome new Game Master");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -77,7 +72,7 @@ namespace SessionCompanion.Hubs
|
|||||||
/// <returns>Wysyła wiadomość "Welcome" do wszystkich zalogowanych użytkoników</returns>
|
/// <returns>Wysyła wiadomość "Welcome" do wszystkich zalogowanych użytkoników</returns>
|
||||||
public Task PlayerCharacterLogin(int characterId)
|
public Task PlayerCharacterLogin(int characterId)
|
||||||
{
|
{
|
||||||
ConnectedCharacters.Add(Context.ConnectionId, characterId);
|
this.sessionHubData.ConnectedCharacters_Prop.Add(Context.ConnectionId, characterId);
|
||||||
Groups.AddToGroupAsync(Context.ConnectionId, "Players");
|
Groups.AddToGroupAsync(Context.ConnectionId, "Players");
|
||||||
|
|
||||||
return Clients.All.SendAsync("Welcome", "Welcome new Player");
|
return Clients.All.SendAsync("Welcome", "Welcome new Player");
|
||||||
|
52
SessionCompanion/SessionCompanion/Hubs/SessionHubData.cs
Normal file
52
SessionCompanion/SessionCompanion/Hubs/SessionHubData.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SessionCompanion.Hubs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Statyczna klasa przechowujaca informacje dotyczące SignalR dla SessionHub
|
||||||
|
/// </summary>
|
||||||
|
public class SessionHubData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Lista zalogowanych graczy i identyfikator wybranej postaci
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<string, int> ConnectedCharacters = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status, czy GM został już zalogowany
|
||||||
|
/// </summary>
|
||||||
|
public static bool GameMasterConnected;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zwraca lub ustawia status zalogowania GM
|
||||||
|
/// </summary>
|
||||||
|
public bool GameMasterConnected_Prop
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return GameMasterConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
GameMasterConnected = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zwraca lub ustawia listę zalogowanych graczy
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, int> ConnectedCharacters_Prop
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ConnectedCharacters;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
ConnectedCharacters = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,12 @@
|
|||||||
<param name="userRegisterModel"> Model uzytkownika do zarejestrowania </param>
|
<param name="userRegisterModel"> Model uzytkownika do zarejestrowania </param>
|
||||||
<returns> SuccessResponse/ErrorResponse </returns>
|
<returns> SuccessResponse/ErrorResponse </returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:SessionCompanion.Controllers.UserController.IsGameMasterAllreadyLogged">
|
||||||
|
<summary>
|
||||||
|
Metoda sprawdza czy ktoś jest już zalogowany jako Game Master
|
||||||
|
</summary>
|
||||||
|
<returns>true jesli ktoś jest już zalogowany i false jeśli nie</returns>
|
||||||
|
</member>
|
||||||
<member name="F:SessionCompanion.Hubs.SessionHub.ConnectedCharacters">
|
<member name="F:SessionCompanion.Hubs.SessionHub.ConnectedCharacters">
|
||||||
<summary>
|
<summary>
|
||||||
Lista zalogowanych graczy i identyfikator wybranej postaci
|
Lista zalogowanych graczy i identyfikator wybranej postaci
|
||||||
@ -58,5 +64,30 @@
|
|||||||
<param name="characterId"> Identyfikator zalogowanego bohatera </param>
|
<param name="characterId"> Identyfikator zalogowanego bohatera </param>
|
||||||
<returns>Wysyła wiadomość "Welcome" do wszystkich zalogowanych użytkoników</returns>
|
<returns>Wysyła wiadomość "Welcome" do wszystkich zalogowanych użytkoników</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:SessionCompanion.Hubs.SessionHubData">
|
||||||
|
<summary>
|
||||||
|
Statyczna klasa przechowujaca informacje dotyczące SignalR dla SessionHub
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:SessionCompanion.Hubs.SessionHubData.ConnectedCharacters">
|
||||||
|
<summary>
|
||||||
|
Lista zalogowanych graczy i identyfikator wybranej postaci
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:SessionCompanion.Hubs.SessionHubData.GameMasterConnected">
|
||||||
|
<summary>
|
||||||
|
Status, czy GM został już zalogowany
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:SessionCompanion.Hubs.SessionHubData.GameMasterConnected_Prop">
|
||||||
|
<summary>
|
||||||
|
Zwraca lub ustawia status zalogowania GM
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:SessionCompanion.Hubs.SessionHubData.ConnectedCharacters_Prop">
|
||||||
|
<summary>
|
||||||
|
Zwraca lub ustawia listę zalogowanych graczy
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
Loading…
Reference in New Issue
Block a user