Initial commit

This commit is contained in:
Chris Chen
2022-09-08 08:04:32 -07:00
commit 184db15773
4604 changed files with 503905 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace WebAPI.Hubs
{
public enum AvalonStage
{
JoinGame,
NewGame,
PickTeammate,
TeamVote,
TeamVoteResult,
QuestVote,
QuestVoteResult
}
public class AvalonHub : Hub
{
private readonly GameRoomLogic gameRoomLogic;
public AvalonHub(GameRoomLogic gameRoomLogic)
{
this.gameRoomLogic = gameRoomLogic;
}
public async Task JoinGame(string connectionId, string username)
{
await Clients.All.SendAsync("JoinGame", connectionId, username);
}
public async Task RefreshStage(AvalonStage stage)
{
await Clients.All.SendAsync("RefreshStage", stage);
}
public async Task Broadcast(string connectionId,string action, string jsonString)
{
//await Clients.AllExcept(connectionId).SendAsync("Broadcast", action, jsonString);
await Clients.Others.SendAsync("Broadcast", action, jsonString);
}
public override Task OnConnectedAsync()
{
var username = Context.GetHttpContext().Request.Query["username"];
var userId = Context.GetHttpContext().Request.Query["userId"];
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception exception)
{
var userId = Context.GetHttpContext().Request.Query["userId"];
Clients.All.SendAsync("Broadcast", "LeaveGame", Context.ConnectionId);
return base.OnDisconnectedAsync(exception);
}
}
}
+73
View File
@@ -0,0 +1,73 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebAPI.Models.IceBreak;
namespace WebAPI.Hubs
{
public class BaseHub : Hub
{
//private const string GAME_ROOM_KEY = "GameRooms";
//private const string GAME_ROOM_ID_KEY = "GameRoomId";
//private const string PLAYER_INFO_KEY = "GameRoomId";
//private readonly IMemoryCache memoryCache;
//public List<GameRoom> GameRooms
//{
// get
// {
// if (memoryCache.Get<List<GameRoom>>(GAME_ROOM_KEY) == null)
// {
// memoryCache.Set(GAME_ROOM_KEY, new List<GameRoom>());
// }
// return memoryCache.Get<List<GameRoom>>(GAME_ROOM_KEY);
// }
// set => memoryCache.Set(GAME_ROOM_KEY, value);
//}
//public string GameRoomId
//{
// get
// {
// if (memoryCache.Get<string>(GAME_ROOM_ID_KEY) == null)
// {
// memoryCache.Set(GAME_ROOM_ID_KEY, string.Empty);
// }
// return memoryCache.Get<string>(GAME_ROOM_ID_KEY);
// }
// set => memoryCache.Set(GAME_ROOM_ID_KEY, value);
//}
//public GamePlayer PlayerInfo
//{
// get
// {
// //this.Context.User
// var name = HttpContext.Session.GetString("12");
// if (HttpContext.Session.GetString("PlayerInfo") == null)
// {
// HttpContext.Session["PlayerInfo"] = new GamePlayer();
// }
// return (GamePlayer)HttpContext.Session["PlayerInfo"];
// }
// set => HttpContext.Session["PlayerInfo"] = value;
//}
//public BaseHub(IMemoryCache memoryCache)
//{
// this.memoryCache = memoryCache;
//}
}
}
+37
View File
@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebAPI.Hubs
{
public class WhoIsSpyHub:Hub
{
private readonly GameRoomLogic gameRoomLogic;
public WhoIsSpyHub(GameRoomLogic gameRoomLogic)
{
this.gameRoomLogic = gameRoomLogic;
}
public async Task JoinGame(string clientId,string username)
{
await Clients.All.SendAsync("JoinGame", clientId, username);
}
public override Task OnConnectedAsync()
{
var username = Context.GetHttpContext().Request.Query["username"];
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception exception)
{
var username = Context.GetHttpContext().Request.Query["username"];
return base.OnDisconnectedAsync(exception);
}
}
}