-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PlayerInfo functionality #1
base: master
Are you sure you want to change the base?
Changes from 5 commits
66cd0eb
70b4039
1148efd
0c75ff7
57ee3d8
682c6da
3c00ff8
15279ea
5baf94a
1b0cb1f
7e245b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package steam | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
"bytes" | ||
) | ||
|
||
type A2SPlayerRequest struct { | ||
} | ||
|
||
func (A2SPlayerRequest) MarshalBinaryFromChallenge(c ChallengeResponse) ([]byte) { | ||
buf := new(bytes.Buffer) | ||
|
||
writeRequestPrefix(buf) | ||
writeByte(buf, 'U') | ||
buf.Write(c.GetChallangeNumber()) | ||
|
||
glog.V(2).Infof("a2SPlayerRequest buffer: %v", buf.Bytes()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all glog lines should have a steam: prefix please have a look at how it has been done so far |
||
return buf.Bytes() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package steam | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is goimports run on this code? |
||
"errors" | ||
"bytes" | ||
) | ||
|
||
type Player struct{ | ||
index byte | ||
name string | ||
score int32 | ||
duration float32 | ||
} | ||
|
||
type A2SPlayersResponse struct{ | ||
playersCount byte | ||
players []Player | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alignment problems. please run goimports |
||
} | ||
|
||
func (a *A2SPlayersResponse) UnMarshalBinary(data []byte) (err error) { | ||
glog.V(2).Infof("unmarshalling binary for A2SPlayersResponse: %v", data) | ||
buf := bytes.NewBuffer(data) | ||
|
||
if header := readByte(buf); header != 0x44{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting issues |
||
return errors.New("steam: invalid header in the a2splayersresponse") | ||
} | ||
|
||
a.playersCount = readByte(buf) | ||
glog.V(3).Infof("players count: %v", a.playersCount) | ||
a.players = make([]Player, a.playersCount) | ||
|
||
for i := 0; i < int(a.playersCount); i++ { | ||
p := &a.players[i] | ||
p.index = readByte(buf) | ||
glog.V(3).Infof("player index: %v", p.index) | ||
p.name = readString(buf) | ||
glog.V(3).Infof("player name: %v", p.name) | ||
p.score = readLong(buf) | ||
glog.V(3).Infof("player score: %v", p.score) | ||
p.duration = readFloat(buf) | ||
glog.V(3).Infof("player duration: %v", p.duration) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *A2SPlayersResponse) String() string{ | ||
str := fmt.Sprintf("players count: %v\n\n", a.playersCount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very bad performance wise as strings are immutable. please use a buffer |
||
|
||
for _, player := range a.players { | ||
str += fmt.Sprintf("player index: %v\n", player.index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have a look at fmt.Fprintf() |
||
str += fmt.Sprintf("player name: %v\n", player.name) | ||
str += fmt.Sprintf("player score: %v\n", player.score) | ||
str += fmt.Sprintf("player duration: %v seconds\n\n", player.duration) | ||
} | ||
|
||
return str | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline missing from EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package steam | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
"bytes" | ||
) | ||
|
||
type ChallengeRequest struct { | ||
} | ||
|
||
func (ChallengeRequest) MarshalBinary() ([]byte) { | ||
buf := new(bytes.Buffer) | ||
|
||
writeRequestPrefix(buf) | ||
writeByte(buf, 'U') | ||
writeRequestPrefix(buf) | ||
|
||
glog.V(2).Infof("challengeRequest buffer: %v", buf.Bytes()) | ||
return buf.Bytes() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package steam | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats with the file name this is not java!? |
||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
) | ||
|
||
type ChallengeResponse struct { | ||
data []byte | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could have been simply: type ChallengeResponse []byte |
||
} | ||
|
||
func (c *ChallengeResponse) GetChallangeNumber() (challenge []byte) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not java! |
||
glog.V(2).Infoln(c) | ||
|
||
return c.data[(len(c.data)-4):] | ||
} | ||
|
||
func (c *ChallengeResponse) String() string { | ||
str := fmt.Sprint("challengeResponse: [") | ||
for i := 0; i < len(c.data); i++ { | ||
str += fmt.Sprintf("%x ", c.data[i]) | ||
} | ||
str += fmt.Sprint("]") | ||
return str | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MarshalBinary is from http://tip.golang.org/pkg/encoding/#BinaryMarshaler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the A2SPlayerRequest should be instantiated with the ChallengeResponse, and not passed to this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the marshalBinary part. But Why should A2SPlayerRequest know Challenge Response. It is built using a challenge Response. The request itself need not have the challenge as a separate entity. In fact the first implementation had something like
type A2SPlayerRequest struct {
c ChallengeResponse
}