workaround for localhost connections

This commit is contained in:
wish
2023-02-25 16:12:51 +11:00
parent bbaec08b67
commit 747f21c4db
3 changed files with 20 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"net" "net"
"strings"
"sync" "sync"
"erupe-ce/config" "erupe-ce/config"
@@ -112,7 +113,11 @@ func (s *Server) handleEntranceServerConnection(conn net.Conn) {
s.logger.Debug("Got entrance server command:\n", zap.String("raw", hex.Dump(pkt))) s.logger.Debug("Got entrance server command:\n", zap.String("raw", hex.Dump(pkt)))
data := makeSv2Resp(s.erupeConfig, s) local := false
if strings.Split(conn.RemoteAddr().String(), ":")[0] == "127.0.0.1" {
local = true
}
data := makeSv2Resp(s.erupeConfig, s, local)
if len(pkt) > 5 { if len(pkt) > 5 {
data = append(data, makeUsrResp(pkt, s)...) data = append(data, makeUsrResp(pkt, s)...)
} }

View File

@@ -17,7 +17,7 @@ var season uint8
// Server Channels // Server Channels
var currentplayers uint16 var currentplayers uint16
func encodeServerInfo(config *config.Config, s *Server) []byte { func encodeServerInfo(config *config.Config, s *Server, local bool) []byte {
serverInfos := config.Entrance.Entries serverInfos := config.Entrance.Entries
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
@@ -30,7 +30,11 @@ func encodeServerInfo(config *config.Config, s *Server) []byte {
if si.IP == "" { if si.IP == "" {
si.IP = config.Host si.IP = config.Host
} }
bf.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(si.IP).To4())) if local {
bf.WriteUint32(0x0100007F) // 127.0.0.1
} else {
bf.WriteUint32(binary.LittleEndian.Uint32(net.ParseIP(si.IP).To4()))
}
bf.WriteUint16(16 + uint16(serverIdx)) bf.WriteUint16(16 + uint16(serverIdx))
bf.WriteUint16(0x0000) bf.WriteUint16(0x0000)
bf.WriteUint16(uint16(len(si.Channels))) bf.WriteUint16(uint16(len(si.Channels)))
@@ -85,9 +89,9 @@ func makeHeader(data []byte, respType string, entryCount uint16, key byte) []byt
return bf.Data() return bf.Data()
} }
func makeSv2Resp(config *config.Config, s *Server) []byte { func makeSv2Resp(config *config.Config, s *Server, local bool) []byte {
serverInfos := config.Entrance.Entries serverInfos := config.Entrance.Entries
rawServerData := encodeServerInfo(config, s) rawServerData := encodeServerInfo(config, s, local)
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
bf.WriteBytes(makeHeader(rawServerData, "SV2", uint16(len(serverInfos)), 0x00)) bf.WriteBytes(makeHeader(rawServerData, "SV2", uint16(len(serverInfos)), 0x00))
return bf.Data() return bf.Data()

View File

@@ -8,6 +8,7 @@ import (
"erupe-ce/server/channelserver" "erupe-ce/server/channelserver"
"fmt" "fmt"
"math/rand" "math/rand"
"strings"
"time" "time"
"go.uber.org/zap" "go.uber.org/zap"
@@ -51,7 +52,11 @@ func (s *Session) makeSignInResp(uid int) []byte {
ps.Uint8(bf, s.server.erupeConfig.PatchServerFile, false) ps.Uint8(bf, s.server.erupeConfig.PatchServerFile, false)
} }
} }
ps.Uint8(bf, fmt.Sprintf("%s:%d", s.server.erupeConfig.Host, s.server.erupeConfig.Entrance.Port), false) if strings.Split(s.rawConn.RemoteAddr().String(), ":")[0] == "127.0.0.1" {
ps.Uint8(bf, fmt.Sprintf("127.0.0.1:%d", s.server.erupeConfig.Entrance.Port), false)
} else {
ps.Uint8(bf, fmt.Sprintf("%s:%d", s.server.erupeConfig.Host, s.server.erupeConfig.Entrance.Port), false)
}
lastPlayed := uint32(0) lastPlayed := uint32(0)
for _, char := range chars { for _, char := range chars {