Repository navigation
Expand file tree
/
Copy pathuser.go
More file actions
71 lines (61 loc) · 1.55 KB
/
Copy pathuser.go
File metadata and controls
71 lines (61 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2011 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.
package main
import (
"encoding/hex"
"os"
)
// This file implements Server's handling of Users.
//
// Users are registered clients on the server.
type User struct {
Id uint32
Name string
Password string
CertHash string
Email string
TextureBlob string
CommentBlob string
LastChannelId int
LastActive uint64
}
// Create a new User
func NewUser(id uint32, name string) (user *User, err os.Error) {
if id < 0 {
return nil, os.NewError("Invalid user id")
}
if len(name) == 0 {
return nil, os.NewError("Invalid username")
}
return &User{
Id: id,
Name: name,
},nil
}
// Does the channel have comment?
func (user *User) HasComment() bool {
return len(user.CommentBlob) > 0
}
// Get the hash of the user's comment blob as a byte slice for transmitting via a protobuf message.
// Returns nil if there is no such blob.
func (user *User) CommentBlobHashBytes() (buf []byte) {
buf, err := hex.DecodeString(user.CommentBlob)
if err != nil {
return nil
}
return buf
}
// Does the user have a texture?
func (user *User) HasTexture() bool {
return len(user.TextureBlob) > 0
}
// Get the hash of the user's texture blob as a byte slice for transmitting via a protobuf message.
// Returns nil if there is no such blob.
func (user *User) TextureBlobHashBytes() (buf []byte) {
buf, err := hex.DecodeString(user.TextureBlob)
if err != nil {
return nil
}
return buf
}