-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
国际象棋 #720
国际象棋 #720
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
总的来说感觉不错,比莲宝 @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意反并发
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
群反并发并非就万事大吉了,一样要做文件的反并发。简单的方法是只在程序启动时才清理/重建一次目录,然后就不管了。
你是? |
需要添加字体 unifont 到 zbpdata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好还是不要用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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你文件反并发呢,最简单的办法是给每个文件名加一个随机值区分。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单个群内同时只允许同时存在一个对局,使用群号作为区分即可解决并发问题。
只有当用户发请求走棋时才需要读取图片,而棋盘也应该同步更新,实际操作为使用新的图片覆盖旧的图片,并立即读取,同一个群/即同一个对局中,图片读取完成后会立即失效,后续不再用到,使用新的图片覆盖也不会存在问题。不同的群/即不同的对局读写的文件路径是完全不同的,相互之间不会存在并发错误。
如果所有文件都使用随机值而不加有效区分的话,会生成大量的临时文件占用磁盘空间。每一次走棋会生成 30KB
的 svg 图片和 80KB
的 png 图片。一盘游戏平均要走 40 步,耗费 20 分钟,即约 4MB 的空间浪费。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那可否不存这个图片,直接作为base64发送,svg渲染用 @kanrichan 的 https://github.com/kanrichan/resvg-go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试着改一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
群反并发并非就万事大吉了,一样要做文件的反并发。简单的方法是只在程序启动时才清理/重建一次目录,然后就不管了。
help wanted |
目前可行的解决方案:
|
@@ -52,7 +54,7 @@ func blindfold(groupCode, senderUin int64, senderName string) message.Message { | |||
// abort 中断对局 | |||
func abort(groupCode int64) message.Message { | |||
if room, ok := chessRoomMap.Load(groupCode); ok { | |||
return abortGame(room, groupCode, "对局已被管理员中断,游戏结束。") | |||
return abortGame(*room, groupCode, "对局已被管理员中断,游戏结束。") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这函数,同步改成指针啊,算了我改吧。
|
应该能跑吧,看下 lint