private void ServerMessageReceived(object sender, Server.MessageReceivedEventArgs args)
        {
            // Make sure any ping messages get acknowledged
            using Message message = args.GetMessage();
            if (serverAcknowledgesPingsAfter != -1 && message.IsPingMessage)
            {
                using Message acknowledgment = Message.CreateEmpty(message.Tag);
                acknowledgment.MakePingAcknowledgementMessage(message);

                Thread.Sleep(serverAcknowledgesPingsAfter);

                bool success = args.Client.SendMessage(acknowledgment, args.SendMode);
                Assert.IsTrue(success);
                messageAssertions.ExpectMessageOnClient(new ReceivedMessage(null, ushort.MaxValue, args.Client.ID, message.Tag, args.SendMode));
            }
        }
Exemple #2
0
        /// <summary>
        ///     Event handler for messages arriving at the server from a client.
        /// </summary>
        /// <param name="sender">The client that sent.</param>
        /// <param name="args">The event args.</param>
        /// <param name="serverID">The ID of the server that received this message.</param>
        private void ServerMessageReceivedFromClient(object sender, Server.MessageReceivedEventArgs args, ushort serverID)
        {
            // Record message
            using (Message message = args.GetMessage())
            {
                string str;
                using (DarkRiftReader reader = message.GetReader())
                {
                    if (reader.Length > 0)
                    {
                        str = reader.ReadString();
                    }
                    else
                    {
                        str = null;
                    }
                }

                messageAssertions.AddMessageOnServer(new ReceivedMessage(str, args.Client.ID, serverID, message.Tag, args.SendMode));
            }

            // Call to other event handlers
            ServerMessageReceived.Invoke(sender, args);
        }