-
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
Open
kunalpowar
wants to merge
11
commits into
kidoman:master
Choose a base branch
from
kunalpowar:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66cd0eb
added glog statements
kunalpowar 70b4039
added playerInfo functionality
kunalpowar 1148efd
refactor: use type casted readLong in readFloat
kunalpowar 0c75ff7
correcting typos
kunalpowar 57ee3d8
changes to a2sPlayerResponse
kunalpowar 682c6da
removing unwanted glogs
kunalpowar 3c00ff8
refactoring code
kunalpowar 15279ea
changed glogs to be consistent
kunalpowar 5baf94a
pulled out send/receive data into a method
kunalpowar 1b0cb1f
changes to as2PlayerRequest
kunalpowar 7e245b8
changed String() methods to be more efficient
kunalpowar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package steam | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
type A2SPlayerRequest struct { | ||
c ChallengeResponse | ||
} | ||
|
||
func (a A2SPlayerRequest) MarshalBinary() []byte { | ||
buf := new(bytes.Buffer) | ||
|
||
writeRequestPrefix(buf) | ||
writeByte(buf, 'U') | ||
buf.Write(a.c.GetChallange()) | ||
|
||
glog.V(2).Infof("steam: a2SPlayerRequest buffer: %v", buf.Bytes()) | ||
return buf.Bytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package steam | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
type Player struct { | ||
index byte | ||
name string | ||
score int32 | ||
duration float32 | ||
} | ||
|
||
type A2SPlayersResponse struct { | ||
playersCount byte | ||
players []Player | ||
} | ||
|
||
func (a *A2SPlayersResponse) UnMarshalBinary(data []byte) (err error) { | ||
glog.V(2).Infof("steam: unmarshalling binary for A2SPlayersResponse: %v", data) | ||
buf := bytes.NewBuffer(data) | ||
|
||
if header := readByte(buf); header != 0x44 { | ||
return errors.New("steam: invalid header in the a2splayersresponse") | ||
} | ||
|
||
a.playersCount = readByte(buf) | ||
a.players = make([]Player, a.playersCount) | ||
|
||
for i := 0; i < int(a.playersCount); i++ { | ||
p := &a.players[i] | ||
p.index = readByte(buf) | ||
p.name = readString(buf) | ||
p.score = readLong(buf) | ||
p.duration = readFloat(buf) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *A2SPlayersResponse) String() string { | ||
buf := new(bytes.Buffer) | ||
|
||
writeString(buf, fmt.Sprintf("players count: %v\n\n", a.playersCount)) | ||
for _, player := range a.players { | ||
writeString(buf, fmt.Sprintf("player index: %v\n", player.index)) | ||
writeString(buf, fmt.Sprintf("player name: %v\n", player.name)) | ||
writeString(buf, fmt.Sprintf("player score: %v\n", player.score)) | ||
writeString(buf, fmt.Sprintf("player duration: %v seconds\n\n", player.duration)) | ||
} | ||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package steam | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
type ChallengeRequest struct { | ||
} | ||
|
||
func (ChallengeRequest) MarshalBinary() []byte { | ||
buf := new(bytes.Buffer) | ||
|
||
writeRequestPrefix(buf) | ||
writeByte(buf, 'U') | ||
writeRequestPrefix(buf) | ||
|
||
glog.V(2).Infof("steam: challengeRequest buffer: %v", buf.Bytes()) | ||
return buf.Bytes() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
) | ||
|
||
type ChallengeResponse []byte | ||
|
||
func (c ChallengeResponse) GetChallange() (challenge []byte) { | ||
glog.V(2).Infof("steam: getting challenge from %v", c) | ||
|
||
return c[(len(c) - 4):] | ||
} | ||
|
||
func (c ChallengeResponse) String() string { | ||
buf := new(bytes.Buffer) | ||
|
||
writeString(buf, fmt.Sprint("challengeResponse: [")) | ||
for i := 0; i < len(c); i++ { | ||
writeString(buf, fmt.Sprintf("%x ", c[i])) | ||
} | ||
writeString(buf, fmt.Sprint("]")) | ||
|
||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is goimports run on this code?