Exemple #1
0
    public override NetIncomingMessage ReadMessage()
    {
        if (!connected)
        {
            return(null);
        }
        if (messages.Count() > 0)
        {
            return(messages.Dequeue());
        }
        if (connected2)
        {
            while (tosend.Count() > 0)
            {
                INetOutgoingMessage msg = tosend.Dequeue();
                DoSendPacket(msg);
            }
        }

        EnetEventRef event_ = new EnetEventRef();

        if (platform.EnetHostService(host, 0, event_))
        {
            do
            {
                switch (event_.e.Type())
                {
                case EnetEventType.Connect:
                    connected2 = true;
                    break;

                case EnetEventType.Receive:
                    byte[] data       = event_.e.Packet().GetBytes();
                    int    dataLength = event_.e.Packet().GetBytesCount();
                    event_.e.Packet().Dispose();
                    NetIncomingMessage msg = new NetIncomingMessage();
                    msg.message       = data;
                    msg.messageLength = dataLength;
                    messages.Enqueue(msg);
                    break;
                }
            }while (platform.EnetHostCheckEvents(host, event_));
        }
        if (messages.Count() > 0)
        {
            return(messages.Dequeue());
        }
        return(null);
    }
Exemple #2
0
    public override NetIncomingMessage ReadMessage()
    {
        if (messages.Count() > 0)
        {
            return(messages.Dequeue());
        }

        if (platform.EnetHostService(host, 0, event_))
        {
            do
            {
                switch (event_.e.Type())
                {
                case EnetEventType.Connect:
                {
                    EnetPeer peer = event_.e.Peer();
                    peer.SetUserData(clientid++);
                    EnetNetConnection senderConnectionConnect = new EnetNetConnection();
                    senderConnectionConnect.platform = platform;
                    senderConnectionConnect.peer     = event_.e.Peer();
                    NetIncomingMessage message = new NetIncomingMessage();
                    message.SenderConnection = senderConnectionConnect;
                    message.Type             = NetworkMessageType.Connect;
                    messages.Enqueue(message);
                }
                break;

                case EnetEventType.Receive:
                {
                    byte[] data = event_.e.Packet().GetBytes();
                    event_.e.Packet().Dispose();
                    EnetNetConnection senderConnectionReceive = new EnetNetConnection();
                    senderConnectionReceive.platform = platform;
                    senderConnectionReceive.peer     = event_.e.Peer();
                    NetIncomingMessage message = new NetIncomingMessage();
                    message.SenderConnection = senderConnectionReceive;
                    message.message          = data;
                    message.Type             = NetworkMessageType.Data;
                    messages.Enqueue(message);
                }
                break;

                case EnetEventType.Disconnect:
                {
                    EnetNetConnection senderConnectionDisconnect = new EnetNetConnection();
                    senderConnectionDisconnect.platform = platform;
                    senderConnectionDisconnect.peer     = event_.e.Peer();
                    NetIncomingMessage message = new NetIncomingMessage();
                    message.SenderConnection = senderConnectionDisconnect;
                    message.Type             = NetworkMessageType.Disconnect;
                    messages.Enqueue(message);
                }
                break;
                }
            }while (platform.EnetHostCheckEvents(host, event_));
        }
        if (messages.Count() > 0)
        {
            return(messages.Dequeue());
        }
        return(null);
    }