Skip to content

Commit

Permalink
fix debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Oct 2, 2023
1 parent 65676a7 commit 97d752a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 12 additions & 6 deletions cmds/liter-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,21 @@ func initBeforeLoad()(_ bool){
}

func main(){
loger.Infof("Liter Server %s", version)

scriptpath := filepath.Join(configDir, "plugins")
var (
err error
server = NewServer(nil)
cfg = getConfig()
manager = script.NewManager()
)

if cfg.Debug {
loger.SetLevel(logger.TraceLevel)
}else{
loger.SetLevel(logger.InfoLevel)
}

loger.Infof("Liter Server %s", version)
manager.SetLogger(loger)

RESTART:
Expand Down Expand Up @@ -174,7 +180,7 @@ WAIT:
}
if cfg.Debug != ncfg.Debug {
if ncfg.Debug {
loger.SetLevel(logger.DebugLevel)
loger.SetLevel(logger.TraceLevel)
}else{
loger.SetLevel(logger.InfoLevel)
}
Expand Down Expand Up @@ -319,7 +325,7 @@ func handler(c *liter.Conn){
io.Copy(conn.RawConn(), rc)
}

func handleServerStatus(loger logger.Logger, c *liter.Conn, version string, motd string){
func handleServerStatus(loger logger.Logger, c *liter.Conn, name string, motd string){
var srp liter.StatusRequestPkt
var err error
if err = c.RecvPkt(0x00, &srp); err != nil {
Expand All @@ -329,8 +335,8 @@ func handleServerStatus(loger logger.Logger, c *liter.Conn, version string, motd
if err = c.SendPkt(0x00, liter.StatusResponsePkt{
Payload: liter.Object{
"version": liter.Object{
"name": "Idle",
"protocol": 0,
"name": name,
"protocol": c.Protocol(),
},
"players": liter.Object{
"max": 1,
Expand Down
18 changes: 10 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,26 @@ func (c *Conn)RecvHandshakePkt()(pkt *HandshakePkt, err error){

func readHandshakePacket(r io.Reader)(p *HandshakePkt, err error){
var (
varb [5]byte
n int = 0
size int32
)
{ // read varint
var (
i int = 0
b [1]byte
v0 uint32
v0 uint32 = 0
)
for {
if _, err = r.Read(b[:]); err != nil {
if _, err = r.Read(varb[n:n + 1]); err != nil {
return
}
if n == 0 && b[0] == 0xfe {
b := varb[n]
if n == 0 && b == 0xfe {
return nil, ErrOldHandshake
}
n++
v0 |= (uint32)(b[0] & 0x7f) << i
if b[0] & 0x80 == 0 {
v0 |= (uint32)(b & 0x7f) << i
if b & 0x80 == 0 {
size = (int32)(v0)
break
}
Expand All @@ -197,8 +198,8 @@ func readHandshakePacket(r io.Reader)(p *HandshakePkt, err error){
buf: make([]byte, (int32)(n) + size),
off: n,
}
encodeVarInt(pr.buf[:n], size)
if _, err = io.ReadFull(r, pr.buf[pr.off:]); err != nil {
copy(pr.buf[:n], varb[:n])
if _, err = io.ReadFull(r, pr.buf[n:]); err != nil {
return nil, err
}
var ok bool
Expand All @@ -210,6 +211,7 @@ func readHandshakePacket(r io.Reader)(p *HandshakePkt, err error){
}
p = new(HandshakePkt)
if err = p.Decode(pr); err != nil {
p = nil
return
}
return
Expand Down

0 comments on commit 97d752a

Please sign in to comment.