public static async Task MessageGuiAsync(this Player @this, string name, IDictionary <string, object> arguments) { if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } await using var stream = new MemoryStream(); using var writer = new BitWriter(stream); writer.Write((byte)Amf3Type.Array); writer.Write <byte>(1); foreach (var(key, value) in arguments) { Amf3Helper.WriteText(writer, key); switch (value) { case string str: writer.Write((byte)Amf3Type.String); Amf3Helper.WriteText(writer, str); break; case int integer: writer.Write((byte)Amf3Type.Integer); Amf3Helper.WriteNumber2(writer, (uint)integer); break; case uint unsigned: writer.Write((byte)Amf3Type.Integer); Amf3Helper.WriteNumber2(writer, unsigned); break; case bool boolean: writer.Write((byte)(boolean ? Amf3Type.True : Amf3Type.False)); break; case null: writer.Write((byte)Amf3Type.Undefined); break; } } writer.Write((byte)Amf3Type.Null); @this.Message(new UiMessageServerToSingleClientMessage { Associate = @this, Content = stream.ToArray(), MessageName = name }); }
public static async Task AddGuildMemberAsync(Player player, int index, GuildMember member) { await using var stream = new MemoryStream(); using var writer = new BitWriter(stream); writer.Write((byte)Amf3Type.Array); writer.Write <byte>(1); Amf3Helper.WriteText(writer, "name"); writer.Write((byte)Amf3Type.String); Amf3Helper.WriteText(writer, member.Name); Amf3Helper.WriteText(writer, "zone"); writer.Write((byte)Amf3Type.String); Amf3Helper.WriteText(writer, member.Zone); Amf3Helper.WriteText(writer, "rank"); writer.Write((byte)Amf3Type.String); Amf3Helper.WriteText(writer, member.Rank); Amf3Helper.WriteText(writer, "online"); writer.Write((byte)(member.Online ? Amf3Type.True : Amf3Type.False)); Amf3Helper.WriteText(writer, "index"); writer.Write((byte)Amf3Type.Integer); Amf3Helper.WriteNumber2(writer, (uint)index); writer.Write((byte)Amf3Type.Null); player.Message(new UiMessageServerToSingleClientMessage { Associate = player, Content = stream.ToArray(), MessageName = "AddGuildMember" }); }