Ejemplo n.º 1
0
    public void SyncCMD(MessageData msg)
    {
        MoveCMD mcmd = new MoveCMD();

        mcmd.Deserialize(msg.data);
        recvCmdQueue.Enqueue(mcmd);
        //   Debug.LogError(mcmd.framID);
    }
Ejemplo n.º 2
0
    private void onReceive(Socket sock, byte[] bytes, int len)
    {
        try
        {
            var clientInfo = clients[sock];
            if (len > 0 && bytes != null)
            {
                if (len > clientInfo.mByteBuffer.canUse())
                {
                    MyByteBuffer byteBuffer = new MyByteBuffer(clientInfo.mByteBuffer.maxSize() * 2 + len, false);
                    byteBuffer.copyFrom(clientInfo.mByteBuffer);
                    clientInfo.mByteBuffer = byteBuffer;
                }

                clientInfo.mByteBuffer.put(bytes, len);

                do
                {
                    if (clientInfo.mByteBuffer.remaining() < 4)
                    {
                        break;
                    }

                    int bufLen = clientInfo.mByteBuffer.readInt32();
                    if (bufLen > clientInfo.mByteBuffer.maxSize() || bufLen <= 0)
                    {
                        Logger.err("数据长度超过限制: " + bufLen);
                        break;
                    }

                    if (clientInfo.mByteBuffer.remaining() < bufLen)
                    {
                        clientInfo.mByteBuffer.resetHead(4);
                        //Log(EventId.Net_Error, "remaining 长度不够:" + bufLen);
                        break;
                    }

                    int msgID = clientInfo.mByteBuffer.readInt32();
                    //
                    byte[] content = null;
                    if (bufLen - 4 > 0)
                    {
                        content = new byte[bufLen - 4];
                        clientInfo.mByteBuffer.readBytes(content);
                    }

                    if (msgID == FrameMsgID.FrameCMD)
                    {
                        var cmd = new MoveCMD();
                        cmd.Deserialize(content);
                        lock (clientInfo.lockObj)
                        {
                            clientInfo.cmdList.AddLast(cmd);
                        }
                    }

                    // Logger.err("收到客户端数据:" + BitConverter.ToInt32(content,0));

                    //////////MessageUtils.sendToGameLogic(msgId, content);
                }while (true);
            }
        }
        catch (Exception ex)
        {
            Logger.err(ex.ToString());
        }
    }