Beispiel #1
0
        public ActionResult AddSession(string sessionguid)
        {
            if (SessionExtensions.ContainsKey(sessionguid))
            {
                MultiPlayerSession currsession = SessionExtensions.Get(sessionguid);

                TaskList.Add(currsession.HostPlayerId, () =>
                {
                    if (SessionExtensions.ContainsKey(currsession.HostPlayerId))
                    {
                        MultiPlayerSession currentActualSession = SessionExtensions.Get(currsession.HostPlayerId);

                        var clientList = currentActualSession.CurrentPlayerList.Select(n => n.UserId.ToString()).ToList();

                        IHubContext multiplayerHub = GlobalHost.ConnectionManager.GetHubContext <MultiplayerHub>();
                        multiplayerHub.Clients.Groups(clientList).broadcastYourClicks();
                    }
                    else
                    {
                        //remove this session.
                        RemoveSession(currsession.HostPlayerId);
                    }
                });
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Session not found."));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK, "Multiplayer session was added to the tasklist."));
        }
Beispiel #2
0
 public ActionResult RemoveSession(string sessionguid)
 {
     if (SessionExtensions.ContainsKey(sessionguid))
     {
         TaskList.Remove(sessionguid);
         return(new HttpStatusCodeResult(HttpStatusCode.OK, "Multiplayer session was removed from the tasklist."));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Session not found."));
 }