-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
135 lines (129 loc) · 3.53 KB
/
Copy pathmain.go
File metadata and controls
135 lines (129 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import(
"github.com/TrickyGameJolt/GoGameJolt" // Please note, this comes in as package gj and not as package GoGameJolt
"bufio"
"strings"
"fmt"
"os"
"time"
)
const gameid="336383"
const gamekey="e8a4b4be97e11da42183a5751cef877b"
var username=""
var token=""
func MyTrim(a string) string{
return strings.Trim(a," \t\n\r\x00")
}
func RawInput(q string) string{
buf := bufio.NewReader(os.Stdin)
fmt.Print(q)
sentence, err := buf.ReadBytes('\n')
if err != nil {
fmt.Println(err)
return ""
} else {
//fmt.Println("*"+string(sentence)+"*")
return MyTrim(string(sentence))
}
}
func main(){
// Authentication Test
username=RawInput("User Name: ")
token =RawInput(" Token: ")
user:=gj.Login(gameid,gamekey,username,token)
//fmt.Println("Logged in = ",user.LoggedIn)
if !user.LoggedIn { os.Exit(0) }
for{
fmt.Println("1 = Test session")
fmt.Println("2 = Test achievement/trophy")
fmt.Println("3 = Test user score")
fmt.Println("4 = Test guest score")
fmt.Println("5 = Test general score fetching")
fmt.Println("6 = Test user score fetching")
fmt.Println("Q = Quit")
kz:=RawInput("Make your choice: ")
if kz=="q" || kz=="Q" { break }
switch kz{
case "1":
fmt.Println("Starting session")
user.StartSession()
fmt.Println("50 pings")
for i:=0;i<50;i++{fmt.Print(".")}
fmt.Print("\r")
for i:=0;i<50;i++{
user.Ping()
fmt.Print("o")
time.Sleep(1100)
}
fmt.Println("\nClosing session")
user.CloseSession()
fmt.Println("\n\n")
case "2":
trophies:=[]string{"Bronze","Silver","Gold","Platinum"}
ids:=[]string{"92488","92489","92490","92491"}
nm:=[]string{"1","2","3","4"}
fmt.Println("Test Trophies")
for i,tn := range trophies{ fmt.Println(i+1,"=",tn) }
tkz:=RawInput("What shall I test? ")
for i:=0;i<len(nm);i++{
if nm[i]==tkz {
if user.AwardTrophy(ids[i]){
fmt.Println(trophies[i]+" awarded!")
} else {
fmt.Println(trophies[i]+" failed!")
}
}
}
fmt.Println();
case "3":
timestamp := int32(time.Now().Unix())
sts:=fmt.Sprintf("%d",timestamp)
if user.SubmitScore(sts+" unix time",sts,"341872"){
fmt.Println("Score ",timestamp," succesfully submitted")
} else {
fmt.Println("Too bad. I could not submit ",timestamp)
}
case "4":
timestamp := int32(time.Now().Unix())
sts:=fmt.Sprintf("%d",timestamp)
guest:=fmt.Sprintf("Guest %x",timestamp)
if gj.SubmitGuestScore(guest,gameid,gamekey,sts+" unix time",sts,"341872"){
fmt.Println("Score ",timestamp," succesfully submitted to a guest")
} else {
fmt.Println("Too bad. I could not submit ",timestamp)
}
case "5":
a:=gj.FetchScore(gameid,"","341872",gamekey)
if a["success"]=="false" {
fmt.Println("FAILED!")
} else {
_,ok:=a["score"]
i:=0
for ok {
is:=""
if i>0 {is=fmt.Sprintf("%d",i)}
fmt.Println(i+1,a["score"+is],"\tscored by user: ",a["user"+is],"\tscored by guest:",a["guest"+is])
i++
_,ok=a[fmt.Sprintf("score%d",i)]
}
}
case "6":
a:=user.FetchScore("","341872")
if a["success"]=="false" {
fmt.Println("FAILED!")
} else {
_,ok:=a["score"]
i:=0
for ok {
is:=""
if i>0 {is=fmt.Sprintf("%d",i)}
fmt.Println(i+1,a["score"+is],"\tscored by user: ",a["user"+is],"\tscored by guest:",a["guest"+is])
i++
_,ok=a[fmt.Sprintf("score%d",i)]
}
}
default:
fmt.Println("I don't understand. Please try again!")
}
}
}