-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Wiesmüller
committed
May 19, 2018
1 parent
7005a42
commit efb09e4
Showing
1,886 changed files
with
932,568 additions
and
461 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package protocol | ||
package battleye | ||
|
||
import ( | ||
"hash/crc32" | ||
|
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package battleye | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// Packet is the real data sent between server and client | ||
type Packet []byte | ||
|
||
// Verify if the packet is valid | ||
func (p *protocol) Verify(d Packet) error { | ||
_, err := stripHeader(d) | ||
if err != nil { | ||
return err | ||
} | ||
checksum, err := getChecksum(d) | ||
if err != nil { | ||
return err | ||
} | ||
match := verifyChecksum(d[6:], checksum) | ||
if !match { | ||
err = ErrInvalidChecksum | ||
return err | ||
} | ||
_, err = p.Sequence(d) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = p.Type(d) | ||
return nil | ||
} | ||
|
||
// Sequence extracts the seq number from a packet | ||
func (p *protocol) Sequence(d Packet) (Sequence, error) { | ||
if len(d) < 9 { | ||
return 0, ErrInvalidSizeNoSequence | ||
} | ||
return Sequence(d[8]), nil | ||
} | ||
|
||
// Type determines the kind of response from a packet | ||
func (p *protocol) Type(d Packet) (Type, error) { | ||
if len(d) < 8 { | ||
return 0, ErrInvalidSize | ||
} | ||
return Type(d[7]), nil | ||
} | ||
|
||
// Data returns the actual data inside the packet | ||
func (p *protocol) Data(d Packet) ([]byte, error) { | ||
data, err := stripHeader(d) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data, nil | ||
} | ||
|
||
// VerifyLogin returns nil on successful login | ||
// and a respective error on failed login | ||
func (p *protocol) VerifyLogin(d Packet) error { | ||
if len(d) != 9 { | ||
fmt.Println("Call:", d) | ||
return ErrInvalidLoginPacket | ||
} | ||
if match, err := verifyChecksumMatch(d); match == false || err != nil { | ||
return err | ||
} | ||
switch Type(d[8]) { | ||
case LoginOk: | ||
return nil | ||
case LoginFail: | ||
return ErrInvalidLogin | ||
} | ||
return errors.Wrap(ErrInvalidLoginPacket, "triggered default error") | ||
} | ||
|
||
// Multi checks whether a packet is part of a multiPacketResponse | ||
// Returns: packetCount, currentPacket and isSingle | ||
func (p *protocol) Multi(d Packet) (byte, byte, bool) { | ||
if len(d) < 3 { | ||
return 0, 0, true | ||
} | ||
if d[0] != 0x01 || d[2] != 0x00 { | ||
return 0, 0, true | ||
} | ||
return d[3], d[4], false | ||
} |
Oops, something went wrong.