Esempio n. 1
0
    void SendPacket(VoiceChatPacket packet, Sfs2X.Util.ByteArray data)
    {
//        SFVoicePacket sfPacket = new SFVoicePacket(packet);
        // CommunicationManager.SendObjectMsg(sfPacket.GetSerialized());

        SFSObject voiceData = new SFSObject();

        voiceData.PutUtfString("type", "voice");
        voiceData.PutByte("c", (byte)packet.Compression);                   // Compression
        voiceData.PutInt("l", packet.Length);                               // Length
        voiceData.PutByteArray("d", new Sfs2X.Util.ByteArray(packet.Data)); // Data
        voiceData.PutInt("i", packet.NetworkId);                            // NetworkId

        bool sendToAllInZone = false;

        if (sendToAllInZone)
        {
            CommunicationManager.SendMsg(new AdminMessageRequest("v", (new MessageRecipientMode((int)MessageRecipientType.TO_ZONE, null)), voiceData));
        }
        else
        {
            CommunicationManager.SendObjectMsg(voiceData);
        }

        // Optimization notes:
        // use class serialization, current method is probably slow (http://docs2x.smartfoxserver.com/AdvancedTopics/class-serialization)
        // can also use the pool setup for the demo, so you don't have to instantiate a new buffer for every message
        // don't need to send compression byte every time, only one networkID needed if a queue is grouped together.
    }
Esempio n. 2
0
    public void OnNewVoiceSample(VoiceChatPacket packet)
    {
        if (!GameManager.DoesLevelHaveSmartFoxRoom(GameManager.Inst.LevelLoaded) || !CommunicationManager.InASmartFoxRoom)
        {
            return;
        }

        Sfs2X.Util.ByteArray data = new Sfs2X.Util.ByteArray();
        data.WriteBytes(packet.Data, 0, packet.Length);
        SendPacket(packet, data);
    }
Esempio n. 3
0
    public static VoiceChatPacket GetVoicePacketFromMsg(ISFSObject msgObj)
    {
        VoiceChatPacket packet = new VoiceChatPacket();

        packet.Compression = (VoiceChatCompression)msgObj.GetByte("c");
        packet.Length      = msgObj.GetInt("l");
        Sfs2X.Util.ByteArray t = msgObj.GetByteArray("d");
        packet.Data      = t.Bytes;
        packet.NetworkId = msgObj.GetInt("i");
        return(packet);
    }
Esempio n. 4
0
    void SendPackets(Queue <VoiceChatPacket> packets)
    {
        if (packets.Count == 0)
        {
            return;
        }

        VoiceChatPacket v = new VoiceChatPacket();

        Sfs2X.Util.ByteArray data = new Sfs2X.Util.ByteArray();
        v.Length = 0;
        while (packets.Count > 0)
        {
            VoiceChatPacket packet = packets.Dequeue();
            v.Compression = packet.Compression;
            data.WriteBytes(packet.Data, 0, packet.Length);
            v.Length   += packet.Length;
            v.NetworkId = packet.NetworkId;
        }
        SendPacket(v, data);
    }
Esempio n. 5
0
    public void BroadcastMousePosition(Vector3 worldSpacePos, bool mouseDown)
    {
        if (!IsNetworkConnectionEstablished())
        {
            return;
        }

        // display your mouse object first
        RemoteMouseManager.Inst.GetMyVisual().SetPosition(worldSpacePos);
        RemoteMouseManager.Inst.GetMyVisual().mouseDown = mouseDown;
        RemoteMouseManager.Inst.GetMyVisual().browserId = id;

        RemoteMouseManager.Inst.GetMyVisual().textureScaleMult = Mathf.Min(transform.lossyScale.x, transform.lossyScale.y) * 0.1f;


        Vector3 mouseLocalPos = transform.InverseTransformPoint(worldSpacePos);

        ISFSObject mousePosObj = new SFSObject();

        Sfs2X.Util.ByteArray mouseBytes = new Sfs2X.Util.ByteArray();

        if (GameManager.buildType == GameManager.BuildType.REPLAY)
        {
            mouseBytes.WriteByte((byte)id);
            mouseBytes.WriteFloat((((mouseLocalPos.x))));
            mouseBytes.WriteFloat((((mouseLocalPos.y))));
            mouseBytes.WriteBool(mouseDown);
            mousePosObj.PutByteArray("mp", mouseBytes);
        }
        else
        {
            mouseBytes.WriteByte((byte)id);
            mouseBytes.WriteByte((byte)(Mathf.Round((mouseLocalPos.x + 0.5f) * 256)));
            mouseBytes.WriteByte((byte)(Mathf.Round((mouseLocalPos.y + 0.5f) * 256)));
            mouseBytes.WriteBool(mouseDown);
            mousePosObj.PutByteArray("mpx", mouseBytes);
        }
        CommunicationManager.SendObjectMsg(mousePosObj);
    }
Esempio n. 6
0
    public void OnObjectMessage(int userID, ISFSObject msgObj)
    {
        //if player is stealth, don't show a mouse sphere to others
        if (GameManager.Inst.playerManager != null && GameManager.Inst.playerManager.GetPlayer(userID) != null && GameManager.Inst.playerManager.GetPlayer(userID).Type == PlayerType.STEALTH)
        {
            return;
        }
        // Light-bandwidth mouse browers index, horizontal, vertical.
        else if (msgObj.ContainsKey("mpx"))
        {
            PlayerMouseVisual visual = GetVisual(userID);
            if (visual == null)
            {
                return;
            }

            Sfs2X.Util.ByteArray mouseBytes = msgObj.GetByteArray("mpx");

            int mouseBrowserID     = mouseBytes.ReadByte();
            int mouseBrowserCoordX = mouseBytes.ReadByte();
            int mouseBrowserCoordY = mouseBytes.ReadByte();
            visual.mouseDown = mouseBytes.ReadBool();
            visual.browserId = mouseBrowserID;

            CollabBrowserTexture mouseBrowser = CollabBrowserTexture.GetAll()[mouseBrowserID];
            if (mouseBrowser)
            {
                visual.SetPosition(mouseBrowserCoordX, mouseBrowserCoordY);
                visual.textureScaleMult = Mathf.Min(mouseBrowser.transform.lossyScale.x, mouseBrowser.transform.lossyScale.y) * 0.1f;
            }
        }
        else if (msgObj.ContainsKey("mp"))
        {
            PlayerMouseVisual visual = GetVisual(userID);
            if (visual == null)
            {
                return;
            }

            Sfs2X.Util.ByteArray mouseBytes = msgObj.GetByteArray("mp");

            int   mouseBrowserID     = mouseBytes.ReadByte();
            float mouseBrowserCoordX = mouseBytes.ReadFloat();
            float mouseBrowserCoordY = mouseBytes.ReadFloat();
            visual.mouseDown = mouseBytes.ReadBool();
            visual.browserId = mouseBrowserID;

            CollabBrowserTexture mouseBrowser = CollabBrowserTexture.GetAll()[mouseBrowserID];
            if (mouseBrowser)
            {
                visual.SetPosition(mouseBrowserCoordX, mouseBrowserCoordY);
                visual.textureScaleMult = Mathf.Min(mouseBrowser.transform.lossyScale.x, mouseBrowser.transform.lossyScale.y) * 0.1f;
            }
        }
        else if (msgObj.ContainsKey("me"))
        {
            PlayerMouseVisual visual = GetVisual(userID);
            if (visual == null)
            {
                return;
            }

            visual.SetVisibility(false);
        }
    }