DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
This commit is contained in:
commit
645b64fe21
4388 files changed
+1405457
No files matched your search
@@ -0,0 +1,130 @@
|
||||
package dnfbridge
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
dnfproto "longheng.io/server/internal/modules/dnf/protocol"
|
||||
)
|
||||
|
||||
func TestConcurrentGameTransportSendsPreserveWireSequence(t *testing.T) {
|
||||
const sendCount = 128
|
||||
|
||||
conn := &bufferConn{}
|
||||
service := &Service{}
|
||||
session := &gameSession{conn: conn, connID: "transport-concurrency"}
|
||||
|
||||
runConcurrentGameSends(t, sendCount, func(index int) error {
|
||||
return service.sendGame(session, 1, uint16(300+index), []byte{byte(index)})
|
||||
})
|
||||
|
||||
stream := conn.write.Bytes()
|
||||
for want := uint32(0); want < sendCount; want++ {
|
||||
if len(stream) < dnfproto.MinTCPFrameSize {
|
||||
t.Fatalf("transport frame %d is missing: remaining=%d", want, len(stream))
|
||||
}
|
||||
frameLength := int(binary.LittleEndian.Uint16(stream[2:4]))
|
||||
if frameLength > len(stream) {
|
||||
t.Fatalf("transport frame %d length=%d remaining=%d", want, frameLength, len(stream))
|
||||
}
|
||||
records, err := dnfproto.ParseLatestGameTCPRecords(stream[:frameLength])
|
||||
if err != nil {
|
||||
t.Fatalf("parse transport frame %d: %v", want, err)
|
||||
}
|
||||
if len(records) != 1 {
|
||||
t.Fatalf("transport frame %d records=%d want=1", want, len(records))
|
||||
}
|
||||
if got := records[0].TransportHeader.Sequence; got != want {
|
||||
t.Fatalf("transport wire sequence=%d want=%d", got, want)
|
||||
}
|
||||
stream = stream[frameLength:]
|
||||
}
|
||||
if len(stream) != 0 {
|
||||
t.Fatalf("transport stream has %d trailing bytes", len(stream))
|
||||
}
|
||||
if got := session.sequence; got != sendCount {
|
||||
t.Fatalf("transport session sequence=%d want=%d", got, sendCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrentGameUpperSendsPreserveWireSequence(t *testing.T) {
|
||||
const sendCount = 128
|
||||
|
||||
conn := &bufferConn{}
|
||||
service := &Service{options: options{
|
||||
gameUpperHeader: gameUpperHeaderChannel13,
|
||||
gameUpperBodyCodec: gameUpperBodyCodecPlain,
|
||||
}}
|
||||
session := &gameSession{conn: conn, connID: "upper-concurrency"}
|
||||
|
||||
runConcurrentGameSends(t, sendCount, func(index int) error {
|
||||
return service.sendGameUpperRawClassNoCodec(
|
||||
session,
|
||||
uint16(300+index),
|
||||
[]byte{byte(index)},
|
||||
dnfproto.DefaultChannelClassification,
|
||||
)
|
||||
})
|
||||
|
||||
stream := conn.write.Bytes()
|
||||
for want := uint16(0); want < sendCount; want++ {
|
||||
packet, rest := splitGameServerUpperPacket(t, stream)
|
||||
if got := packet.Header.Seq; got != want {
|
||||
t.Fatalf("upper wire sequence=%d want=%d", got, want)
|
||||
}
|
||||
stream = rest
|
||||
}
|
||||
if len(stream) != 0 {
|
||||
t.Fatalf("upper stream has %d trailing bytes", len(stream))
|
||||
}
|
||||
if got := session.upperSeq; got != sendCount {
|
||||
t.Fatalf("upper session sequence=%d want=%d", got, sendCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGamePacketLogSequenceIsAtomic(t *testing.T) {
|
||||
const logCount = 256
|
||||
|
||||
service := &Service{}
|
||||
session := &gameSession{connID: "packet-log-concurrency"}
|
||||
|
||||
runConcurrentGameSends(t, logCount, func(index int) error {
|
||||
service.logGamePacket(session, "SEND", "concurrency-test", []byte{byte(index)})
|
||||
return nil
|
||||
})
|
||||
|
||||
if got := atomic.LoadUint64(&session.packetSeq); got != logCount {
|
||||
t.Fatalf("packet log sequence=%d want=%d", got, logCount)
|
||||
}
|
||||
}
|
||||
|
||||
func runConcurrentGameSends(t *testing.T, count int, send func(index int) error) {
|
||||
t.Helper()
|
||||
|
||||
start := make(chan struct{})
|
||||
errors := make(chan error, count)
|
||||
var group sync.WaitGroup
|
||||
group.Add(count)
|
||||
for index := 0; index < count; index++ {
|
||||
index := index
|
||||
go func() {
|
||||
defer group.Done()
|
||||
<-start
|
||||
if err := send(index); err != nil {
|
||||
errors <- fmt.Errorf("send %d: %w", index, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
close(start)
|
||||
group.Wait()
|
||||
close(errors)
|
||||
for err := range errors {
|
||||
t.Error(err)
|
||||
}
|
||||
if t.Failed() {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user