/** * 挂载玩家数据实体 * @var Data_UserGame */ public $game; /** * @var bool userInfo是否需要回写 */ public $userInfoChanged = false; // /** * @param Req $req * @return Req */ public function __construct($req) { if (is_string($req)) { // fix黑窗调试直接调用 $req = JsonUtil::decode($req); } parent::__construct($req); if ($this->CV == "unityEditor") { # 对特殊CV做下处理 $this->CV = "999.999.999"; } self::$_req = $this; // ---赋值--- switch ($this->cmd) { case CmdCode::cmd_user_getzonelist: # 下载分区列表 case CmdCode::cmd_user_loginuserinfo : # 登录 case CmdCode::cmd_user_gameconstinfo : # 下载常量 //case CmdCode::cmd_user_registerNewRole : # 测试注册角色 # 这些消息不需要初始化UserInfo break; default : # 其余消息,初始化UserInfo if ($this->uid) { $this->game = UserProc::getUserGame($this->zoneid, $this->uid); if (null == $this->game) { Err(">>>>>>>>>>用户数据读取为空!!<<<<<<<<<<<[$this->uid]:PreProc"); } if (!Index::$isDebugging && $this->TK != $this->game->TK) { Err(ErrCode::err_anotherlogin); } } break; } } /** * 把Req对象序列化到字符串 * @return type */ public function __toString() { $clone = clone $this; unset($clone->userInfoChanged); # 删除不必要的字段 unset($clone->game); # 删除不必要的字段 $str = JsonUtil::encode($clone); # json return $str; } /** * 获得用户的平台字符串 * @return string */ function getPlatStr() { $uid = $this->uid; return match (PLAT) { Enum_Plat::Online_dev => 'qzone', # # 过时的平台,QQ空间 Enum_Plat::Online_IOS => 'ios', # # ios平台, 尚未开启 default => strrpos($uid, '_') > 0 ? substr($uid, strrpos($uid, '_') + 1) : "", # 提取渠道后缀字符串 }; // switch (PLAT) { // case 'web': # web版 // return 'qzone'; # only QQ空间 // case 'ios': # ios版 // return 'ios'; # only ios // case 'and': # 安卓版/默认 // default : // return strrpos($uid, '_') > 0 ? substr($uid, strrpos($uid, '_') + 1) : ""; # 提取平台字符串 // } //PS. substr() 函数返回字符串的一部分 strrpos() 函数查找字符串在另一字符串中最后一次出现的位置。 } /** * 获得用户的平台唯一id. * @return string */ public function getPlatOid() { return substr($this->uid, 0, strrpos($this->uid, '_')); # 提取平台给的唯一id字符串 //PS. substr() 函数返回字符串的一部分 strrpos() 函数查找字符串在另一字符串中最后一次出现的位置。 } /** * 将要进行存储的数据 * @return Req */ public function storage() { $clone = clone $this; if (!$clone->userInfoChanged) { unset($clone->game); # 删除不必要的字段 } return (array) $clone; } // /** * 全局实例 * @return Req */ public static function Ins() { return self::$_req; } private static $_req; // }