예제 #1
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
        public void Login(User user)
        {
            if (user == null)
            {
                //TODO: YOU WILL NEED Context.ConnectionId
                //throw new ArgumentException("User handed to Login() is null");
            }
            AllGamesList.Add(testGame);
            AvailableGames.Add(testGame);
            AvailableGames.Add(testGame1);
            AvailableGames.Add(testGame2);
            AvailableGames.Add(testGame3);
            AvailableGames.Add(testGame4);
            user.ContextId = Context.ConnectionId;
            tu1.ContextId = Context.ConnectionId;
            tu2.ContextId = Context.ConnectionId;
            tu3.ContextId = Context.ConnectionId;
            tu4.ContextId = Context.ConnectionId;
            // Add client & broadcast new chat user message to all clients connected to this Hub.
            OnlineUsers.Add(user);
            OnlineUsers.Add(tu1);
            OnlineUsers.Add(tu2);
            OnlineUsers.Add(tu3);
            OnlineUsers.Add(tu4);
            UsersConextID.Add(Context.ConnectionId);
            //Clients.All.addChatMessage(newPlayer.UserName + " has joined the Chatroom!");
            //Clients.All.addNewMessageToPage("Loing", "New user = "******"login";
            message.Message = "You are Logged in.";
            //Clients.All.addNewUpdate(user, message);

            //OnlineUsers.Add(testUser);
            //UsersConextID.Add(testUser.UserId);
            //Clients.User(user.UserName).mainUpdate("user", "  hi");
            //Clients.All.mainUpdate("ALL", "  SENt");
            //Clients.User(user.UserName).mainUpdate(user, usersGames, message);
            // Organizing clients in groups ..
            //Groups.Add(Context.ConnectionId, "OnlineUsers");
            //Clients.Group("OnlineUsers").addNewUpdate(user, message);
            //Clients.Group("OnlineUsers").addNewMessageToPage("LOGIN", "From Group addNewMessagePage");
            //Clients.All.addNewUpdate(user, message);
            //Test("Server", user);
            UpdateUser(user, message);
        }
예제 #2
0
 public async virtual void UserUpdate(User tabletChatMessage, ServerMessage s)
 {
     // Post message to Server Chatroom.
     await SignalRGameHub.Invoke("UpdateUser", tabletChatMessage, s);
 }
예제 #3
0
 private void CallLogin()
 {
     if (called)
     {
         ServerMessage s = new ServerMessage(0, "update", "null");
         try
         {
             App.Current.SignalRHub.UserUpdate(App.Current.AppUser, s);
         }
         catch(Exception ex)
         {
             
             ServerDown(ex);
         }
         
     }
     else
     {
         called = true;
         App.Current.SignalRHub.UserLogin(App.Current.AppUser);
     }
 }
예제 #4
0
        private async void OpenMessageDialog(Game g)
        {
            try
            {
                var messageDialog = new MessageDialog("Do you want to Join the Game now?");
                // Add commands and set their command ids
                messageDialog.Commands.Add(new UICommand("Not Now", (command) =>
                {
                    //App.Current.CurrentGame = null;
                    //ServerMessage sm = new ServerMessage(0, "update", "created a game");

                    //App.Current.SignalRHub.UserUpdate(App.Current.AppUser,sm );
                    j = false;
                },
                0));
                messageDialog.Commands.Add(new UICommand("Join Game", (command) =>
                {
                    App.Current.CurrentGame = g;
                    //App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                    //ChangeListener();

                    //Frame.Navigate(typeof(LobbyPage));
                    j = true;
                },
                1));

                // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 1;

                // Show the message dialog and get the event that was invoked via the async operator
                var commandChosen = await messageDialog.ShowAsync();

                if (j == true)
                {
                    App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                    ChangeListener();

                    Frame.Navigate(typeof(LobbyPage));
                }
                else
                {
                    App.Current.CurrentGame = null;
                    ServerMessage sm = new ServerMessage(0, "update", "created a game");

                    App.Current.SignalRHub.UserUpdate(App.Current.AppUser, sm);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Join Dialog Exception " + ex.Message);
            }
 
        }
예제 #5
0
        private async void LoadingGames()
        {

            // Ready and waiting for other user
            var messageDialog = new MessageDialog("Loading Games and Opponents");
            // Add commands and set their command ids
            messageDialog.Commands.Add(new UICommand("Okay", (command) =>
            {
                ServerMessage s1m = new ServerMessage(0, "", "null");
                App.Current.SignalRHub.UserUpdate(App.Current.AppUser, s1m);
            },
            0));


            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = 1;

            // Show the message dialog and get the event that was invoked via the async operator
            var commandChosen = await messageDialog.ShowAsync();

        }
예제 #6
0
        private async void EndGame(Game g)
        {
            string wm;
            if (g.Winner.UserId == App.Current.AppUser.UserId)
            {
                wm = "Game Over, you WON!";
            }
            else
            {
                wm = "Game Over, you lost.";
            }
            var messageDialog = new MessageDialog(wm);
            // Add commands and set their command ids
            messageDialog.Commands.Add(new UICommand("Ok", (command) =>
            {
                App.Current.CurrentGame = null;
                App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification);
                ServerMessage sm = new ServerMessage(0, "update", "null");
                App.Current.SignalRHub.UserUpdate(App.Current.AppUser, sm);
                Frame.Navigate(typeof(HubPage));
            },
            0));


            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = 0;

            // Show the message dialog and get the event that was invoked via the async operator
            var commandChosen = await messageDialog.ShowAsync();
        }
예제 #7
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
        public void JoinGame(User user, Game game)
        {
            ServerMessage jm = new ServerMessage();
            jm.Command = 3;
            int a = -1;
            a = AvailableGames.FindIndex(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated) && (fg.DronePlayer.UserId.Equals(user.UserId) || fg.SpheroPlayer.UserId.Equals(user.UserId)));
            bool triggerStart = false;
            if (a > 0 )
            {
                game.GameStatus++;
                if (game.GameStatus <= 2)
                {
                    jm.Action = "join";
                    jm.Message = user.UserName + " has entered the Lobby";
                    AvailableGames.RemoveAt(a);
                    AvailableGames.Insert(a, game);
                    Groups.Add(Context.ConnectionId, game.GameId);
                    Clients.Group(game.GameId).lobbyMessage(user, game, jm);
                }
                else
                {
                    if (game.GameStatus==3)
                    {
                        jm.Action = "ready";
                        jm.Message = user.UserName + " is Ready to Start the game. ";
                        AvailableGames.RemoveAt(a);
                        AvailableGames.Insert(a, game);
                        //Groups.Add(Context.ConnectionId, game.GameId);
                        Clients.Group(game.GameId).lobbyMessage(user, game, jm);
                    }
                    if (game.GameStatus == 4)
                    {
                        InGameMessage igm = new InGameMessage();
                        igm.Action = "start";
                        
                        game.GameState = 0;

                        /*
                        if (InPlayGames.Count == 0) //No Games Are Running
                        {
                            //Start Timer ...for duration of the game
                            //on every tick check all the games end time === startime + timeInterval of maxtime*60*1000
                            //if curtime < endtime Do nothing... if curtime> endtime then send end event! for that game with igm and keep going...
                            startServerTimer(game);
                        }*/
                        AvailableGames.RemoveAt(a);

                        InPlayGames.Add(game);

                        //Groups.Add(Context.ConnectionId, game.GameId);
                        Clients.Group(game.GameId).inGameMessage(game, igm);
                    }

                }
               
            }
            else
            {
                if (AvailableGames.ElementAt(a).GameId != game.GameId)
                {
                    jm.Message = "ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST";
                    //game not in list
                    Debug.WriteLine("ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST");
                }
                else
                {
                    jm.Message = "ERROR - Tried to Join a game you weren't invited to";
                    //game not in list
                    Debug.WriteLine("ERROR - WRONG USER, trying to access game");
                }
            }

        }
예제 #8
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
 /*
  * We want to create a game
  * Then send a game created event - this triggers Client side (Do you want to Join this game)
  * So the created events needs game message and message and sent to all Users!
  * 
  */
        public void CreateGame(User user, Game g)
        {
            // Call the addNewMessageToPage method to update clients.
            AllGamesList.Add(g);
            AvailableGames.Add(g);
            //int i = AllGamesList.FindIndex(x => x.Equals(g));
           // g.Id = i.ToString(); 
            //AvailableGames.Add(g);


            ServerMessage sm = new ServerMessage();
            sm.Command = 2;
            sm.Action = "created";
            sm.Message = "game created";
            //Clients.User(g.SpheroPlayer.UserName).gameCreated(g, sm); //The User() takes contextID - so make UID = contextID

            //string context;

            //Clients.User("user1").addNewMessageToPage(name, message);
            //if (user.UserId != null) {
            //    context = user.UserId;
            //    Clients.User(context).gameCreated(g, sm);

            //}
            //else
            //{
            //    Clients.All.gameCreated(g, sm);

            //}
            Clients.All.gameCreated(g, sm);
        }
예제 #9
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
        public void UpdateUser(User u, ServerMessage s)
        {
            //TODO: CHECK if u == null or s == null

            int i = -1;

            i = OnlineUsers.FindIndex(x => x.UserName.Equals(u.UserName));
            if (i >-1)
            {
                if (u.ContextId == null)
                {
                    //make u = FindIndex
                    u = OnlineUsers[i];
                }
                else
                {
                    OnlineUsers.RemoveAt(i);
                    OnlineUsers.Insert(i, u);
                }

            }
            else
            {
                OnlineUsers.Add(u);
            }
            List<Game> usersGames = new List<Game>();
            List<User> oppList = new List<User>();
            foreach (User opp in OnlineUsers)
            {
                if (opp.UserName != u.UserName)
                    oppList.Add(opp);
            }

            //Check to see if there are any available games, //... check to see game history...
            foreach (Game g in AvailableGames)
            {
                if (g.DronePlayer.UserName == u.UserName || g.SpheroPlayer.UserName == u.UserName)
                {
                    usersGames.Add(g);
                }
            }
            ServerMessage sm = new ServerMessage();

            if(s.Action == Common.ServerCommand.login.ToString()){
                sm.Command = 0;
                sm.Action = Common.ServerCommand.login.ToString();
                sm.Message = "User Login successful.";
            }
            if (s.Action == "update")
            {
                sm.Command = 1;
                sm.Action = "update";
                sm.Message = "Updateing Games and Sats";
            }
            if(s.Action == "end"){
                sm.Command = 1;
                sm.Action = "update";
                sm.Message = "User Returning to Main Hub ";
            }

            // Call the addNewMessageToPage method to update clients.
            
           /* if (u.UserId != null)
            {

                Clients.User(u.UserId).update(u, usersGames, sm);
            }
            else{
                Clients.All.update(u, usersGames, sm);
            }*/
            Clients.All.update(u, usersGames, oppList,  sm);

            //Clients.User("user1").addNewMessageToPage(name, message);
            //Clients.Group("OnlineUsers").update(u, usersGames, sm);
        }
예제 #10
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
 public void Test(string name, User u)
 {
     // Call the addNewMessageToPage method to update clients.
     User temp = new User();
     temp.UserName = "******";
     ServerMessage sm = new ServerMessage();
     sm.Command = 0;
     sm.Action = "Click";
     sm.Message = "Test Method - " + u.UserName;
     //Clients.All.addNewMessageToPage(name);
     Clients.All.addNewUpdate(temp, sm);
     //Clients.User("user1").addNewMessageToPage(name, message);
     Clients.Group("OnlineUsers").addNewMessageToPage("Groups is working");
 }
예제 #11
0
파일: GameHub.cs 프로젝트: KHCM/SpheroWin8
        /*******
         * 
         * EDIT THIS
         * 
        public void LeaveChatRoom(User userToRemove)
        {
            // Clean-up.
            ConnectedClientsList.Remove(userToRemove);
            Clients.All.addChatMessage(userToRemove.UserName + " has left the Chatroom!");

            Groups.Remove(Context.ConnectionId, "ChatRoom A");
        }

        public void PushChatMessageToClients(string message)
        {
            // Push to all connected clients.
            Clients.All.addChatMessage(message);

            // Communicate to a Group.
            // Clients.Group("ChatRoom A").addChatMessage(message);

            // Invoke a method on the calling client only.
            // Clients.Caller.addChatMessage(message);

            // Similar to above, the more verbose way.
            // Clients.Client(Context.ConnectionId).addChatMessage(message);            
        }
         */
        public void Send(string name, string message)
        {
            // Call the addNewMessageToPage method to update clients.
            User temp = new User();
            temp.UserName = "******";
            ServerMessage sm = new ServerMessage();
            sm.Command = 0; 
            sm.Action = "Login";
            sm.Message = "TEST ON WEB CLICK";
            Clients.All.addNewMessageToPage(name, message);
            Clients.All.addNewUpdate(temp, sm);
            //Clients.User("user1").addNewMessageToPage(name, message);
            Clients.Group("OnlineUsers").addNewMessageToPage(name, message);
        }