From 53fc721ea9bdcbd319667ab937bf51bf1c778624 Mon Sep 17 00:00:00 2001 From: unknown <0xlunaric@gmail.com> Date: Mon, 25 May 2020 16:51:01 +0200 Subject: [PATCH] Added a Clan struct. Implemented most primitive clan functions --- Facepunch.Steamworks.Test/ClanTest.cs | 59 +++++++++++++++++++++++++++ Facepunch.Steamworks/SteamFriends.cs | 8 ++++ Facepunch.Steamworks/Structs/Clan.cs | 50 +++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 Facepunch.Steamworks.Test/ClanTest.cs create mode 100644 Facepunch.Steamworks/Structs/Clan.cs diff --git a/Facepunch.Steamworks.Test/ClanTest.cs b/Facepunch.Steamworks.Test/ClanTest.cs new file mode 100644 index 0000000..eefb64e --- /dev/null +++ b/Facepunch.Steamworks.Test/ClanTest.cs @@ -0,0 +1,59 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Steamworks +{ + [DeploymentItem("steam_api64.dll")] + [DeploymentItem("steam_api.dll")] + [TestClass] + public class ClanTest + { + [TestMethod] + public void GetName() + { + var clan = new Clan(103582791433666425); + + Assert.AreEqual("Steamworks Development", clan.Name); + } + + [TestMethod] + public void GetClanTag() + { + var clan = new Clan(103582791433666425); + + Assert.AreEqual("SteamworksDev", clan.Tag); + } + + [TestMethod] + public async Task GetOwner() + { + var clan = new Clan(103582791433666425); + await clan.RequestOfficerList(); + + Assert.AreNotEqual(new SteamId(), clan.Owner.Id); + } + + [TestMethod] + public void GetOfficers() + { + var clan = new Clan(103582791433666425); + foreach (var officer in clan.GetOfficers()) + { + Console.WriteLine($"{officer.Name} : {officer.Id}"); + } + } + + [TestMethod] + public async Task RequestOfficerList() + { + var clan = new Clan(103582791433666425); + bool res = await clan.RequestOfficerList(); + + Assert.AreEqual(true, res); + } + } +} diff --git a/Facepunch.Steamworks/SteamFriends.cs b/Facepunch.Steamworks/SteamFriends.cs index 46c48e5..0a075d3 100644 --- a/Facepunch.Steamworks/SteamFriends.cs +++ b/Facepunch.Steamworks/SteamFriends.cs @@ -151,6 +151,14 @@ public static IEnumerable GetFromSource( SteamId steamid ) } } + public static IEnumerable GetClans() + { + for (int i = 0; i < Internal.GetClanCount(); i++) + { + yield return new Clan( Internal.GetClanByIndex( i ) ); + } + } + /// /// The dialog to open. Valid options are: /// "friends", diff --git a/Facepunch.Steamworks/Structs/Clan.cs b/Facepunch.Steamworks/Structs/Clan.cs new file mode 100644 index 0000000..6bcdda8 --- /dev/null +++ b/Facepunch.Steamworks/Structs/Clan.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Steamworks +{ + public struct Clan + { + public SteamId Id; + + public Clan(SteamId id) + { + Id = id; + } + + public string Name => SteamFriends.Internal.GetClanName(Id); + + public string Tag => SteamFriends.Internal.GetClanTag(Id); + + public int ChatMemberCount => SteamFriends.Internal.GetClanChatMemberCount(Id); + + public Friend Owner => new Friend(SteamFriends.Internal.GetClanOwner(Id)); + + public bool Public => SteamFriends.Internal.IsClanPublic(Id); + + /// + /// Is the clan an official game group? + /// + public bool Official => SteamFriends.Internal.IsClanOfficialGameGroup(Id); + + /// + /// Asynchronously fetches the officer list for a given clan + /// + /// Whether the request was successful or not + public async Task RequestOfficerList() + { + var req = await SteamFriends.Internal.RequestClanOfficerList(Id); + return req.HasValue && req.Value.Success != 0x0; + } + + public IEnumerable GetOfficers() + { + for (int i = 0; i < SteamFriends.Internal.GetClanOfficerCount(Id); i++) + { + yield return new Friend(SteamFriends.Internal.GetClanOfficerByIndex(Id, i)); + } + } + } +}