/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using Sog; using Sog.Gate; using ProtoCSStruct; namespace Version { public static class VersionCheckReqHandler { public static void ProcessVersionReq(uint gateServerID, ClientConnectInfo clientInfo, ref CSVersionCheckReq req) { VersionSvc m_versionSvc = VersionMsgHandler.GetInstance().GetVersionSvcObj(); ServerApp m_app = VersionMsgHandler.GetInstance().GetApp(); long sessionID = clientInfo.iConnectSessionID; //缺省渠道包默认为google包,由于历史原因,默认渠道设置为en //台湾金流包的差异包和huawei统一处理 if (req.Version.ApkChannel.IsEmpty()) { req.Version.ApkChannel.SetString("en"); } else if (req.Version.ApkChannel.GetString() == "google" || req.Version.ApkChannel.GetString() == "ios" || req.Version.Os.GetString() == "ios") { req.Version.ApkChannel.SetString("en"); } else if(req.Version.ApkChannel.GetString() == "jinliu") { req.Version.ApkChannel.SetString("huawei"); } else if(req.Version.ApkChannel.GetString() == "taptap") { req.Version.ApkChannel.SetString("taptap"); } //非法消息可以不用管 if (m_versionSvc.CheckValidVersionInfo(ref req.Version) == false) { TraceLog.Error("VersionCheckReqHandler.ProcessVersionReq versioninfo invalid! session {0}", sessionID); return; } VersionBillUtils.LogVersionCheck(ref req, clientInfo.ip); long reqVersion = AppVersion.ToIntVersion(req.Version.AppVersion.GetString()); if (reqVersion == 0) { TraceLog.Error("VersionCheckReqHandler.ProcessVersionReq versioninfo invalid, session {0}, version {1}", sessionID, req.Version.AppVersion); return; } long apkVersion = AppVersion.ToIntVersion(req.ApkVersion.GetString()); if (apkVersion == 0) { TraceLog.Error("VersionCheckReqHandler.ProcessVersionReq apkversion invalid, session {0}, ApkVersion {1}", sessionID, req.ApkVersion); return; } // 强行把windows版本修改成android版本, 方便unity下测试 if (req.Version.Os.Equals("win")) { req.Version.Os.SetString("android"); } int forReview = 0; CSVersionCheckRes res = new CSVersionCheckRes(); //不管如何,设置一下GateUrl,客户端没有这个会lua报错 res.GateUrl.SetString(""); res.ForReview = forReview; string gateUrl = m_versionSvc.SelectGateUrl(clientInfo.ip, ref req, out forReview); TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq SelectGateUrl session {0} gateUrl {1} forReview {2}" , sessionID, gateUrl, forReview); if (forReview == 1)//提审服,立刻返回,不存在维护状态和更新 { res.Ret = 0; res.NewVersion.SetString(req.Version.AppVersion.GetPtr()); res.GateUrl.SetString(gateUrl); res.ForReview = forReview; TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq version is need not check {0} , need not update, gateUrl {1}", req.Version, res.GateUrl); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } return; } bool maintenanceModeForThisClient = m_versionSvc.IsMaintenanceMode(); //如果配置了黑名单,那意思肯定就是永远不对这个客户端开放 //如果配置了白名单,那么维护的时候允许进入服务器 if(maintenanceModeForThisClient) { if(LimitIPList.IsWhiteVer(req.Version.Os.ToString(), reqVersion) || LimitIPList.IsIPInWhiteList(clientInfo.ip) || LimitIPList.IsDeviceIdInWhiteList(req.DeviceId.GetString())) { maintenanceModeForThisClient = false; } } else { if(LimitIPList.IsIPInBlackList(clientInfo.ip)) { maintenanceModeForThisClient = true; } } // 通知客户端系统维护 if (maintenanceModeForThisClient) { res.Ret = 0; res.MaintenanceMode = 1; res.MaintenanceNotice.SetString(m_versionSvc.GetMaintenanceNotice()); res.MaintenanceRemainTime = m_versionSvc.GetMaintenanceRemainTime(); TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq CheckIPValid failed, notify client MaintenanceMode, session {0} version {1} ip {2}" , sessionID, req.Version.AppVersion, clientInfo.ip); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } return; } string apkChannel = req.Version.ApkChannel.GetString(); string os = req.Version.Os.GetString(); TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq CheckIPValid success, session {0} version {1} ip {2} channel {3} os {4} apk {5} packageType {6}" , sessionID, req.Version.AppVersion, clientInfo.ip, apkChannel, os, req.ApkVersion, req.Version.PackageType); if(req.Version.ProductId.IsEmpty()) { req.Version.ProductId.SetString("wechat"); } long currVer = AppVersion.ToIntVersion(m_versionSvc.GetLatestVersion(ref req.Version)); if (m_versionSvc.IsSkipCheckVersion()) { res.Ret = 0; res.NewVersion.SetString(req.Version.AppVersion.GetPtr()); res.GateUrl.SetString(gateUrl); res.ForReview = forReview; TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq version is need not check {0} , need not update, gateUrl {1}", req.Version, res.GateUrl); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } return; } TraceLog.Debug("VersionCheckReqHandler.ProcessVersionReq versioninfo session {0}, Appversion {1} Os {2}, Language {3}, currVer {4}, reqVersion {5}", sessionID, req.Version.AppVersion, req.Version.Os, req.Version.Language, currVer, reqVersion); // 版本号比当前版本大, 不需要更新 if (reqVersion >= currVer) { res.Ret = 0; res.NewVersion.SetString(AppVersion.ToStringVersion(currVer)); res.GateUrl.SetString(gateUrl); res.ForReview = forReview; TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq reqVersion {0} >= curVersion {1}, need not udpate, gateUrl {2}" , req.Version, res.NewVersion, res.GateUrl); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } return; } else { //提示需要更新 res.Ret = 10; res.NewVersion.SetString(AppVersion.ToStringVersion(currVer)); res.ForReview = forReview; TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq reqVersion {0} < curVersion {1}, need udpate " , req.Version, res.NewVersion); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } return; } //配置了最小版本号限制 long minApkVersion = AppVersion.ToIntVersion(VersionServerUtils.GetServerConfig().minApkVersion); if(minApkVersion > apkVersion) { //打印日志 TraceLog.Debug("VersionCheckReqHandler.ProcessVersionReq req ApkVersion {0} < minApkVersion {1}, need jump to app store" , req.ApkVersion, VersionServerUtils.GetServerConfig().minApkVersion); } res.Ret = 0; res.NewVersion.SetString(AppVersion.ToStringVersion(currVer)); res.GateUrl.SetString(gateUrl); res.ForReview = forReview; //这种情况说明有更新包,那么清空hotpatch的信息(如果有的话) res.HotPatchFileMd5.Clear(); res.HotPatchFileSize = 0; res.HotPatchDownloadUrl.Clear(); res.HotPatchDownloadBackupUrl.Clear(); res.HotPatchUpdateSelf = 0; TraceLog.Trace("VersionCheckReqHandler.ProcessVersionReq path url is {0}, gateUrl {1} size {2} md5 {3}" , "", res.GateUrl, res.PatchFileSize, res.PatchFileMd5); if (gateServerID != 0) { GateService.SendToGate(0, m_app.GetCluster(), gateServerID, sessionID, (int)CSMsgID.VersionRes, ref res); } } } }