Beispiel #1
0
        /// <summary>
        /// Handler the server registers to react to network messages
        /// </summary>
        void ServerOnDataHandler(object source, NetworkEventArgs n)
        {
            NetIncomingMessage msg     = n.GetData();
            NetworkMessageType msgType = n.GetInfo();

            if (msgType == NetworkMessageType.LoadFinish)
            {
                //just ignore the message content for now
                _loadedClients++;
                if (_loadedClients == _targetClientCount)
                {
                    OnAllLoaded();
                }
            }
            else if (msgType == NetworkMessageType.TankControl)
            {
                //read from old message
                int           networkId     = msg.ReadInt32(32);
                NetworkAction networkAction = (NetworkAction)msg.ReadByte();

                //write to new message
                NetOutgoingMessage relayMessage = Server.CreateMessage(n.GetData().LengthBits);
                relayMessage.Write((byte)NetworkMessageType.TankControl);
                relayMessage.Write(networkId, 32);
                relayMessage.Write((byte)networkAction);
                Server.SendToAll(relayMessage, NetDeliveryMethod.ReliableUnordered);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handler the server registers to react to network messages
        /// </summary>
        void ServerOnDataHandler(object source, NetworkEventArgs n)
        {
            NetIncomingMessage msg = n.GetData();
            NetworkMessageType msgType = n.GetInfo();
            if (msgType == NetworkMessageType.LoadFinish)
            {
                //just ignore the message content for now
                _loadedClients++;
                if (_loadedClients == _targetClientCount)
                    OnAllLoaded();
            }
            else if (msgType == NetworkMessageType.TankControl)
            {
                //read from old message
                int networkId = msg.ReadInt32(32);
                NetworkAction networkAction = (NetworkAction)msg.ReadByte();

                //write to new message
                NetOutgoingMessage relayMessage = Server.CreateMessage(n.GetData().LengthBits);
                relayMessage.Write((byte)NetworkMessageType.TankControl);
                relayMessage.Write(networkId, 32);
                relayMessage.Write((byte)networkAction);
                Server.SendToAll(relayMessage, NetDeliveryMethod.ReliableUnordered);
            }
        }