Skip to content

Commit

Permalink
hold packets before login
Browse files Browse the repository at this point in the history
  • Loading branch information
olebeck committed Jul 12, 2024
1 parent 4d3eb2a commit d797631
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
24 changes: 24 additions & 0 deletions handlers/worlds/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,31 @@ func (w *worldsHandler) getEntity(id worldstate.EntityRuntimeID) *worldstate.Ent
return w.currentWorld.GetEntity(id)
}

type pkRecv struct {
pk packet.Packet
toServer bool
timeReceived time.Time
preLogin bool
}

func (w *worldsHandler) packetCB(_pk packet.Packet, toServer bool, timeReceived time.Time, preLogin bool) (packet.Packet, error) {
if !w.serverState.haveStartGame {
switch _pk.(type) {
case *packet.LevelChunk, *packet.SubChunk, *packet.SetTime, *packet.BlockActorData, *packet.UpdateBlock, *packet.UpdateBlockSynced, *packet.UpdateSubChunkBlocks:
w.worldPacketsHeld = append(w.worldPacketsHeld, pkRecv{_pk, toServer, timeReceived, preLogin})
return _pk, nil
}
} else if len(w.worldPacketsHeld) > 0 {
held := w.worldPacketsHeld
w.worldPacketsHeld = nil
for _, recv := range held {
_, err := w.packetCB(recv.pk, recv.toServer, recv.timeReceived, recv.preLogin)
if err != nil {
return nil, err
}
}
}

// general / startup
switch pk := _pk.(type) {
case *packet.CompressedBiomeDefinitionList: // for client side generation, disabled by proxy
Expand Down
2 changes: 2 additions & 0 deletions handlers/worlds/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type worldsHandler struct {
serverState serverState
settings WorldSettings
customBlocks []protocol.BlockEntry

worldPacketsHeld []pkRecv
}

type itemContainer struct {
Expand Down
17 changes: 5 additions & 12 deletions utils/proxy/resourcepacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (r *rpHandler) OnResourcePacksInfo(pk *packet.ResourcePacksInfo) error {
for _, pack := range pk.TexturePacks {
packID := pack.UUID + "_" + pack.Version

if r.filterDownloadResourcePacks(packID) {
r.downloadQueue.serverPackAmount--
continue
}

_, alreadyDownloading := r.downloadQueue.downloadingPacks[pack.UUID]
alreadyIgnored := slices.ContainsFunc(r.ignoredResourcePacks, func(e exemptedResourcePack) bool { return e.uuid == pack.UUID })
if alreadyDownloading || alreadyIgnored {
Expand Down Expand Up @@ -288,18 +293,6 @@ func (r *rpHandler) OnResourcePacksInfo(pk *packet.ResourcePacksInfo) error {
}
}

packsToDownload = slices.DeleteFunc(packsToDownload, func(id string) bool {
ignore := r.filterDownloadResourcePacks(id)
if ignore {
idsplit := strings.Split(id, "_")
r.ignoredResourcePacks = append(r.ignoredResourcePacks, exemptedResourcePack{
uuid: idsplit[0],
version: idsplit[1],
})
}
return ignore
})

if len(packsToDownload) != 0 {
// start downloading from server whenever a pack info is sent
r.packDownloads = make(chan *packet.ResourcePackDataInfo, len(packsToDownload))
Expand Down

0 comments on commit d797631

Please sign in to comment.