SES-77 #12
@ -8,5 +8,44 @@ namespace SessionCompanion.Hubs
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ namespace SessionCompanion
|
||||
endpoints.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller}/{action=Index}/{id?}");
|
||||
|
||||
endpoints.MapHub<SessionHub>("/sessionhub", options =>
|
||||
{
|
||||
options.Transports =
|
||||
|
Loading…
Reference in New Issue
Block a user