Пример #1
0
    public void Execute()
    {
        if (!connection[0].IsCreated)
        {
            if (done[0] != 1)
            {
                Debug.Log("Something went wrong during connect");
            }
            return;
        }

        DataStreamReader stream;

        NetworkEvent.Type cmd;

        while ((cmd = connection[0].PopEvent(driver, out stream)) !=
               NetworkEvent.Type.Empty)
        {
            switch (cmd)
            {
            case NetworkEvent.Type.Connect:
                Debug.Log("CLIENT: Our client is now connected to the server");
                ServerConnection.init(driver, connection[0]);
                // Sending a hello...
                ClientMessageHello hello = new ClientMessageHello();
                ServerConnection.Send(hello);
                break;

            case NetworkEvent.Type.Data:
                Debug.Log("CLIENT: Got Back data from the server.");
                try
                {
                    IncomingServerMessageParser.ParseIncomingMessage(driver, connection[0], stream);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Debug.Log("CLIENT: IndexOutOfRange, bad server data?? disconnecting.");
                    connection[0] = default(NetworkConnection);
                }

                break;

            case NetworkEvent.Type.Disconnect:
                Debug.Log("CLIENT: Our client was disconnected...");
                //connection[0] = default(NetworkConnection);
                // connection[0] = driver.Connect(endpoint);
                break;
            }
        }
    }
Пример #2
0
    public static void ParseIncomingMessage(NetworkConnection connection, DataStreamReader stream,
                                            EntityCommandBuffer.Concurrent commandBuffer, int connectionIndex, UdpCNetworkDriver.Concurrent driver)
    {
        var  readerCtx = default(DataStreamReader.Context);
        uint messageID = stream.ReadUInt(ref readerCtx);

        if (messageID == ClientMessages.ClientMessageHello.id)
        {
            ClientMessageHello hello = new ClientMessageHello();
            hello.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
        else if (messageID == ClientMessageGoodbye.id)
        {
            ClientMessageGoodbye msg = new ClientMessageGoodbye();
            msg.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
        else if (messageID == ClientMessageFire.id)
        {
            ClientMessageFire msg = new ClientMessageFire();
            msg.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
        else if (messageID == ClientMessageShield.id)
        {
            ClientMessageShield msg = new ClientMessageShield();
            msg.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
        else if (messageID == ClientMessageMoveJoy.id)
        {
            ClientMessageMoveJoy msg = new ClientMessageMoveJoy();
            msg.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
        else if (messageID == ClientMessagePing.id)
        {
            ClientMessagePing msg = new ClientMessagePing();
            msg.Recieve(connection, stream, commandBuffer, connectionIndex, driver);
        }
    }