forked from cernodile/reEgg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ei_server_gifts.go
100 lines (82 loc) · 2.37 KB
/
ei_server_gifts.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
package main
import (
"log"
"time"
ei "biehdc.reegg/eggpb"
"google.golang.org/protobuf/proto"
)
// get_periodicals: user_id:"aaa" piggy_full:true piggy_found_full:false seconds_full_realtime:96802.13004922867 seconds_full_gametime:13304.21092633903 soul_eggs:1290.0000000000002 current_client_version:26 debug:false
func (egg *eggstore) serverGifts(pr *ei.GetPeriodicalsRequest) []*ei.ServerGift {
if pr.UserId == nil {
return nil
}
pending, _ := egg.pendinggifts.LoadAndDelete(*pr.UserId)
//delete(egg.pendinggifts, *pr.UserId)
backup, _ := egg.users.Load(*pr.UserId)
gift := serverGiftEarningsboost(backup)
if gift != nil {
//log.Printf("user %s is getting free money: %f", *pr.UserId, *gift.RewardAmount)
pending = append(pending, gift)
}
return pending
}
// random money
func serverGiftEarningsboost(backup *ei.Backup) *ei.ServerGift {
if backup == nil {
return nil
}
if backup.Game == nil {
return nil
}
if backup.Game.CurrentFarm == nil {
return nil
}
currentfarmid := *backup.Game.CurrentFarm
if backup.Farms == nil {
return nil
}
if backup.Farms[currentfarmid] == nil {
return nil
}
farm := backup.Farms[currentfarmid]
if farm.CashEarned == nil {
return nil
}
cash := *farm.CashEarned
var (
reward = ei.RewardType_CASH
amount = cash / 5 // idk yet, maybe?
)
casheggs := ei.ServerGift{
RewardType: &reward,
RewardAmount: &amount,
}
return &casheggs
}
// make 250 soul eggs for contracts
func serverGiftSouleggs(amount float64) *ei.ServerGift {
var reward = ei.RewardType_SOUL_EGGS
souleggs := ei.ServerGift{
RewardType: &reward,
RewardAmount: &amount,
}
return &souleggs
}
func path_daily_gift_info(_ []byte) []byte {
today := time.Now()
gametoday := today.Sub(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))
currentday := uint32(gametoday.Hours() / 24)
tomorrow := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location()) //midnight today
tomorrow.AddDate(0, 0, 1) //midnight tomorrow
secondstonext := 86400 - today.Sub(tomorrow).Seconds()
dgi := ei.DailyGiftInfo{}
dgi.CurrentDay = ¤tday
dgi.SecondsToNextDay = &secondstonext
// log.Printf("dailygiftinfo: %s", dgi.String())
resp, err := proto.Marshal(&dgi)
if err != nil {
log.Printf("failed to marshal DailyGiftInfo: %s", err.Error())
return nil
}
return resp
}