refactor: modularize connection handling and streamline event loop structure

This commit is contained in:
adman
2026-01-05 12:40:43 +01:00
parent 83a3b0f886
commit 253a7020f9
11 changed files with 176 additions and 200 deletions
+3 -18
View File
@@ -1,8 +1,6 @@
package modules
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
@@ -34,7 +32,7 @@ func (s *LoginClient) Default(event event.Unhandled) (err error) {
return
}
func (s *LoginClient) OnCycle(_ event.OnLoopCycle) (err error) {
func (s *LoginClient) OnCycle(_ event.Tick) (err error) {
return
}
@@ -109,20 +107,7 @@ func (s *LoginClient) OnEncrypt(packet v1_21_8.LoginToClientPacketEncryptionBegi
if err != nil {
return
}
var b cipher.Block
b, err = aes.NewCipher(sharedSecret)
if err != nil {
return
}
s.R = cipher.StreamReader{
S: crypto.NewCFB8Decrypt(b, sharedSecret),
R: s.Conn,
}
s.W = cipher.StreamWriter{
S: crypto.NewCFB8Encrypt(b, sharedSecret),
W: s.Conn,
}
err = s.SetSecret(sharedSecret)
return
}
@@ -134,7 +119,7 @@ func (s *LoginClient) OnSuccess(success *v1_21_8.LoginToClientPacketSuccess) (er
return
}
s.State = proto_base.Configuration
err = event.HandlerDone
err = event.ErrHandlerDone
return
}