mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 15:34:38 +01:00
fix RNG
This commit is contained in:
@@ -2,6 +2,7 @@ package mhfitem
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
|
"erupe-ce/common/token"
|
||||||
_config "erupe-ce/config"
|
_config "erupe-ce/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,6 +44,9 @@ type MHFItemStack struct {
|
|||||||
func ReadWarehouseItem(bf *byteframe.ByteFrame) MHFItemStack {
|
func ReadWarehouseItem(bf *byteframe.ByteFrame) MHFItemStack {
|
||||||
var item MHFItemStack
|
var item MHFItemStack
|
||||||
item.WarehouseID = bf.ReadUint32()
|
item.WarehouseID = bf.ReadUint32()
|
||||||
|
if item.WarehouseID == 0 {
|
||||||
|
item.WarehouseID = token.RNG.Uint32()
|
||||||
|
}
|
||||||
item.Item.ItemID = bf.ReadUint16()
|
item.Item.ItemID = bf.ReadUint16()
|
||||||
item.Quantity = bf.ReadUint16()
|
item.Quantity = bf.ReadUint16()
|
||||||
item.Unk0 = bf.ReadUint32()
|
item.Unk0 = bf.ReadUint32()
|
||||||
@@ -76,6 +80,9 @@ func ReadWarehouseEquipment(bf *byteframe.ByteFrame) MHFEquipment {
|
|||||||
equipment.Sigils[i].Effects = make([]MHFSigilEffect, 3)
|
equipment.Sigils[i].Effects = make([]MHFSigilEffect, 3)
|
||||||
}
|
}
|
||||||
equipment.WarehouseID = bf.ReadUint32()
|
equipment.WarehouseID = bf.ReadUint32()
|
||||||
|
if equipment.WarehouseID == 0 {
|
||||||
|
equipment.WarehouseID = token.RNG.Uint32()
|
||||||
|
}
|
||||||
equipment.ItemType = bf.ReadUint8()
|
equipment.ItemType = bf.ReadUint8()
|
||||||
equipment.Unk0 = bf.ReadUint8()
|
equipment.Unk0 = bf.ReadUint8()
|
||||||
equipment.ItemID = bf.ReadUint16()
|
equipment.ItemID = bf.ReadUint16()
|
||||||
|
|||||||
@@ -5,18 +5,19 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var RNG = NewRNG()
|
||||||
|
|
||||||
// Generate returns an alphanumeric token of specified length
|
// Generate returns an alphanumeric token of specified length
|
||||||
func Generate(length int) string {
|
func Generate(length int) string {
|
||||||
rng := RNG()
|
|
||||||
var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
b := make([]rune, length)
|
b := make([]rune, length)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
b[i] = chars[rng.Intn(len(chars))]
|
b[i] = chars[RNG.Intn(len(chars))]
|
||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RNG returns a new RNG generator
|
// NewRNG returns a new NewRNG generator
|
||||||
func RNG() *rand.Rand {
|
func NewRNG() *rand.Rand {
|
||||||
return rand.New(rand.NewSource(time.Now().UnixNano()))
|
return rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
m := binpacket.MsgBinChat{
|
m := binpacket.MsgBinChat{
|
||||||
Type: BinaryMessageTypeChat,
|
Type: BinaryMessageTypeChat,
|
||||||
Flags: 4,
|
Flags: 4,
|
||||||
Message: fmt.Sprintf(`%d`, token.RNG().Intn(100)+1),
|
Message: fmt.Sprintf(`%d`, token.RNG.Intn(100)+1),
|
||||||
SenderName: author,
|
SenderName: author,
|
||||||
}
|
}
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ func generateFeatureWeapons(count int) activeFeature {
|
|||||||
nums := make([]int, 0)
|
nums := make([]int, 0)
|
||||||
var result int
|
var result int
|
||||||
for len(nums) < count {
|
for len(nums) < count {
|
||||||
rng := token.RNG()
|
num := token.RNG.Intn(_max)
|
||||||
num := rng.Intn(_max)
|
|
||||||
exist := false
|
exist := false
|
||||||
for _, v := range nums {
|
for _, v := range nums {
|
||||||
if v == num {
|
if v == num {
|
||||||
|
|||||||
@@ -455,7 +455,7 @@ func handleMsgMhfEntryFesta(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleFail(s, pkt.AckHandle, make([]byte, 4))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
team := uint32(token.RNG().Intn(2))
|
team := uint32(token.RNG.Intn(2))
|
||||||
switch team {
|
switch team {
|
||||||
case 0:
|
case 0:
|
||||||
s.server.db.Exec("INSERT INTO festa_registrations VALUES ($1, 'blue')", guild.ID)
|
s.server.db.Exec("INSERT INTO festa_registrations VALUES ($1, 'blue')", guild.ID)
|
||||||
|
|||||||
@@ -433,13 +433,14 @@ func handleMsgMhfOperateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
func addWarehouseItem(s *Session, item mhfitem.MHFItemStack) {
|
func addWarehouseItem(s *Session, item mhfitem.MHFItemStack) {
|
||||||
giftBox := warehouseGetItems(s, 10)
|
giftBox := warehouseGetItems(s, 10)
|
||||||
item.WarehouseID = token.RNG().Uint32()
|
item.WarehouseID = token.RNG.Uint32()
|
||||||
giftBox = append(giftBox, item)
|
giftBox = append(giftBox, item)
|
||||||
s.server.db.Exec("UPDATE warehouse SET item10=$1 WHERE character_id=$2", mhfitem.SerializeWarehouseItems(giftBox), s.charID)
|
s.server.db.Exec("UPDATE warehouse SET item10=$1 WHERE character_id=$2", mhfitem.SerializeWarehouseItems(giftBox), s.charID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addWarehouseEquipment(s *Session, equipment mhfitem.MHFEquipment) {
|
func addWarehouseEquipment(s *Session, equipment mhfitem.MHFEquipment) {
|
||||||
giftBox := warehouseGetEquipment(s, 10)
|
giftBox := warehouseGetEquipment(s, 10)
|
||||||
|
equipment.WarehouseID = token.RNG.Uint32()
|
||||||
giftBox = append(giftBox, equipment)
|
giftBox = append(giftBox, equipment)
|
||||||
s.server.db.Exec("UPDATE warehouse SET equip10=$1 WHERE character_id=$2", mhfitem.SerializeWarehouseEquipment(giftBox), s.charID)
|
s.server.db.Exec("UPDATE warehouse SET equip10=$1 WHERE character_id=$2", mhfitem.SerializeWarehouseEquipment(giftBox), s.charID)
|
||||||
}
|
}
|
||||||
@@ -509,7 +510,7 @@ func handleMsgMhfUpdateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
uItem.WarehouseID = token.RNG().Uint32()
|
uItem.WarehouseID = token.RNG.Uint32()
|
||||||
fItems = append(fItems, uItem)
|
fItems = append(fItems, uItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,7 +533,7 @@ func handleMsgMhfUpdateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
uEquip.WarehouseID = token.RNG().Uint32()
|
uEquip.WarehouseID = token.RNG.Uint32()
|
||||||
fEquip = append(fEquip, uEquip)
|
fEquip = append(fEquip, uEquip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user