got udp test workign

This commit is contained in:
Joseph Holley
2018-12-19 02:56:20 -05:00
parent 632415c746
commit ab90f5f6e0
4 changed files with 44 additions and 28 deletions

View File

@ -141,34 +141,34 @@ func main() {
ppJSON(match.Properties)
fmt.Println(match)
/*
// Get players from the json properties.roster field
log.Println("Gathering roster from received match...")
players := make([]string, 0)
result := gjson.Get(match.Properties, "properties.roster")
result.ForEach(func(teamName, teamRoster gjson.Result) bool {
teamRoster.ForEach(func(_, player gjson.Result) bool {
players = append(players, player.String())
return true // keep iterating
})
// Get players from the json properties.roster field
log.Println("Gathering roster from received match...")
players := make([]string, 0)
result := gjson.Get(match.Properties, "properties.roster")
result.ForEach(func(teamName, teamRoster gjson.Result) bool {
teamRoster.ForEach(func(_, player gjson.Result) bool {
players = append(players, player.String())
return true // keep iterating
})
//log.Printf("players = %+v\n", players)
return true // keep iterating
})
//log.Printf("players = %+v\n", players)
// Assign players in this match to our server
log.Println("Assigning players to DGS at example.com:12345")
// Assign players in this match to our server
connstring := "example.com:12345"
if len(os.Args) >= 1 {
connstring = os.Args[1]
}
log.Println("Assigning players to DGS at", connstring)
playerstr := strings.Join(players, " ")
ci := &backend.ConnectionInfo{ConnectionString: connstring}
roster := &backend.Roster{PlayerIds: playerstr}
ci := &backend.ConnectionInfo{ConnectionString: "example.com:12345"}
assign := &backend.Assignments{Roster: roster, ConnectionInfo: ci}
_, err = client.CreateAssignments(context.Background(), assign)
if err != nil {
panic(err)
}
*/
assign := &backend.Assignments{Rosters: match.Rosters, ConnectionInfo: ci}
_, err = client.CreateAssignments(context.Background(), assign)
if err != nil {
panic(err)
}
log.Println("Success. Not deleting assignments [demo mode].")
}

View File

@ -3,14 +3,15 @@ kind: Fleet
metadata:
name: udp-server
spec:
replicas: 2
replicas: 1
template:
spec:
ports:
- name: default
containerPort: 7007
portPolicy: "dynamic"
containerPort: 10001
template:
spec:
containers:
- name: simple-udp
image: gcr.io/open-match-222408/udp-server:latest
image: gcr.io/matchmaker-dev-201405/udp-server:latest

View File

@ -0,0 +1,14 @@
#!/bin/bash -x
kubectl apply -f 01-fleet.yaml
UNSTARTED=true
while $UNSTARTED; do
kubectl get pods | grep udp-server | grep Running 2>&1 1>/dev/null
if [ ${?} -eq 0 ]; then
UNSTARTED=false
fi
done
echo "Game server started."
kubectl create -f 02-fleetallocation.yaml
CONNSTRING=$(bash 03-get-gameserver-addr.sh)
echo "Server available, asking for match to assign to ${CONNSTRING}"

View File

@ -8,7 +8,7 @@ import (
"time"
"agones.dev/agones/pkg/util/signals"
"agones.dev/agones/sdks/go"
sdk "agones.dev/agones/sdks/go"
)
const maxBufferSize = 1024
@ -48,7 +48,7 @@ func main() {
log.Fatalf("Could not send ready message")
}
err = server(ctx, "localhost:7007")
err = server(ctx, ":10001") // Bind to all IPs for the machine
if err != nil {
log.Print(err)
}
@ -56,6 +56,7 @@ func main() {
func server(ctx context.Context, address string) (err error) {
// Start listening
log.Printf("Listening on %v:%v", address)
pc, err := net.ListenPacket("udp", address)
if err != nil {
return