テキストチャットメッセージを外部ストレージに送信する

Diarkis Room には、テキストチャット機能が搭載されています。チャットデータはルームのメモリ内に保存・管理され、永続化されることはありません。チャットデータを永続化する必要がある場合は、チャットデータをどこかに送信する必要があります。

ここでは、サーバーで新しいテキストチャットメッセージを受信したときに、チャットメッセージのデータを別の場所に送信する方法について説明します。

// import github.com/Diarkis/dairkis/server, github.com/Diarkis/diarkis/room github.com/Diarkis/diarkis/util

// This exposes all room commands
room.ExposeCommands()
// This exposes all room support commands including text chat
roomSupport.ExposeCommands()

// Make sure you write this block of code AFTER calling room.ExposeCommands() and roomSupport.ExposeCommands()
// By doing so, we make sure sendTextChatData function is executed after the text chat is handled
server.HandleCommand(util.CmdBuiltInVer, util.CmdRoomChatSync, sendTextChatData)

// This function handles the sending of incoming text chat message
func sendTextChatData(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)) {
if len(payload) == 0 {
// Empty data, ignore it
next(nil)
return
}
textChatData := string(payload)
// Send textChatData somewhere else here!
next(nil)
}