Exemple #1
0
// GetCurrentId returns the id of the user currently logged in.
//
// This function requires the client to be logged in.
func GetCurrentId(client *rbxweb.Client) (id int32, err error) {
	resp, err := client.Get(client.GetURL(`www`, `/Game/GetCurrentUser.ashx`, nil))
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	defer resp.Body.Close()

	var r bytes.Buffer
	r.ReadFrom(resp.Body)
	id, err = client.Atoi32(r.String())
	if err != nil {
		return 0, errors.New("user is not authorized")
	}
	return id, nil
}
Exemple #2
0
// GetIdFromName returns a user id from a user name.
func GetIdFromName(client *rbxweb.Client, name string) (id int32, err error) {
	if name == "" {
		return 0, errors.New("name not specified")
	}
	query := url.Values{
		"UserName": {name},
	}
	req, _ := http.NewRequest("HEAD", client.GetURL(`www`, `/User.aspx`, query), nil)
	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	resp.Body.Close()
	values, err := url.ParseQuery(resp.Header.Get("Location"))
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	return client.Atoi32(values.Get("ID"))
}