Skip to content

Commit 74e05ad

Browse files
authored
Merge pull request #46 from Quaver/test-env
Fix various bugs
2 parents 5c6a855 + 24234e8 commit 74e05ad

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

handlers/ClientPong.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ func handleClientPong(user *sessions.User, packet *packets.ClientPong) {
1717

1818
user.SetLastPongTimestamp()
1919

20-
packetProcs := packet.ParseProcessList()
20+
parsed := packet.Parse()
2121

22-
if packetProcs == nil || len(packetProcs) == 0 {
23-
// webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, []string{"NO PROCESSES PROVIDED"})
24-
// log.Printf("[%v - %v] Sent a Pong packet without any process list\n", user.Info.Id, user.Info.Username)
22+
checkProcesses(user, parsed.Processes)
23+
checkLibraries(user, parsed.Libraries)
24+
}
25+
26+
func checkProcesses(user *sessions.User, processes []packets.Process) {
27+
if processes == nil || len(processes) == 0 {
2528
return
2629
}
2730

28-
dbProcs, err := db.FetchProcesses()
31+
dbProcesses, err := db.FetchProcesses()
2932

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

35-
detected := detectProcesses(dbProcs, packetProcs)
38+
detected := detectProcesses(dbProcesses, processes)
3639

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

4649
user.SetLastDetectedProcesses(detected)
50+
4751
webhooks.SendAntiCheatProcessLog(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(), user.Info.AvatarUrl.String, detected)
4852

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

56+
func checkLibraries(user *sessions.User, libraries []string) {
57+
if libraries == nil || len(libraries) == 0 {
58+
return
59+
}
60+
61+
if slices.Equal(libraries, user.GetLastLibraries()) {
62+
return
63+
}
64+
65+
user.SetLastLibraries(libraries)
66+
67+
webhooks.SendAntiCheatLibraries(user.Info.Username, user.Info.Id, user.Info.GetProfileUrl(),
68+
user.Info.AvatarUrl.String, libraries)
69+
70+
log.Printf("[%v - #%v] Detected %v libraries \n", user.Info.Username, user.Info.Id, len(libraries))
71+
}
72+
5273
// Goes through both the db processes and packet processes and checks if any are found
5374
func detectProcesses(dbProcesses []*db.Process, packetProcesses []packets.Process) []string {
5475
detected := make([]string, 0)

handlers/login.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ func HandleLogin(conn net.Conn, r *http.Request) error {
5454
return logFailedLogin(conn, err)
5555
}
5656

57-
err = checkSteamAppOwnership(data.Id)
58-
59-
if err != nil {
60-
return logFailedLogin(conn, err)
61-
}
62-
6357
user, err := db.GetUserBySteamId(data.Id)
6458

6559
if err != nil {

packets/ClientPong.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
type ClientPong struct {
99
Packet
10-
ProcessList string `json:"p"`
10+
Data string `json:"p"`
1111
}
1212

13-
type Processes struct {
13+
type PongPacketData struct {
1414
Processes []Process `json:"Processes"`
15+
Libraries []string `json:"Libraries"`
1516
}
1617

1718
type Process struct {
@@ -20,15 +21,15 @@ type Process struct {
2021
FileName string `json:"FileName"`
2122
}
2223

23-
func (p *ClientPong) ParseProcessList() []Process {
24-
var data Processes
24+
func (p *ClientPong) Parse() *PongPacketData {
25+
var data PongPacketData
2526

26-
err := json.Unmarshal([]byte(p.ProcessList), &data)
27+
err := json.Unmarshal([]byte(p.Data), &data)
2728

2829
if err != nil {
2930
log.Println(err)
3031
return nil
3132
}
3233

33-
return data.Processes
34+
return &data
3435
}

sessions/user.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type User struct {
4040
// The last detected processes that were discovered on the user
4141
lastDetectedProcesses []string
4242

43+
// Last libraries for the user
44+
lastLibraries []string
45+
4346
// The current client status of the user
4447
status *objects.ClientStatus
4548

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

183+
// GetLastLibraries Gets the user's last libraries
184+
func (u *User) GetLastLibraries() []string {
185+
u.Mutex.Lock()
186+
defer u.Mutex.Unlock()
187+
188+
return u.lastLibraries
189+
}
190+
191+
// SetLastLibraries Sets the user's last libraries
192+
func (u *User) SetLastLibraries(libraries []string) {
193+
u.Mutex.Lock()
194+
defer u.Mutex.Unlock()
195+
196+
u.lastLibraries = libraries
197+
}
198+
180199
// GetClientStatus Gets the current user client status
181200
func (u *User) GetClientStatus() *objects.ClientStatus {
182201
u.Mutex.Lock()

webhooks/webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ func SendAntiCheatProcessLog(username string, userId int, url string, icon strin
8989
SendAntiCheat(username, userId, url, icon, "Detected Processes", formatted)
9090
}
9191

92+
func SendAntiCheatLibraries(username string, userId int, url string, icon string, libraries []string) {
93+
formatted := ""
94+
95+
for i, library := range libraries {
96+
formatted += fmt.Sprintf("**%v. %v**\n", i+1, library)
97+
}
98+
99+
SendAntiCheat(username, userId, url, icon, "Detected Libraries", formatted)
100+
}
101+
92102
// SendChatMessage Sends a chat message webhook to Discord
93103
func SendChatMessage(webhook webhook.Client, senderUsername string, senderProfileUrl string, senderAvatarUrl, receiverName string, message string) {
94104
if webhook == nil {

0 commit comments

Comments
 (0)