-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstation_part.go
123 lines (116 loc) · 3.51 KB
/
station_part.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
package main
import (
"fmt"
"strconv"
"strings"
"time"
)
//either adds new one with defined time or adds duration to existing
func update_sdonator(server, ckey string, dur time.Duration) bool {
defer logging_recover("update_sdonator")
ckey = ckey_simplifier(ckey)
state := db_template("update_station_donators").exec(server, ckey, int64(dur.Seconds())).count() > 0 || db_template("insert_station_donators").exec(server, ckey, time.Now().Add(dur).Unix()).count() > 0 //duration is in nanoseconds, we want seconds for unix format
if !state {
panic("add_sdonator failed horribly")
}
cleanup_sdonators()
return true
}
func cleanup_sdonators() {
defer logging_recover("cleanup_sd")
db_template("cleanup_station_donators").exec(time.Now().Unix())
}
func expend_donator(server, keyname string, curround int, role string, friends int, hunter bool) {
defer logging_recover("expend_donator")
ckey := ckey_simplifier(keyname)
cur_next_round := 0
db_template("check_station_donator_next_round").row(server, ckey).parse(&cur_next_round)
if curround > cur_next_round {
cur_next_round = curround
}
var cooldown int
var err error
switch role {
case "traitor":
cooldown, err = strconv.Atoi(get_config_must("st_d_traitor_cooldown"))
noerror(err)
case "changeling":
cooldown, err = strconv.Atoi(get_config_must("st_d_changeling_cooldown"))
noerror(err)
case "wizard":
cooldown, err = strconv.Atoi(get_config_must("st_d_wizard_cooldown"))
noerror(err)
case "devil":
cooldown, err = strconv.Atoi(get_config_must("st_d_devil_cooldown"))
noerror(err)
case "revenant":
cooldown, err = strconv.Atoi(get_config_must("st_d_revenant_cooldown"))
noerror(err)
}
if friends > 0 {
cooldown -= 1
if hunter {
cooldown -= 1
}
}
cur_next_round += cooldown
db_template("expend_station_donator").exec(server, ckey, cur_next_round)
}
func check_donators(server string, round int) string {
defer logging_recover("check_donators")
cleanup_sdonators()
res := make([]string, 0)
tmp := ""
callback := func() {
res = append(res, tmp)
}
db_template("check_station_donators").query(server, round).parse(callback, &tmp)
return strings.Join(res, " ")
}
func list_donators(server string) string {
defer logging_recover("list_donators")
cleanup_sdonators()
ret := ""
var ckey string
var uptotime int64
var next_round int
closure_callback := func() {
time_secs := uptotime - time.Now().Unix()
time_minutes := time_secs / 60
time_hours := time_minutes / 60
time_days := time_hours / 24
time_secs %= 60
time_minutes %= 60
time_hours %= 24
ret += fmt.Sprintf("`%v` -> **%vd %vh %vm %vs** *%v*\n", ckey, time_days, time_hours, time_minutes, time_secs, next_round)
}
db_template("list_station_donators").query(server).parse(closure_callback, &ckey, &uptotime, &next_round)
return ret
}
func get_donator(server, key string) string {
defer logging_recover("get_donator")
cleanup_sdonators()
ret := ""
key = ckey_simplifier(key)
var ckey string
var uptotime int64
var next_round int
closure_callback := func() {
if key != ckey {
return
}
time_secs := uptotime - time.Now().Unix()
time_minutes := time_secs / 60
time_hours := time_minutes / 60
time_days := time_hours / 24
time_secs %= 60
time_minutes %= 60
time_hours %= 24
ret += fmt.Sprintf("`%v` -> **%vd %vh %vm %vs** *%v*\n", ckey, time_days, time_hours, time_minutes, time_secs, next_round)
}
db_template("list_station_donators").query(server).parse(closure_callback, &ckey, &uptotime, &next_round)
if ret == "" {
ret = "no active sdonators"
}
return ret
}