Switch to new mt API
parent
18e7ba7977
commit
6f4494e1d0
|
@ -136,7 +136,7 @@ func handleContent(cc *contentConn) {
|
|||
break
|
||||
}
|
||||
|
||||
cc.log("->", err)
|
||||
cc.log("<-", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ func handleContent(cc *contentConn) {
|
|||
cc.SendCmd(&mt.ToSrvSRPBytesM{
|
||||
M: M,
|
||||
})
|
||||
case *mt.ToCltDisco:
|
||||
case *mt.ToCltKick:
|
||||
cc.log("<-", "deny access", cmd)
|
||||
case *mt.ToCltAcceptAuth:
|
||||
cc.auth.method = 0
|
||||
|
|
2
go.mod
2
go.mod
|
@ -4,5 +4,5 @@ go 1.17
|
|||
|
||||
require (
|
||||
github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b
|
||||
github.com/anon55555/mt v0.0.0-20210909184202-d6ba88b091f6
|
||||
github.com/anon55555/mt v0.0.0-20210919124550-bcc58cb3048f
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,4 +1,4 @@
|
|||
github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b h1:xqNC1S76U5U+eFyzr5Ld+8aPOLaDFCw6f1uddjui+h8=
|
||||
github.com/HimbeerserverDE/srp v0.0.0-20210331172529-2b5dbec6b82b/go.mod h1:pxNH8S2nh4n2DWE0ToX5GnnDr/uEAuaAhJsCpkDLIWw=
|
||||
github.com/anon55555/mt v0.0.0-20210909184202-d6ba88b091f6 h1:JcKyABhWe6hGGA4IUqoCidNiKT1CCT6Sgp4D0VY7ako=
|
||||
github.com/anon55555/mt v0.0.0-20210909184202-d6ba88b091f6/go.mod h1:jH4ER+ahjl7H6TczzK+q4V9sXY++U2Geh6/vt3r4Xvs=
|
||||
github.com/anon55555/mt v0.0.0-20210919124550-bcc58cb3048f h1:tZU8VPYLyRrG3Lj9zBZvTVF5tUGciC/2aUIgTcU4WaM=
|
||||
github.com/anon55555/mt v0.0.0-20210919124550-bcc58cb3048f/go.mod h1:jH4ER+ahjl7H6TczzK+q4V9sXY++U2Geh6/vt3r4Xvs=
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"github.com/anon55555/mt"
|
||||
)
|
||||
|
||||
// Kick sends mt.ToCltDisco with the specified custom reason
|
||||
// Kick sends mt.ToCltKick with the specified custom reason
|
||||
// and closes the ClientConn.
|
||||
func (cc *ClientConn) Kick(reason string) {
|
||||
go func() {
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{
|
||||
Reason: mt.Custom,
|
||||
Custom: reason,
|
||||
})
|
||||
|
|
32
process.go
32
process.go
|
@ -25,7 +25,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
cc.setState(csInit)
|
||||
if cmd.SerializeVer != latestSerializeVer {
|
||||
cc.Log("<-", "invalid serializeVer")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnsupportedVer})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnsupportedVer})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -38,7 +38,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if cmd.MaxProtoVer < latestProtoVer {
|
||||
cc.Log("<-", "invalid protoVer")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnsupportedVer})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnsupportedVer})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -51,7 +51,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if len(cmd.PlayerName) == 0 || len(cmd.PlayerName) > maxPlayerNameLen {
|
||||
cc.Log("<-", "invalid player name length")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.BadName})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.BadName})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -64,7 +64,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if !playerNameChars.MatchString(cmd.PlayerName) {
|
||||
cc.Log("<-", "invalid player name")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.BadNameChars})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.BadNameChars})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -88,7 +88,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
_, ok := players[cc.Name()]
|
||||
if ok {
|
||||
cc.Log("<-", "already connected")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.AlreadyConnected})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.AlreadyConnected})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -105,7 +105,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if cc.Name() == "singleplayer" {
|
||||
cc.Log("<-", "name is singleplayer")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.BadName})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.BadName})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -119,7 +119,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
// user limit
|
||||
if len(players) >= Conf().UserLimit {
|
||||
cc.Log("<-", "player limit reached")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.TooManyClts})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.TooManyClts})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -149,7 +149,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
if cc.state() == csInit {
|
||||
if cc.auth.method != mt.FirstSRP {
|
||||
cc.Log("->", "unauthorized password change")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnexpectedData})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnexpectedData})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -167,7 +167,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if cmd.EmptyPasswd && Conf().RequirePasswd {
|
||||
cc.Log("<-", "empty password disallowed")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.EmptyPasswd})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.EmptyPasswd})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -180,7 +180,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
|
||||
if err := authIface.SetPasswd(cc.Name(), cmd.Salt, cmd.Verifier); err != nil {
|
||||
cc.Log("<-", "set password fail")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.SrvErr})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.SrvErr})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -231,7 +231,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
return
|
||||
}
|
||||
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnexpectedData})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnexpectedData})
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
case <-ack:
|
||||
|
@ -251,7 +251,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
salt, verifier, err := authIface.Passwd(cc.Name())
|
||||
if err != nil {
|
||||
cc.Log("<-", "SRP data retrieval fail")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.SrvErr})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.SrvErr})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -267,7 +267,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
cc.auth.srpB, _, cc.auth.srpK, err = srp.Handshake(cc.auth.srpA, verifier)
|
||||
if err != nil || cc.auth.srpB == nil {
|
||||
cc.Log("<-", "SRP safety check fail")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnexpectedData})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnexpectedData})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -299,7 +299,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
return
|
||||
}
|
||||
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.UnexpectedData})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.UnexpectedData})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -336,7 +336,7 @@ func (cc *ClientConn) process(pkt mt.Pkt) {
|
|||
}
|
||||
|
||||
cc.Log("<-", "invalid password")
|
||||
ack, _ := cc.SendCmd(&mt.ToCltDisco{Reason: mt.WrongPasswd})
|
||||
ack, _ := cc.SendCmd(&mt.ToCltKick{Reason: mt.WrongPasswd})
|
||||
|
||||
select {
|
||||
case <-cc.Closed():
|
||||
|
@ -528,7 +528,7 @@ func (sc *ServerConn) process(pkt mt.Pkt) {
|
|||
})
|
||||
|
||||
return
|
||||
case *mt.ToCltDisco:
|
||||
case *mt.ToCltKick:
|
||||
sc.Log("<-", "deny access", cmd)
|
||||
ack, _ := clt.SendCmd(cmd)
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ func handleSrv(sc *ServerConn) {
|
|||
}
|
||||
|
||||
if sc.client() != nil {
|
||||
ack, _ := sc.client().SendCmd(&mt.ToCltDisco{
|
||||
ack, _ := sc.client().SendCmd(&mt.ToCltKick{
|
||||
Reason: mt.Custom,
|
||||
Custom: "Server connection closed unexpectedly.",
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue