public async void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- " + e.ChatMessageFromServer); if (e.CustomServerMessage != null) { App.Current.CurrentGame = e.CustomGameObject; switch (e.CustomServerMessage.Command) { //Login case 0: /* //Update Game List if (e.CustomServerMessage.Action == "login") { App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; Debug.WriteLine(e.UserUpdate.UserName + " " + e.CustomServerMessage.Message); }*/ break; case 1: Debug.WriteLine(e.CustomServerMessage.Action + "MESSAGE- " + e.CustomServerMessage.Message); break; case 2: /* if (e.CustomServerMessage.Action == "created") { //Add game to users game list App.Current.AllGames.Add(e.CustomGameObject); Debug.WriteLine("Created A Game " + e.ChatMessageFromServer); Frame.Navigate(typeof(LobbyPage)); //Ask if they want to join //OpenMessageDialog("join",e.CustomGameObject); }*/ break; case 3: if (e.CustomServerMessage.Action == "join") { //This means you are the first , or second to join // Message: User has joined the Game // Message: User has left Game Lobby chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; } if (e.CustomServerMessage.Action == "ready") { //if you get here then you were not the one to hit ready chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; /* if (e.UserUpdate.UserName == App.Current.AppUser.UserName && e.CustomGameObject.GameStatus<3) { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message + " Waiting for opponent..."; md = e.CustomServerMessage.Message + " Waiting for opponent..."; } else { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; md = e.CustomServerMessage.Message; } if (e.CustomGameObject.GameStatus > 2) { StartingGame(App.Current.CurrentGame, e.UserUpdate); } */ } /* if (e.CustomServerMessage.Action == "start") { chatDialog.Text += "\r\n" + e.CustomServerMessage.Message; //chatDialog.Text += "\r\n" + "Game now starting..."; //if (e.UserUpdate.UserName == App.Current.AppUser.UserName) //{ StartGame(App.Current.CurrentGame,e.UserUpdate); //} } * */ break; case 4: ChangeToGamePage(); break; //start command default: break; } } // Add to local ChatRoom. //chatDialog.Text += "\r\n" + e.ChatMessageFromServer; }); }
public async virtual void UserLogin(User tabletChatClient) { // Fire up SignalR Connection & join chatroom. try { await gameConnection.Start(); if (gameConnection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected) { await SignalRGameHub.Invoke("Login", tabletChatClient); } } catch (Exception ex) { // Do some error handling. Could not connect to Sever Error. Debug.WriteLine("Error: "+ ex.Message); } // On // Listen to chat events on SignalR Server & wire them up appropriately. SignalRGameHub.On<User, ServerMessage>("addNewUpdate", (user, message) => { SignalREventArgs userArgs = new SignalREventArgs(); userArgs.UserUpdate = user; userArgs.CustomServerMessage = message; // Raise custom event & let it bubble up. SignalRServerNotification(this, userArgs); }); SignalRGameHub.On<string, string>("addNewMessageToPage", (message, word) => { SignalREventArgs chatArgs = new SignalREventArgs(); chatArgs.ChatMessageFromServer = message; chatArgs.ChatMessageFromServer = word; // Raise custom event & let it bubble up. SignalRServerNotification(this, chatArgs); }); SignalRGameHub.On<User, List<Game>, List<User>, ServerMessage>("update", (user, agl, ul, sm) => { SignalREventArgs uArgs = new SignalREventArgs(); uArgs.UserUpdate = user; uArgs.CustomGameList = agl; uArgs.CustomAvailableOpponents = ul; uArgs.CustomServerMessage = sm; // Raise custom event & let it bubble up. SignalRServerNotification(this, uArgs); }); SignalRGameHub.On<Game, ServerMessage>("gameCreated", (g, sm) => { SignalREventArgs gArgs = new SignalREventArgs(); gArgs.CustomGameObject = g; gArgs.CustomServerMessage = sm; // Raise custom event & let it bubble up. SignalRServerNotification(this, gArgs); }); SignalRGameHub.On<User, Game, ServerMessage>("lobbyMessage", (u, g, sm) => { SignalREventArgs gArgs = new SignalREventArgs(); gArgs.UserUpdate = u; gArgs.CustomGameObject = g; gArgs.CustomServerMessage = sm; // Raise custom event & let it bubble up. SignalRServerNotification(this, gArgs); }); SignalRGameHub.On<Game, InGameMessage>("inGameMessage", (g, im) => { SignalREventArgs gArgs = new SignalREventArgs(); gArgs.CustomGameObject = g; gArgs.InGameActionMessageEvent = im; // Raise custom event & let it bubble up. SignalRServerNotification(this, gArgs); }); }
public virtual void OnSignalRServerNotificationReceived(SignalREventArgs e) { if (SignalRServerNotification != null) { SignalRServerNotification(this, e); } }
protected async void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- "+e.ChatMessageFromServer); if (e.CustomServerMessage != null) { switch (e.CustomServerMessage.Command) { //Login case 0: //Update Game List if (e.CustomServerMessage.Action == "login") if(App.Current.AppUser.UserName == e.UserUpdate.UserName){ App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; //App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification); Frame.Navigate(typeof(HubPage)); } break; case 1: if (e.CustomServerMessage.Action == "update") { if (App.Current.AppUser.UserName == e.UserUpdate.UserName) { App.Current.AppUser = e.UserUpdate; App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; //Upload Games Frame.Navigate(typeof(HubPage)); } } break; default: break; } } }); }
protected async void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //Debug.WriteLine("SEND, - SIMPLE CHAT WORKS- "+e.ChatMessageFromServer); if (e.CustomServerMessage.Command >-1) { switch (e.CustomServerMessage.Command) { //Login case 0: //Update Game List if (e.CustomServerMessage.Action == "login") { if (e.UserUpdate.UserName != App.Current.AppUser.UserName) { App.Current.OppUsers.Add(e.UserUpdate); } else { App.Current.AppUser = e.UserUpdate; //Upload Games App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; } } break; case 1: if (e.CustomServerMessage.Action == "update") { if (App.Current.AppUser.UserName == e.UserUpdate.UserName) { App.Current.AppUser = e.UserUpdate; //Upload Games // App.Current.AllGames = e.CustomGameList; App.Current.OppUsers = e.CustomAvailableOpponents; if (_spheroGames != null) { Debug.WriteLine(_spheroGames.GameItems.Count()); _spheroGames.GameItems.Clear(); } else { fillgamelist(); } foreach (var g in e.CustomGameList) { if (_spheroGames.GameItems.Contains(g)) { } else { _spheroGames.GameItems.Add(g); } } } } break; case 2: if (e.CustomServerMessage.Action == "created") { //Add game to users game list Debug.WriteLine("Created A Game " + e.CustomServerMessage.Message); //Frame.Navigate(typeof(LobbyPage)); //Ask if they want to join if (e.CustomGameObject.OpponentName == App.Current.AppUser.UserName) { App.Current.AllGames.Add(e.CustomGameObject); App.Current.CurrentGame = e.CustomGameObject; //Someone else created the game notify user to call on navigated to Debug.WriteLine("HubPage: CREATED < someone challenged you" + e.CustomServerMessage.Message); //updateGames(); } else { OpenMessageDialog(e.CustomGameObject); } } break; case 3: if (e.CustomServerMessage.Action == "join") { //This means you are the first , or second to join // Message: User has joined the Game // Message: User has left Game Lobby //ChangeListener(); //Frame.Navigate(typeof(LobbyPage)); //chatDialog.Text += "\r\n" + e.ChatMessageFromServer; Debug.WriteLine("JOIN WENT TO HUBPAGE"); } if (e.CustomServerMessage.Action == "ready") { } break; default: //Notify the User that you're getting not defined Messages Debug.WriteLine("Just Recieved unknown command"+e.CustomServerMessage.Action + " " + e.CustomServerMessage.Message); break; } } // Add to local ChatRoom. //chatDialog.Text += "\r\n" + e.ChatMessageFromServer; }); }
protected async void SignalRHub_SignalRServerNotification(object sender, SignalREventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { //...has already started //upDate Game Object Start time //start timer //e.InGameActionMessageEvent(state) App.Current.CurrentGame = e.CustomGameObject; LivesLeftBlock.Text = "Lives Left: " + App.Current.CurrentGame.MaxHits; StateBlock.Text = "State: " + App.Current.CurrentGame.GameState; //feed back from Ready if (e.CustomGameObject.GameStatus < 4) //opp not ready { waitingBlock.Text = "Waiting for Opponent..."; } else { //Make visible in Visible image.Visibility = Windows.UI.Xaml.Visibility.Collapsed; image2.Visibility = Windows.UI.Xaml.Visibility.Collapsed; waitingBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } if (e.InGameActionMessageEvent.Action == "end") { //Triger End event if (App.Current.CurrentGame != null) { if(e.CustomGameObject.SpheroPlayer.UserName == App.Current.AppUser.UserName) { if (e.CustomGameObject.Winner.UserName == App.Current.AppUser.UserName) { App.Current.AppUser.GWAS++; } else { App.Current.AppUser.GLAS++; } } App.Current.CurrentGame = new Game(); EndGame(e.CustomGameObject); } } else { switch (e.CustomGameObject.GameState) { //main state of game case 0: if (e.InGameActionMessageEvent.Action == "start") { //STOP HERE!!!!!!!! //if I'm a sphero display Warning if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { NotificationBlock.Text = "One minute before Targeting systems are active."; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { NotificationBlock.Text = "You have One minute to hide!"; } } if (e.InGameActionMessageEvent.Action == "hit") { _hits = e.InGameActionMessageEvent.Hits; if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { NotificationBlock.Text = "Hit Successful"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { NotificationBlock.Text = "You've been hit!"; int x = e.CustomGameObject.MaxHits--; LivesLeftBlock.Text = "Lives left: " + x.ToString(); } } if (e.InGameActionMessageEvent.Action == "lost") { if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { NotificationBlock.Text = "Lost Target!"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { NotificationBlock.Text = "Evaded the enemy"; } } //Actions - update GameObject - start Time, targeted, end break; //targeted state case 1: if (e.InGameActionMessageEvent.Action == "targeted") { //if I'm a sphero display Warning if (App.Current.AppUser.UserId == e.CustomGameObject.DronePlayer.UserId) { NotificationBlock.Text = "Locked on Target"; } if (App.Current.AppUser.UserId == e.CustomGameObject.SpheroPlayer.UserId) { NotificationBlock.Text = "TARGETED!"; } } //Actions - fire, end(time), end(hits), lost break; //End State (show Winner message) case 2: //Current.Game = null break; default: break; } } }); }