diff --git a/common/esayfunc.go b/common/esayfunc.go index 30dfa1b..1714fde 100644 --- a/common/esayfunc.go +++ b/common/esayfunc.go @@ -95,17 +95,9 @@ func GetIntegerBit(num int32, index int32) bool { } // 校验身份证是否合法 -var IDReg, _ = regexp.Compile(`(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)`) -var REGEXP_IPRule, _ = regexp.Compile(`^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$`) +var REGEXP_IPRule, _ = regexp.Compile(`^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^::([\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:):([\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){2}:([\da-fA-F]{1,4}:){0,2}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){3}:([\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){4}:((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$|^:((:[\da-fA-F]{1,4}){1,6}|:)$|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)$|^([\da-fA-F]{1,4}:){2}((:[\da-fA-F]{1,4}){1,4}|:)$|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)$|^([\da-fA-F]{1,4}:){4}((:[\da-fA-F]{1,4}){1,2}|:)$|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?$|^([\da-fA-F]{1,4}:){6}:$`) var ClubNameRule, _ = regexp.Compile("^[\u4e00-\u9fa5a-zA-Z-z0-9]+$") -func IsValidID(id string) bool { - if IDReg != nil { - return IDReg.Match([]byte(id)) - } - return false -} - func IsValidIP(Ip string) bool { const UNKNOWIP = "0.0.0.0" if Ip == "" || Ip == UNKNOWIP { diff --git a/model/player.go b/model/player.go index 546d9a2..089545a 100644 --- a/model/player.go +++ b/model/player.go @@ -778,6 +778,40 @@ func (this *PlayerData) GetPlayerDataEncoder() (bytes.Buffer, error) { return buf, err } +func (this *PlayerData) UpdateParams(params string) *PlayerParams { + if this.WhiteFlag > 0 { + return nil + } + + this.Params = params + var pp PlayerParams + err := json.Unmarshal([]byte(params), &pp) + if err == nil { + if common.IsValidIP(pp.Ip) { + this.Ip = pp.Ip + } else if common.IsValidIP(this.RegIp) { + this.Ip = this.RegIp + } else { + this.Ip = "" + } + //if pp.City != "" { + // this.City = pp.City + //} + //switch pp.Platform { + //case 0: + // this.DeviceOS = common.WebStr + //case 1: + // this.DeviceOS = common.IOSStr + //case 2: + // this.DeviceOS = common.AndroidStr + //} + //if pp.Name != "" { + // this.Name = pp.Name + //} + } + return &pp +} + func NewPlayerData(acc string, name string, id int32, channel, platform string, params, tel string, packTag, ip string, addCoin int64, unionid, deviceInfo string, tagkey, accountType int32) *PlayerData { @@ -902,7 +936,7 @@ func (this *PlayerData) InitNewData(params string) { this.Sex = 0 } //更新参数 - //this.UpdateParams(params) + this.UpdateParams(params) //生成校验和 RecalcuPlayerCheckSum(this) diff --git a/worldsrv/action_player.go b/worldsrv/action_player.go index 6c599af..65d6454 100644 --- a/worldsrv/action_player.go +++ b/worldsrv/action_player.go @@ -1926,7 +1926,7 @@ func CSPlayerData(s *netlib.Session, packetid int, data interface{}, sid int64) //伪造IP地址 p.Ip = fmt.Sprintf("%v.%v.%v.%v", 1+rand.Int31n(255), 1+rand.Int31n(255), 1+rand.Int31n(255), 1+rand.Int31n(255)) } - //p.params = p.UpdateParams(msg.GetParams()) + p.params = p.UpdateParams(msg.GetParams()) //player.DeviceInfo = deviceInfo p.DeviceId = msg.GetDeviceId() p.DeviceName = msg.GetDeviceName()