void Disconnect()
    {
        foreach (KeyValuePair <int, NetworkIdentity> netComp in netComps)
        {
            if (netComp.Value != null)
            {
                netComp.Value.SendMessage("OnDisconnect", null, SendMessageOptions.DontRequireReceiver);
            }
        }
        netComps.Clear();

        if (tcpClient == null || !tcpClient.Connected)
        {
            return;
        }

        if (msgReceiveThread != null)
        {
            msgReceiveThread.Abort();
        }

        DespawnMessage msg = new DespawnMessage();;

        msg.objectId = clientId;

        Send(msg);

        // tcpClient.Close();

        Debug.Log("[" + sceneName + "] Disconected");
    }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        /// <param name="targetId">
        /// </param>
        /// <returns>
        /// </returns>
        public static DespawnMessage Create(Identity targetId)
        {
            var message = new DespawnMessage {
                Identity = targetId, Unknown = 0x01
            };

            return(message);
        }
Esempio n. 3
0
    /// <summary>
    /// Inform all clients about this despawn event
    /// </summary>
    /// <param name="result">results of the despawn that was already performed server side</param>
    /// <returns></returns>
    public static void SendToAll(DespawnResult result)
    {
        DespawnMessage msg = new DespawnMessage
        {
            DespawnedObject = result.GameObject.NetId()
        };

        msg.SendToAll();
    }
Esempio n. 4
0
    /// <summary>
    /// Inform all clients about this despawn event
    /// </summary>
    /// <param name="recipient">client to inform</param>
    /// <param name="result">results of the spawn that was already performed server side</param>
    /// <returns></returns>
    public static void Send(GameObject recipient, DespawnResult result)
    {
        DespawnMessage msg = new DespawnMessage
        {
            DespawnedObject = result.GameObject.NetId()
        };

        msg.SendTo(recipient);
    }
Esempio n. 5
0
        /// <summary>
        /// </summary>
        /// <param name="targetIdentity">
        /// </param>
        /// <returns>
        /// </returns>
        public static IMSendAOtomationMessageToPlayfieldOthers CreateIM(Identity targetIdentity)
        {
            DespawnMessage message = Create(targetIdentity);

            return(new IMSendAOtomationMessageToPlayfieldOthers()
            {
                Body = message, Identity = targetIdentity
            });
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
    public override void despawnObject(string objectID)
    {
        ServerQTObject despawnedObj = (ServerQTObject)spawnedObjects[objectID];

        DespawnMessage message = new DespawnMessage();

        message.objectID = despawnedObj.objectID;
        WorkerServerManager.instance.sendMessageToAllReady(message);

        QTDebugger.instance.debug(QTDebugger.debugType.BASE, "Despawned " + despawnedObj.prefabName + " with ID - " + objectID);
        processDespawn(objectID);
    }
Esempio n. 8
0
    /// <summary>
    /// Note - for internal use by spawn system only. Fires all server side despawn hooks then informs
    /// client to call client side despawn hooks
    /// </summary>
    /// <param name="result"></param>
    public static void _ServerFireDespawnHooks(DespawnResult result)
    {
        //fire server hooks
        var comps = result.GameObject.GetComponents <IServerDespawn>();

        if (comps != null)
        {
            foreach (var comp in comps)
            {
                comp.OnDespawnServer(result.DespawnInfo);
            }
        }

        //fire client hooks
        DespawnMessage.SendToAll(result);
    }
Esempio n. 9
0
    public override void handleMessage(QTMessage message)
    {
        switch (message.messageType)
        {
        case QTMessage.type.SPAWN:
            SpawnMessage spawnMessage = (SpawnMessage)message;
            BaseQTObject obj          = ClientManager.instance.spawnManager.spawnObject(spawnMessage.objectID, spawnMessage.prefabName, spawnMessage.spawnPosition, spawnMessage.spawnRotation);
            obj.gameObject.SetActive(spawnMessage.active);
            break;

        case QTMessage.type.DESPAWN:
            DespawnMessage despawnMessage = (DespawnMessage)message;
            ClientManager.instance.spawnManager.despawnObject(despawnMessage.objectID);
            break;
        }
    }
Esempio n. 10
0
        /// <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);
        }
    IEnumerator MsgHandling()
    {
        while (true)
        {
            if (messageQueue.Count <= 0)
            {
                yield return(null);

                continue;
            }

            byte[] buffer = messageQueue.Dequeue();

            if ((MessageId)buffer[0] == MessageId.Transform)
            {
                TransformMessage msg = new TransformMessage();
                msg.Deserialize(ref buffer);

                if (!netComps.ContainsKey(msg.sourceId))
                {
                    Debug.LogWarning("[" + sceneName + "] Object with netId " + msg.sourceId + " not found!");
                    continue;
                }

                NetworkIdentity netId = netComps[msg.sourceId];

                netId.SendMessage("ApplyTransform", msg, SendMessageOptions.DontRequireReceiver);
            }
            else if ((MessageId)buffer[0] == MessageId.Spawn)
            {
                SpawnMessage msg = new SpawnMessage();
                msg.Deserialize(ref buffer);

                if (netComps.ContainsKey(msg.objectId))
                {
                    continue;
                }

                GameObject spawned = Instantiate(spawnablePrefabs[msg.prefabId].gameObject, transform.position, transform.rotation);
                SceneManager.MoveGameObjectToScene(spawned, gameObject.scene);
                spawned.SetActive(msg.hasAuthority);

                NetworkIdentity netId = spawned.GetComponent <NetworkIdentity>();
                netComps.Add(msg.objectId, netId);

                netId.id                 = msg.objectId;
                netId.spawned            = true;
                netId.connectionToServer = this;
                netId.hasAuthority       = msg.hasAuthority;
            }
            else if ((MessageId)buffer[0] == MessageId.Despawn)
            {
                DespawnMessage msg = new DespawnMessage();
                msg.Deserialize(ref buffer);

                if (netComps.ContainsKey(msg.objectId))
                {
                    NetworkIdentity netComp = netComps[msg.objectId];
                    netComps.Remove(msg.objectId);

                    Destroy(netComp.gameObject);
                }
            }
            else if ((MessageId)buffer[0] == MessageId.Enable)
            {
                EnableMessage msg = new EnableMessage();
                msg.Deserialize(ref buffer);

                if (netComps.ContainsKey(msg.objectId))
                {
                    NetworkIdentity netComp = netComps[msg.objectId];

                    netComp.transform.position = new Vector3(msg.position[0], msg.position[1], msg.position[2]);
                    netComp.transform.rotation = new Quaternion(msg.rotation[0], msg.rotation[1], msg.rotation[2], msg.rotation[3]);

                    netComp.gameObject.SetActive(msg.toEnable);
                }
            }

            yield return(null);
        }
    }