mirror of
https://github.com/gissleh/irc.git
synced 2026-09-29 00:35:35 +00:00
This commit is contained in:
@@ -98,7 +98,7 @@ type Client struct {
|
|||||||
// tear down clients upon quitting.
|
// tear down clients upon quitting.
|
||||||
func New(ctx context.Context, config Config) *Client {
|
func New(ctx context.Context, config Config) *Client {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
id: generateClientID(),
|
id: generateClientID("C"),
|
||||||
values: make(map[string]interface{}),
|
values: make(map[string]interface{}),
|
||||||
events: make(chan *Event, 64),
|
events: make(chan *Event, 64),
|
||||||
sends: make(chan string, 64),
|
sends: make(chan string, 64),
|
||||||
@@ -672,7 +672,7 @@ func (client *Client) AddTarget(target Target) (id string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id = generateClientID()
|
id = generateClientID("T")
|
||||||
client.targets = append(client.targets, target)
|
client.targets = append(client.targets, target)
|
||||||
client.targetIds[target] = id
|
client.targetIds[target] = id
|
||||||
|
|
||||||
@@ -1493,22 +1493,16 @@ func (client *Client) handleInTarget(target Target, event *Event) {
|
|||||||
client.mutex.RUnlock()
|
client.mutex.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateClientID() string {
|
func generateClientID(prefix string) string {
|
||||||
bytes := make([]byte, 12)
|
buffer := [12]byte{}
|
||||||
_, err := rand.Read(bytes)
|
_, err := rand.Read(buffer[:])
|
||||||
|
|
||||||
// Ugly fallback if crypto rand doesn't work.
|
// Ugly fallback if crypto rand doesn't work.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rng := mathRand.NewSource(time.Now().UnixNano())
|
mathRand.Read(buffer[:])
|
||||||
result := strconv.FormatInt(rng.Int63(), 16)
|
|
||||||
for len(result) < 24 {
|
|
||||||
result += strconv.FormatInt(rng.Int63(), 16)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result[:24]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binary.BigEndian.PutUint32(bytes[4:], uint32(time.Now().Unix()))
|
binary.BigEndian.PutUint32(buffer[4:], uint32(time.Now().Unix()))
|
||||||
|
|
||||||
return hex.EncodeToString(bytes)
|
return prefix + hex.EncodeToString(buffer[:])[1:]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
Reference in New Issue
Block a user