From 2669deeb40ae4bebb045b8c9a644ea174d5aca65 Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Mon, 17 Oct 2022 19:39:06 +0200 Subject: [PATCH] first commit --- README.md | 46 ++++++ go.mod | 18 +++ go.sum | 23 +++ main.go | 311 ++++++++++++++++++++++++++++++++++++++ research/alert.mp3 | Bin 0 -> 6184 bytes research/beep.go | 47 ++++++ research/intel2noise.go | 148 ++++++++++++++++++ research/params.go | 26 ++++ research/partial.go | 46 ++++++ research/regex_funpark.go | 60 ++++++++ research/searchlog.go | 162 ++++++++++++++++++++ research/tailLocal.go | 20 +++ 12 files changed, 907 insertions(+) create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 research/alert.mp3 create mode 100644 research/beep.go create mode 100644 research/intel2noise.go create mode 100644 research/params.go create mode 100644 research/partial.go create mode 100644 research/regex_funpark.go create mode 100644 research/searchlog.go create mode 100644 research/tailLocal.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..6483942 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +For future reference: + +* `go run intel2noise.go -l "/home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/Etherium_Intel_20220208_175248_93488613.txt" -s c-v6dq,1pf-bc,ex-gbt,z-fet0,BNX-AS,QNXJ-M,4LJ6-Q` + +* Location: /home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs +* Intel channels: Etherium_Intel + +``` +Etherium_Intel_20220206_111758_93488613.txt +``` + +# Program Structure: + +## Main: +* Check parameters, for errors, set stuff internally. + +## Main Loop: +* Go into Logs Folder +* Generate a date-stamp +* Find all files in the Folder + * Find `Local_*` + * Find `$IntelChannel_*` +* For each new set of $IntelChannel and Local File, open a go-routine with these two file as parameters + +## The Go-Routine +* Parse Local file and figure out the last system + * If nono are found. Do nothing + * If its found, continue +* ... + +Need more thinky think about: +* Find and cache adjecent systems +* Find and cache characters + + +--- + +# ESI Exploration +Required to find adjacent systems + +Reference: https://esi.evetech.net/ui/ + +* `curl -H "accept: application/json" https://esi.evetech.net/v1/universe/regions/10000027` +* `curl -H "accept: application/json" https://esi.evetech.net/v1/universe/constellations/20000336/` +* `curl -s -H "accept: application/json" https://esi.evetech.net/v4/universe/systems/30002290/ | python3 -m json.tool` +* `curl -s -H "accept: application/json" https://esi.evetech.net/v1/universe/stargates/50000569/ | python3 -m json.tool` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ee91659 --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module gitea/EVE-Online/Intel2Noise + +go 1.17 + +require ( + github.com/hajimehoshi/go-mp3 v0.3.2 + github.com/hajimehoshi/oto v1.0.1 +) + +require ( + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/nxadm/tail v1.4.8 // indirect + golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect + golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect + golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect + golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c23c9ca --- /dev/null +++ b/go.sum @@ -0,0 +1,23 @@ +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/hajimehoshi/go-mp3 v0.3.2 h1:xSYNE2F3lxtOu9BRjCWHHceg7S91IHfXfXp5+LYQI7s= +github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM= +github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= +github.com/hajimehoshi/oto v1.0.1 h1:8AMnq0Yr2YmzaiqTg/k1Yzd6IygUGk2we9nmjgbgPn4= +github.com/hajimehoshi/oto v1.0.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 h1:idBdZTd9UioThJp8KpM/rTSinK/ChZFBE43/WtIy8zg= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 h1:KYGJGHOQy8oSi1fDlSpcZF0+juKwk/hEMv5SiwHogR0= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 h1:vyLBGJPIl9ZYbcQFM2USFmJBK6KI+t+z6jL0lbwjrnc= +golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872 h1:cGjJzUd8RgBw428LXP65YXni0aiGNA4Bl+ls8SmLOm8= +golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/main.go b/main.go new file mode 100644 index 0000000..002673e --- /dev/null +++ b/main.go @@ -0,0 +1,311 @@ +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "runtime" + "strings" + "time" + + "github.com/nxadm/tail" +) + +// findPath Find the path in which the log files are stored. +func findPath(LogLocation string) (logPath string) { + + if LogLocation != "" { + logPath = LogLocation + return + } + + var err error + var homedir string + var Path string + var Paths []string + var PathsLinux []string + var PathsMac []string + var PathsWindows []string + + // Determine the homedir of the user. + homedir, err = os.UserHomeDir() + if err != nil { + log.Fatal(err) + } + + // Define Paths to check out + PathsLinux = append(PathsLinux, "/Documents/EVE/logs/") + PathsLinux = append(PathsLinux, "/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/") + + PathsMac = append(PathsMac, "/Documents/EVE/logs/") + PathsMac = append(PathsMac, "/Library/Application Support/EVE Online/p_drive/User/My Documents/EVE/") + + PathsWindows = append(PathsWindows, "C:\\Users\\YourUserName\\Documents\\EVE\\logs") + PathsWindows = append(PathsWindows, "MyDocuments -> EVE -> Logs") + + switch runtime.GOOS { + case "linux": + Paths = PathsLinux + case "darwin": + Paths = PathsMac + case "windows": + Paths = PathsWindows + } + + for _, Path = range Paths { + if _, err := os.Stat(homedir + Path); !os.IsNotExist(err) { + logPath = homedir + Path + } + } + + return +} + +// OrchestrateIntelMonitoring routine to periodically check the logpath for the intel channels. +func OrchestrateIntelMonitoring(logPath string, intelChannel string, LogSystemsRaw string) { + + // Declare variables + var files []fs.FileInfo + var lastName string + var tempName string + + // Enter a for-loop that periodically checks. + for { + files = fetchFileListing(logPath) + tempName = findLatestLog(logPath, intelChannel, files) + + if !strings.EqualFold(lastName, tempName) { + lastName = tempName + fmt.Println("Tracking file:" + lastName) + go TrackLogfile(lastName, LogSystemsRaw) + } + + // Sleep a minute before we check again. + time.Sleep(time.Second * 60) + } + +} + +// TrackLogfile The actual work +func TrackLogfile(logPath string, LogSystemsRaw string) { + // Split the CSV string into different parts + LogSystems := strings.Split(LogSystemsRaw, ",") + + // Do the main loop and start parsing the logfiles + t, err := tail.TailFile(logPath, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + // Cast a line to a text, trim the trash + logLine := string(line.Text) + logLine = strings.Trim(logLine, "\n") + + // Figure out if this is a message we want to deal with + // > is critical in this regard because it is the start of the message + // and everything behind it until it hits ] is the username + splitpos := strings.Index(logLine, ">") + if -1 == splitpos { + continue + } + + // Somehow I cannot filter out this stuff. + // EVE System > Channel MOTD + LineDate, LineTime, LineUser, Payload := ParseChat(logLine) + + if CompareElements(LogSystems, Payload) { + playBeep() + fmt.Println("[", LineDate, LineTime, "]", LineUser, ">", Payload) + } + } + + // We should never reach this +} + +// fetchFileListing As it says on the tin. +func fetchFileListing(logPath string) (files []fs.FileInfo) { + + // Declare Variables + var err error + var folder *os.File + + // Open the folder we need to open. + folder, err = os.Open(logPath) + if err != nil { + log.Fatal(err) + } + + // Read the files UwU + files, err = folder.Readdir(-1) + folder.Close() + if err != nil { + log.Fatal(err) + } + + // Off you go! \o/ + return +} + +// findLatestLog Find the last log-file based on the Internet +func findLatestLog(logPath string, intelChannel string, files []fs.FileInfo) (lastName string) { + + // Declare Variables + var lastTime time.Time + var tempTime time.Time + + for _, file := range files { + file, err := os.Stat(logPath + file.Name()) + if err != nil { + log.Fatal(err) + } + + if strings.EqualFold(intelChannel, file.Name()[:len(intelChannel)]) { + tempTime = file.ModTime() + if tempTime.After(lastTime) { + lastTime = tempTime + lastName = logPath + file.Name() + } + } + } + + // And there you are (or not) + return + +} + +// StartIntelMonitoring -- The Main Loop! +func StartIntelMonitoring(intelChannels string, LogSystemsRaw string, LogLocation string) { + + // Declare variables + var logPath string + var IntelChannelsSplit []string + var IntelChannel string + + // Split the CSV string into different parts + IntelChannelsSplit = strings.Split(intelChannels, ",") + + // Get the path we need to + logPath = findPath(LogLocation) + + for _, IntelChannel = range IntelChannelsSplit { + IntelChannel = strings.ReplaceAll(IntelChannel, " ", "_") + go OrchestrateIntelMonitoring(logPath, IntelChannel, LogSystemsRaw) + } + +} + +// ParseChat Parses a string, returns the payload of the chat +// *sigh* +// This took effing forever to get right. +// "Lets start with Regex, cannot go wrong". +// You have this string: +// ��[ 2022.02.09 10:05:43 ] Kaysee Guru > EX-GBT clr nd +// Cool. Looks easy. +// .*\[ (.*?) (.*?) \] (.*?) > (.*) +// regex101.com says its good +// And no matter what I do just does not work for some magical reason. +// +// Lets do this with splitting by space and compare it with that. Do a bunch of ifs, it works in test aaaaaand.... +// It doesn't work. +// +// By now I have a somewhat reliable version, but it fails to look for the word MOTD. +// I should prolly look into runes() +// This is terrible +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, Payload []string) { + logLine := chatline[3:] + + var LinePayload string + var splitpos int + + splitpos = strings.Index(logLine, ">") + LineDate = logLine[2:23] + LineTime = logLine[25:41] + LineUser = logLine[46 : splitpos-2] + LinePayload = logLine[splitpos+4:] + LinePayload = shorten(LinePayload) + Payload = strings.Fields(LinePayload) + + //fmt.Println(logLine) + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(splitpos) + //fmt.Println(LinePayload) + //fmt.Println(Payload) + + return +} + +func shorten(payload string) (logLine string) { + runes := []rune(payload) + for pos, char := range runes { + if pos%2 == 0 && char != 13 { + logLine = logLine + string(char) + } + } + return +} + +// CompareElements Compares a log msg with systems we wish to track +func CompareElements(alerts []string, payload []string) bool { + + for _, word := range payload { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + //fmt.Println("Found (EF): ", alert, "in", word) + return true + } //else { + // fmt.Println(word, "!=", alert) + //} + + // In the odd case somebody links "C-V6DQ*" + if len(word) > 6 { + //alert = alert[:len(word)] + word = word[:6] + } + + // In case of partials like "C-V" + if len(word) < 6 && len(word) >= 3 { + //word = word[:5] + alert = alert[:len(word)] + } + + if strings.EqualFold(word, alert) { + //fmt.Println("Found: ", alert, "in", word) + return true + } + } + } + return false +} + +// playBeep Play a beep +// Honestly, I tried to play alert.mp3, but after two executions I got a segfault and thought 0x07 it is! +func playBeep() { + fmt.Print("\a") +} + +// main Something Importang. Dunno +func main() { + + // Handle Parameters + var intelChannels = flag.String("i", "Etherium Intel,Bean-Intel", "Comma-separated list of intel channels.") + LogSystemsRaw := flag.String("s", "c-v6dq,1pf-bc,ex-gbt,z-fet0", "Comma-seperated list of systems to monitor for") + LogLocation := flag.String("l", "", "Location of the log-file to track.") + flag.Parse() + + // Start the main loop + go StartIntelMonitoring(*intelChannels, *LogSystemsRaw, *LogLocation) + + // Go into the eternal loop and sit this one out. + // But bug every hour, reminding them that you are still there. + for { + time.Sleep(time.Second * 3600) + fmt.Println("Hi. This is your hourly reminder that this program is still runnig and hasn't crashed!") + } + +} diff --git a/research/alert.mp3 b/research/alert.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..7b386d0200df2f313dfef08e4af58ba6d799819a GIT binary patch literal 6184 zcmeZtF=l39U|XJBCb|1X1~grS6?fWeAEpFy7?k)f0!g&~t6pCOB( zlp&8Hogs%Il|hdok0F(zgh8L7l%bd*m7xgCDq=`tNMxvD$Y;o7&}S%M$Y&^GC}Bur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&8N`hrf_iZ=3PG7ZL ziNnD$IdoV7hKf;{~62j{_5`% zrf(k#xo}2j?(?~pJX21?$^U4SQoXR0y0Gy5^Oye=-?jeuQ8e%W;p+Woc$~FBF=W8N zTp079R+53svS~Np@&ycHS1%_-b}}$r<;@kBYG8OYS4p5;A(cTU2fv?vU_fv$-ALos(w0Q=}C?i9ul0_i%p*Hf1k$aCu=0o*wDhtq0f9hdhKEd z1_ma9V9n^a?EjlR+!lS>fBV~wy%R3){ikU0zOeVeIp!v*gZax`-|-%EW;fxTb7NP8 z!1m4q`VN*J7W^V}UW)1bNnu@+>N=&7L1BqWv4`ftbAKEUFR)}hqVGBhfx)Y2NCMquB71NiPHNAAEbp0ofm?lnP zrkHRGla7Tx>zq$+Oq+D)q^M=*N~1|$uKWKl2-*Js|IbMd91aYO$sbLwD{vk1Np5e{ zNtWT%*m#fO;S(M62O1{MoU>KJ|DCY2NK8$QD)CYM^hW!iR-;$F1DndUS#E_L4NeIX zES?9$^^U7+G@V#lCS~1{m9#n8d(J=O z(re$SnB6y{-kETLVn~($(|?VP;*t#v1}dQi4|*6F7#No@Ffb@EFqkwjFtE&Jo5x*$ zIQXLAL+!@-S`UR!GrKyw&i&u&;onmm^k~(`{xxS;trubOWMj&8X5=zhpp=lXK+A_k zl(liu!bJyGx5WSd|1?Gk*0<3!UNs6x2!RkscW6a`gUTo=DX`MlPb^Kz%+D&#OV3Hw X%S$cMFD*_j(l0H-FN?!SB;o%6q EX-GBT clr nd +// Cool. Looks easy. +// .*\[ (.*?) (.*?) \] (.*?) > (.*) +// regex101.com says its good +// And no matter what I do just does not work for some magical reason. +// +// Lets do this with splitting by space and compare it with that. Do a bunch of ifs, it works in test aaaaaand.... +// It doesn't work. +// +// By now I have a somewhat reliable version, but it fails to look for the word MOTD. +// I should prolly look into runes() +// This is terrible +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, Payload []string) { + logLine := chatline[3:] + + //var LineDate string + //var LineTime string + //var LineUser string + var LinePayload string + //var Payload []string + var splitpos int + + splitpos = strings.Index(logLine, ">") + LineDate = logLine[4:24] + LineTime = logLine[24:42] + LineUser = logLine[46 : splitpos-2] + LinePayload = logLine[splitpos+4:] + LinePayload = shorten(LinePayload) + Payload = strings.Fields(LinePayload) + + //fmt.Println(logLine) + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(splitpos) + //fmt.Println(LinePayload) + //fmt.Println(Payload) + + return +} + +func shorten(payload string) (logLine string) { + runes := []rune(payload) + for pos, char := range runes { + if pos%2 == 0 && char != 13 { + logLine = logLine + string(char) + } + } + return +} + +// CompareElements Compares a log msg with systems we wish to track +func CompareElements(alerts []string, payload []string) bool { + + for _, word := range payload { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + //fmt.Println("Found (EF): ", alert, "in", word) + return true + } //else { + // fmt.Println(word, "!=", alert) + //} + + // In the odd case somebody links "C-V6DQ*" + if len(word) > 6 { + //alert = alert[:len(word)] + word = word[:6] + } + + // In case of partials like "C-V" + if len(word) < 6 && len(word) >= 3 { + //word = word[:5] + alert = alert[:len(word)] + } + + if strings.EqualFold(word, alert) { + //fmt.Println("Found: ", alert, "in", word) + return true + } + } + } + return false +} + +// playBeep Play a beep +// Honestly, I tried to play alert.mp3, but after two executions I got a segfault and thought 0x07 it is! +func playBeep() { + fmt.Print("\a") +} + +func main() { + + // Deal with parameters first. + LogLocation := flag.String("l", "", "Location of the log-file to track.") + LogSystemsRaw := flag.String("s", "jita,Perimeter,New Caldari,Sobaseki", "comma-seperated list of systems") + //LogAlarm := flag.String("a", "alert.mp3", "Audio file to play when an alert needs to be triggered") + flag.Parse() + + // Split the CSV string into different parts + LogSystems := strings.Split(*LogSystemsRaw, ",") + + // Do the main loop and start parsing the logfiles + t, err := tail.TailFile(*LogLocation, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + // Cast a line to a text, trim the trash + logLine := string(line.Text) + logLine = strings.Trim(logLine, "\n") + + // Figure out if this is a message we want to deal with + // > is critical in this regard because it is the start of the message + // and everything behind it until it hits ] is the username + splitpos := strings.Index(logLine, ">") + if -1 == splitpos { + continue + } + + // Somehow I cannot filter out this stuff. + // EVE System > Channel MOTD + LineDate, LineTime, LineUser, Payload := ParseChat(logLine) + + if CompareElements(LogSystems, Payload) { + playBeep() + fmt.Println("On", LineDate, "at", LineTime, "", LineUser, "posted", Payload) + } + + } + +} diff --git a/research/params.go b/research/params.go new file mode 100644 index 0000000..7409a57 --- /dev/null +++ b/research/params.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "fmt" + "strings" +) + +func main() { + num := flag.Int("n", 5, "# of iterations") + mysystems := flag.String("s", "jita,New Caldari", "comma-seperated list of systems") + flag.Parse() + + n := *num + i := 0 + + for i < n { + fmt.Println("falcon") + i++ + } + + fmt.Println(*mysystems) + s := strings.Split(*mysystems, ",") + fmt.Println(s) + +} diff --git a/research/partial.go b/research/partial.go new file mode 100644 index 0000000..b1e2c38 --- /dev/null +++ b/research/partial.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + chatline := "c-v Morretus Isayeki nv" + words := strings.Fields(chatline) + alerts := [...]string{"C-V6DQ", "1PF-BC", "EX-GBT", "Z-FET0"} + + //var found bool + + for _, word := range words { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + fmt.Println("Found: ", alert, "in", word) + } + + // In the odd case somebody links "C-V6DQ*" + if len(word) < 6 { + alert = alert[:len(word)] + } + + // In case of partials like "C-V" + if len(word) > 6 { + word = word[:5] + } + if strings.EqualFold(word, alert) { + fmt.Println("Found: ", alert, "in", word) + } + + fmt.Println(word) + fmt.Println(alert) + fmt.Println("---") + + } + } + + //fmt.Println(string(myString[:3])) + //fmt.Println("Dit") + //fmt.Println(strings.EqualFold(myString[:3], "Dit")) + +} diff --git a/research/regex_funpark.go b/research/regex_funpark.go new file mode 100644 index 0000000..e587ff8 --- /dev/null +++ b/research/regex_funpark.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "strings" +) + +// ParseChat Parses a string, returns the payload of the chat +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, LinePayload []string) { + words := strings.Fields(chatline) + //fmt.Println(len(words)) + //var LineDate string + //var LineTime string + //var LineUser string + //var LinePayload []string + var SplitFound int + + for i := range words { + + if i == 1 { + LineDate = words[i] + } + + if i == 2 { + LineTime = words[i] + } + + if i >= 5 && SplitFound == 1 { + LinePayload = append(LinePayload, words[i]) + } + + if words[i] == ">" { + SplitFound = 1 + } + + if i >= 4 && SplitFound == 0 { + if LineUser == "" { + LineUser = words[i] + } else { + LineUser = LineUser + " " + words[i] + } + } + + } + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(LinePayload) + return +} + +func main() { + + mystring := "��[ 2022.02.07 19:57:52 ] Samoa Serine > BY-7PY Morretus Isayeki nv" + + LineDate, LineTime, LineUser, Payload := ParseChat(mystring) + fmt.Println("On " + LineDate + " " + LineTime + " " + LineUser + " posted the following: ") + fmt.Println(Payload) + +} diff --git a/research/searchlog.go b/research/searchlog.go new file mode 100644 index 0000000..e3cef68 --- /dev/null +++ b/research/searchlog.go @@ -0,0 +1,162 @@ +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "runtime" + "strings" + "time" +) + +// findPath Find the path in which the log files are stored. +func findPath() (logPath string) { + + var err error + var homedir string + var Path string + var Paths []string + var PathsLinux []string + var PathsMac []string + var PathsWindows []string + + // Determine the homedir of the user. + homedir, err = os.UserHomeDir() + if err != nil { + log.Fatal(err) + } + + // Define Paths to check out + PathsLinux = append(PathsLinux, "/Documents/EVE/logs/") + PathsLinux = append(PathsLinux, "/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/") + + PathsMac = append(PathsMac, "/Documents/EVE/logs/") + PathsMac = append(PathsMac, "/Library/Application Support/EVE Online/p_drive/User/My Documents/EVE/") + + PathsWindows = append(PathsWindows, "C:\\Users\\YourUserName\\Documents\\EVE\\logs") + PathsWindows = append(PathsWindows, "MyDocuments -> EVE -> Logs") + + switch runtime.GOOS { + case "linux": + Paths = PathsLinux + case "darwin": + Paths = PathsMac + case "windows": + Paths = PathsWindows + } + + for _, Path = range Paths { + if _, err := os.Stat(homedir + Path); !os.IsNotExist(err) { + logPath = homedir + Path + } + } + + return +} + +// OrchestrateIntelMonitoring routine to periodically check the logpath for the intel channels. +func OrchestrateIntelMonitoring(logPath string, intelChannel string) { + + // Declare variables + var files []fs.FileInfo + var lastName string + var tempName string + + // Enter a for-loop that periodically checks. + for { + files = fetchFileListing(logPath) + tempName = findLatestLog(logPath, intelChannel, files) + + if !strings.EqualFold(lastName, tempName) { + lastName = tempName + fmt.Println("Found a new LogFile! Its " + lastName) + } + + // Sleep a minute before we check again. + time.Sleep(time.Second * 60) + } + +} + +// fetchFileListing As it says on the tin. +func fetchFileListing(logPath string) (files []fs.FileInfo) { + + // Declare Variables + var err error + var folder *os.File + + // Open the folder we need to open. + folder, err = os.Open(logPath) + if err != nil { + log.Fatal(err) + } + + // Read the files UwU + files, err = folder.Readdir(-1) + folder.Close() + if err != nil { + log.Fatal(err) + } + + // Off you go! \o/ + return +} + +// findLatestLog Find the last log-file based on the Internet +func findLatestLog(logPath string, intelChannel string, files []fs.FileInfo) (lastName string) { + + // Declare Variables + var lastTime time.Time + var tempTime time.Time + + for _, file := range files { + file, err := os.Stat(logPath + file.Name()) + if err != nil { + log.Fatal(err) + } + + if strings.EqualFold(intelChannel, file.Name()[:len(intelChannel)]) { + tempTime = file.ModTime() + if tempTime.After(lastTime) { + lastTime = tempTime + lastName = logPath + file.Name() + } + } + } + + // And there you are (or not) + return + +} + +// main Something Importang. Dunno +func main() { + + // Declare variables + var logPath string + var IntelChannelsSplit []string + var IntelChannel string + + // Handle Parameters + var intelChannels = flag.String("i", "Etherium Intel,Bean-Intel", "A commaseparated list of intel channels.") + flag.Parse() + + // Split the CSV string into different parts + IntelChannelsSplit = strings.Split(*intelChannels, ",") + + // Get the path we need to + logPath = findPath() + + for _, IntelChannel = range IntelChannelsSplit { + IntelChannel = strings.ReplaceAll(IntelChannel, " ", "_") + go OrchestrateIntelMonitoring(logPath, IntelChannel) + } + + for { + time.Sleep(time.Second * 3600) + fmt.Println("Hi. This is your hourly reminder that this program is still runnig and hasn't crashed!") + } + +} diff --git a/research/tailLocal.go b/research/tailLocal.go new file mode 100644 index 0000000..cbce583 --- /dev/null +++ b/research/tailLocal.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + + "github.com/nxadm/tail" +) + +var logFile = "/home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/Etherium_Intel_20220207_154354_93488613.txt" + +func main() { + t, err := tail.TailFile(logFile, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + fmt.Println(line.Text) + } +}