/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Character character, Coordinate destination, IQuaternion heading, Identity playfield) { // Prevent client from entering this again if (character.DoNotDoTimers) { return; } character.DoNotDoTimers = true; // Teleport to another playfield ZoneEngine.Core.Packets.Teleport.Send(character, destination, heading, playfield); // Send packet, disconnect, and other playfield waits for connect DespawnMessage despawnMessage = ZoneEngine.Core.Packets.Despawn.Create(character.Identity); this.AnnounceOthers(despawnMessage, character.Identity); character.RawCoordinates = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }; character.RawHeading = new Quaternion(heading.xf, heading.yf, heading.zf, heading.wf); character.Save(); CharacterDao.SetPlayfield(character.Identity.Instance, (int)playfield.Type, playfield.Instance); // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields) // for now, just transmit our ip and port IPAddress tempIp; if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false) { IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP); foreach (IPAddress ip in zoneHost.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { tempIp = ip; break; } } } var redirect = new ZoneRedirectionMessage { ServerIpAddress = tempIp, ServerPort = (ushort)this.server.TcpEndPoint.Port }; character.Client.SendCompressed(redirect); character.DoNotDoTimers = false; // character.Client.Server.DisconnectClient(character.Client); }
/// <summary> /// </summary> /// <param name="dynel"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Dynel dynel, Coordinate destination, IQuaternion heading, Identity playfield) { // Prevent client from entering this again if (dynel.DoNotDoTimers) { return; } Thread.Sleep(200); int dynelId = dynel.Identity.Instance; // Disable sending stat changes and wait a bit to clear the queue dynel.DoNotDoTimers = true; Thread.Sleep(1000); // Teleport to another playfield TeleportMessageHandler.Default.Send( dynel as ICharacter, destination.coordinate, (Vector.Quaternion)heading, playfield); // Send packet, disconnect, and other playfield waits for connect DespawnMessage despawnMessage = DespawnMessageHandler.Default.Create(dynel.Identity); this.AnnounceOthers(despawnMessage, dynel.Identity); dynel.RawCoordinates = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }; dynel.RawHeading = new Vector.Quaternion(heading.xf, heading.yf, heading.zf, heading.wf); // IMPORTANT!! // Dispose the character object, save new playfield data and then recreate it // else you would end up at weird coordinates in the same playfield // Save client object ZoneClient client = (ZoneClient)dynel.Controller.Client; // Set client=null so dynel can really dispose IPlayfield newPlayfield = this.server.PlayfieldById(playfield); Pool.Instance.GetObject <Playfield>( Identity.None, new Identity() { Type = playfield.Type, Instance = playfield.Instance }); if (newPlayfield == null) { newPlayfield = new Playfield(this.server, playfield); } dynel.Playfield = newPlayfield; dynel.Controller.Client = null; dynel.Dispose(); LogUtil.Debug(DebugInfoDetail.Database, "Saving to pf " + playfield.Instance); // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields) // for now, just transmit our ip and port IPAddress tempIp; if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false) { IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP); foreach (IPAddress ip in zoneHost.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { tempIp = ip; break; } } } var redirect = new ZoneRedirectionMessage { ServerIpAddress = tempIp, ServerPort = (ushort)this.server.TcpEndPoint.Port }; if (client != null) { client.SendCompressed(redirect); } // client.Server.DisconnectClient(client); }