Skip to content

Commit 3bec127

Browse files
committed
Fix
1 parent a15f4db commit 3bec127

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

server/player/player.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,20 @@ ViewDistance returns the view distance of the client, in chunks, or the server's
8383
*/
8484
func (p *Player) ViewDistance() int32 {
8585
plVd := int32(p.ClientInformation.Load().ViewDistance)
86-
/*if plVd == 0 || plVd > int32(session.config.ViewDistance) {
87-
return int32(session.config.ViewDistance)
88-
}*/ // todo add this back
86+
if plVd == 0 || plVd > p.serverProperties.ViewDistance {
87+
return p.serverProperties.ViewDistance
88+
}
8989

9090
return plVd
9191
}
9292

93+
// writeOrKill tries to write the packet to the player and kills it on failure
94+
func (p *Player) writeOrKill(pk packet.Encodeable) {
95+
if err := p.WritePacket(pk); err != nil {
96+
p.killConnection(false, "lost connection")
97+
}
98+
}
99+
93100
// finishConfiguration finishes the configuration phase by sending the server brand, registries and tags
94101
func (p *Player) finishConfiguration() error {
95102
// begin packet reading in the background

server/player/playerlist.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ func (list *PlayerList) Player(uuid uuid.UUID) *Player {
3232
return nil
3333
}
3434

35+
func (list *PlayerList) PlayerByUsername(name string) *Player {
36+
for i := uintptr(0); i < list.playerList.Len(); i++ {
37+
player := list.playerAtIndex(i)
38+
39+
if player.Username() == name {
40+
return player
41+
}
42+
}
43+
return nil
44+
}
45+
3546
func (list *PlayerList) playerAtIndex(index uintptr) *Player {
3647
return *(**Player)(list.playerList.Element(index))
3748
}
@@ -56,7 +67,7 @@ func (list *PlayerList) AddPlayer(player *Player) {
5667

5768
for i := uintptr(0); i < list.playerList.Len(); i++ {
5869
player := list.playerAtIndex(i)
59-
player.WritePacket(update)
70+
player.writeOrKill(update)
6071
}
6172
}
6273

server/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"github.com/zeppelinmc/zeppelin/properties"
7+
"github.com/zeppelinmc/zeppelin/protocol/net/packet/configuration"
78
"github.com/zeppelinmc/zeppelin/server/player"
89
"image/png"
910
"os"
@@ -195,12 +196,12 @@ func (srv *Server) Start(ts time.Time) {
195196

196197
func (srv *Server) handleNewConnection(conn *net.Conn) {
197198
log.Infolnf("%sPlayer attempting to connect: %s (%s)", log.FormatAddr(srv.cfg.LogIPs, conn.RemoteAddr()), conn.Username(), conn.UUID())
198-
/*if _, ok := srv.World.Broadcast.SessionByUsername(conn.Username()); ok {
199-
conn.WritePacket(&configuration.Disconnect{
199+
if p := srv.playerList.PlayerByUsername(conn.Username()); p != nil {
200+
_ = conn.WritePacket(&configuration.Disconnect{
200201
Reason: text.TextComponent{Text: "You are already connected to the server from another session. Please disconnect then try again"},
201202
})
202203
return
203-
}*/
204+
}
204205
playerData, err := srv.World.PlayerData(conn.UUID().String())
205206
if err != nil {
206207
playerData = srv.World.NewPlayerData(conn.UUID())

0 commit comments

Comments
 (0)