好友邀请码
This commit is contained in:
parent
1d22f2052e
commit
6f7280e8b5
@ -32,6 +32,8 @@ const (
|
|||||||
CONDITION_LT = "<" // 小于
|
CONDITION_LT = "<" // 小于
|
||||||
CONDITION_GE = ">=" // 大于等于
|
CONDITION_GE = ">=" // 大于等于
|
||||||
CONDITION_LE = "<=" // 小于等于
|
CONDITION_LE = "<=" // 小于等于
|
||||||
|
|
||||||
|
LETTER = "GhCvgqSNTUMVeRfwakiYmcxWKtJQpZrDIBXnPyLsAFdzjHbulE"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 加密字符串
|
// 加密字符串
|
||||||
@ -312,3 +314,114 @@ func UniqueInts(input []int) []int {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#codebase: GoUtil
|
||||||
|
修改函数UniqueStringFromInt
|
||||||
|
|
||||||
|
功能说明:
|
||||||
|
将整数转换为包含字母和数字的唯一字符串
|
||||||
|
|
||||||
|
算法步骤:
|
||||||
|
1. 将输入整数格式化为5位数字符串(不足前补0)
|
||||||
|
2. 分割字符串:前2位、中2位、最后1位
|
||||||
|
3. 将各段转为整数,作为字母表索引
|
||||||
|
4. 从预定义字母表中选择对应字符
|
||||||
|
5. 随机生成2个数字字符
|
||||||
|
6. 随机插入数字字符到字母串中
|
||||||
|
7. 返回最终唯一标识字符串
|
||||||
|
*/
|
||||||
|
|
||||||
|
func UniqueStringFromInt(n int) string {
|
||||||
|
n = n % 100000 // 确保n在0-99999范围内
|
||||||
|
str := fmt.Sprintf("%05d", n)
|
||||||
|
a1 := str[0:2]
|
||||||
|
a2 := str[2:4]
|
||||||
|
a3 := str[4:5]
|
||||||
|
|
||||||
|
s1, _ := strconv.Atoi(a1)
|
||||||
|
s2, _ := strconv.Atoi(a2)
|
||||||
|
s3, _ := strconv.Atoi(a3)
|
||||||
|
|
||||||
|
// 修改索引计算逻辑
|
||||||
|
var letter1, letter2 string
|
||||||
|
if s1 >= len(LETTER) {
|
||||||
|
letter1 = string(LETTER[s1%len(LETTER)]) + strconv.Itoa(s1/len(LETTER))
|
||||||
|
} else {
|
||||||
|
letter1 = string(LETTER[s1])
|
||||||
|
}
|
||||||
|
|
||||||
|
if s2 >= len(LETTER) {
|
||||||
|
idx := (s2) % len(LETTER)
|
||||||
|
letter2 = string(LETTER[idx]) + strconv.Itoa(s2/len(LETTER))
|
||||||
|
} else {
|
||||||
|
letter2 = string(LETTER[s2])
|
||||||
|
}
|
||||||
|
|
||||||
|
letter3 := string(LETTER[s3+20])
|
||||||
|
letter := fmt.Sprintf("%s%s%s", letter1, letter2, letter3)
|
||||||
|
lastLetter := 5 - len(letter)
|
||||||
|
indices := rand.Perm(8)[:2]
|
||||||
|
chars := []byte{byte('2' + indices[0]), byte('2' + indices[1])}
|
||||||
|
if lastLetter > 0 {
|
||||||
|
for i := 0; i < lastLetter; i++ {
|
||||||
|
insertPos1 := rand.Intn(len(letter) + 1)
|
||||||
|
letter = letter[:insertPos1] + string(chars[0]) + letter[insertPos1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos := rand.Intn(len(LETTER))
|
||||||
|
letter += string(LETTER[pos])
|
||||||
|
return fmt.Sprintf("%s-%s", letter[:3], letter[3:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// 反解析 UniqueStringFromInt 生成的字符串,返回原始整数(0-99999),失败返回 -1
|
||||||
|
func ParseUniqueStringToInt(s string) int {
|
||||||
|
arr := strings.Split(s, "-")
|
||||||
|
// 去除字符串中大于1的数字
|
||||||
|
s1 := arr[2] + arr[3]
|
||||||
|
s1 = s1[:len(s1)-1] // 去掉最后一个字符
|
||||||
|
s2 := ""
|
||||||
|
for _, ch := range s1 {
|
||||||
|
if ch < '2' || ch > '9' {
|
||||||
|
s2 += string(ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index1 := 0
|
||||||
|
s3 := ""
|
||||||
|
for i := 0; i < len(s2); i++ {
|
||||||
|
index := strings.Index(LETTER, string(s2[i]))
|
||||||
|
|
||||||
|
if i < len(s2)-1 && s2[i+1] == '1' {
|
||||||
|
index += len(LETTER)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
index1++
|
||||||
|
if i == len(s2)-1 {
|
||||||
|
index -= 20 // 最后一位是字母,减去20
|
||||||
|
s3 += fmt.Sprintf("%d", index)
|
||||||
|
} else {
|
||||||
|
s3 += fmt.Sprintf("%02d", index)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return Int(s3)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GenerateShuffledAlphabet() string {
|
||||||
|
// 包含所有大小写字母的字符串
|
||||||
|
alphabet := "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
// 转换为字节切片以便打乱
|
||||||
|
bytes := []byte(alphabet)
|
||||||
|
|
||||||
|
// 使用当前时间作为随机种子
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
// Fisher-Yates 洗牌算法
|
||||||
|
for i := len(bytes) - 1; i > 0; i-- {
|
||||||
|
j := rand.Intn(i + 1)
|
||||||
|
bytes[i], bytes[j] = bytes[j], bytes[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|||||||
@ -51,8 +51,8 @@ var Server struct {
|
|||||||
KafkaHost string
|
KafkaHost string
|
||||||
KafkaPort string
|
KafkaPort string
|
||||||
Version string
|
Version string
|
||||||
|
CountryCode string
|
||||||
IdVerify bool
|
IdVerify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
"RedisPort" :"6379",
|
"RedisPort" :"6379",
|
||||||
"RedisPwd" :"",
|
"RedisPwd" :"",
|
||||||
"GoogleVerify":false,
|
"GoogleVerify":false,
|
||||||
|
"CountryCode" : "001",
|
||||||
"RemoteAddr":"host.docker.internal:9001",
|
"RemoteAddr":"host.docker.internal:9001",
|
||||||
"Partition":3,
|
"Partition":3,
|
||||||
"KafkaHost":"kafka-server",
|
"KafkaHost":"kafka-server",
|
||||||
|
|||||||
@ -736,6 +736,7 @@ func (ad *GameLogic) RegisterNetWorkFunc() {
|
|||||||
RegisterMsgProcessFunc("ReqFriendTLUpvote", ReqFriendTLUpvote) // 请求时间线点赞
|
RegisterMsgProcessFunc("ReqFriendTLUpvote", ReqFriendTLUpvote) // 请求时间线点赞
|
||||||
RegisterMsgProcessFunc("ReqAddNpc", ReqAddNpc) // 增加npc
|
RegisterMsgProcessFunc("ReqAddNpc", ReqAddNpc) // 增加npc
|
||||||
RegisterMsgProcessFunc("ReqWishApply", ReqWishApply) // 同意好友心愿单请求
|
RegisterMsgProcessFunc("ReqWishApply", ReqWishApply) // 同意好友心愿单请求
|
||||||
|
RegisterMsgProcessFunc("ReqFriendByCode", ReqFriendByCode) // 根据邀请码查询好友
|
||||||
|
|
||||||
RegisterMsgProcessFunc("ReqSearchPlayer", ReqSearchPlayer) // 搜索好友
|
RegisterMsgProcessFunc("ReqSearchPlayer", ReqSearchPlayer) // 搜索好友
|
||||||
RegisterMsgProcessFunc("ReqApplyFriend", ReqApplyFriend) // 申请好友
|
RegisterMsgProcessFunc("ReqApplyFriend", ReqApplyFriend) // 申请好友
|
||||||
|
|||||||
@ -147,3 +147,25 @@ func (p *Player) NotifyPlayroomKiss() {
|
|||||||
}
|
}
|
||||||
p.PushClientRes(m)
|
p.PushClientRes(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BackUserInfo(p *Player) {
|
||||||
|
BaseMod := p.PlayMod.getBaseMod()
|
||||||
|
FaceMod := p.PlayMod.getFaceMod()
|
||||||
|
AvatarMod := p.PlayMod.getAvatarMod()
|
||||||
|
DecorateMod := p.PlayMod.getDecorateMod()
|
||||||
|
p.PushClientRes(&proto.UserInfo{
|
||||||
|
Uid: p.M_DwUin,
|
||||||
|
Nickname: BaseMod.NickName,
|
||||||
|
Avatar: int32(AvatarMod.SetId),
|
||||||
|
Face: int32(FaceMod.SetId),
|
||||||
|
DecorateCnt: int32(DecorateMod.DecorateNum),
|
||||||
|
AvatarList: AvatarMod.BackData(),
|
||||||
|
FaceList: FaceMod.BackData(),
|
||||||
|
EmojiList: p.PlayMod.getEmojiMod().BackData(),
|
||||||
|
SetEmoji: p.PlayMod.getEmojiMod().GetEmojiSet(),
|
||||||
|
Login: int32(BaseMod.GetLoginTime()),
|
||||||
|
PetName: BaseMod.PetName,
|
||||||
|
IdNum: BaseMod.IdCardNum,
|
||||||
|
AddCode: BaseMod.AddCode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -586,27 +586,6 @@ func CancelOrder(p *Player, OrderSn string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func BackUserInfo(p *Player) {
|
|
||||||
BaseMod := p.PlayMod.getBaseMod()
|
|
||||||
FaceMod := p.PlayMod.getFaceMod()
|
|
||||||
AvatarMod := p.PlayMod.getAvatarMod()
|
|
||||||
DecorateMod := p.PlayMod.getDecorateMod()
|
|
||||||
p.PushClientRes(&proto.UserInfo{
|
|
||||||
Uid: p.M_DwUin,
|
|
||||||
Nickname: BaseMod.NickName,
|
|
||||||
Avatar: int32(AvatarMod.SetId),
|
|
||||||
Face: int32(FaceMod.SetId),
|
|
||||||
DecorateCnt: int32(DecorateMod.DecorateNum),
|
|
||||||
AvatarList: AvatarMod.BackData(),
|
|
||||||
FaceList: FaceMod.BackData(),
|
|
||||||
EmojiList: p.PlayMod.getEmojiMod().BackData(),
|
|
||||||
SetEmoji: p.PlayMod.getEmojiMod().GetEmojiSet(),
|
|
||||||
Login: int32(BaseMod.GetLoginTime()),
|
|
||||||
PetName: BaseMod.PetName,
|
|
||||||
IdNum: BaseMod.IdCardNum,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCardInfoMsg(CardInfo *card.CardInfo) *proto.ResFriendCard {
|
func GetCardInfoMsg(CardInfo *card.CardInfo) *proto.ResFriendCard {
|
||||||
Uid := 0
|
Uid := 0
|
||||||
if CardInfo.Type == card.TYPE_CARD_SEND {
|
if CardInfo.Type == card.TYPE_CARD_SEND {
|
||||||
@ -747,9 +726,6 @@ func GetRecommendPlayer(p *Player, Num int) []int {
|
|||||||
PlayerList1 := make([]int, 0)
|
PlayerList1 := make([]int, 0)
|
||||||
FriendMod := p.PlayMod.getFriendMod()
|
FriendMod := p.PlayMod.getFriendMod()
|
||||||
for _, v := range PlayerList {
|
for _, v := range PlayerList {
|
||||||
if v.Score < 15 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if v.Uid == int(p.M_DwUin) {
|
if v.Uid == int(p.M_DwUin) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"server/GoUtil"
|
"server/GoUtil"
|
||||||
|
"server/conf"
|
||||||
cardCfg "server/conf/card"
|
cardCfg "server/conf/card"
|
||||||
collectCfg "server/conf/collect"
|
collectCfg "server/conf/collect"
|
||||||
decorateCfg "server/conf/decorate"
|
decorateCfg "server/conf/decorate"
|
||||||
@ -4448,3 +4449,45 @@ func ReqId2Verify(player *Player, buf []byte) error {
|
|||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReqFriendByCode(player *Player, buf []byte) error {
|
||||||
|
req := &msg.ReqFriendByCode{}
|
||||||
|
proto.Unmarshal(buf, req)
|
||||||
|
if req.Code == "" {
|
||||||
|
player.SendErrClienRes(&msg.ResFriendByCode{
|
||||||
|
Code: msg.RES_CODE_FAIL,
|
||||||
|
Msg: "code is empty",
|
||||||
|
})
|
||||||
|
return fmt.Errorf("code is empty")
|
||||||
|
}
|
||||||
|
CodeNum := GoUtil.ParseUniqueStringToInt(req.Code)
|
||||||
|
if CodeNum <= 0 {
|
||||||
|
player.SendErrClienRes(&msg.ResFriendByCode{
|
||||||
|
Code: msg.RES_CODE_FAIL,
|
||||||
|
Msg: "code is invalid",
|
||||||
|
})
|
||||||
|
return fmt.Errorf("code is invalid")
|
||||||
|
}
|
||||||
|
Uid := int64(CodeNum) + int64(conf.Server.ServerID*100000) + int64(conf.Server.AppID*100000000)
|
||||||
|
if Uid == player.M_DwUin {
|
||||||
|
player.SendErrClienRes(&msg.ResFriendByCode{
|
||||||
|
Code: msg.RES_CODE_FAIL,
|
||||||
|
Msg: "can not add yourself",
|
||||||
|
})
|
||||||
|
return fmt.Errorf("can not add yourself")
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerSimpleData := G_GameLogicPtr.GetResSimplePlayerByUid(int(Uid))
|
||||||
|
if PlayerSimpleData == nil {
|
||||||
|
player.SendErrClienRes(&msg.ResFriendByCode{
|
||||||
|
Code: msg.RES_CODE_FAIL,
|
||||||
|
Msg: "player not exist",
|
||||||
|
})
|
||||||
|
return fmt.Errorf("player not exist")
|
||||||
|
}
|
||||||
|
player.PushClientRes(&msg.ResFriendByCode{
|
||||||
|
Code: msg.RES_CODE_SUCCESS,
|
||||||
|
Player: PlayerSimpleData,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package base
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"server/GoUtil"
|
"server/GoUtil"
|
||||||
|
"server/conf"
|
||||||
baseCfg "server/conf/base"
|
baseCfg "server/conf/base"
|
||||||
"server/game/mod/item"
|
"server/game/mod/item"
|
||||||
"server/msg"
|
"server/msg"
|
||||||
@ -41,12 +42,17 @@ type Base struct {
|
|||||||
Lang msg.LANG_TYPE // 语言
|
Lang msg.LANG_TYPE // 语言
|
||||||
IdCardName string
|
IdCardName string
|
||||||
IdCardNum string
|
IdCardNum string
|
||||||
|
AddCode string // 用于添加好友的code
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Base) InitData(Uid int) {
|
func (b *Base) InitData(Uid int) {
|
||||||
// b.EnergyMul = 1
|
if b.AddCode == "" {
|
||||||
// b.IsFirstBuy = false
|
CountryCode := conf.Server.CountryCode
|
||||||
// b.EnergyBuy = 0
|
if CountryCode == "" {
|
||||||
|
CountryCode = "000"
|
||||||
|
}
|
||||||
|
b.AddCode = fmt.Sprintf("MMM-%s-%s", conf.Server.CountryCode, GoUtil.UniqueStringFromInt(Uid))
|
||||||
|
}
|
||||||
if b.NickName == "" {
|
if b.NickName == "" {
|
||||||
b.NickName = fmt.Sprintf("Player_%d", Uid)
|
b.NickName = fmt.Sprintf("Player_%d", Uid)
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user