server group list
Closed this issue · 4 comments
Please could you explain how/if I can directly get the servergrouplist in a result other then a string.
var serverGroups = await client.SendCommandAsync("servergrouplist");
The short answer is "create your own parser".
ServerQueryClient
has a few examples that'll help. Probably start with BanList
.
You'd create a ServerGroupInfoResult
class that decorates its properties with the expected property mappings:
public class BanInfoResult : ServerQueryBaseResult
{
[PropertyMapping("banid", Required = true)]
public int BanId { get; set; }
[PropertyMapping("ip", Required = true)]
public string Ip { get; set; }
[PropertyMapping("name", Required = true)]
public string Name { get; set; }
etc...
You can find the property names in the TS3 ServerQuery documentation. Fair warning; I found the documented properties to be out of date and prone to misspellings, and I went through some trial and error with the commands I implemented.
Then you'd create a ServerGroupListResult
class, which overrides the Parse
method:
public class BanListResult : ServerQueryBaseResult
{
public List<BanInfoResult> Values { get; set; }
public override bool Parse(string message)
{
// Is this an error response?
if (base.Parse(message))
{
return true;
}
Values = message.ToResultList<BanInfoResult>();
if (Values.Any())
{
Success = true;
Response = message;
return true;
}
return false;
}
}
Then you'd call SendCommandAsync with your new ServerGroupListResult
type and Command.servergrouplist
:
public Task<BanListResult> BanList()
{
return SendCommandAsync(new ServerQueryCommand<BanListResult>(Command.banlist));
}
public class ServerGroupInfoResult : ServerQueryBaseResult
{
[PropertyMapping("sgid", Required = true)]
public int Sgid { get; set; }
[PropertyMapping("name", Required = true)]
public string Name { get; set; }
[PropertyMapping("type", Required = true)]
public string Type { get; set; }
[PropertyMapping("iconid", Required = true)]
public string Iconid { get; set; }
[PropertyMapping("savedb", Required = true)]
public string Savedb { get; set; }
[PropertyMapping("sortid", Required = true)]
public string Sortid { get; set; }
[PropertyMapping("namemode", Required = true)]
public string Namemode { get; set; }
[PropertyMapping("n_modifyp", Required = true)]
public string N_modifyp { get; set; }
[PropertyMapping("n_member_addp", Required = true)]
public string n_member_addp { get; set; }
[PropertyMapping("n_member_removep", Required = true)]
public string N_member_removep { get; set; }
}
public class ServerGroupListResult : ServerQueryBaseResult
{
public List<ServerGroupInfoResult> Values { get; set; }
public override bool Parse(string message)
{
// Is this an error response?
if (base.Parse(message))
{
return true;
}
Values = message.ToResultList<ServerGroupInfoResult>();
if (Values.Any())
{
Success = true;
Response = message;
return true;
}
return false;
}
}
Looks like you've got this one sorted.