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); }
public virtual void OnInitializeComplete(EventArgs e) { InitializeComplete?.Invoke(this, e); }
public virtual void Initialize() { Initialized = true; InitializeComplete?.Invoke(this, new EventArgs()); }