Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended OnlineClient information variables #43

Merged
merged 6 commits into from
Feb 13, 2024
Merged

Extended OnlineClient information variables #43

merged 6 commits into from
Feb 13, 2024

Conversation

bdeb1337
Copy link
Contributor

Hello,

First off thank you for this great library, which is working great for a project of mine.

I was having somewhat the same request as @30 of wanting to expand the basic clientlist command. I've read the latest serverquery documentation that ships with ts3 server version 3.13.7 and included all parameters regarding this command:

image

I haven't included servergroups yet, since trying to map it as a []int didn't immediately work. I guess it would have something to do with helpers.go line 74 which states // TODO(steve): support groups but I could be wrong. If you are OK with this I could try to give it a go later in a separate pull request? I feel like it might be a little much for one PR otherwise and I could use some guidance in the right direction for that change.

Kind regards

Bob

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As not everyone will want all of this information this should really be an extension not a hard coded set.

@bdeb1337
Copy link
Contributor Author

As not everyone will want all of this information this should really be an extension not a hard coded set.

Thanks for your reply, I agree. I tried implementing this as an optional string parameter for the ClientList() function with the ability to request "all". Don't know if there would be a better way of doing this.

server_cmds.go Outdated Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
Added flags for ClientList to use
Changed OnlineClient struct to use pointers for optional parameters so it would be clear when no value was returned
Added support for client_servergroups which needed comma delimiting.
Tried to add/adapt relevant testing for everything changed.
@bdeb1337
Copy link
Contributor Author

bdeb1337 commented Sep 5, 2023

I have added a new commit in which I have tried to address the remarks and questions you made earlier. On the remarks you made above I have added a response with what I wrote this time. Also I have tried editing the *_test.go files to add testing for the standard ClientList and extended Clientlist requests, but I am not that sure if I handled that correctly.

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, making good progress.

helpers.go Outdated Show resolved Hide resolved
mockserver_test.go Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
server_cmds.go Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
server_cmds_test.go Outdated Show resolved Hide resolved
server_cmds_test.go Outdated Show resolved Hide resolved
@bdeb1337
Copy link
Contributor Author

bdeb1337 commented Sep 7, 2023

I have added a new commit trying to implement your recommendations and remarks. Kind regards.

mockserver_test.go Outdated Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
server_cmds_test.go Outdated Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
@bdeb1337
Copy link
Contributor Author

In the new commit, an embedded struct pointer that holds all optional struct pointers and values for options of clientlist has been added. The mapstructure library didn't support the combination of reflection and nil values to determine the type when squashing embedded pointers from map to struct. But it does work with regular structs: (https://github.com/mitchellh/mapstructure/blob/bf980b35cac4dfd34e05254ee5aba086504c3f96/mapstructure_test.go#L729C17-L729C54).
I have added a workaround by injecting the correct type while decoding, and nil'ling them after if needed.

@bdeb1337
Copy link
Contributor Author

Hi @stevenh , I hope you are doing well.
Time has gone by fast since September and I apologize for not bumping this earlier. I was wondering if you have had a chance to look at my latest commit and share your thoughts about the implementation.
I appreciate your feedback and suggestions because I already learned a lot from you.
Thank you for your time and attention.
Kind regards!

@stevenh
Copy link
Contributor

stevenh commented Nov 29, 2023

Thanks for the bump @bdeb1337 will try to look over the next few days, but as I no longer have merge access, also poking @lwaddicor

server_cmds.go Show resolved Hide resolved
server_cmds.go Outdated Show resolved Hide resolved
@lwaddicor
Copy link
Collaborator

lwaddicor commented Nov 30, 2023

Hey!

Just had a quick look and ran the change against a local teamspeak server I fired up in docker, and it looks as populated as I'd expect.

Just a couple of minor things around the comments to please the linters and make it easier for users in their IDEs. Other than that it looks very nice!

Validation

package main

import (
	"fmt"
	"log"

	"github.com/kr/pretty"
	"github.com/multiplay/go-ts3"
)

func main() {
	c, err := ts3.NewClient("localhost:10011")
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	if err := c.Login("serveradmin", "M2EhMOoP"); err != nil {
		log.Fatal(err)
	}

	v, err := c.Version()
	if err != nil {
		log.Fatal(fmt.Errorf("fail to version list: %w", err))
	}
	fmt.Println("Server is running:")
	pretty.Print(v)

	if err := c.Server.Use(1); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Client fist full:")
	cl, err := c.Server.ClientList(ts3.ClientListFull)
	if err != nil {
		log.Fatal(fmt.Errorf("fail to client list: %w", err))
	}
	pretty.Print(cl)
}

Output:

Server is running:
&ts3.Version{Version:"3.13.7", Platform:"Linux", Build:1655727713}
Client fist full:
[]*ts3.OnlineClient{
    &ts3.OnlineClient{
        ID:              13,
        ChannelID:       1,
        DatabaseID:      1,
        Nickname:        "serveradmin",
        Type:            1,
        Away:            false,
        AwayMessage:     "",
        OnlineClientExt: &ts3.OnlineClientExt{
            UniqueIdentifier:  &"serveradmin",
            OnlineClientVoice: &ts3.OnlineClientVoice{
                FlagTalking:        &bool(false),
                InputMuted:         &bool(false),
                OutputMuted:        &bool(false),
                InputHardware:      &bool(false),
                OutputHardware:     &bool(false),
                TalkPower:          &int(0),
                IsTalker:           &bool(false),
                IsPrioritySpeaker:  &bool(false),
                IsRecording:        &bool(false),
                IsChannelCommander: &bool(false),
            },
            OnlineClientTimes: &ts3.OnlineClientTimes{
                IdleTime:      &int(6),
                Created:       &int(0),
                LastConnected: &int(0),
            },
            OnlineClientGroups: &ts3.OnlineClientGroups{
                ChannelGroupID:                 &int(8),
                ChannelGroupInheritedChannelID: &int(1),
                ServerGroups:                   &[]int{2},
            },
            OnlineClientInfo: &ts3.OnlineClientInfo{
                Version:  &"ServerQuery",
                Platform: &"ServerQuery",
            },
            Country: &"",
            IP:      &"172.17.0.1",
            Badges:  &"",
            IconID:  &int(0),
        },
    },
    &ts3.OnlineClient{
        ID:              6,
        ChannelID:       1,
        DatabaseID:      3,
        Nickname:        "Lewis",
        Type:            0,
        Away:            true,
        AwayMessage:     "",
        OnlineClientExt: &ts3.OnlineClientExt{
            UniqueIdentifier:  &"lnxjPE/99+DR/wFXWawTtpeMBg4=",
            OnlineClientVoice: &ts3.OnlineClientVoice{
                FlagTalking:        &bool(false),
                InputMuted:         &bool(false),
                OutputMuted:        &bool(false),
                InputHardware:      &bool(true),
                OutputHardware:     &bool(true),
                TalkPower:          &int(75),
                IsTalker:           &bool(false),
                IsPrioritySpeaker:  &bool(false),
                IsRecording:        &bool(false),
                IsChannelCommander: &bool(true),
            },
            OnlineClientTimes: &ts3.OnlineClientTimes{
                IdleTime:      &int(312470),
                Created:       &int(1701366169),
                LastConnected: &int(1701366169),
            },
            OnlineClientGroups: &ts3.OnlineClientGroups{
                ChannelGroupID:                 &int(8),
                ChannelGroupInheritedChannelID: &int(1),
                ServerGroups:                   &[]int{6},
            },
            OnlineClientInfo: &ts3.OnlineClientInfo{
                Version:  &"3.6.1 [Build: 1690193193]",
                Platform: &"OS X",
            },
            Country: &"",
            IP:      &"172.17.0.1",
            Badges:  &"",
            IconID:  &int(0),
        },
    },
}

* Add comments for forgotten exported types
* Add proper comments for the extension consts
@bdeb1337
Copy link
Contributor Author

bdeb1337 commented Dec 1, 2023

Hey!

Just had a quick look and ran the change against a local teamspeak server I fired up in docker, and it looks as populated as I'd expect.

Just a couple of minor things around the comments to please the linters and make it easier for users in their IDEs. Other than that it looks very nice!

Thanks a bunch for checking it out so quickly! I've added your latest suggestions in a new commit.

@bdeb1337
Copy link
Contributor Author

Hi @lwaddicor and @stevenh

My best wishes for the starting of the new year 🎆 . I would kindly like to bump this PR again as I am looking forward to what you guys think and what I should try to improve or change.

Thank you!
Kind regards

Copy link
Collaborator

@lwaddicor lwaddicor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Looks good to me

@lwaddicor lwaddicor merged commit af46acd into Unity-Technologies:master Feb 13, 2024
@bdeb1337
Copy link
Contributor Author

No problem, thank you @lwaddicor for checking and merging. And also @stevenh thanks again for the guidance in this PR, appreciate that.
Kind regards,
Bob.

@bdeb1337 bdeb1337 deleted the onlineClient branch February 14, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants