SES-77 #12
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 =
|
||||||
|
Loading…
Reference in New Issue
Block a user