示例#1
0
        protected override void ProcessOutgoingData(byte[] buff, int start, int len)
        {
            var type = (Utilities.PackType)buff[start];

            switch (type)
            {
            case Utilities.PackType.Udp:
                if (Outgoing != null)
                {
                    if (start == 0)
                    {
                        Outgoing.Enqueue(buff);
                    }
                    else
                    {
                        var buf = new byte[len];
                        Array.Copy(buff, start, buf, 0, len);
                        Outgoing.Enqueue(buf);
                    }
                }
                break;

            case Utilities.PackType.Kcp:
                base.ProcessOutgoingData(buff, start + 1, len - 1);
                break;

            default:
                break;
            }
        }
示例#2
0
 private void PublishWorldState(World world)
 {
     using (var stream = new MemoryStream()) {
         Serializer.Serialize(stream, world);
         var bytes = stream.ToArray();
         var msg   = new NetMQMessage();
         msg.AppendEmptyFrame();
         msg.Append("world");
         msg.Append(bytes);
         Outgoing.Enqueue(msg);
     }
 }
示例#3
0
        protected override unsafe int udp_output(byte *buf, int len, IKCPCB *kcp, void *user)
        {
            byte[] buff = new byte[len + 1];
            Marshal.Copy(new IntPtr(buf), buff, 1, len);
#if PRINTPACK
            printpack($"kcp_output:{buff.Length}:{string.Join(",",buff)}");
#endif
            buff[0] = (byte)Utilities.PackType.Kcp;
            if (Outgoing != null)
            {
                Outgoing.Enqueue(buff);
            }
            return(0);
        }