public TwoWayResult SendMessageTo(string messageTo, string message)
 {
     dynamic call = new ClientCall { ClientId = messageTo, CallerId = CurrentUser };
     //make the remote call
     call.messageReceived(CurrentUser, message , true);
     return new TwoWayResult(call);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Used to raise the Connection lost event from outside
 /// </summary>
 /// <param name="call">The call that failed</param>
 internal static void RaiseConnectionLostEvent(ClientCall call)
 {
     if (ConnectionLost != null)
     {
         ConnectionLost(call);
     }
 }
        public TwoWayResult AcceptChallenge(Guid challengeId)
        {
            //get the challenge
            var match = factory.GetGame().AcceptChallenge(challengeId);
            //inform the challenger that the challenge was accepted
            string clientId = factory.GetPlayerPresence().GetClientId(match.Item2);

            if (!string.IsNullOrWhiteSpace(clientId))
            {
                //Clients[clientId].challengeAccepted(match.Item1);
                //The client accepted the challenge
                dynamic call1 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
                call1.game.challengeAccepted(match.Item1);
                RemoteExecution.ExecuteOnClient(call1);

                //Caller.goToGame(match.Item1);
                //Tell the caller to go to the match
                dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call2.game.goToGame(match.Item1);
                return new TwoWayResult(call2);
            }
            else
            {
                //Caller.otherPlayerNotOnline();
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call.game.otherPlayerNotOnline();
                return call;
            }
        }
 void TwoWayController_ConnectionLost(ClientCall call)
 {
     //remove it from the logged users
     UserHelper.UserLogoff(call.ClientId);
     //tell everybody to reload the userlist
     ReloadUserList();
 }
 public TwoWayResult SendMessageTo(string messageTo, string message)
 {
     dynamic call = new ClientCall { ClientId = messageTo, CallerId = User.Identity.Name };
     //make the remote call
     call.messageReceived(User.Identity.Name, message , true);
     return new TwoWayResult(call);
 }
 void TwoWayController_ConnectionLost(ClientCall call)
 {
     //remove it from the logged users
     if (CurrentUsers.Contains(call.ClientId))
         CurrentUsers.Remove(call.ClientId);
     //tell everybody to reload the userlist
     ReloadUserList();
 }
 public void CallerIdTest()
 {
     ClientCall target = new ClientCall(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.CallerId = expected;
     actual = target.CallerId;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public TwoWayResult ChallengePlayer(Guid playerId)
 {
     string clientId = factory.GetPlayerPresence().GetClientId(playerId);
     Guid fromId = factory.GetPlayerPresence().GetPlayerId(Context.ConnectionId);
     factory.GetGame().ChallengePlayer(fromId, playerId);
     //inform the player that has a new challenge
     //Clients[clientId].newChallenge();
     dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
     call.game.newChallenge();
     return new TwoWayResult(call);
 }
 /// <summary>
 /// This is used when a the javascript call its part of a javascript namespace
 /// </summary>
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     //if clientId or callerid is invoked set the values
     if (binder.Name == "ClientId")
         result = this.ClientId;
     else if (binder.Name == "CallerId")
         result = this.CallerId;
     else
     {
         //we are not invoking, we try to use a namespace
         dynamic res = new ClientCall { };
         Child = res;
         result = res;
         //set the name of the method to invoke
         Method = binder.Name;
     }
     //always return true
     return true;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// This is used when a the javascript call its part of a javascript namespace
 /// </summary>
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     //if clientId or callerid is invoked set the values
     if (binder.Name == "ClientId")
     {
         result = this.ClientId;
     }
     else if (binder.Name == "CallerId")
     {
         result = this.CallerId;
     }
     else
     {
         //we are not invoking, we try to use a namespace
         dynamic res = new ClientCall {
         };
         Child  = res;
         result = res;
         //set the name of the method to invoke
         Method = binder.Name;
     }
     //always return true
     return(true);
 }
 public static void ReloadUserList()
 {
     dynamic reload = new ClientCall { CallerId = string.Empty, ClientId = string.Empty };
     reload.getUsers();
     RemoteExecution.BroadcastExecuteOnClient(reload);
 }		       
 void TwoWayController_ConnectionLost(ClientCall call)
 {
     //Implement code that needs to be executed when a connection is lost
 }
 public void TryInvokeMemberTest()
 {
     ClientCall target = new ClientCall(); // TODO: Initialize to an appropriate value
     InvokeMemberBinder binder = null; // TODO: Initialize to an appropriate value
     object[] args = null; // TODO: Initialize to an appropriate value
     object result = null; // TODO: Initialize to an appropriate value
     object resultExpected = null; // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.TryInvokeMember(binder, args, out result);
     Assert.AreEqual(resultExpected, result);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        public TwoWayResult RejectChallenge(Guid challengeId)
        {
            var data = factory.GetGame().RejectChallenge(challengeId);
            if (!string.IsNullOrWhiteSpace(data.Item1))
            {
                //the challenge was not accepted
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = data.Item1 };
                call.game.challengeRejected(data.Item2);
                ///RemoteExecution.ExecuteOnClient(call);
                return new TwoWayResult(call);
                //Clients[data.Item1].challengeRejected(data.Item2);
            }

            return null;
        }
        public TwoWayResult PlayMatch(Guid matchId)
        {
            var m = factory.GetGame(matchId, true);
            m.RestartMatch();
            //send the match info
            string player1ClientId = factory.GetPlayerPresence().GetClientId(m.Player1);
            string player2ClientId = factory.GetPlayerPresence().GetClientId(m.Player2);
            //verify the client id
            if (Context.ConnectionId != player1ClientId && Context.ConnectionId != player2ClientId)
            {
                //cannot determine the ID of the caller
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call.game.identityError();
                //Caller.identityError();
                return new TwoWayResult(call);
            }
            //create a group for this match
            //base.GroupManager.AddToGroup(player1ClientId, string.Format("match_", id));
            //base.GroupManager.AddToGroup(player2ClientId, string.Format("match_", id));

            string player1Name = factory.GetPlayerPresence().GetPlayerNameByClientId(player1ClientId);
            string player2Name = factory.GetPlayerPresence().GetPlayerNameByClientId(player2ClientId);
            var mi = new MatchInfo
            {
                MatchId = m.MatchId,
                Player1 = m.Player1,
                Player2 = m.Player2,
                Turn = m.Turn,
                Player1ClientId = player1ClientId,
                Player2ClientId = player2ClientId,
                OponentClientId = player1ClientId == Context.ConnectionId ? player2ClientId : player1ClientId,
                PlayerId = player1ClientId == Context.ConnectionId ? m.Player1 : m.Player2,
                MyPlayerName = player1ClientId == Context.ConnectionId ? player1Name : player2Name,
                OtherPlayerName = player1ClientId == Context.ConnectionId ? player2Name : player1Name
            };
            Guid iam = player1ClientId == Context.ConnectionId ? m.Player1 : m.Player2;
            mi.Units = m.Units.Where(u => u.PlayerId == iam).Select(u =>
                        new UnitInfo
                        {
                            UnitId = u.UnitId,
                            PlayerId = u.PlayerId,
                            Name = u.Name,
                            MaxHealth = u.MaxHealth,
                            Health = u.Health,
                            Col = u.Column,
                            Row = u.Row
                        }
                        ).ToArray();
            //send the match info to the player
            //Caller.matchReady(mi);
            dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
            call2.game.matchReady(mi);
            return new TwoWayResult(call2);
        }
        public void PlayerReady(Guid matchId, Guid playerId)
        {
            var m = factory.GetGame(matchId, true);
            m.PlayerReady(playerId);
            string clientId1 = factory.GetPlayerPresence().GetClientId(playerId);
            string clientId2 = factory.GetPlayerPresence().GetClientId(playerId == m.Player1 ? m.Player2 : m.Player1);
            //start the match if both are ready
            if (m.Player1Ready && m.Player2Ready)
            {
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId1 };
                call.game.startMatch();
                RemoteExecution.ExecuteOnClient(call);

                dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId2 };
                call2.game.startMatch();
                RemoteExecution.ExecuteOnClient(call2);

                //Clients[string.Format("match_", matchId)].startMatch();
            }
            else
            {
                //inform the other player that the player is ready
                if (RemoteExecution.ClientIsOnLine(clientId2))
                {
                    dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId2 };
                    //Clients[clientId].otherPlayerIsReady();
                    call.game.otherPlayerIsReady();
                    RemoteExecution.ExecuteOnClient(call, false);
                }
                else //TODO:tell the client that the other player is not online
                {
                    dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId1};
                    call.game.otherPlayerNotOnline();
                    RemoteExecution.ExecuteOnClient(call);
                }
            }
        }
        public TwoWayResult PlayerChat(string message, string clientId)
        {
            //sanitize the message
            message = Encoder.HtmlEncode(message);
            dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
            call.game.receiveMessage(message);
            return new TwoWayResult(call);

            //Clients[clientId].receiveMessage(message);
        }
 public void TrySetMemberTest()
 {
     ClientCall target = new ClientCall(); // TODO: Initialize to an appropriate value
     SetMemberBinder binder = null; // TODO: Initialize to an appropriate value
     object value = null; // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.TrySetMember(binder, value);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
 /// <summary>
 /// Used to raise the Connection lost event from outside
 /// </summary>
 /// <param name="call">The call that failed</param>
 internal static void RaiseConnectionLostEvent(ClientCall call)
 {
     if (ConnectionLost != null)
         ConnectionLost(call);
 }
 public void ClientCallConstructorTest()
 {
     dynamic target = new ClientCall { CallerId = "Test", ClientId = "Test" };
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
        public TwoWayResult InvitePlayer(Guid matchId, string clientId)
        {
            var player = factory.GetPlayerPresence().GetPlayerNameByClientId(Context.ConnectionId);

            dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
            call.game.inviteToMatch(matchId, player);
            return new TwoWayResult(call);

            //Clients[clientId].inviteToMatch(matchId, player);
        }
        public void PlayerAttack(Guid matchId, Guid playerId, int row, int col)
        {
            var m = factory.GetGame(matchId, true);
            string clientId = factory.GetPlayerPresence().GetClientId(m.Player1 == playerId ? m.Player2 : m.Player1);
            var result = m.PlayerAttack(new Position { Row = row, Column = col }, playerId);

            if (result.Command == Command.GameAction && result.Action == GameAction.ShotMade)
            {
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call.game.sucessfulAttack(row, col);
                RemoteExecution.ExecuteOnClient(call);

                dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
                call2.game.takeDamage(new Damage { UnitId = result.UnitId, HealthAfterAttack = result.HealthAfterAttack });
                RemoteExecution.ExecuteOnClient(call2);

                //Caller.sucessfulAttack(row, col);
                //Clients[clientId].takeDamage(new Damage { UnitId = result.UnitId, HealthAfterAttack = result.HealthAfterAttack });
            }
            else if (result.Command == Command.GameAction && result.Action == GameAction.ShotMissed)
            {
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call.game.attackMissed(row, col);
                RemoteExecution.ExecuteOnClient(call);

                dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
                call2.game.shotMissed();
                RemoteExecution.ExecuteOnClient(call2);

                //Caller.attackMissed(row, col);
                //Clients[clientId].shotMissed();
            }
            else if (result.Command == Command.EndGame)
            {
                dynamic call = new ClientCall { CallerId = Context.ConnectionId, ClientId = Context.ConnectionId };
                call.game.endMatch(result.Winner);
                RemoteExecution.ExecuteOnClient(call);

                dynamic call2 = new ClientCall { CallerId = Context.ConnectionId, ClientId = clientId };
                call2.game.endMatch(result.Winner);
                RemoteExecution.ExecuteOnClient(call2);

                //Clients[string.Format("match_", matchId)].endMatch(result.Winner);
            }
        }
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="call">The call to execute on the client</param>
 public TwoWayResult(ClientCall call)
 {
     this.Call = call;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="call">The call to execute on the client</param>
 public TwoWayResult(ClientCall call)
 {
     this.Call = call;
 }