|
|
|
|
@ -18,6 +18,33 @@ import ( |
|
|
|
|
|
|
|
|
|
// Copyright (c) 2025 Robert Strutts, License MIT
|
|
|
|
|
|
|
|
|
|
// Globals Vars:
|
|
|
|
|
var ( |
|
|
|
|
encryptor Encryptor |
|
|
|
|
config Config |
|
|
|
|
userManagerTCP *UserManagerTCP |
|
|
|
|
userManagerUDP *UserManagerUDP |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Message struct { |
|
|
|
|
Username string |
|
|
|
|
Text string |
|
|
|
|
Time string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Encryptor interface { |
|
|
|
|
Encrypt([]byte) ([]byte, error) |
|
|
|
|
Decrypt([]byte) ([]byte, error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type AESEncryptor struct { |
|
|
|
|
key []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type XXTEAEncryptor struct { |
|
|
|
|
key []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Config represents the server configuration
|
|
|
|
|
type Config struct { |
|
|
|
|
Server struct { |
|
|
|
|
@ -72,7 +99,6 @@ func (um *UserManagerUDP) AddClientUDP(addr *net.UDPAddr, username string) { |
|
|
|
|
um.clients[addr.String()] = &ClientUDP{addr: addr, username: username} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (um *UserManagerTCP) RemoveClientTCP(conn net.Conn) { |
|
|
|
|
um.mutex.Lock() |
|
|
|
|
defer um.mutex.Unlock() |
|
|
|
|
@ -115,32 +141,6 @@ func (um *UserManagerUDP) GetUserListUDP() string { |
|
|
|
|
return userList |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
userManagerTCP *UserManagerTCP |
|
|
|
|
userManagerUDP *UserManagerUDP |
|
|
|
|
config Config |
|
|
|
|
key []byte |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Message struct { |
|
|
|
|
Username string |
|
|
|
|
Text string |
|
|
|
|
Time string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Encryptor interface { |
|
|
|
|
Encrypt([]byte) ([]byte, error) |
|
|
|
|
Decrypt([]byte) ([]byte, error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type AESEncryptor struct { |
|
|
|
|
key []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type XXTEAEncryptor struct { |
|
|
|
|
key []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (a *AESEncryptor) Encrypt(plaintext []byte) ([]byte, error) { |
|
|
|
|
block, err := aes.NewCipher(a.key) |
|
|
|
|
if err != nil { |
|
|
|
|
@ -190,9 +190,9 @@ func (x *XXTEAEncryptor) Decrypt(ciphertext []byte) ([]byte, error) { |
|
|
|
|
return result, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var encryptor Encryptor |
|
|
|
|
|
|
|
|
|
func loadConfig(filename string) error { |
|
|
|
|
var key []byte |
|
|
|
|
|
|
|
|
|
data, err := os.ReadFile(filename) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("error reading config file: %v", err) |
|
|
|
|
@ -437,7 +437,6 @@ func broadcastTCP(data []byte, sender net.Conn, message string) { |
|
|
|
|
} else if message != "" { |
|
|
|
|
sayTCP(client, message, "@YOU-Said") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|