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); } }
public JsonResult PushVideoFragment() { //Get the audio stream and store it on a local collection MemoryStream ms = new MemoryStream(); Request.Files[0].InputStream.CopyTo(ms); ms.Position = 0; string id = Guid.NewGuid().ToString().Replace("-", ""); audios.Add(id, ms); //store the images locally var frames = new List <string>(); foreach (string k in Request.Form.Keys) { frames.Add(Request.Form[k]); } //send the audio to everyone but me var receivers = RemoteController.Users.Where(u => u != Request.Cookies["videoChatUser"].Value); foreach (var u in receivers) { dynamic call = new ClientCall { CallerId = Request.Cookies["videoChatUser"].Value, ClientId = u }; //since we cannot send the audio, we just send the ID of the audio that we just received call.updateVideoFragment(id, frames, Request.Cookies["videoChatUser"].Value); RemoteExecution.ExecuteOnClient(call, false); } return(Json(new { success = true })); }
/// <summary> /// The override does not send anything but makes a client call /// </summary> public override void ExecuteResult(ControllerContext context) { //make the client call if (string.IsNullOrEmpty(this.Call.ClientId)) { RemoteExecution.BroadcastExecuteOnClient(this.Call); } else { RemoteExecution.ExecuteOnClient(this.Call, false); //wait until the call has been made so the connection is not trunckated int len = (int)(string.Concat("data:", this.Call.ToString(), "\n").Length / 20); while (true) { if (SseHelper.ConnectionsMade.Contains(this.Call.ClientId)) { break; } //wait a few miliseconds Thread.Sleep(len); } //send just success var jsonp = new JavaScriptSerializer().Serialize(new { success = true }); context.HttpContext.Response.ContentType = "application/json"; context.HttpContext.Response.Write(jsonp); } }
public void ExecuteOnClientTest() { ClientCall remoteCall = null; // TODO: Initialize to an appropriate value bool raiseEventOnError = false; // TODO: Initialize to an appropriate value RemoteExecution.ExecuteOnClient(remoteCall, raiseEventOnError); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
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 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); } }