SES-77 #12

Merged
s426135 merged 3 commits from SES-77 into master 2020-12-05 21:32:05 +01:00
2 changed files with 40 additions and 0 deletions
Showing only changes of commit a88dfaa54f - Show all commits

View File

@ -8,5 +8,44 @@ namespace SessionCompanion.Hubs
{ {
public class SessionHub : Hub public class SessionHub : Hub
{ {
private static Dictionary<string, int> ConnectedCharacters = new Dictionary<string, int>();
public SessionHub()
{
}
public override Task OnDisconnectedAsync(Exception exception)
{
// if true then it is character, if false it is GM
if (ConnectedCharacters.ContainsKey(Context.ConnectionId))
{
Groups.RemoveFromGroupAsync(Context.ConnectionId, "Players");
ConnectedCharacters.Remove(Context.ConnectionId);
}
else
Groups.RemoveFromGroupAsync(Context.ConnectionId, "GameMaster");
Clients.All.SendAsync("GoodBye", "Player has left the game");
return base.OnDisconnectedAsync(exception);
}
#region GameMaster
public Task GameMasterLogin()
{
Groups.AddToGroupAsync(Context.ConnectionId, "GameMaster");
return Clients.All.SendAsync("Welcome", "Welcome new Game Master");
}
#endregion
#region Player
public Task PlayerCharacterLogin(int characterId)
{
ConnectedCharacters.Add(Context.ConnectionId, characterId);
Groups.AddToGroupAsync(Context.ConnectionId, "Players");
return Clients.All.SendAsync("Welcome", "Welcome new Player");
}
#endregion
} }
} }

View File

@ -72,6 +72,7 @@ namespace SessionCompanion
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller}/{action=Index}/{id?}"); pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapHub<SessionHub>("/sessionhub", options => endpoints.MapHub<SessionHub>("/sessionhub", options =>
{ {
options.Transports = options.Transports =