aboutsummaryrefslogtreecommitdiff
path: root/clients.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients.go')
-rw-r--r--clients.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/clients.go b/clients.go
index 15512c0..a1e0641 100644
--- a/clients.go
+++ b/clients.go
@@ -1,7 +1,9 @@
package main
import (
+ "crypto/rand"
"log/slog"
+ "math/big"
"net"
"sync"
)
@@ -58,6 +60,32 @@ func (client *Client) Teardown() {
}
}
+func NewLocalClient(conn *net.Conn) (*Client, error) {
+ client := &Client{
+ conn: conn,
+ Server: self,
+ State: ClientStatePreRegistration,
+ Nick: "*",
+ }
+ for _ = range 10 {
+ var uid_ = []byte(self.SID)
+ for _ = range 6 {
+ randint, err := rand.Int(rand.Reader, big.NewInt(26))
+ if err != nil {
+ return nil, err
+ }
+ uid_ = append(uid_, byte(65 + randint.Uint64()))
+ }
+ uid := string(uid_)
+ _, exists := uidToClient.LoadOrStore(uid, client)
+ if !exists {
+ client.UID = uid
+ return client, nil
+ }
+ }
+ return nil, ErrUIDBusy
+}
+
func (client *Client) checkRegistration() {
if client.State != ClientStatePreRegistration {
slog.Error("spurious call to checkRegistration", "client", client)