Skip to content

Commit f80c40d

Browse files
committed
修复雀魂刷新页面或掉线重连时牌谱解析异常的 bug
1 parent a695e38 commit f80c40d

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,19 @@ func main() {
8787

8888
flags, restArgs := parseArgs(os.Args[1:])
8989

90+
considerOldYaku := flags.Bool("old")
91+
util.SetConsiderOldYaku(considerOldYaku)
92+
9093
isMajsoul := flags.Bool("majsoul")
9194
isTenhou := flags.Bool("tenhou")
9295
isAnalysis := flags.Bool("analysis")
9396
isInteractive := flags.Bool("i", "interactive")
97+
9498
showImproveDetail = flags.Bool("detail")
9599
showAgariAboveShanten1 = flags.Bool("a", "agari")
96100
showScore = flags.Bool("s", "score")
97-
considerOldYaku := flags.Bool("old")
98101
showAllYakuTypes = flags.Bool("y", "yaku")
99102

100-
util.SetConsiderOldYaku(considerOldYaku)
101-
102103
humanDoraTiles := flags.String("d", "dora")
103104
humanTiles := strings.Join(restArgs, " ")
104105
humanTilesInfo := &model.HumanTilesInfo{

majsoul.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type majsoulMessage struct {
4141
// 座位变更
4242
ChangeSeatTo *int `json:"change_seat_to"`
4343

44+
// 游戏重连时收到的数据
45+
SyncGameActions []*majsoulRecordAction `json:"sync_game_actions"`
46+
4447
// ResAuthGame
4548
// {"seat_list":[x,x,x,x],"is_game_start":false,"game_config":{"category":1,"mode":{"mode":1,"ai":true,"detail_rule":{"time_fixed":60,"time_add":0,"dora_count":3,"shiduan":1,"init_point":25000,"fandian":30000,"bianjietishi":true,"ai_level":1,"fanfu":1}},"meta":{"room_id":18269}},"ready_id_list":[0,0,0]}
4649
IsGameStart *bool `json:"is_game_start"` // false=新游戏,true=重连
@@ -221,11 +224,6 @@ func (d *majsoulRoundData) SkipMessage() bool {
221224
}
222225
}
223226

224-
// 筛去重连的消息,目前的程序不考虑重连的情况 TODO
225-
if msg.IsGameStart != nil && *msg.IsGameStart {
226-
return true
227-
}
228-
229227
return false
230228
}
231229

@@ -330,13 +328,10 @@ func (d *majsoulRoundData) ParseInit() (roundNumber int, benNumber int, dealer i
330328

331329
func (d *majsoulRoundData) IsSelfDraw() bool {
332330
msg := d.msg
333-
331+
// ActionDealTile
334332
if msg.Seat == nil || msg.Moqie != nil || msg.Tile == "" {
335333
return false
336334
}
337-
338-
// FIXME: 更好的判断?
339-
// ActionDealTile
340335
who := d.parseWho(*msg.Seat)
341336
return who == 0
342337
}
@@ -376,7 +371,6 @@ func (d *majsoulRoundData) ParseDiscard() (who int, discardTile int, isRedFive b
376371

377372
func (d *majsoulRoundData) IsOpen() bool {
378373
msg := d.msg
379-
// FIXME: 更好的判断?
380374
// ActionChiPengGang || ActionAnGangAddGang
381375
if msg.Tiles == nil {
382376
return false

server.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,9 @@ func (h *mjHandler) runAnalysisMajsoulMessageTask() {
322322
go analysisCache.runMajsoulRecordAnalysisTask(fullActions)
323323
}
324324

325-
if len(actions) == 0 {
326-
break
327-
}
328-
329-
fastRecordEnd := util.MaxInt(0, len(actions)-3)
330-
h.majsoulRoundData.skipOutput = true
331-
// 留最后三个刷新,这样确保会刷新界面
332-
for _, action := range actions[:fastRecordEnd] {
333-
h._analysisMajsoulRoundData(action.Action, "")
334-
}
335-
h.majsoulRoundData.skipOutput = false
336-
for _, action := range actions[fastRecordEnd:] {
337-
h._analysisMajsoulRoundData(action.Action, "")
338-
}
325+
h._fastLoadActions(actions)
326+
case len(d.SyncGameActions) > 0:
327+
h._fastLoadActions(d.SyncGameActions)
339328
default:
340329
// 其他:AI 分析
341330
h._analysisMajsoulRoundData(d, originJSON)
@@ -382,13 +371,32 @@ func (h *mjHandler) _loadLiveAction(action *majsoulRecordAction, isFast bool) er
382371
}
383372

384373
func (h *mjHandler) _analysisMajsoulRoundData(data *majsoulMessage, originJSON string) {
374+
//if originJSON == "{}" {
375+
// return
376+
//}
385377
h.majsoulRoundData.msg = data
386378
h.majsoulRoundData.originJSON = originJSON
387379
if err := h.majsoulRoundData.analysis(); err != nil {
388380
h.logError(err)
389381
}
390382
}
391383

384+
func (h *mjHandler) _fastLoadActions(actions []*majsoulRecordAction) {
385+
if len(actions) == 0 {
386+
return
387+
}
388+
fastRecordEnd := util.MaxInt(0, len(actions)-3)
389+
h.majsoulRoundData.skipOutput = true
390+
// 留最后三个刷新,这样确保会刷新界面
391+
for _, action := range actions[:fastRecordEnd] {
392+
h._analysisMajsoulRoundData(action.Action, "")
393+
}
394+
h.majsoulRoundData.skipOutput = false
395+
for _, action := range actions[fastRecordEnd:] {
396+
h._analysisMajsoulRoundData(action.Action, "")
397+
}
398+
}
399+
392400
func (h *mjHandler) _onRecordClick(clickAction string, clickActionIndex int, fastRecordTo int) {
393401
if debugMode {
394402
fmt.Println("[_onRecordClick] 收到", clickAction, clickActionIndex, fastRecordTo)

0 commit comments

Comments
 (0)