Conversation
fumiama
left a comment
There was a problem hiding this comment.
总的来说感觉不错,比莲宝 @lianhong2758 好太多了,莲宝你多学学🤣👉
| // generateBoardSVG 生成棋盘 SVG 图片 | ||
| func generateBoardSVG(svgFilePath, fenStr string, gameTurn chess.Color, sqs ...chess.Square) error { | ||
| os.Remove(svgFilePath) | ||
| f, err := os.Create(svgFilePath) |
There was a problem hiding this comment.
群反并发并非就万事大吉了,一样要做文件的反并发。简单的方法是只在程序启动时才清理/重建一次目录,然后就不管了。
你是? |
|
需要添加字体 unifont 到 zbpdata |
fumiama
left a comment
There was a problem hiding this comment.
最好还是不要用cmd.exec,我偏向于纯go实现。 @kanrichan 你那个能用吗?
| highlightSquare = append(highlightSquare, lastMove.S2()) | ||
| } | ||
| // 生成棋盘 svg 文件 | ||
| svgFilePath := path.Join(tempFileDir, fmt.Sprintf("%d.svg", groupCode)) |
There was a problem hiding this comment.
单个群内同时只允许同时存在一个对局,使用群号作为区分即可解决并发问题。
只有当用户发请求走棋时才需要读取图片,而棋盘也应该同步更新,实际操作为使用新的图片覆盖旧的图片,并立即读取,同一个群/即同一个对局中,图片读取完成后会立即失效,后续不再用到,使用新的图片覆盖也不会存在问题。不同的群/即不同的对局读写的文件路径是完全不同的,相互之间不会存在并发错误。
如果所有文件都使用随机值而不加有效区分的话,会生成大量的临时文件占用磁盘空间。每一次走棋会生成 30KB 的 svg 图片和 80KB 的 png 图片。一盘游戏平均要走 40 步,耗费 20 分钟,即约 4MB 的空间浪费。
There was a problem hiding this comment.
那可否不存这个图片,直接作为base64发送,svg渲染用 @kanrichan 的 https://github.com/kanrichan/resvg-go
There was a problem hiding this comment.
可否不存这个图片
不可以,调用inkscape必须指定文件路径
svg渲染用 @kanrichan 的 https://github.com/kanrichan/resvg-go
不会用
| // generateBoardSVG 生成棋盘 SVG 图片 | ||
| func generateBoardSVG(svgFilePath, fenStr string, gameTurn chess.Color, sqs ...chess.Square) error { | ||
| os.Remove(svgFilePath) | ||
| f, err := os.Create(svgFilePath) |
There was a problem hiding this comment.
群反并发并非就万事大吉了,一样要做文件的反并发。简单的方法是只在程序启动时才清理/重建一次目录,然后就不管了。
|
help wanted |
|
目前可行的解决方案:
|
| func abort(groupCode int64) message.Message { | ||
| if room, ok := chessRoomMap.Load(groupCode); ok { | ||
| return abortGame(room, groupCode, "对局已被管理员中断,游戏结束。") | ||
| return abortGame(*room, groupCode, "对局已被管理员中断,游戏结束。") |
|



应该能跑吧,看下 lint