Esempio n. 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."));
        }
Esempio n. 2
0
 public static void Add(string key, MultiPlayerSession Session)
 {
     Session.CurrentPlayerList.Add(new Player {
         UserId = Guid.Empty
     });
     lock (AccessLock)
         Sessions.Add(key, Session);
 }
 private async void UpdateSession(MultiPlayerSession session)
 {
     //got a session update from the server. this happens when someone joins your session, or you are playing the game.
     var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;
     await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         OnSessionUpdateReceived?.Invoke(session, null);
     });
 }
        private void ReceiveBossMonsterBroadcast(List <Player> players, BossGamePlatform pl, bool force)
        {
            MultiPlayerSession session = new MultiPlayerSession
            {
                CurrentPlayerList = players,
                CurrentLevel      = new GamePlatform()
                {
                    Monster = pl.Monster, Scene = pl.Scene
                },
                ForceUpdate = force
            };

            UpdateSession(session);
        }
        private async void InitProxyAsync(string serverUrl)
        {
            //perform async initiating operations.
            var pl = await PlayerContext.GetPlayerStateAsync(DeviceInfo.Instance.GetSystemId());

            CurrentPlayerGuid = pl.UserId.ToString();

            hubConnection = new HubConnection(serverUrl);
            hubConnection.Headers.Add("UserGuid", CurrentPlayerGuid);
            MultiPlayerHub              = hubConnection.CreateHubProxy("MultiplayerHub");
            hubConnection.StateChanged += HubConnection_StateChanged;
            await hubConnection.Start().ContinueWith(async task =>
            {
                if (task.IsFaulted)
                {
                    OnConnectionError?.Invoke(task.Exception);
                    //could also be unauthorized due to no correct userguid
                }
                else
                {
                    //connected:
                    MultiPlayerHub.On <MultiPlayerSession>("updateSession", sessionObject => UpdateSession(sessionObject));
                    MultiPlayerHub.On <List <Player>, NormalGamePlatform, bool>("receiveNormalMonsterBroadcast", ReceiveNormalMonsterBroadcast);
                    MultiPlayerHub.On <List <Player>, BossGamePlatform, bool>("receiveBossMonsterBroadcast", ReceiveBossMonsterBroadcast);
                    MultiPlayerHub.On("broadcastYourClicks", RequestClickBatches);
                    MultiPlayerHub.On <BatchedClick>("receiveUploadedBatchClicks", ReceiveUploadedBatchClicks);
                    MultiPlayerHub.On <InviteModel>("receiveInvite", ReceiveInvite);
                }

                //for now render a new level anyways.
                SessionContext = new MultiPlayerSession {
                    CurrentPlayerList = new List <Player> {
                        pl
                    }, HostPlayerId = CurrentPlayerGuid
                };
                SessionContext.CurrentLevel = LevelGenerator.BuildLevel(SessionContext.CurrentPlayerList);
                await BroadcastSessionToServer();
            });

            InitializeComplete?.Invoke(null, null);

            Dictionary <string, string> dingetje = new Dictionary <string, string>
            {
                { "sessionguid", CurrentPlayerGuid }
            };
            await RestHelper.GetRequestAsync("api/multiplayer/AddSession", dingetje);
        }