Пример #1
0
    public void Send(MeshPacket packet)
    {
        //Debug.Log("Send(): Dest. object: " + packet.GetTargetObjectId());
        if (meshnet.database == null)
        {
            Debug.LogError("Trying to send packet when database does not exist.");
        }

        if (packet.GetTargetPlayerId() == meshnet.GetLocalPlayerID())
        {
            ParseData(packet);
            return;
        }

        byte[]   data       = packet.GetSerializedBytes();
        Player[] allPlayers = meshnet.database.GetAllPlayers();
        if (packet.GetTargetPlayerId() == (byte)ReservedPlayerIDs.Broadcast)
        {
            foreach (Player p in allPlayers)
            {
                if (p.GetUniqueID() == meshnet.GetLocalPlayerID() && packet.GetPacketType() == PacketType.TransformUpdate)
                {
                    continue;
                }

                SteamNetworking.SendP2PPacket(new CSteamID(p.GetUniqueID()), data, (uint)data.Length, packet.qos);
            }
        }
        else
        {
            SteamNetworking.SendP2PPacket(new CSteamID(packet.GetTargetPlayerId()), data, (uint)data.Length, packet.qos);
        }
    }
Пример #2
0
    protected void RegisterWithProvider()
    {
        networkUIController.SetUIMode(UIMode.Connecting);

        //Create a PlayerJoin packet, which the provider will use as a trigger to
        //register a new player. It will update its internal database, and will
        //distribute this info as a normal DatabaseUpdate.
        MeshPacket p = new MeshPacket(new byte[0],
                                      PacketType.PlayerJoin,
                                      SteamUser.GetSteamID().m_SteamID,
                                      SteamMatchmaking.GetLobbyOwner(lobby).m_SteamID,
                                      (byte)ReservedObjectIDs.Unspecified,
                                      (byte)ReservedObjectIDs.DatabaseObject,
                                      (byte)ReservedSubcomponentIDs.Unspecified);

        p.qos = EP2PSend.k_EP2PSendReliable;
        RoutePacketDirect(p, p.GetTargetPlayerId());
        //Soon, we will receive a DatabaseUpdate with all of the up to date database information,
        //including our own player object!
    }