From e11c782d1f7af04f7e31fc273ff3a2ce8921e5f8 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:06:01 -0400 Subject: [PATCH 01/16] Update mainserver.yml --- mainserver.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mainserver.yml b/mainserver.yml index 94410f9d..c0607535 100644 --- a/mainserver.yml +++ b/mainserver.yml @@ -28,6 +28,7 @@ admins: ee11ee9258594dd7aac18f1fa43d5d32482ec063c86fc3386a058540b4ccbe26: 'Ishan Goel: quackduck' 3a3534a3d4727957a7e22c05d751d8921ef4a667973bd6d864a40c8ba39b9680: 'PPTide: github.com/PPTide' 120d352818aef5c2115b32d497253bffc67d26b09e65e8b63ee80f0acc8a8458: 'CaenJones: github.com/CaenJones' + d31bbe3dc058a935e29019e59d0c39d1a0a869db9042959198967c1c7b308e6e: 'CaenJones: (server) github.com/CaenJones' dfc419ee8fc1a9ec4c608ead49113872ee42d85637faf4d542d72f64415a51e2: 'Alex S: hackclub, github.com/ajs256' 6acb2173bfe514c32d06639d5c3cac833e8e5a7af608c462cd737cd535bedc4f: 'Ry Hatton, Purdue, github.com/1ryh' bed8118812b901da0f3768a2cfd3307ef8ce3597d8bb2095f33bcfcb90da27c7: 'Lukas Krapukaitis, Purdue' From 508ace3cd5619d131977995726e777100eb7ea6c Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:20:33 +0000 Subject: [PATCH 02/16] Devzat Logger Premium (record user logins to csv file) This records what time a user joins and leaves Devzat onto a csv file. This file will not be erased unlike the normal Devzat logfile. --- main.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 59e51670..68244f3a 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( _ "embed" + "encoding/csv" "encoding/json" "fmt" "image" @@ -895,7 +896,7 @@ func calculateLinesTaken(u *User, s string, width int) { } // bansContains reports if the addr or id is found in the bans list -func bansContains(b []Ban, addr string, id string) bool { +func bansContains(b []Ban, addr string, id string) bool { //caen wuz here for i := 0; i < len(b); i++ { if b[i].Addr == addr || b[i].ID == id { return true @@ -903,3 +904,37 @@ func bansContains(b []Ban, addr string, id string) bool { } return false } + +func logUserActivity(user *User, action string) { + timestamp := time.Now().Format("2010-03-07 15:04:05") + message := "" + + switch action { + case "login": + message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) + case "logout": + message = fmt.Sprintf("%s left at %s", user.Name, timestamp) + default: + message = "Invalid action" + } + + file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + writer := csv.NewWriter(file) + + record := []string{user.Name, action, timestamp} + if err := writer.Write(record); err != nil { + fmt.Println("Error writing to CSV:", err) + } + + writer.Flush() + + if err := writer.Error(); err != nil { + fmt.Println("Error flushing CSV writer:", err) + } +} From 51c5e77e59511d7c9971ece433f0600a0733ac20 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:21:52 +0000 Subject: [PATCH 03/16] Create users.csv --- users.csv | 1 + 1 file changed, 1 insertion(+) create mode 100644 users.csv diff --git a/users.csv b/users.csv new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/users.csv @@ -0,0 +1 @@ + From e3da43b5b16650934a5d4086bf57498c5f9f2048 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:23:17 +0000 Subject: [PATCH 04/16] Update main.go --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 68244f3a..1f03f7f7 100644 --- a/main.go +++ b/main.go @@ -896,7 +896,7 @@ func calculateLinesTaken(u *User, s string, width int) { } // bansContains reports if the addr or id is found in the bans list -func bansContains(b []Ban, addr string, id string) bool { //caen wuz here +func bansContains(b []Ban, addr string, id string) bool { for i := 0; i < len(b); i++ { if b[i].Addr == addr || b[i].ID == id { return true @@ -905,7 +905,7 @@ func bansContains(b []Ban, addr string, id string) bool { //caen wuz here return false } -func logUserActivity(user *User, action string) { +func logUserActivity(user *User, action string) { //caen wuz here timestamp := time.Now().Format("2010-03-07 15:04:05") message := "" From 5740676531c5fec5c3385248142abd3a69167dbc Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:52:00 +0000 Subject: [PATCH 05/16] Delete users.csv --- users.csv | 1 - 1 file changed, 1 deletion(-) delete mode 100644 users.csv diff --git a/users.csv b/users.csv deleted file mode 100644 index 8b137891..00000000 --- a/users.csv +++ /dev/null @@ -1 +0,0 @@ - From c87c4a30b5bd476d41bc5b4d1a1b7a794e24b45b Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:58:52 +0000 Subject: [PATCH 06/16] Update main.go --- main.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 1f03f7f7..f9bf3446 100644 --- a/main.go +++ b/main.go @@ -905,7 +905,11 @@ func bansContains(b []Ban, addr string, id string) bool { return false } -func logUserActivity(user *User, action string) { //caen wuz here +func logUserActivity(user *User, action string, loggingEnabled bool) { + if !loggingEnabled { + return + } + timestamp := time.Now().Format("2010-03-07 15:04:05") message := "" @@ -918,12 +922,12 @@ func logUserActivity(user *User, action string) { //caen wuz here message = "Invalid action" } - file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - fmt.Println("Error opening file:", err) - return - } - defer file.Close() + file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) +if err != nil { + fmt.Println("Error opening file:", err) + return +} +defer file.Close() writer := csv.NewWriter(file) From db3812ceff8ca0e83b1ef2a9d1b4a827e8f4fda9 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:00:12 +0000 Subject: [PATCH 07/16] Update main.go --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index f9bf3446..d5c291b4 100644 --- a/main.go +++ b/main.go @@ -906,7 +906,7 @@ func bansContains(b []Ban, addr string, id string) bool { } func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { + if !loggingEnabled { false //logging on Devzat is disabled by default, to enable it please switch the statement from false to true return } From 8c9ff7466b7b8fe4d9da396f0cfd955856483aec Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Wed, 8 Nov 2023 14:22:02 +0000 Subject: [PATCH 08/16] Update main.go --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index d5c291b4..9c5df6f9 100644 --- a/main.go +++ b/main.go @@ -911,7 +911,7 @@ func logUserActivity(user *User, action string, loggingEnabled bool) { } timestamp := time.Now().Format("2010-03-07 15:04:05") - message := "" + message := "%s joined at: %timestamp%" switch action { case "login": From 5c569741286ab8adb5ab3304d18b47a7102cad11 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:03:45 +0000 Subject: [PATCH 09/16] Update main.go --- main.go | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/main.go b/main.go index 9c5df6f9..33436846 100644 --- a/main.go +++ b/main.go @@ -904,41 +904,41 @@ func bansContains(b []Ban, addr string, id string) bool { } return false } - func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { false //logging on Devzat is disabled by default, to enable it please switch the statement from false to true - return - } - - timestamp := time.Now().Format("2010-03-07 15:04:05") - message := "%s joined at: %timestamp%" - - switch action { - case "login": - message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) - case "logout": - message = fmt.Sprintf("%s left at %s", user.Name, timestamp) - default: - message = "Invalid action" - } - - file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) -if err != nil { - fmt.Println("Error opening file:", err) - return -} -defer file.Close() - - writer := csv.NewWriter(file) - - record := []string{user.Name, action, timestamp} - if err := writer.Write(record); err != nil { - fmt.Println("Error writing to CSV:", err) - } - - writer.Flush() - - if err := writer.Error(); err != nil { - fmt.Println("Error flushing CSV writer:", err) - } + if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true + return + } + + timestamp := time.Now().Format("2010-03-07 15:04:05") + + var message string + + switch action { + case "login": + message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) + case "logout": + message = fmt.Sprintf("%s left at %s", user.Name, timestamp) + default: + message = "Invalid action" + } + + file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + writer := csv.NewWriter(file) + + record := []string{user.Name, action, timestamp} + if err := writer.Write(record); err != nil { + fmt.Println("Error writing to CSV:", err) + } + + writer.Flush() + + if err := writer.Error(); err != nil { + fmt.Println("Error flushing CSV writer:", err) + } } From df705a2357a27294bcb6c2aa69ac79b48778e181 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:19:08 +0000 Subject: [PATCH 10/16] Update main.go --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 33436846..9a4f0915 100644 --- a/main.go +++ b/main.go @@ -904,14 +904,14 @@ func bansContains(b []Ban, addr string, id string) bool { } return false } + func logUserActivity(user *User, action string, loggingEnabled bool) { if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true return } - + timestamp := time.Now().Format("2010-03-07 15:04:05") - - var message string + message := "" switch action { case "login": @@ -919,12 +919,12 @@ func logUserActivity(user *User, action string, loggingEnabled bool) { case "logout": message = fmt.Sprintf("%s left at %s", user.Name, timestamp) default: - message = "Invalid action" + message = "Invalid Action" } file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) if err != nil { - fmt.Println("Error opening file:", err) + fmt.Println("Error Opening CSV File:", err) return } defer file.Close() @@ -933,12 +933,13 @@ func logUserActivity(user *User, action string, loggingEnabled bool) { record := []string{user.Name, action, timestamp} if err := writer.Write(record); err != nil { - fmt.Println("Error writing to CSV:", err) + fmt.Println("Error writing to CSV File:", err) } writer.Flush() if err := writer.Error(); err != nil { fmt.Println("Error flushing CSV writer:", err) + //todo: add averages for user join times and messages sent } } From f0497f055760d0525d1e8bee2abe736b635c3d4e Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:16:52 +0000 Subject: [PATCH 11/16] Update main.go --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 9a4f0915..51863efd 100644 --- a/main.go +++ b/main.go @@ -905,10 +905,10 @@ func bansContains(b []Ban, addr string, id string) bool { return false } -func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true - return - } +func logUserActivity(user *User, action string, loggingEnabled bool) { + if !loggingEnabled { false //logging on devzat is disabled by default, to enable logging please switch the statement to true + return // If logging is not enabled, it exits the function immediately + } timestamp := time.Now().Format("2010-03-07 15:04:05") message := "" From 48643fef389c9e6b2db6693120a2f7951c08d05a Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:17:39 +0000 Subject: [PATCH 12/16] Update main.go --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 51863efd..3a44bad3 100644 --- a/main.go +++ b/main.go @@ -911,7 +911,6 @@ func logUserActivity(user *User, action string, loggingEnabled bool) { } timestamp := time.Now().Format("2010-03-07 15:04:05") - message := "" switch action { case "login": From fbaffdbbbd44ed749433528c13a3e2c5cd5af934 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:24:17 +0000 Subject: [PATCH 13/16] Update main.go --- main.go | 71 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/main.go b/main.go index 3a44bad3..a45f2967 100644 --- a/main.go +++ b/main.go @@ -906,39 +906,40 @@ func bansContains(b []Ban, addr string, id string) bool { } func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { false //logging on devzat is disabled by default, to enable logging please switch the statement to true - return // If logging is not enabled, it exits the function immediately - } - - timestamp := time.Now().Format("2010-03-07 15:04:05") - - switch action { - case "login": - message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) - case "logout": - message = fmt.Sprintf("%s left at %s", user.Name, timestamp) - default: - message = "Invalid Action" - } - - file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) - if err != nil { - fmt.Println("Error Opening CSV File:", err) - return - } - defer file.Close() - - writer := csv.NewWriter(file) - - record := []string{user.Name, action, timestamp} - if err := writer.Write(record); err != nil { - fmt.Println("Error writing to CSV File:", err) - } - - writer.Flush() - - if err := writer.Error(); err != nil { - fmt.Println("Error flushing CSV writer:", err) - //todo: add averages for user join times and messages sent - } + if !loggingEnabled { false + // logging on devzat is disabled by default, to enable logging please switch the statement to true + return // If logging is not enabled, exit the function immediately + } + + timestamp := time.Now().Format("2010-03-07 15:04:05") + message := "" + + switch action { + case "login": + message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) + case "logout": + message = fmt.Sprintf("%s left at %s", user.Name, timestamp) + default: + message = "Invalid Action" + } + + file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error Opening CSV File:", err) + return + } + defer file.Close() + + writer := csv.NewWriter(file) + + record := []string{user.Name, action, timestamp} + if err := writer.Write(record); err != nil { + fmt.Println("Error writing to CSV File:", err) + } + + writer.Flush() + + if err := writer.Error(); err != nil { + fmt.Println("Error flushing CSV writer:", err) + } } From ff9a3de5bc6cf924212f4bfb96fa7b5b284881aa Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:11:58 +0000 Subject: [PATCH 14/16] test --- main.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/main.go b/main.go index a45f2967..e3026af8 100644 --- a/main.go +++ b/main.go @@ -905,15 +905,12 @@ func bansContains(b []Ban, addr string, id string) bool { return false } -func logUserActivity(user *User, action string, loggingEnabled bool) { +func logUserActivity(user *User, action string, loggingEnabled) { if !loggingEnabled { false // logging on devzat is disabled by default, to enable logging please switch the statement to true return // If logging is not enabled, exit the function immediately } - timestamp := time.Now().Format("2010-03-07 15:04:05") - message := "" - switch action { case "login": message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) From e7601cd8e275bdb05e799c1e242443477ea59943 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:14:04 +0000 Subject: [PATCH 15/16] Update main.go --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index e3026af8..1e594f81 100644 --- a/main.go +++ b/main.go @@ -905,7 +905,7 @@ func bansContains(b []Ban, addr string, id string) bool { return false } -func logUserActivity(user *User, action string, loggingEnabled) { +func logUserActivity(user *User, action string, loggingEnabled bool) { if !loggingEnabled { false // logging on devzat is disabled by default, to enable logging please switch the statement to true return // If logging is not enabled, exit the function immediately From fa876d17a408e18337de3649f8c3d2599ac60f2b Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:17:27 +0000 Subject: [PATCH 16/16] Update main.go --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1e594f81..109a8e6e 100644 --- a/main.go +++ b/main.go @@ -906,11 +906,14 @@ func bansContains(b []Ban, addr string, id string) bool { } func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { false + if !loggingEnabled { // logging on devzat is disabled by default, to enable logging please switch the statement to true return // If logging is not enabled, exit the function immediately } + timestamp := time.Now().Format("2010-03-07 15:04:05") + message := "" + switch action { case "login": message = fmt.Sprintf("%s joined at %s", user.Name, timestamp)