상속: MessageDataBuffer
예제 #1
0
 public void DeliverMessage(byte[] data, NetworkMessageInfo info)
 {
     ConnectionId sender = NetworkPlayerToConnectionId(info.sender);
     ByteArrayBuffer bab = new ByteArrayBuffer(data);
     NetworkEvent ev = new NetworkEvent(NetEventType.ReliableMessageReceived, sender, bab);
     mEvents.Enqueue(ev);
 }
예제 #2
0
        public void SingleEndpoint_OnSerialize(BitStream stream, NetworkPlayer senderOrReceiver)
        {
            //doesnt work. server sends messages automatically to all others


            if (stream.isReading)
            {
                char countin = (char)0;
                stream.Serialize(ref countin);
                int count = (int)countin;
                //Debug.Log(count + " packages sent");
                for (int k = 0; k < count; k++)
                {
                    int   length   = 0;
                    short lengthin = 0;
                    stream.Serialize(ref lengthin);
                    length = ((int)(ushort)lengthin); //just making sure it converts the - values back into high positive values
                    ByteArrayBuffer msg = ByteArrayBuffer.Get(length);



                    for (int i = 0; i < length; i++)
                    {
                        char c = 'v';
                        stream.Serialize(ref c);
                        msg.array[i] = (byte)c;
                        msg.positionWrite++;
                    }
                    NetworkEvent ev = new NetworkEvent(NetEventType.UnreliableMessageReceived, NetworkPlayerToConnectionId(senderOrReceiver), msg);
                    mEvents.Enqueue(ev);
                }
            }
            else
            {
                Queue <ByteArrayBuffer> userOut;
                ConnectionId            userid;
                userid = NetworkPlayerToConnectionId(senderOrReceiver);

                // NetworkPlayerToInt(senderOrReceiver);

                bool found = mOutgoingUnreliableMessages.TryGetValue(userid, out userOut);

                if (found && userOut.Count > 0)
                {
                    char count = (char)0;
                    if (userOut.Count > 255)
                    {
                        Debug.LogWarning("Too many messages at once");
                        count = (char)255;
                    }
                    else
                    {
                        count = (char)userOut.Count;
                    }

                    stream.Serialize(ref count);

                    for (int i = 0; userOut.Count > 0 && i < 256; i++)
                    {
                        ByteArrayBuffer msg = userOut.Dequeue();

                        short length = (short)msg.positionWrite;

                        stream.Serialize(ref length);
                        for (int k = 0; k < length; k++)
                        {
                            char c = (char)msg.array[k];
                            stream.Serialize(ref c);
                        }
                        msg.Dispose();
                    }
                    //Debug.Log(count + " messages sent to " + userid);
                }
            }
        }