示例#1
0
        private string TranslateTCP(TcpClient client, EN_TCP_PACKET_TYPE type, byte[] bytes)
        {
            string s = "";

            if (type == EN_TCP_PACKET_TYPE.CONNECT)
            {
                EN_PacketConnect packet = EN_Protocol.BytesToObject <EN_PacketConnect>(bytes);

                // Resend older important messages from before
                ResendStackTCP(client);

                // Send out this connection packet to the rest of the clients
                BroadcastAllTCP(bytes);

                // Add connect request to the stack of important messages
                packet_stack.Add(bytes);

                s = packet.packet_client_name + " connected.";

                IPEndPoint temp = (IPEndPoint)client.Client.RemoteEndPoint;
                udp_clients.Add(temp);
                // Add client to list of unique ID's
                //clients.Add(new EN_ClientInfo(client, packet.packet_client_guid, packet.packet_client_name));
            }
            if (type == EN_TCP_PACKET_TYPE.MESSAGE)
            {
                EN_PacketMessage packet = EN_Protocol.BytesToObject <EN_PacketMessage>(bytes);
                s = packet.packet_message;
            }
            if (type == EN_TCP_PACKET_TYPE.SPAWN_OBJECT)
            {
                EN_PacketSpawnObject packet = EN_Protocol.BytesToObject <EN_PacketSpawnObject>(bytes);

                current_networkID++;
                networkIDs.Add(packet.packet_network_id, current_networkID);

                packet.packet_network_id = networkIDs[packet.packet_network_id];

                byte[] bytes_data = EN_Protocol.ObjectToBytes(packet);

                BroadcastTCP(client, bytes_data);

                s = packet.packet_prefab + " with network ID " + packet.packet_network_id + " was spawned.";
            }
            if (type == EN_TCP_PACKET_TYPE.REMOVE_OBJECT)
            {
                EN_PacketRemoveObject packet = EN_Protocol.BytesToObject <EN_PacketRemoveObject>(bytes);

                packet.packet_network_id = networkIDs[packet.packet_network_id];

                byte[] bytes_data = EN_Protocol.ObjectToBytes(packet);

                BroadcastTCP(client, bytes_data);

                s = "Prefab with network ID " + packet.packet_network_id + " was removed.";
            }

            return(s);
        }
示例#2
0
    private void TranslateUDP(EN_UDP_PACKET_TYPE type, byte[] bytes)
    {
        if (type == EN_UDP_PACKET_TYPE.TRANSFORM)
        {
            EN_PacketTransform packet = EN_Protocol.BytesToObject <EN_PacketTransform>(bytes);

            GameObject go = EN_NetworkObject.Find(packet.packet_network_id);
            if (go != null)
            {
                go.GetComponent <EN_SyncTransformClient>().Translate(packet.tX, packet.tY, packet.tZ, packet.rX, packet.rY, packet.rZ, packet.vX, packet.vY, packet.vZ);
            }
        }
    }
示例#3
0
        private void TranslateUDP(IPEndPoint source, EN_UDP_PACKET_TYPE type, byte[] bytes)
        {
            if (type == EN_UDP_PACKET_TYPE.TRANSFORM)
            {
                EN_PacketTransform packet = EN_Protocol.BytesToObject <EN_PacketTransform>(bytes);

                // This comes in as a Unity InstanceID, we need to networkID-it
                packet.packet_network_id = networkIDs[packet.packet_network_id];

                byte[] bytes_data = EN_Protocol.ObjectToBytes(packet);

                BroadcastUDP(source, bytes_data);
            }
        }
示例#4
0
    private void TranslateTCP(EN_TCP_PACKET_TYPE type, byte[] bytes)
    {
        if (type == EN_TCP_PACKET_TYPE.CONNECT)
        {
            // Someone connected and we want to establish who it is
            EN_PacketConnect packet = EN_Protocol.BytesToObject <EN_PacketConnect>(bytes);

            if (packet.packet_client_guid.Equals(EN_ClientSettings.CLIENT_GUID) == true)
            {
                packet.packet_client_name += " (you)";
            }

            AddClient(packet.packet_client_guid, packet.packet_client_name);
        }
        if (type == EN_TCP_PACKET_TYPE.GAME_STATE)
        {
            EN_PacketGameState packet = EN_Protocol.BytesToObject <EN_PacketGameState>(bytes);
        }
        if (type == EN_TCP_PACKET_TYPE.SPAWN_OBJECT)
        {
            EN_PacketSpawnObject packet = EN_Protocol.BytesToObject <EN_PacketSpawnObject>(bytes);
            Vector3    pos = new Vector3(packet.tX, packet.tY, packet.tZ);
            Quaternion rot = Quaternion.Euler(packet.rX, packet.rY, packet.rZ);
            GameObject go  = Instantiate(EN_NetworkPrefabs.Prefab(packet.packet_prefab), pos, rot);
            go.AddComponent <EN_NetworkObject>().network_id = packet.packet_network_id;

            EN_NetworkObject.Add(packet.packet_network_id, go);

            ConsoleMessage(string.Format("Spawned {0} with network ID {1}", go.name, packet.packet_network_id));
        }
        if (type == EN_TCP_PACKET_TYPE.REMOVE_OBJECT)
        {
            EN_PacketRemoveObject packet = EN_Protocol.BytesToObject <EN_PacketRemoveObject>(bytes);

            GameObject go = EN_NetworkObject.Find(packet.packet_network_id);
            string     n  = go.name;
            EN_NetworkObject.Remove(packet.packet_network_id);
            Destroy(go);

            ConsoleMessage(string.Format("Removed {0} with network ID {1}", n, packet.packet_network_id));
        }
    }