Skip to content

Commit 385380a

Browse files
author
Zbynek Novotny
committedDec 9, 2017
Thrown out remaining old (un)marshaling code from client.
Made use of proper JSON tags, although some code duplication has been introduced for similar data structures. I guess that is just the way things roll in Go.
1 parent 2c7e69e commit 385380a

17 files changed

+56
-832
lines changed
 

‎gameclient/client/join_match.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ func JoinMatch(c *http.Client, ps net.PlayerSession) error {
6868
// ongoing matches of all types and creates a mapping
6969
// between their ID's and their game types to make it
7070
// easier for the user to pick one. Since game type is
71-
// required on server's input, it
71+
// required on server's input, it is preferable to let
72+
// the player pick just the ID and add the game type
73+
// automatically
7274
func collectMatchIDsAndGameTypes(ml *match.Matchlist) map[match.Number]string {
7375
retval := make(map[match.Number]string)
7476
for _, m := range ml.DM {

‎gameclient/client/leaderboard/ctf.go

-49
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,3 @@ type CTFLeaderboardRecord struct {
1616
// CTFLeaderboard is a slice of CTF leaderboard records
1717
type CTFLeaderboard []CTFLeaderboardRecord
1818

19-
// UnmarshalCTFLeaderboard unmarshals a map of elements
20-
// into an instance of the CTFLeaderboardRecord
21-
/*func UnmarshalCTFLeaderboard(in []map[string]interface{}) (*CTFLeaderboard, error) {
22-
retval := CTFLeaderboard{}
23-
24-
for _, lbRecIf := range in {
25-
lbRec, err := unmarshalCTFLeaderboardRecord(lbRecIf)
26-
if err != nil {
27-
return nil, err
28-
}
29-
retval = append(retval, lbRec)
30-
}
31-
32-
return &retval, nil
33-
}
34-
35-
// unmarshalCTFLeaderboardRecord unmarshals the contents
36-
// of the input map into an instance of CTFLeaderboardRecord
37-
// structure and returns it
38-
func unmarshalCTFLeaderboardRecord(in map[string]interface{}) (CTFLeaderboardRecord, error) {
39-
p, err := player.FromMap(in)
40-
if err != nil {
41-
return CTFLeaderboardRecord{}, err
42-
}
43-
44-
var kills, deaths, captures uint
45-
kills, err = shared.KillCountFromMap(in)
46-
if err != nil {
47-
return CTFLeaderboardRecord{}, err
48-
}
49-
50-
deaths, err = shared.DeathCountFromMap(in)
51-
if err != nil {
52-
return CTFLeaderboardRecord{}, err
53-
}
54-
55-
captures, err = shared.CaptureCountFromMap(in)
56-
if err != nil {
57-
return CTFLeaderboardRecord{}, err
58-
}
59-
60-
return CTFLeaderboardRecord{
61-
Player: p,
62-
Kills: kills,
63-
Deaths: deaths,
64-
Captures: captures,
65-
}, nil
66-
}
67-
*/

‎gameclient/client/leaderboard/dm.go

-44
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,3 @@ type DMLeaderboardRecord struct {
1515

1616
// DMLeaderboard is a slice of DM leaderboard records
1717
type DMLeaderboard []DMLeaderboardRecord
18-
19-
// UnmarshalDMLeaderboard unmarshals a map of elements
20-
// into an instance of the DMLeaderboardRecord
21-
/*func UnmarshalDMLeaderboard(in []map[string]interface{}) (*DMLeaderboard, error) {
22-
retval := DMLeaderboard{}
23-
24-
for _, lbRecIf := range in {
25-
lbRec, err := unmarshalDMLeaderboardRecord(lbRecIf)
26-
if err != nil {
27-
return nil, err
28-
}
29-
retval = append(retval, lbRec)
30-
}
31-
32-
return &retval, nil
33-
}
34-
35-
// unmarshalDMLeaderboardRecord unmarshals the contents
36-
// of the input map into an instance of DMLeaderboardRecord
37-
// structure and returns it
38-
func unmarshalDMLeaderboardRecord(in map[string]interface{}) (DMLeaderboardRecord, error) {
39-
p, err := player.FromMap(in)
40-
if err != nil {
41-
return DMLeaderboardRecord{}, err
42-
}
43-
44-
var kills, deaths uint
45-
kills, err = shared.KillCountFromMap(in)
46-
if err != nil {
47-
return DMLeaderboardRecord{}, err
48-
}
49-
50-
deaths, err = shared.DeathCountFromMap(in)
51-
if err != nil {
52-
return DMLeaderboardRecord{}, err
53-
}
54-
55-
return DMLeaderboardRecord{
56-
Player: p,
57-
Kills: kills,
58-
Deaths: deaths,
59-
}, nil
60-
}
61-
*/

‎gameclient/client/leaderboard/duel.go

-49
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,3 @@ type DuelLeaderboardRecord struct {
1414
// DuelLeaderboard is a slice of Duel-type leaderboard records
1515
type DuelLeaderboard []DuelLeaderboardRecord
1616

17-
// UnmarshalDuelLeaderboard unmarshals a map of elements
18-
// into an instance of the DuelLeaderboardRecord
19-
/*func UnmarshalDuelLeaderboard(in []map[string]interface{}) (*DuelLeaderboard, error) {
20-
retval := DuelLeaderboard{}
21-
22-
for _, lbRecIf := range in {
23-
lbRec, err := unmarshalDuelLeaderboardRecord(lbRecIf)
24-
if err != nil {
25-
return nil, err
26-
}
27-
retval = append(retval, lbRec)
28-
}
29-
30-
return &retval, nil
31-
}
32-
33-
// unmarshalDuelLeaderboardRecord unmarshals the contents
34-
// of the input map into an instance of DuelLeaderboardRecord
35-
// structure and returns it
36-
func unmarshalDuelLeaderboardRecord(in map[string]interface{}) (DuelLeaderboardRecord, error) {
37-
p, err := player.FromMap(in)
38-
if err != nil {
39-
return DuelLeaderboardRecord{}, err
40-
}
41-
42-
var kills, deaths, wins uint
43-
kills, err = shared.KillCountFromMap(in)
44-
if err != nil {
45-
return DuelLeaderboardRecord{}, err
46-
}
47-
48-
deaths, err = shared.DeathCountFromMap(in)
49-
if err != nil {
50-
return DuelLeaderboardRecord{}, err
51-
}
52-
53-
wins, err = shared.WinCountFromMap(in)
54-
if err != nil {
55-
return DuelLeaderboardRecord{}, err
56-
}
57-
58-
return DuelLeaderboardRecord{
59-
Player: p,
60-
Kills: kills,
61-
Deaths: deaths,
62-
Wins: wins,
63-
}, nil
64-
}
65-
*/

‎gameclient/client/leaderboard/lms.go

-50
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,3 @@ type LMSLeaderboardRecord struct {
1515

1616
// LMSLeaderboard is a slice of LMS-type leaderboard records
1717
type LMSLeaderboard []LMSLeaderboardRecord
18-
19-
// UnmarshalLMSLeaderboard unmarshals a map of elements
20-
// into an instance of the LMSLeaderboardRecord
21-
/*func UnmarshalLMSLeaderboard(in []map[string]interface{}) (*LMSLeaderboard, error) {
22-
retval := LMSLeaderboard{}
23-
24-
for _, lbRecIf := range in {
25-
lbRec, err := unmarshalLMSLeaderboardRecord(lbRecIf)
26-
if err != nil {
27-
return nil, err
28-
}
29-
retval = append(retval, lbRec)
30-
}
31-
32-
return &retval, nil
33-
}
34-
35-
// unmarshalLMSLeaderboardRecord unmarshals the contents
36-
// of the input map into an instance of LMSLeaderboardRecord
37-
// structure and returns it
38-
func unmarshalLMSLeaderboardRecord(in map[string]interface{}) (LMSLeaderboardRecord, error) {
39-
p, err := player.FromMap(in)
40-
if err != nil {
41-
return LMSLeaderboardRecord{}, err
42-
}
43-
44-
var kills, deaths, wins uint
45-
kills, err = shared.KillCountFromMap(in)
46-
if err != nil {
47-
return LMSLeaderboardRecord{}, err
48-
}
49-
50-
deaths, err = shared.DeathCountFromMap(in)
51-
if err != nil {
52-
return LMSLeaderboardRecord{}, err
53-
}
54-
55-
wins, err = shared.WinCountFromMap(in)
56-
if err != nil {
57-
return LMSLeaderboardRecord{}, err
58-
}
59-
60-
return LMSLeaderboardRecord{
61-
Player: p,
62-
Kills: kills,
63-
Deaths: deaths,
64-
Wins: wins,
65-
}, nil
66-
}
67-
*/

‎gameclient/client/list_match.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ import (
1111
// ListMatches queries the server using player's credentials
1212
// and prints out to stdout the list of active matches
1313
func ListMatches(c *http.Client, ps net.PlayerSession) (*match.Matchlist, error) {
14-
var mu match.MatchlistUnmarshaler
14+
var m match.Matchlist
1515

16-
if err := net.Get(c, "/matches", ps, &mu); err != nil {
16+
if err := net.Get(c, "/matches", ps, &m); err != nil {
1717
return nil, err
1818
}
1919

20-
listDMMatches(&mu.Matchlist.DM)
21-
listCTFMatches(&mu.Matchlist.CTF)
22-
listLMSMatches(&mu.Matchlist.LMS)
23-
listDuelMatches(&mu.Matchlist.Duel)
24-
return &mu.Matchlist, nil
20+
listDMMatches(&m.DM)
21+
listCTFMatches(&m.CTF)
22+
listLMSMatches(&m.LMS)
23+
listDuelMatches(&m.Duel)
24+
return &m, nil
2525
}
2626

2727
func listDMMatches(ml *match.DMMatches) {

‎gameclient/client/match/ctf.go

-71
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,3 @@ type CTFMatch struct {
2626

2727
// CTFMatches defines a slice of CTF-type matches
2828
type CTFMatches []*CTFMatch
29-
30-
// unmarshalCTFMatch unmarshals the contents of the
31-
// input map into an instance of CTFMatch
32-
/*func unmarshalCTFMatch(in map[string]interface{}) (*CTFMatch, error) {
33-
mID, err := IDFromMap(in)
34-
if err != nil {
35-
return nil, err
36-
}
37-
38-
var playerRanks map[string]interface{}
39-
playerRanks, err = shared.RanksFromMap(in)
40-
if err != nil {
41-
return nil, err
42-
}
43-
44-
var ranks CTFPlayerRanks
45-
for _, r := range playerRanks {
46-
rm, ok := r.(map[string]interface{})
47-
if !ok {
48-
return nil, errors.New("Rank record not a map of values")
49-
}
50-
51-
rank, err := unmarshalCTFRankRecord(rm)
52-
if err != nil {
53-
return nil, err
54-
}
55-
56-
ranks = append(ranks, rank)
57-
}
58-
59-
return &CTFMatch{
60-
Number: Number(mID),
61-
Ranks: ranks,
62-
}, nil
63-
}
64-
65-
// unmarshalCTFRankRecord unmarshals the contents
66-
// of the input map into an instance of
67-
// the CTFPlayerRank structure
68-
func unmarshalCTFRankRecord(in map[string]interface{}) (CTFPlayerRank, error) {
69-
player, err := player.FromMap(in)
70-
if err != nil {
71-
return CTFPlayerRank{}, err
72-
}
73-
74-
var kills uint
75-
kills, err = shared.KillCountFromMap(in)
76-
if err != nil {
77-
return CTFPlayerRank{}, err
78-
}
79-
80-
var deaths uint
81-
deaths, err = shared.DeathCountFromMap(in)
82-
if err != nil {
83-
return CTFPlayerRank{}, err
84-
}
85-
86-
var captures uint
87-
captures, err = shared.CaptureCountFromMap(in)
88-
if err != nil {
89-
return CTFPlayerRank{}, err
90-
}
91-
92-
return CTFPlayerRank{
93-
Player: player,
94-
Kills: kills,
95-
Deaths: deaths,
96-
Captures: captures,
97-
}, nil
98-
}
99-
*/

‎gameclient/client/match/dm.go

-64
Original file line numberDiff line numberDiff line change
@@ -24,67 +24,3 @@ type DMMatch struct {
2424

2525
// DMMatches defines a slice of DeathMatch-type matches
2626
type DMMatches []*DMMatch
27-
28-
// unmarshalDMMatch unmarshals the contents of the
29-
// input map into an instance of DMMatch
30-
/*func unmarshalDMMatch(in map[string]interface{}) (*DMMatch, error) {
31-
mID, err := IDFromMap(in)
32-
if err != nil {
33-
return nil, err
34-
}
35-
36-
var playerRanks map[string]interface{}
37-
playerRanks, err = shared.RanksFromMap(in)
38-
if err != nil {
39-
return nil, err
40-
}
41-
42-
var ranks DMPlayerRanks
43-
for _, r := range playerRanks {
44-
rm, ok := r.(map[string]interface{})
45-
if !ok {
46-
return nil, errors.New("Rank record not a map of values")
47-
}
48-
49-
rank, err := unmarshalDMRankRecord(rm)
50-
if err != nil {
51-
return nil, err
52-
}
53-
54-
ranks = append(ranks, rank)
55-
}
56-
57-
return &DMMatch{
58-
Number: Number(mID),
59-
Ranks: ranks,
60-
}, nil
61-
}
62-
63-
// unmarshalDMRankRecord unmarshals the contents
64-
// of the input map into an instance of
65-
// the DMPlayerRank structure
66-
func unmarshalDMRankRecord(in map[string]interface{}) (DMPlayerRank, error) {
67-
player, err := player.FromMap(in)
68-
if err != nil {
69-
return DMPlayerRank{}, err
70-
}
71-
72-
var kills uint
73-
kills, err = shared.KillCountFromMap(in)
74-
if err != nil {
75-
return DMPlayerRank{}, err
76-
}
77-
78-
var deaths uint
79-
deaths, err = shared.DeathCountFromMap(in)
80-
if err != nil {
81-
return DMPlayerRank{}, err
82-
}
83-
84-
return DMPlayerRank{
85-
Player: player,
86-
Kills: kills,
87-
Deaths: deaths,
88-
}, nil
89-
}
90-
*/

‎gameclient/client/match/duel.go

-64
Original file line numberDiff line numberDiff line change
@@ -25,67 +25,3 @@ type DuelMatch struct {
2525

2626
// DuelMatches defines a slice of Duel-type matches
2727
type DuelMatches []*DuelMatch
28-
29-
// unmarshalDuelMatch unmarshals the contents of the
30-
// input map into an instance of DuelMatch
31-
/*func unmarshalDuelMatch(in map[string]interface{}) (*DuelMatch, error) {
32-
mID, err := IDFromMap(in)
33-
if err != nil {
34-
return nil, err
35-
}
36-
37-
var playerRanks map[string]interface{}
38-
playerRanks, err = shared.RanksFromMap(in)
39-
if err != nil {
40-
return nil, err
41-
}
42-
43-
var ranks DuelPlayerRanks
44-
for _, r := range playerRanks {
45-
rm, ok := r.(map[string]interface{})
46-
if !ok {
47-
return nil, errors.New("Rank record not a map of values")
48-
}
49-
50-
rank, err := unmarshalDuelRankRecord(rm)
51-
if err != nil {
52-
return nil, err
53-
}
54-
55-
ranks = append(ranks, rank)
56-
}
57-
58-
return &DuelMatch{
59-
Number: Number(mID),
60-
Ranks: ranks,
61-
}, nil
62-
}
63-
64-
// unmarshalDuelRankRecord unmarshals the contents
65-
// of the input map into an instance of
66-
// the DuelPlayerRank structure
67-
func unmarshalDuelRankRecord(in map[string]interface{}) (DuelPlayerRank, error) {
68-
player, err := player.FromMap(in)
69-
if err != nil {
70-
return DuelPlayerRank{}, err
71-
}
72-
73-
var kills uint
74-
kills, err = shared.KillCountFromMap(in)
75-
if err != nil {
76-
return DuelPlayerRank{}, err
77-
}
78-
79-
var deaths uint
80-
deaths, err = shared.DeathCountFromMap(in)
81-
if err != nil {
82-
return DuelPlayerRank{}, err
83-
}
84-
85-
return DuelPlayerRank{
86-
Player: player,
87-
Kills: kills,
88-
Deaths: deaths,
89-
}, nil
90-
}
91-
*/

‎gameclient/client/match/lms.go

-64
Original file line numberDiff line numberDiff line change
@@ -25,67 +25,3 @@ type LMSMatch struct {
2525

2626
// LMSMatches defines a slice of LMS-type matches
2727
type LMSMatches []*LMSMatch
28-
29-
// unmarshalLMSMatch unmarshals the contents of the
30-
// input map into an instance of LMSMatch
31-
/*func unmarshalLMSMatch(in map[string]interface{}) (*LMSMatch, error) {
32-
mID, err := IDFromMap(in)
33-
if err != nil {
34-
return nil, err
35-
}
36-
37-
var playerRanks map[string]interface{}
38-
playerRanks, err = shared.RanksFromMap(in)
39-
if err != nil {
40-
return nil, err
41-
}
42-
43-
var ranks LMSPlayerRanks
44-
for _, r := range playerRanks {
45-
rm, ok := r.(map[string]interface{})
46-
if !ok {
47-
return nil, errors.New("Rank record not a map of values")
48-
}
49-
50-
rank, err := unmarshalLMSRankRecord(rm)
51-
if err != nil {
52-
return nil, err
53-
}
54-
55-
ranks = append(ranks, rank)
56-
}
57-
58-
return &LMSMatch{
59-
Number: Number(mID),
60-
Ranks: ranks,
61-
}, nil
62-
}
63-
64-
// unmarshalLMSRankRecord unmarshals the contents
65-
// of the input map into an instance of
66-
// the LMSPlayerRank structure
67-
func unmarshalLMSRankRecord(in map[string]interface{}) (LMSPlayerRank, error) {
68-
player, err := player.FromMap(in)
69-
if err != nil {
70-
return LMSPlayerRank{}, err
71-
}
72-
73-
var kills uint
74-
kills, err = shared.KillCountFromMap(in)
75-
if err != nil {
76-
return LMSPlayerRank{}, err
77-
}
78-
79-
var deaths uint
80-
deaths, err = shared.DeathCountFromMap(in)
81-
if err != nil {
82-
return LMSPlayerRank{}, err
83-
}
84-
85-
return LMSPlayerRank{
86-
Player: player,
87-
Kills: kills,
88-
Deaths: deaths,
89-
}, nil
90-
}
91-
*/

‎gameclient/client/match/match.go

-20
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,3 @@ type ID struct {
1414
Number Number `json:"id"`
1515
Type string `json:"type"`
1616
}
17-
18-
// IDFromMap retrieves an element with key "match_id"
19-
// from the map in the argument and verifies that the
20-
// element's type is an uint64.
21-
/*func IDFromMap(m map[string]interface{}) (uint64, error) {
22-
if v, ok := m["match_id"]; !ok {
23-
return 0, errors.New("Match does not seem to have 'match_id' key")
24-
} else if IDNum, ok := v.(json.Number); !ok {
25-
return 0, errors.New("Match ID does not seem to be a number, but " + reflect.TypeOf(v).Name())
26-
} else {
27-
// I have to use ParseUint, because overflows may happen
28-
// when Number.Int64() is called on an unsigned value
29-
// sent by the server
30-
ID, err := strconv.ParseUint(IDNum.String(), 10, 64)
31-
if err != nil {
32-
return 0, err
33-
}
34-
return ID, nil
35-
}
36-
}*/

‎gameclient/client/match/matchlist.go

-210
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package match
22

3-
import (
4-
"encoding/json"
5-
)
6-
73
// Matchlist defines a structure that holds
84
// lists of existing matches for all game types
95
type Matchlist struct {
@@ -12,209 +8,3 @@ type Matchlist struct {
128
LMS LMSMatches `json:"lms"`
139
Duel DuelMatches `json:"duel"`
1410
}
15-
16-
// MatchlistUnmarshaler unmarshals the contents
17-
// of the Matchlist structure from JSON byte slice
18-
type MatchlistUnmarshaler struct {
19-
Matchlist Matchlist
20-
}
21-
22-
// UnmarshalJSON unmarshals the contents of a server's
23-
// response into the internal structure of match lists
24-
func (m *MatchlistUnmarshaler) UnmarshalJSON(in []byte) error {
25-
return json.Unmarshal(in, &m.Matchlist)
26-
// Read opening curly brace
27-
/* var t json.Token
28-
var err error
29-
if t, err = d.Token(); err != nil {
30-
return err
31-
}
32-
33-
for d.More() {
34-
var gt string
35-
var ok bool
36-
37-
// Get the game type identifier
38-
t, err = d.Token()
39-
gt, ok = t.(string)
40-
if !ok {
41-
return errors.New("Token not a string (game type)")
42-
}
43-
fmt.Printf("Processing match list for type %v\n", gt)
44-
45-
if err = d.Decode(&gt); err != nil {
46-
fmt.Println("Failed to read game type identifier")
47-
return err
48-
}
49-
50-
switch gt {
51-
case DeathMatch:
52-
err = m.unmarshalDMMatchlist(d)
53-
case CaptureTheFlag:
54-
err = m.unmarshalCTFMatchlist(d)
55-
case LastManStanding:
56-
err = m.unmarshalLMSMatchlist(d)
57-
case Duel:
58-
err = m.unmarshalDuelMatchlist(d)
59-
}
60-
61-
if err != nil {
62-
return err
63-
}
64-
}
65-
66-
return nil
67-
*/
68-
}
69-
70-
/*
71-
func (m *Matchlist) unmarshalDMMatchlist(d *json.Decoder) error {
72-
matches := make(DMMatches, 0, 5)
73-
if err := d.Decode(&matches); err != nil {
74-
return err
75-
}
76-
77-
m.DM = matches
78-
return nil
79-
}
80-
81-
func (m *Matchlist) unmarshalCTFMatchlist(d *json.Decoder) error {
82-
matches := make(CTFMatches, 0, 5)
83-
if err := d.Decode(&matches); err != nil {
84-
return err
85-
}
86-
87-
m.CTF = matches
88-
return nil
89-
}
90-
91-
func (m *Matchlist) unmarshalLMSMatchlist(d *json.Decoder) error {
92-
matches := make(LMSMatches, 0, 5)
93-
if err := d.Decode(&matches); err != nil {
94-
return err
95-
}
96-
97-
m.LMS = matches
98-
return nil
99-
}
100-
101-
func (m *Matchlist) unmarshalDuelMatchlist(d *json.Decoder) error {
102-
matches := make(DuelMatches, 0, 5)
103-
if err := d.Decode(&matches); err != nil {
104-
return err
105-
}
106-
107-
m.Duel = matches
108-
return nil
109-
}
110-
111-
/*
112-
// UnmarshalJSON unmarshals input byteslice into
113-
// a map structure, from which individual match
114-
// type instances are synthesized
115-
func (m *Matchlist) UnmarshalJSON(in []byte) error {
116-
// TODO Maybe I should do piecemeal unmarshaling
117-
// That way I should be able to leave the unmarshaling
118-
// to the sub-structures themselves.
119-
inMap := make(map[string]interface{})
120-
err := shared.DecodeJSON(in, &inMap)
121-
if err != nil {
122-
return err
123-
}
124-
125-
for k, v := range inMap {
126-
// fmt.Printf("Key-value: K: %v, V: %v\n", k, v)
127-
if reflect.TypeOf(v).Kind() == reflect.Slice && len(v.([]interface{})) == 0 {
128-
continue
129-
}
130-
131-
// fmt.Println("Type of non-empty v:", reflect.TypeOf(v))
132-
vMapSlice, ok := v.([]interface{})
133-
if !ok {
134-
return errors.New("Item in game type matchlist not a slice of maps")
135-
}
136-
137-
switch k {
138-
case DeathMatch:
139-
err = m.unmarshalDMMatches(vMapSlice)
140-
case CaptureTheFlag:
141-
err = m.unmarshalCTFMatches(vMapSlice)
142-
case LastManStanding:
143-
err = m.unmarshalLMSMatches(vMapSlice)
144-
case Duel:
145-
err = m.unmarshalDuelMatches(vMapSlice)
146-
}
147-
148-
if err != nil {
149-
return err
150-
}
151-
}
152-
153-
return nil
154-
}
155-
156-
157-
func (m *Matchlist) unmarshalDMMatches(in []interface{}) error {
158-
for _, mMapIf := range in {
159-
mMap, ok := mMapIf.(map[string]interface{})
160-
if !ok {
161-
return errors.New("Item in slice not a map of values")
162-
}
163-
164-
match, err := unmarshalDMMatch(mMap)
165-
if err != nil {
166-
return err
167-
}
168-
m.DM = append(m.DM, match)
169-
}
170-
return nil
171-
}
172-
173-
func (m *Matchlist) unmarshalCTFMatches(in []interface{}) error {
174-
for _, mMapIf := range in {
175-
mMap, ok := mMapIf.(map[string]interface{})
176-
if !ok {
177-
return errors.New("Item in slice not a map of values")
178-
}
179-
180-
match, err := unmarshalCTFMatch(mMap)
181-
if err != nil {
182-
return err
183-
}
184-
m.CTF = append(m.CTF, match)
185-
}
186-
return nil
187-
}
188-
189-
func (m *Matchlist) unmarshalLMSMatches(in []interface{}) error {
190-
for _, mMapIf := range in {
191-
mMap, ok := mMapIf.(map[string]interface{})
192-
if !ok {
193-
return errors.New("Item in slice not a map of values")
194-
}
195-
196-
match, err := unmarshalLMSMatch(mMap)
197-
if err != nil {
198-
return err
199-
}
200-
m.LMS = append(m.LMS, match)
201-
}
202-
return nil
203-
}
204-
205-
func (m *Matchlist) unmarshalDuelMatches(in []interface{}) error {
206-
for _, mMapIf := range in {
207-
mMap, ok := mMapIf.(map[string]interface{})
208-
if !ok {
209-
return errors.New("Item in slice not a map of values")
210-
}
211-
212-
match, err := unmarshalDuelMatch(mMap)
213-
if err != nil {
214-
return err
215-
}
216-
m.Duel = append(m.Duel, match)
217-
}
218-
return nil
219-
}
220-
*/

‎gameclient/client/net/restfunctions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package net
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"errors"
67
"io/ioutil"
78
"net/http"
89

910
"github.com/mrclayman/rest-and-go/gameclient/client/config"
10-
"github.com/mrclayman/rest-and-go/gameclient/client/shared"
1111
)
1212

1313
func processResponse(resp *http.Response, out interface{}) error {
@@ -23,7 +23,7 @@ func processResponse(resp *http.Response, out interface{}) error {
2323
return errors.New("Unexpected response content type: " + ct)
2424
}
2525

26-
return shared.DecodeJSON(respData, out)
26+
return json.Unmarshal(respData, out)
2727
}
2828

2929
// Post sends a POST request to the server, then parses

‎gameclient/client/play_match.go

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"net/http"
67

@@ -35,12 +36,54 @@ func getUserAction() uint16 {
3536
return choice
3637
}
3738

39+
func printDMPlayerList(data []byte) {
40+
var m match.DMMatch
41+
if err := json.Unmarshal(data, &m); err != nil {
42+
fmt.Println(err.Error())
43+
} else {
44+
printDMMatch(&m)
45+
}
46+
}
47+
48+
func printCTFPlayerList(data []byte) {
49+
var m match.CTFMatch
50+
if err := json.Unmarshal(data, &m); err != nil {
51+
fmt.Println(err.Error())
52+
} else {
53+
printCTFMatch(&m)
54+
}
55+
}
56+
57+
func printLMSPlayerList(data []byte) {
58+
var m match.LMSMatch
59+
if err := json.Unmarshal(data, &m); err != nil {
60+
fmt.Println(err.Error())
61+
} else {
62+
printLMSMatch(&m)
63+
}
64+
}
65+
66+
func printDuelPlayerList(data []byte) {
67+
var m match.DuelMatch
68+
if err := json.Unmarshal(data, &m); err != nil {
69+
fmt.Println(err.Error())
70+
} else {
71+
printDuelMatch(&m)
72+
}
73+
}
74+
3875
func printPlayerList(gt string, data []byte) {
3976
fmt.Printf("---------------\nMatch type: %v\n---------------\n", gt)
4077

4178
switch gt {
4279
case match.DeathMatch:
43-
80+
printDMPlayerList(data)
81+
case match.CaptureTheFlag:
82+
printCTFPlayerList(data)
83+
case match.LastManStanding:
84+
printLMSPlayerList(data)
85+
case match.Duel:
86+
printDuelPlayerList(data)
4487
}
4588
}
4689

‎gameclient/client/player/functions.go

-32
This file was deleted.

‎gameclient/client/shared/decodejson.go

-16
This file was deleted.

‎gameclient/client/shared/unmarshal.go

-88
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.