2021-10-01 14:29:05 -04:00
|
|
|
package main
|
2021-10-01 14:24:31 -04:00
|
|
|
|
|
|
|
import (
|
2021-10-02 13:26:49 -04:00
|
|
|
"bufio"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"git.saintnet.tech/tomecraft/tome_lib"
|
2021-10-01 14:24:31 -04:00
|
|
|
coordinator "git.saintnet.tech/tomecraft/tome_server"
|
2021-10-02 13:26:49 -04:00
|
|
|
"github.com/google/uuid"
|
2021-10-01 14:24:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-10-02 13:26:49 -04:00
|
|
|
admin := flag.Bool("admin", false, "enable admin console")
|
|
|
|
flag.Parse()
|
2021-10-01 14:24:31 -04:00
|
|
|
c := coordinator.NewCoordinator()
|
2021-10-02 13:26:49 -04:00
|
|
|
if *admin {
|
|
|
|
file, err := os.OpenFile("serverlog.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetOutput(file)
|
|
|
|
go console(c)
|
|
|
|
}
|
|
|
|
|
2021-10-01 14:24:31 -04:00
|
|
|
c.Start()
|
|
|
|
Serve(c)
|
|
|
|
}
|
2021-10-02 13:26:49 -04:00
|
|
|
|
|
|
|
func console(c *coordinator.Coordinator) {
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
fmt.Printf("> ")
|
|
|
|
match := uuid.Nil
|
|
|
|
var err error
|
|
|
|
player := -1
|
|
|
|
for scanner.Scan() {
|
|
|
|
in := scanner.Text()
|
|
|
|
cmd := strings.Split(in, " ")
|
|
|
|
switch cmd[0] {
|
|
|
|
case "get":
|
|
|
|
switch cmd[1] {
|
|
|
|
case "matches":
|
|
|
|
fmt.Println(c.Matches)
|
|
|
|
case "queue":
|
|
|
|
fmt.Println(c.PlayerPool)
|
|
|
|
case "match":
|
|
|
|
fmt.Println(c.Matches[match])
|
|
|
|
case "game":
|
|
|
|
if match == uuid.Nil {
|
|
|
|
fmt.Println("needs match")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Println(c.Matches[match].Game)
|
|
|
|
case "player":
|
|
|
|
if match == uuid.Nil {
|
|
|
|
fmt.Println("needs match")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == -1 {
|
|
|
|
fmt.Println("needs player")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == tome_lib.SentinalID {
|
|
|
|
fmt.Println(c.Matches[match].Game.SentinalPlayer)
|
|
|
|
} else {
|
|
|
|
fmt.Println(c.Matches[match].Game.ScourgePlayer)
|
|
|
|
}
|
|
|
|
case "deck":
|
|
|
|
if match == uuid.Nil {
|
|
|
|
fmt.Println("needs match")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == -1 {
|
|
|
|
fmt.Println("needs player")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == tome_lib.SentinalID {
|
|
|
|
deck := c.Matches[match].Game.SentinalDeck
|
|
|
|
fmt.Println(deck)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < deck.Size() {
|
|
|
|
fmt.Println(view_card(deck.Cards[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
deck := c.Matches[match].Game.ScourgeDeck
|
|
|
|
fmt.Println(deck)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < deck.Size() {
|
|
|
|
fmt.Println(view_card(deck.Cards[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "hand":
|
|
|
|
if match == uuid.Nil {
|
|
|
|
fmt.Println("needs match")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == -1 {
|
|
|
|
fmt.Println("needs player")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == tome_lib.SentinalID {
|
|
|
|
hand := c.Matches[match].Game.SentinalPlayer.Hand
|
|
|
|
fmt.Println(hand)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < len(hand) {
|
|
|
|
fmt.Println(view_card(hand[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hand := c.Matches[match].Game.ScourgePlayer.Hand
|
|
|
|
fmt.Println(hand)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < len(hand) {
|
|
|
|
fmt.Println(view_card(hand[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "board":
|
|
|
|
if match == uuid.Nil {
|
|
|
|
fmt.Println("needs match")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == -1 {
|
|
|
|
fmt.Println("needs player")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if player == tome_lib.SentinalID {
|
|
|
|
board := c.Matches[match].Game.GameBoard.Sentinal
|
|
|
|
fmt.Println(board)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < len(board) {
|
|
|
|
fmt.Println(view_card(board[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
board := c.Matches[match].Game.GameBoard.Scourge
|
|
|
|
fmt.Println(board)
|
|
|
|
if len(cmd) == 3 {
|
|
|
|
crd, err := strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("invalid index")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if crd < len(board) {
|
|
|
|
fmt.Println(view_card(board[crd]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "set":
|
|
|
|
switch cmd[1] {
|
|
|
|
case "match":
|
|
|
|
match, err = uuid.Parse(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error setting match")
|
|
|
|
}
|
|
|
|
case "player":
|
|
|
|
player, err = strconv.Atoi(cmd[2])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("error setting player")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "reset":
|
|
|
|
match = uuid.Nil
|
|
|
|
player = -1
|
|
|
|
case "quit":
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
fmt.Printf("> ")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func view_card(c *tome_lib.Card) string {
|
|
|
|
return fmt.Sprintf("%v %v/%v %v %v %v %v %v %v", c.Type, c.BasePower, c.Power, c.Id, c.Sick, c.Counters, c.Owner, c.Position, c.Effects)
|
|
|
|
}
|