From da0c451528392a5e2728c8fbac2d412d67352f8c Mon Sep 17 00:00:00 2001 From: MihailPestrikov Date: Sun, 19 Jan 2025 23:31:00 +0000 Subject: [PATCH] feat: add send message to players with runtime.Notify --- contracts/room_contract.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/contracts/room_contract.go b/contracts/room_contract.go index b317ab1..3150a36 100644 --- a/contracts/room_contract.go +++ b/contracts/room_contract.go @@ -87,9 +87,10 @@ func getRoom(ctx storage.Context, roomId string) Room { return room } -// Function to send message to player, now it is default -func sendMessageToPlayer(message string, player Player) { - // todo: Сделать основную логику +// Function to send message to players, event is recorded in blockchain +// Could be read through getapplicationlog or RPC call +func sendMessageToPlayers(notificationName, message string) { + runtime.Notify(notificationName, message) } // MAIN METHODS TO PLAY IN GAME @@ -196,9 +197,7 @@ func AskQuestion(roomId string, question string) bool { room.Rounds = append(room.Rounds, round) room.Status = RoomStatusAnswering - for _, player := range room.Players { - sendMessageToPlayer(question, player) - } + sendMessageToPlayers("RoundQuestion", question) // todo: Не забыть про nns // todo: Добавить списание токенов за создание вопроса @@ -261,11 +260,9 @@ func EndQuestion(roomId string) bool { var result string for i, answer := range round.Answers { result += fmt.Sprintf("index:%d, player:%s, answer:%s\n", i, answer.Wallet, answer.Content) - } + } // todo: нужно проверить нормально ли всё с \n в логах - for _, player := range room.Players { - sendMessageToPlayer(result, player) - } + sendMessageToPlayers("RoundAnswers", result) setRoom(ctx, &room) return true @@ -360,9 +357,7 @@ func GetRoundWinner(roomId string) bool { result += fmt.Sprintf("place:%d, winner:%s, votes:%s\n", i, answer.Wallet, answer.Votes) } - for _, player := range room.Players { - sendMessageToPlayer(result, player) - } + sendMessageToPlayers("RoundWinners", result) // todo: Отправка награды победителям @@ -426,7 +421,7 @@ func ManuallyFinishGame(roomId string) bool { func finishGame(ctx storage.Context, room *Room) bool { var winners = getGameWinner(room) - + // todo: Отправка награды победителям и хосту // todo: Нотификация результатов всей игры