public override void Activate() { Profile.SyncPlayerLives(); if (_levelData != null) { ObjectsToSerialize.Remove(_levelData); } _attemptsAtCurrentLevel = NextSceneParameters.Get <int>("attempt-count"); _levelComplete = false; _rankingCoordinator.Reset(); _levelData = new SurvivalLevelData(); _levelData.AttemptsAtLevel = _attemptsAtCurrentLevel; ObjectsToSerialize.Add(_levelData); StatusDisplay.CurrentLevelData = _levelData; StatusDisplay.FreezeDisplayedScore = false; RaceAreaName = ""; base.Activate(); if (Profile.PauseOnSceneActivation) { if (!_rankingCoordinator.LevelCompleted) { if (Profile.CurrentAreaData.Name == "Tutorial") { _tutorialRunner.CheckForStepTrigger(_player.WorldPosition); } if (!_paused) { EnablePause(); } } Profile.PauseOnSceneActivation = false; } if (!RecoveredFromTombstone) { ((PlayerMotionEngine)_player.MotionEngine).DifficultySpeedBoosterUnit = Profile.CurrentAreaData.SpeedStep; _readyPopup.Activate(); } else if (_rankingCoordinator.LevelCompleted) { HandleLevelCleared(); } }
public void SendDatas(ObjectsToSerialize datas) { this.receivedDatas = false; this.obj = datas; //Creer un thread de traitement parallèle this.threadSend = new Thread(new ThreadStart(actionSend)); if (localSocketListening != null) { //Fermer la socket d'ecoute localSocketListening.Close(); } if (this.threadListenAndReceive != null) { //Arreter le thread d'ecoute en attente this.threadListenAndReceive.Abort(); } //Lancer le thread this.threadSend.Start(); }
private void actionListenAndReceive() { try { while (true) { //Creation de la socket du serveur localSocketListening = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Lier la socket au point de communication voulue localSocketListening.Bind(targetAdress); //Mettre en ecoute le serveur localSocketListening.Listen(1); //Mettre le serveur en attente de connexion Socket clientSocket = localSocketListening.Accept(); //if (clientSocket.Connected == true) //MessageBox.Show("Nouvelle connexion reussite avec " + clientSocket.AddressFamily.ToString()); int index = 0; int bytes = 0; //Verifier si le dossier temp existe DirectoryInfo dir = new DirectoryInfo(Application.StartupPath + @"\Temp"); if (!dir.Exists) { dir.Create(); } //Verifier si le fichier TXT temp existe string fileTempPath = Application.StartupPath + @"\Temp\datasTemp.xml"; // File.Create(fileTempPath); FileStream fs = new FileStream(fileTempPath, FileMode.Create); StreamWriter writer = new StreamWriter(fs); byte[] buffer; buffer = new byte[5000]; int tailleALire; clientSocket.Receive(buffer); tailleALire = Convert.ToInt32(ASCIIEncoding.ASCII.GetString(buffer)); buffer = new byte[tailleALire * 8]; clientSocket.Receive(buffer); writer.Write((ASCIIEncoding.ASCII.GetString(buffer)).ToCharArray()); /*do * { * try * { * bytes = 0; * * //Recevoir une reponse ... * buffer = new byte[512 * 1024]; * * bytes = clientSocket.Receive(buffer, buffer.Length, 0); * clientSocket.re * //Ecrire les bytes dans un fichier texte temp * //writer.Write(buffer, index, bytes); * writer. * index += bytes; * if (bytes == 0) * break; * } * catch { } * * * * } while (bytes > 0);*/ writer.Close(); fs.Close(); writer = null; fs = null; //Recuperer les objets sérialises du codage XML this.obj = new ObjectsToSerialize(); this.obj = obj.Deserialise(fileTempPath); //Marquer la presence de données this.receivedDatas = true; //Fermer la socket d'ecoute et de reception this.localSocketListening.Close(); //Supprimer le fichier temp File.Delete(Application.StartupPath + @"/Temp/datasTemp.xml"); } } catch (Exception ex) { MessageBox.Show("ERREUR ListenAndReceive : " + ex.Message); localSocketListening.Close(); threadListenAndReceive.Abort(); this.receivedDatas = false; } }
private void actionListenAndReceive() { try { while (true) { //Creation de la socket du serveur localSocketListening = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Lier la socket au point de communication voulue localSocketListening.Bind(targetAdress); //Mettre en ecoute le serveur localSocketListening.Listen(1); //Mettre le serveur en attente de connexion Socket clientSocket = localSocketListening.Accept(); //if (clientSocket.Connected == true) //MessageBox.Show("Nouvelle connexion reussite avec " + clientSocket.AddressFamily.ToString()); int index = 0; int bytes = 0; //Verifier si le dossier temp existe DirectoryInfo dir = new DirectoryInfo(Application.StartupPath + @"\Temp"); if (!dir.Exists) dir.Create(); //Verifier si le fichier TXT temp existe string fileTempPath = Application.StartupPath + @"\Temp\datasTemp.xml"; // File.Create(fileTempPath); FileStream fs = new FileStream(fileTempPath,FileMode.Create); StreamWriter writer = new StreamWriter(fs); byte[] buffer; buffer = new byte[5000]; int tailleALire; clientSocket.Receive(buffer); tailleALire = Convert.ToInt32(ASCIIEncoding.ASCII.GetString(buffer)); buffer = new byte[tailleALire*8]; clientSocket.Receive(buffer); writer.Write((ASCIIEncoding.ASCII.GetString(buffer)).ToCharArray()); /*do { try { bytes = 0; //Recevoir une reponse ... buffer = new byte[512 * 1024]; bytes = clientSocket.Receive(buffer, buffer.Length, 0); clientSocket.re //Ecrire les bytes dans un fichier texte temp //writer.Write(buffer, index, bytes); writer. index += bytes; if (bytes == 0) break; } catch { } } while (bytes > 0);*/ writer.Close(); fs.Close(); writer = null; fs = null; //Recuperer les objets sérialises du codage XML this.obj = new ObjectsToSerialize(); this.obj = obj.Deserialise(fileTempPath); //Marquer la presence de données this.receivedDatas = true; //Fermer la socket d'ecoute et de reception this.localSocketListening.Close(); //Supprimer le fichier temp File.Delete(Application.StartupPath + @"/Temp/datasTemp.xml"); } } catch (Exception ex) { MessageBox.Show("ERREUR ListenAndReceive : " + ex.Message); localSocketListening.Close(); threadListenAndReceive.Abort(); this.receivedDatas = false; } }