aboutsummaryrefslogtreecommitdiff
path: root/hotline/transaction.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-07-17 15:41:20 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-07-17 15:42:37 -0700
commitfd740bc499ebc6d3a381479316f74cdc736d02de (patch)
treee77563ce0997e51debaec75c9f7a053759ca3a0a /hotline/transaction.go
parent80aed6b19ff0b0927670e459ce5cc7a16ef047ec (diff)
Extensive refactor, quality of life enhancements
* Added ability to reload config, agreement, news, and user accounts without restarting the server by sending SIGHUP to the running process * Added ability to use modern unix or windows line breaks in Agreement.txt and MessageBoard.txt instead of classic MacOS `\r` breaks. * Extensive refactor towards swappable backends for the active server state * Extensive refactored towards making the hotline package generic and re-usable for alternate server implemenations * Fix bug where users whose accounts have been deleted would not be disconnected
Diffstat (limited to 'hotline/transaction.go')
-rw-r--r--hotline/transaction.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/hotline/transaction.go b/hotline/transaction.go
index 7a456a5..fa1e96d 100644
--- a/hotline/transaction.go
+++ b/hotline/transaction.go
@@ -85,18 +85,18 @@ type Transaction struct {
ParamCount [2]byte // Number of the parameters for this transaction
Fields []Field
- clientID [2]byte // Internal identifier for target client
- readOffset int // Internal offset to track read progress
+ ClientID ClientID // Internal identifier for target client
+ readOffset int // Internal offset to track read progress
}
var tranTypeNames = map[TranType]string{
TranChatMsg: "Receive chat",
TranNotifyChangeUser: "User change",
TranError: "Error",
- TranShowAgreement: "Show Agreement",
+ TranShowAgreement: "Show agreement",
TranUserAccess: "User access",
TranNotifyDeleteUser: "User left",
- TranAgreed: "TranAgreed",
+ TranAgreed: "Accept agreement",
TranChatSend: "Send chat",
TranDelNewsArt: "Delete news article",
TranDelNewsItem: "Delete news item",
@@ -141,18 +141,15 @@ var tranTypeNames = map[TranType]string{
TranDownloadBanner: "Download banner",
}
-//func (t TranType) LogValue() slog.Value {
-// return slog.StringValue(tranTypeNames[t])
-//}
-
-// NewTransaction creates a new Transaction with the specified type, client Type, and optional fields.
-func NewTransaction(t TranType, clientID [2]byte, fields ...Field) Transaction {
+// NewTransaction creates a new Transaction with the specified type, client, and optional fields.
+func NewTransaction(t TranType, clientID ClientID, fields ...Field) Transaction {
transaction := Transaction{
Type: t,
- clientID: clientID,
+ ClientID: clientID,
Fields: fields,
}
+ // Give the transaction a random ID.
binary.BigEndian.PutUint32(transaction.ID[:], rand.Uint32())
return transaction
@@ -183,7 +180,7 @@ func (t *Transaction) Write(p []byte) (n int, err error) {
copy(t.ParamCount[:], p[20:22])
scanner := bufio.NewScanner(bytes.NewReader(p[22:tranLen]))
- scanner.Split(fieldScanner)
+ scanner.Split(FieldScanner)
for i := 0; i < int(paramCount); i++ {
if !scanner.Scan() {