-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
163 lines (154 loc) · 3.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (C) 2018 Betalo AB - All Rights Reserved
package main
import (
"fmt"
"forward/WindowsUI"
"strings"
"sync"
"time"
)
var i int32
var j int32
var AllowMinutesToPlay int32
var isKilled bool
var killTime string
var startTime string
var endTime string
var StrProcess string
func main() {
//time.Minute to time.Second
var GameTicker = time.NewTicker(time.Minute * 1) // 每分钟执行一次
i = 0
j = 0
AllowMinutesToPlay = 34
isKilled = false
killTime = ""
startTime = "" //no use it
endTime = ""
cf := "./configs.toml"
StrProcess = "Palgame.exe,YURI.exe,gamemd.exe,msedge.exe"
if ExistsFile(cf) {
cfConf, err := ReadConfigs(cf)
if err != nil {
fmt.Println("config file not exist.")
}
StrProcess = cfConf.KillProcessName
AllowMinutesToPlay = cfConf.AllowMinutesToPlay
}
fmt.Println(StrProcess)
fp := "./gamekill.toml"
if ExistsFile(fp) {
conf, err := ReadToml(fp)
if err != nil {
i = 0
j = 0
isKilled = false
killTime = ""
startTime = ""
endTime = ""
} else {
i = conf.CountI
j = conf.CountJ
isKilled = conf.IsKilled
killTime = conf.KillTime
startTime = conf.StartTime
endTime = conf.EndTime
if killTime != "" {
stamp, _ := time.ParseInLocation("2006-01-02 15:04:05", killTime, time.Local)
t := time.Now()
diff := t.Sub(stamp)
m := int32(diff.Minutes())
if m > 175 {
i = 0
j = 0
isKilled = false
killTime = ""
startTime = ""
endTime = ""
} else {
j = m
}
}
if endTime != "" && !isKilled {
stamp, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
t := time.Now()
diff := t.Sub(stamp)
m := int32(diff.Minutes())
if m > 160 {
i = 0
j = 0
isKilled = false
killTime = ""
startTime = ""
endTime = ""
}
}
}
}
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
for range GameTicker.C {
if isGameProcessExist() && !isKilled {
if i == 0 {
startTime = time.Now().Format("2006-01-02 15:04:05")
}
endTime = time.Now().Format("2006-01-02 15:04:05")
i++
if i > AllowMinutesToPlay-2 && i < AllowMinutesToPlay+1 { //32
WindowsUI.WTSSendMessage(1, "Hello", "The Game time is coming to end, Please save !", WindowsUI.MB_YESNO, 30)
}
if i > AllowMinutesToPlay {
KillAllGameProcess()
isKilled = true
killTime = time.Now().Format("2006-01-02 15:04:05")
startTime = ""
endTime = ""
}
}
if isKilled {
j++
KillAllGameProcess()
if j > 180 {
i = 0
j = 0
isKilled = false
killTime = ""
startTime = ""
endTime = ""
}
}
fmt.Println(i, j, isKilled, killTime)
WriteToml(fp, i, j, isKilled, killTime, startTime, endTime)
}
}()
wg.Wait()
fmt.Println("bye")
}
func KillAllGameProcess() {
tmp := strings.Split(StrProcess, ",")
for i := 0; i < len(tmp); i++ {
killProcessByName(strings.TrimSpace(tmp[i]))
}
}
func isGameProcessExist() bool {
/*
a, _, _ := isProcessExist("Palgame.exe")
b, _, _ := isProcessExist("YURI.exe")
c, _, _ := isProcessExist("gamemd.exe")
d, _, _ := isProcessExist("msedge.exe")
if a || b || c || d {
return true
} else {
return false
}*/
boolTmp := false
tmp := strings.Split(StrProcess, ",")
for i := 0; i < len(tmp); i++ {
a, _, _ := isProcessExist(strings.TrimSpace(tmp[i]))
if a {
boolTmp = true
}
}
return boolTmp
}