cloud-game/pkg/session/session.go
sergystepanov a779353569
Reduce coordinator dependencies tree (#292)
* Reduce coordinator dependencies tree

* Parallelize build/check

* Update dependencies
2021-03-15 13:08:15 +03:00

27 lines
624 B
Go

package session
import (
"math/rand"
"strconv"
"strings"
)
const separator = "___"
// getGameNameFromRoomID parse roomID to get roomID and gameName
func GetGameNameFromRoomID(roomID string) string {
parts := strings.Split(roomID, separator)
if len(parts) > 1 {
return parts[1]
}
return ""
}
// generateRoomID generate a unique room ID containing 16 digits
func GenerateRoomID(gameName string) string {
// RoomID contains random number + gameName
// Next time when we only get roomID, we can launch game based on gameName
roomID := strconv.FormatInt(rand.Int63(), 16) + separator + gameName
return roomID
}