Ejemplo n.º 1
0
 /// <summary>
 ///     Adds the private channel.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="privateChannel">The private channel.</param>
 private static void AddPrivateChannel(NetworkMessage message, IPrivateChannel privateChannel)
 {
     message.AddUInt16((ushort)privateChannel.Owner.Id);
     AddUsers(message, privateChannel);
     message.AddUInt16((ushort)privateChannel.Invitations.Count);
     foreach (ICharacterSpawn invitation in privateChannel.Invitations)
     {
         message.AddString(invitation.Character.Name);
     }
     message.AddUInt16(0x00);
 }
Ejemplo n.º 2
0
            public IPrivateChannel[] GetPrivateChannels()
            {
                IPrivateChannel[] privateChannels = new IPrivateChannel[_privateChannels.Count];
                int i = 0;

                foreach (var channel in _privateChannels.Select(GetChannel))
                {
                    if (channel is IPrivateChannel directChannel)
                    {
                        privateChannels[i] = directChannel;
                        i++;
                    }
                }

                // Nullability is improperly accessed here
#pragma warning disable CS8629
                Array.Resize(ref privateChannels, i);
                Array.Sort(privateChannels, Comparer <IPrivateChannel> .Create((item1, item2) =>
                {
                    bool i1Null = !item1.LastMessageId.HasValue;
                    bool i2Null = !item2.LastMessageId.HasValue;

                    if (i1Null && i2Null)
                    {
                        return(0);
                    }
                    if (i2Null)
                    {
                        return(-1);
                    }
                    if (i1Null)
                    {
                        return(1);
                    }

                    long compare = (long)item2.LastMessageId.Value - (long)item1.LastMessageId.Value;
                    return(compare switch
                    {
                        < 0 => - 1,
                        > 0 => 1,
                        _ => 0
                    });
Ejemplo n.º 3
0
 /// <summary>
 /// Converts an existing <see cref="IPrivateChannel"/> to an abstracted <see cref="IPrivateChannel"/> value.
 /// </summary>
 /// <param name="privateChannel">The existing <see cref="IPrivateChannel"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="privateChannel"/>.</exception>
 /// <returns>An <see cref="IPrivateChannel"/> that abstracts <paramref name="privateChannel"/>.</returns>
 public static IPrivateChannel Abstract(this IPrivateChannel privateChannel)
 => privateChannel switch
 {
     null
     => throw new ArgumentNullException(nameof(privateChannel)),