moved globals, no code changes other than formatting.

main
Robert 10 months ago
parent ff7e57a2ab
commit 6196b3ccad
  1. 15
      chat_client.go
  2. 59
      chat_server.go

@ -20,6 +20,12 @@ import (
// Copyright (c) 2025 Robert Strutts, License MIT
// Global Vars:
var (
encryptor Encryptor
config Config
)
type Config struct {
Window struct {
Title string `yaml:"title"`
@ -39,11 +45,6 @@ type Config struct {
} `yaml:"user"`
}
var (
config Config
key []byte
)
type Message struct {
Username string
Text string
@ -112,9 +113,9 @@ func (x *XXTEAEncryptor) Decrypt(ciphertext []byte) ([]byte, error) {
return result, nil
}
var encryptor Encryptor
func loadConfig(filename string) (*Config, error) {
var key []byte
data, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("error reading config file: %v", err)

@ -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")
}
}
}

Loading…
Cancel
Save