Skip to content

Commit

Permalink
Merge pull request #46 from Quaver/test-env
Browse files Browse the repository at this point in the history
Fix various bugs
  • Loading branch information
Swan authored Aug 6, 2024
2 parents 5c6a855 + 24234e8 commit 74e05ad
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
33 changes: 27 additions & 6 deletions handlers/ClientPong.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ func handleClientPong(user *sessions.User, packet *packets.ClientPong) {

user.SetLastPongTimestamp()

packetProcs := packet.ParseProcessList()
parsed := packet.Parse()

if packetProcs == nil || len(packetProcs) == 0 {
// webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, []string{"NO PROCESSES PROVIDED"})
// log.Printf("[%v - %v] Sent a Pong packet without any process list\n", user.Info.Id, user.Info.Username)
checkProcesses(user, parsed.Processes)
checkLibraries(user, parsed.Libraries)
}

func checkProcesses(user *sessions.User, processes []packets.Process) {
if processes == nil || len(processes) == 0 {
return
}

dbProcs, err := db.FetchProcesses()
dbProcesses, err := db.FetchProcesses()

if err != nil {
log.Printf("Failed to fetch process from database - %v\n", err)
return
}

detected := detectProcesses(dbProcs, packetProcs)
detected := detectProcesses(dbProcesses, processes)

if len(detected) == 0 {
user.SetLastDetectedProcesses([]string{})
Expand All @@ -44,11 +47,29 @@ func handleClientPong(user *sessions.User, packet *packets.ClientPong) {
}

user.SetLastDetectedProcesses(detected)

webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, detected)

log.Printf("[%v - #%v] Detected %v flagged processes \n", user.Info.Username, user.Info.Id, len(detected))
}

func checkLibraries(user *sessions.User, libraries []string) {
if libraries == nil || len(libraries) == 0 {
return
}

if slices.Equal(libraries, user.GetLastLibraries()) {
return
}

user.SetLastLibraries(libraries)

webhooks.SendAntiCheatLibraries(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(),
user.Info.AvatarUrl.String, libraries)

log.Printf("[%v - #%v] Detected %v libraries \n", user.Info.Username, user.Info.Id, len(libraries))
}

// Goes through both the db processes and packet processes and checks if any are found
func detectProcesses(dbProcesses []*db.Process, packetProcesses []packets.Process) []string {
detected := make([]string, 0)
Expand Down
6 changes: 0 additions & 6 deletions handlers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ func HandleLogin(conn net.Conn, r *http.Request) error {
return logFailedLogin(conn, err)
}

err = checkSteamAppOwnership(data.Id)

if err != nil {
return logFailedLogin(conn, err)
}

user, err := db.GetUserBySteamId(data.Id)

if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions packets/ClientPong.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

type ClientPong struct {
Packet
ProcessList string `json:"p"`
Data string `json:"p"`
}

type Processes struct {
type PongPacketData struct {
Processes []Process `json:"Processes"`
Libraries []string `json:"Libraries"`
}

type Process struct {
Expand All @@ -20,15 +21,15 @@ type Process struct {
FileName string `json:"FileName"`
}

func (p *ClientPong) ParseProcessList() []Process {
var data Processes
func (p *ClientPong) Parse() *PongPacketData {
var data PongPacketData

err := json.Unmarshal([]byte(p.ProcessList), &data)
err := json.Unmarshal([]byte(p.Data), &data)

if err != nil {
log.Println(err)
return nil
}

return data.Processes
return &data
}
19 changes: 19 additions & 0 deletions sessions/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type User struct {
// The last detected processes that were discovered on the user
lastDetectedProcesses []string

// Last libraries for the user
lastLibraries []string

// The current client status of the user
status *objects.ClientStatus

Expand Down Expand Up @@ -177,6 +180,22 @@ func (u *User) SetLastDetectedProcesses(processes []string) {
u.lastDetectedProcesses = processes
}

// GetLastLibraries Gets the user's last libraries
func (u *User) GetLastLibraries() []string {
u.Mutex.Lock()
defer u.Mutex.Unlock()

return u.lastLibraries
}

// SetLastLibraries Sets the user's last libraries
func (u *User) SetLastLibraries(libraries []string) {
u.Mutex.Lock()
defer u.Mutex.Unlock()

u.lastLibraries = libraries
}

// GetClientStatus Gets the current user client status
func (u *User) GetClientStatus() *objects.ClientStatus {
u.Mutex.Lock()
Expand Down
10 changes: 10 additions & 0 deletions webhooks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func SendAntiCheatProcessLog(username string, userId int, url string, icon strin
SendAntiCheat(username, userId, url, icon, "Detected Processes", formatted)
}

func SendAntiCheatLibraries(username string, userId int, url string, icon string, libraries []string) {
formatted := ""

for i, library := range libraries {
formatted += fmt.Sprintf("**%v. %v**\n", i+1, library)
}

SendAntiCheat(username, userId, url, icon, "Detected Libraries", formatted)
}

// SendChatMessage Sends a chat message webhook to Discord
func SendChatMessage(webhook webhook.Client, senderUsername string, senderProfileUrl string, senderAvatarUrl, receiverName string, message string) {
if webhook == nil {
Expand Down

0 comments on commit 74e05ad

Please sign in to comment.