123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881 |
- <?php
- //
- //namespace loyalsoft;
- //
- ///**
- // * 好友模块各种操作类型-枚举值
- // */
- //class enum_Friend_op extends Enum {
- //
- // const __default = 0;
- // // 删除好友
- // const remove = 1;
- // // 加好友
- // const apply = 2;
- // // 接受请求
- // const accepted = 3;
- // // 示好, 送心...
- // const gift = 4;
- // // 加好友请求的发送记录
- // const applied = 5;
- // // 示好,送心的记录
- // const giftrecord = 6;
- //
- //}
- //
- ///**
- // * 好友处理流程
- // * @version
- // * 1.0.0 Created at 2017-3-6. by --gwang
- // * @author gwang (mail@wanggangzero.cn)
- // * @copyright ? 2017-3-6, SJZ LoyalSoft Corporation & gwang. All rights reserved.
- // */
- //class FriendProc {
- //
- // /**
- // * 好友发送消息的最大长度(超过的截断)
- // */
- // const MaxMessageLength = 80;
- //
- // /**
- // * 逻辑分发
- // * 所有的Proc中必须有这样一个方法
- // * @param type $req
- // */
- // static function procMain($req) {
- // switch ($req->cmd) {
- // case CmdCode::cmd_user_friend_search: # [6110]查找好友
- // return FriendProc::SearchFriend($req);
- // case CmdCode::cmd_user_friend_suggestList: # [6111]添加好友界面获取一批推荐好友列表
- // return FriendProc::GetSuggestList($req);
- // case CmdCode::cmd_user_friend_get_list: # [6106]获取好友列表 ok下发好友个人公会信息
- // return FriendProc::getAppFriends($req);
- // case CmdCode::cmd_user_friend_get_infos: # [6107]获取详细信息
- // return FriendProc::getAppFriendInfos($req);
- //// ------------------------------------------
- //
- // case CmdCode::cmd_user_friend_gift_getlist: # [6113]拉取好友赠送礼物的记录
- // return FriendProc::getAppFriendGiftList($req);
- // case CmdCode::cmd_user_friend_gift_redraw: # [6114]领取好友赠送的礼物[并回赠]
- // return FriendProc::getAppFriendGift($req);
- // case CmdCode::cmd_user_friend_gift_send: # [6115]向好友发送礼物,示好
- // return FriendProc::sendGiftToAppFriend($req);
- // case CmdCode::cmd_user_friend_unduckmsg:
- // return FriendProc::CheckUnduckMessage($req);
- ////--------------------------------------------
- // case CmdCode::cmd_user_friend_apply: # [6101]加好友
- // return FriendProc::ApplyToAddNewFriend($req);
- // case CmdCode::cmd_user_friend_accept: # [6102]接受好友请求
- // return FriendProc::Accept($req);
- // case CmdCode::cmd_user_friend_deny: # [6103]拒绝好友请求
- // return FriendProc::Deny($req);
- // case CmdCode::cmd_user_friend_remove: # [6104]删除好友
- // return FriendProc::Remove($req);
- // case CmdCode::cmd_user_friend_getapplylist: # [6105]好友请求列表
- // return FriendProc::GetApplyList($req);
- ////-----------------------------------------------
- // case CmdCode::cmd_user_friend_leave_message: # [6108]给好友发消息
- // return FriendProc::SendMessage($req);
- // case CmdCode::cmd_user_friend_get_message: # [6109]刷新消息
- // return FriendProc::GetNewMessage($req);
- //
- ////-----------------------------------------------
- // case CmdCode::cmd_user_friend_reload: # [6112]更新好友
- // return FriendProc::Reload($req);
- // case CmdCode::cmd_user_friend_LookGuildInfo: # [6117]查看好友所在部落信息
- // return FriendProc::LookGuildInfo($req);
- // case CmdCode::cmd_user_friend_LookFriendInfo: # [6118]查看好友简介
- // return FriendProc::LookFriendInfo($req);
- // default:
- // return Resp::err(ErrCode::cmd_err);
- // }
- // }
- //
- // /**
- // * 查看好友的部落信息
- // * @param type $req
- // */
- // static function LookGuildInfo($req) {
- // $friendId = $req->paras[0];
- // $zoneid = $req->zoneid;
- // $mem = $req->mem;
- //
- // $sql = "select * from `tab_rolename` where userID = '$friendId'";
- // $rows = daoInst()->query($sql)->fetchAll();
- // my_Assert(count($rows) > 0, ErrCode::err_user_no); # 找不到玩家数据
- // $friendGuildInfo = GuildProc::getMemUserGuildInfo($mem, $friendId, $zoneid);
- // my_Assert($friendGuildInfo != null, "好友公会数据为空");
- // my_Assert($friendGuildInfo->guildId > 0, ErrCode::err_guild_userguildinfono);
- //
- // $guildInfo = GuildProc::getMemGuildInfo($mem, $friendGuildInfo->guildId, $zoneid);
- // my_Assert($guildInfo != null, ErrCode::err_guild_guildinfono); # 找不到公会
- //
- // return Resp::ok($guildInfo);
- // }
- //
- // /**
- // * 查看好友简介
- // * @param type $req
- // */
- // static function LookFriendInfo($req) {
- // $friendId = $req->paras[0]; //好友id
- // $mem = $req->mem;
- // $sql = "select * from `tab_rolename` where userID = '$friendId'";
- // $rows = daoInst()->query($sql)->fetchAll();
- // my_Assert(count($rows) > 0, ErrCode::err_user_no); # 找不到玩家角色记录
- // $friendInfo = self::initfriendInfo($mem, $rows[0]['userID'], $rows[0]['zoneid']);
- // my_Assert($friendInfo != null, ErrCode::err_user_no); # 好友数据初始化成功
- // $friendInfo->fightPower = GuildProc::initFightTeamInfo($mem, $rows[0]['userID'], $rows[0]['zoneid']);
- // return Resp::ok(array("friendInfo" => $friendInfo,));
- // }
- //
- // /**
- // * 检查玩家的好友信息是否有未处理的
- // * @param type $req
- // */
- // public static function CheckUnduckMessage($req) {
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid = $req->uid;
- // $result = -1;
- // // 别人的赠送列表
- // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
- // if (count((array) $fgiftlist) <= 0) {
- // $result = 0;
- // } else {
- // foreach ($fgiftlist as $key => $value) {
- // if (count((array) $value) <= 0) {
- // continue;
- // } else {
- // $result = 1;
- // break;
- // }
- // }
- // }
- // //找别人发来的申请加好友的列表
- // if ($result == 0) {
- // $ret = FriendProc::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::apply);
- // $result = (count((array) $ret) > 0) ? 1 : 0;
- // }
- // return Resp::ok(array('ret' => $result));
- // }
- //
- // /**
- // * [6112] 核算好友的离线操作
- // * @param Req $req
- // */
- // public static function Reload($req) {
- // $mem = $req->mem;
- // $uid = $req->uid;
- // $zoneid = $req->zoneid;
- //
- // // 刷新接受请求列表, 将已接受的好友添加到
- // $allOps = self::getOps($mem, $uid, $zoneid);
- // $op = new enum_Friend_op(enum_Friend_op::accepted);
- // $ops = $allOps->$op;
- // if (count($ops) > 0) {
- // foreach ($ops as $u => $ts) { # 立即将对方添加到好友列表
- // self::_AddFriend($mem, $uid, $zoneid, $u);
- // }
- // $ops = "{}";
- // $allOps->$op = $ops;
- // }
- //
- // // 刷新删除列表, 看谁和我解除了好友关系, 删掉他
- // $op = new enum_Friend_op(enum_Friend_op::remove);
- // $ops = $allOps->$op;
- // if (count($ops) > 0) {
- // foreach ($ops as $u => $ts) {
- // self::_RemoveFriend($mem, $uid, $zoneid, $u);
- // }
- // $allOps->$op = "{}";
- // }
- // $g = glc();
- //
- // self::filterOutDateRecords($allOps, # # 清理过期的请求记录,
- // new enum_Friend_op(enum_Friend_op::applied), $g->User_Friends_Apply_ExpireTs);
- //
- // self::filterOutDateRecords($allOps, # # 刷新别人发来的好友请求列表, 过期而没有处理的也删掉(莫名其妙的消失,玩家会不会不爽?要不要加上倒计时?).
- // new enum_Friend_op(enum_Friend_op::apply), $g->User_Friends_Apply_ExpireTs);
- //
- // self::saveOps($mem, $uid, $zoneid, $allOps, 0); # 回存数据
- // // 清理过期的互动记录, 不清除, 一个好友最多保留3条记录
- // // 更新好友数量
- // return Resp::ok(array("ret" => "ok"));
- // }
- //
- // private static function filterOutDateRecords($allOps, $op, $outts) {
- // $ops = $allOps->$op;
- // if (count((array) $ops) > 0) {
- // $ops = array_filter((array) $ops, function ($ts)use($outts) {
- // return (intval($ts) + $outts) > now();
- // });
- // $allOps->$op = (is_null($ops) || 0 == count((array) $ops)) ? "{}" : $ops;
- // }
- // }
- //
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 聊天/留言 ">
- // //
- //
- // /**
- // * [6108]发送消息/留言
- // * @param Req $req
- // */
- // public static function SendMessage($req) {
- // // todo:检查是否好友
- // $mem = $req->mem;
- // $uid_from = $req->uid;
- // $uid_to = $req->paras[0];
- // $msg = $req->paras[1];
- // if (strlen($msg) > self::MaxMessageLength) {
- // $msg = substr($msg, 0, self::MaxMessageLength) . "...";
- // }
- // $key = MemKey_User::FriendsMsgQueue_hash($req->zoneid, $uid_to);
- // $arr = $mem->hget($key, $uid_from);
- // if (null == $arr) {
- // $arr = ArrayInit();
- // }
- // $ts = now();
- // array_push($arr, "{$msg}{$ts}");
- // if (count($arr) > glc()->User_Friends_MessageCount_Max) {
- // array_shift($arr);
- // }
- // $mem->hset($key, $uid_from, $arr);
- ////
- // $mts = isset($req->paras[2]) ? $req->paras[2] : 0;
- // $newmsg = self::_GetNewMessage($mem, $req->zoneid, $uid_from, $uid_to, $mts);
- // return Resp::ok(array("ret" => "ok", 'newmsg' => $newmsg));
- // }
- //
- // /**
- // * [6109]拉取最新消息/留言
- // *
- // * @param Req $req
- // */
- // public static function GetNewMessage($req) {
- // if (count($req->paras) < 2) {
- // return Resp::err(ErrCode::parasnotenough_msg);
- // }
- // $uid_filter = $req->paras[0];
- // $ts = $req->paras[1];
- // $arr = self::_GetNewMessage($req->mem, $req->zoneid, $req->uid, $uid_filter, $ts);
- //
- // return Resp::ok($arr);
- // }
- //
- // /**
- // * 取留言消息
- // * @param CredisUtil $mem
- // * @param int $zoneid
- // * @param string $uid
- // * @param string $f_uid
- // * @param ts $ts
- // * @return asoc_array
- // */
- // private static function _GetNewMessage($mem, $zoneid, $uid, $f_uid, $ts) {
- // $key = MemKey_User::FriendsMsgQueue_hash($zoneid, $uid);
- // $arr = array($f_uid => $mem->hget($key, $f_uid));
- // // 依据ts时间戳,剔除客户端不需要的消息,然后传送.
- // foreach ($arr as &$msgq) {
- // if (null == $msgq) { // 防御
- // continue;
- // }
- // $msgq = array_filter($msgq, function($msg) use($ts) {
- // return $ts < substr($msg, -10); // 时间戳10位
- // });
- // }
- // return $arr;
- // }
- //
- // //
- // //
- //// </editor-fold>
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 待定 ">
- // //
- //
- // /**
- // * 设置默认同意好友请求
- // * @param Req $req
- // */
- // public static function SetAutoAccept($req) {
- //
- // }
- //
- //// </editor-fold>
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 好友操作 ">
- ////
- //
- // /**
- // * [6105] 拉取好友请求列表
- // * @param Req $req
- // */
- // public static function GetApplyList($req) {
- // $ret = FriendProc::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::apply);
- // return Resp::ok(array("ret" => (count((array) $ret) > 0) ? $ret : array()));
- // }
- //
- // /**
- // * [6101]添加好友
- // * @param Req $req
- // */
- // public static function ApplyToAddNewFriend($req) { // 取目标玩家的ops列表插入请求
- // $mem = $req->mem;
- // $uid_to = $req->paras[0];
- // $uid_from = $req->uid;
- // if ($uid_from == $uid_to) {
- // return Resp::err(ErrCode::paras_err, "添加的好友ID非法!");
- // }
- //
- // $err = self::AddOp($mem, $req->zoneid, $uid_to, enum_Friend_op::apply, $uid_from);
- // if (ErrCode::ok != $err) {
- // return Resp::err($err);
- // }
- // $err = self::AddOp($mem, $req->zoneid, $req->uid, enum_Friend_op::applied, $uid_to);
- // if (ErrCode::ok != $err) {
- // return Resp::err($err);
- // }
- // return Resp::ok(array("ret" => "ok"));
- // }
- //
- // /**
- // * [6102]接受好友请求
- // * @param Req $req
- // */
- // public static function Accept($req) { // 将对方立即放到自己的好友列表中, 并给对方发送接受的op, 删除请求记录
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid_my = $req->uid;
- // $uid_arr = explode(',', $req->paras[0]);
- // foreach ($uid_arr as $uid_to) {
- // $myOp = self::getOps($mem, $req->uid, $zoneid, enum_Friend_op::apply); // 自己的请求列表
- // unset($myOp->$uid_to); // 删除请求记录
- // self::saveOps($mem, $req->uid, $zoneid, $myOp, enum_Friend_op::apply); // 更新自己的请求列表
- //
- // $err = self::AddOp($mem, $zoneid, $uid_to, enum_Friend_op::accepted, $uid_my); // 向对方的已接受列表中添加记录
- // if ($err != ErrCode::ok) { // 出错
- // return Resp::err($err);
- // }
- // self::_AddFriend($mem, $uid_my, $zoneid, $uid_to);
- //// $mem->sadd(MemKey_User::FriendsList_set($zoneid, $req->uid), $uid_to); // 立即将对方添加到好友列表
- // }
- //
- // return Resp::ok(array("ret" => "ok"));
- // }
- //
- // /**
- // * [6103]拒接好友请求
- // * @param Req $req
- // */
- // public static function Deny($req) { // 直接 删除请求记录, 不通知对方了
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid_my = $req->uid;
- // $uid_to = $req->paras[0];
- //
- // // 从自己的列表中删除就行了,不用通知对方
- // $myOp = self::getOps($mem, $uid_my, $zoneid, enum_Friend_op::apply); // 自己的请求列表
- // unset($myOp->$uid_to);
- // self::saveOps($mem, $uid_my, $zoneid, $myOp, enum_Friend_op::apply); // 更新自己的请求列表
- //
- // return Resp::ok(array("ret" => "ok"));
- // }
- //
- // /**
- // * [6104]删除好友
- // * @param Req $req
- // */
- // public static function Remove($req) {// 将对方立即从自己的好友列表中删除, 并给对方发送remove的op
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid_to = $req->paras[0]; // 删除谁
- // $uid_my = $req->uid;
- //
- // $tOp = self::getOps($mem, $uid_to, $zoneid, enum_Friend_op::remove); // 对方的删除列表
- // $ts = now();
- // $userInfo_my = UserProc::getUserInfo($mem, $zoneid, $uid_my);
- // $name = $userInfo_my->game->name;
- // $tOp->$uid_my = $ts . "_" . $name;
- // self::saveOps($mem, $uid_to, $zoneid, $tOp, enum_Friend_op::remove); // 更新对方的删除列表
- // self::_RemoveFriend($mem, $uid_my, $zoneid, $uid_to);
- //
- // return Resp::ok(array("ret" => "ok"));
- // }
- //
- ////
- //// </editor-fold>
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 搜索 ">
- //
- // /**
- // * [6110]搜索好友
- // * @param Req $req
- // */
- // static function SearchFriend($req) {
- // //客户端参数解析
- // if (count($req->paras) <= 1) { // 参数非法
- // return Resp::err(ErrCode::parasnotenough_msg);
- // }
- // $zoneid = $req->zoneid;
- // $filter = $req->paras[0];
- // $start = 0;
- // if (count($req->paras) > 1) {
- // $start = $req->paras[1];
- // }
- // $max = 8; // 每次查询返回的数据条目数量
- // $sql = "select * from `tab_rolename` where (`userID`='$filter' OR `roleName` like '%$filter%') and zoneid = $zoneid limit $start, $max ;";
- // $paydb = CPayInit();
- // $rows = $paydb->fetch_array($sql);
- // $ret = ArrayInit();
- // foreach ($rows as $row) {
- // $uid = $row['userID'];
- // $zone_all = $row['zoneid'];
- // if ($uid == $req->uid) {
- // continue;
- // }
- // $friendInfo = self::initfriendInfo($req->mem, $uid, $zone_all);
- // if ($friendInfo != null) {
- // $ret[] = $friendInfo;
- // }
- // }
- // $ops = self::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::applied);
- // return Resp::ok(array('fList' => $ret, 'applied' => $ops));
- // }
- //
- // static function initfriendInfo($mem, $uid, $zoneid) {
- // $userInfo = UserProc::getUserInfo($mem, $zoneid, $uid);
- // if ($userInfo == null) {
- // return null;
- // }
- // $userGuildInfo = GuildProc::getMemUserGuildInfo($mem, $uid, $zoneid);
- // if ($userGuildInfo == null) {
- // $userGuildInfo = ObjectInit();
- // $userGuildInfo->guildName = "";
- // $userGuildInfo->guildId = 0;
- // }
- // $key_cur = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid);
- // $score = $mem->zscore($key_cur, $uid);
- // $userGuildInfo->cupScore = $score == null ? 0 : $score;
- // $friendObj = new initfriendInfoModel(null, $uid, $userInfo->game->name, $userInfo->game->level, $userInfo->game->img, #
- // $userInfo->game->imgBorderId, $userGuildInfo->guildName, $userGuildInfo->guildId, $userGuildInfo->cupScore);
- // return $friendObj;
- // }
- //
- // /**
- // * [6111]添加好友界面获取一批推荐好友列表
- // * @param Req $req
- // */
- // static function GetSuggestList($req) {
- // //客户端参数解析
- // if (count($req->paras) < 1) { // 参数非法
- // return Resp::err(ErrCode::parasnotenough_msg);
- // }
- // $zoneid = $req->zoneid;
- // $start = $req->paras[0]; // 第几页
- // $max = 8; // 每次查询返回的数据条目数量
- // $sql = "select * from `tab_rolename` where `zoneid`=$zoneid order by ts desc limit $start, $max ;";
- // $paydb = CPayInit();
- // $rows = $paydb->fetch_array($sql);
- // $arr = ArrayInit();
- // foreach ($rows as $row) {
- // if ($row['userID'] == $req->uid) {
- // continue;
- // }
- // unset($row["tid"]);
- // unset($row["zoneid"]);
- //
- // $arr[] = $row['userID'];
- // }
- // $applidops = self::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::applied);
- // $ret = array('fList' => array_unique($arr), 'applied' => $applidops);
- // return Resp::ok($ret);
- // }
- //
- //// </editor-fold>
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 好友列表 ">
- //
- // /**
- // * [6106]获取好友ID列表
- // * @param Req $req
- // * @return int
- // */
- // static function getAppFriends($req) {
- // self::Reload($req);
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // //客户端参数解析
- // $friendIds = self::_GetFriendList($mem, $req->uid, $zoneid); // 取好友列表
- //
- // $userArr = ArrayInit();
- // foreach ($friendIds as $index => $uid) {
- // $friendInfo = self::initfriendInfo($mem, $uid, $zoneid);
- // if ($friendInfo == null) {
- // continue;
- // }
- // $userArr[] = $friendInfo;
- // }
- // //$mygiftops = self::getOps($mem, $req->uid, $req->zoneid, enum_Friend_op::giftrecord);
- // $resp = Resp::ok(array(
- // #"friends" => $friendIds,
- // 'userGuild' => $userArr,
- // ));
- // return $resp;
- // }
- //
- // /**
- // * 查找好友数量
- // * @param Req $req
- // */
- // public static function getCurrentFriendsCount($req) {
- // return $req->mem->scard(MemKey_User::FriendsList_set($req->zoneid, $req->uid));
- // }
- //
- // /**
- // * [6107] 获取好友信息列表
- // * @param Req $req
- // * @return type
- // */
- // static function getAppFriendInfos($req) {
- // $mem = $req->mem;
- // //客户端参数解析
- // $zoneid = $req->zoneid;
- // $fuids = explode(',', $req->paras[0]); // 逗号分割uid字符串
- // $max = 8; # 一次最多取八个数据
- // $n = count($fuids);
- //// var_dump($fuids);
- // if ($n > 0 && $n <= $max) {
- // $fuidkeys = array_map(function ($i) use($zoneid) {
- // return MemKey_User::Info($zoneid, $i);
- // }, $fuids);
- // $arr = $mem->getMulti($fuidkeys);
- // $friendInfos = ArrayInit();
- // $n = 0;
- // foreach ($arr as $userInfo) {
- // isEditor() && $userInfo = new UserGameModel;
- // isEditor() && $shareInfo = new UserHeroModel;
- // $uid = $fuids[$n++];
- // if (!$userInfo # 玩家数据不为空
- // || !property_exists($userInfo, 'heros') # 存在heros数据
- // || !$userInfo->heros) { # heros数据不为空
- // continue;
- // }
- // $sharedHeroId = $userInfo->heros->firendSupportHeroUID;
- // if ($sharedHeroId) {
- // $shareInfo = $userInfo->heros->collectHeros->$sharedHeroId;
- // } else { // todo: 暂定如果没有设置共享英雄,默认取集合中第一个英雄, 征询策划是否修订规则
- // $coll = $userInfo->heros->collectHeros;
- // $keys = array_keys((array) $coll);
- // if (count($keys) <= 0) {
- // continue;
- // }
- // $sharedHeroId = $keys[0];
- // $shareInfo = $userInfo->heros->collectHeros->$sharedHeroId;
- // }
- // // 额外将英雄的装备数据替换为实例数据
- // self::getArmor($userInfo, $shareInfo, 'weapon');
- // self::getArmor($userInfo, $shareInfo, 'armor');
- // self::getArmor($userInfo, $shareInfo, 'ring');
- // $friendInfos[$uid] = array('sharedHero' => $shareInfo,
- // 'lastLoginTs' => isset($userInfo->lastLogin) ? $userInfo->lastLogin : 0,
- // 'level' => $userInfo->level,
- // 'nickname' => $userInfo->name
- // );
- // }
- // if (count($friendInfos) <= 0) {
- // $friendInfos = null;
- // }
- // $resp = Resp::ok(array('ret' => $friendInfos));
- // } else {
- // $resp = Resp::err(ErrCode::paras_err);
- // }
- // return $resp;
- // }
- //
- // static function getArmor($userInfo, $hero, $armor) {
- // $armorid = $hero->equip->$armor->itemuid;
- //
- // if ($armorid > 0 && isset($userInfo->store->equipment->$armorid)) {
- // $hero->equip->$armor = $userInfo->store->equipment->$armorid;
- // } else {
- // $hero->equip->$armor = null;
- // }
- // }
- //
- //// </editor-fold>
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 示好 ">
- ////
- //
- // /**
- // * [6115]向好友发送礼物(示好)
- // * @param Req $req
- // */
- // static function sendGiftToAppFriend($req) {
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid = $req->uid;
- // //客户端参数解析
- // $fuids = explode(',', $req->paras[0]); // 逗号分割的uid数组
- //// $pr = $req->paras[1]; // other参数 preserved
- // $n = count($fuids);
- // if ($n <= 0) {
- // return Resp::ok(array("ret" => 0));
- // }
- // $mygiftrecord = self::getOps($mem, $uid, $zoneid, enum_Friend_op::giftrecord);
- // $m = 0;
- // for ($i = 0; $i < $n; $i++) {
- // $fid = $fuids[$i];
- // $tsDay = tsDay();
- // if (property_exists($mygiftrecord, $fid) // 判断对方是否能够领取礼物(当天已经发送过,则不再发送)
- // && $mygiftrecord->$fid >= $tsDay) {
- // continue;
- // }
- // $mygiftrecord->$fid = $tsDay; # 更新发送记录
- // $fgiftinfo = self::getOps($mem, $fid, $zoneid, enum_Friend_op::gift);
- // if (null == $fgiftinfo) { // 防御
- // $fgiftinfo = ObjectInit(); // 没找到好友数据, 则创建
- // }
- // // 给对方身上插入操作记录
- // if (!isset($fgiftinfo->$uid) or ! is_array($fgiftinfo->$uid)) {//防御
- // $fgiftinfo->$uid = ArrayInit();
- // }
- // $arr = $fgiftinfo->$uid;
- // $arr[] = tsDay();
- // if (count($arr) > 3) { // 最多保留3条记录
- // sort($arr);
- // array_shift($arr);
- // }
- // $fgiftinfo->$uid = $arr; // 更新下
- // self::saveOps($mem, $fid, $zoneid, $fgiftinfo, enum_Friend_op::gift);
- //
- // $m++;
- // }
- // // 回存数据
- // self::saveOps($mem, $uid, $zoneid, $mygiftrecord, enum_Friend_op::giftrecord);
- // // 其他检查比如任务、成就系统
- // // ...
- // // 返回结果
- // return Resp::ok(array("ret" => $m));
- // }
- //
- // /**
- // * [6113]查询游戏中哪些好友给我发送了礼物的列表
- // * @param Req $req
- // */
- // static function getAppFriendGiftList($req) {
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid = $req->uid;
- // // 别人的赠送列表
- // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
- // if (count((array) $fgiftlist) <= 0) {
- // $fgiftlist = NULL;
- // }
- // return Resp::ok(array('ret' => $fgiftlist));
- // }
- //
- // /**
- // * [6114]领取来自好友的礼物[并回赠]
- // * @param Req $req
- // */
- // static function getAppFriendGift($req) {
- // $mem = $req->mem;
- // $zoneid = $req->zoneid;
- // $uid = $req->uid;
- // //客户端参数解析
- // $fuids = explode(',', $req->paras[0]); // 逗号分割的uidtsday数组
- // $bSendback = true; // 是否回赠
- //
- // $arr = array();
- // array_map(function($f)use(&$arr) {
- // $arr[substr($f, -5)] = substr($f, 0, -5); // tsday()占5个字符
- // }, $fuids);
- // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
- //
- // $recieved = 0;
- // foreach ($arr as $ts => $fid) {
- // if (isset($fgiftlist->$fid) && in_array($ts, $fgiftlist->$fid)) {
- // StlUtil::arrayRemove($fgiftlist->$fid, $ts);
- // $recieved++;
- // }
- // }
- // $req->userInfo->game->friendPoint += $recieved;
- // self::saveOps($mem, $uid, $zoneid, $fgiftlist, enum_Friend_op::gift);
- // UserProc::updateUserInfo();
- // if ($bSendback && $recieved > 0) {
- // $uids_send = array_unique(array_values($arr));
- // $req->paras[0] = implode(',', $uids_send);
- //// var_dump($uids_send);
- // self::sendGiftToAppFriend($req);
- // }
- // // 当天领取好友礼物有没有上限? 比如100个心.
- // // 检查是否存在对应的礼物记录,
- // // 发送礼物
- // // 删除礼物记录
- // // 回写数据
- // // 返回值
- //
- // return Resp::ok(array("ret" => $recieved));
- // }
- //
- // /**
- // * 玩家初始化
- // * @param Req $req
- // */
- // static function Init($req) {
- // $mem = $req->mem;
- // $z = $req->zoneid;
- // $uid = $req->uid;
- //// $mem->sadd(MemKey_User::FriendsList_set($z, $uid), "");
- // $mem->hset(MemKey_User::FriendsMsgQueue_hash($z, $uid), "sys", "");
- // $mem->hmset(MemKey_User::FriendsOps_hash($z, $uid), array("apply" => "{}",
- // "applied" => "{}",
- // "gift" => "{}",
- // "accepted" => "{}",
- // "remove" => "{}",
- // 'giftrecord' => "{}"));
- // }
- //
- ////
- //// </editor-fold>
- ////
- ////-------------以下是辅助方法-----------------
- ////
- //
- // /**
- // * 验证是否好友
- // * @param Req $req
- // */
- // public static function isFriendship($zoneid, $myUid, $fUid) {
- // return gMem()->sismember(MemKey_User::FriendsList_set($zoneid, $myUid), $fUid);
- // }
- //
- // /**
- // * 添加fuid到好友列表
- // */
- // private static function _AddFriend($mem, $uid, $zoneid, $fuid) {
- // $mem->sadd(MemKey_User::FriendsList_set($zoneid, $uid), $fuid);
- // }
- //
- // /**
- // * 从好友列表中删除fuid
- // */
- // private static function _RemoveFriend($mem, $uid, $zoneid, $fuid) {
- // $mem->sremove(MemKey_User::FriendsList_set($zoneid, $uid), $fuid);
- // }
- //
- // private static function _GetFriendList($mem, $uid, $zoneid) {
- // $arr = $mem->smembers(MemKey_User::FriendsList_set($zoneid, $uid));
- // if (!$arr) { # 数据为空
- // $arr = ArrayInit();
- // }
- // $friendIds = array_values(array_filter($arr, function ($a) {
- // return $a != "";
- // }));
- // return $friendIds;
- // }
- //
- ////
- //// <editor-fold defaultstate="collapsed" desc=" 读写玩家好友数据 ">
- //
- // /**
- // * 添加操作
- // * @param enum_Friend_op $op
- // * @param Req $req
- // */
- // private static function AddOp($mem, $zoneid, $uid, $op, $uid_from) {
- // $enop = new enum_Friend_op($op);
- // if (!$enop->isValidValue($op)) {
- // return ErrCode::paras_err;
- // }
- // $ts = now();
- // $tOp = FriendProc::getOps($mem, $uid, $zoneid, $op);
- //
- // $userInfo = UserProc::getUserInfo($mem, $zoneid, $uid_from);
- // $userName = $userInfo->game->name;
- // $tOp->$uid_from = $ts . "_" . $userName; # 可以按照时间戳排序
- // return FriendProc::saveOps($mem, $uid, $zoneid, $tOp, $op);
- // }
- //
- // /**
- // * 查询好友异步操作队列
- // * @param CRedisUtil $mem
- // * @param string $uid
- // * @param int $zoneid
- // * @param enum_Friend_op $op
- // * @return mixed
- // */
- // private static function getOps($mem, $uid, $zoneid, $op = 0) {
- // $ret = ObjectInit();
- // if ($op == enum_Friend_op::__default) {
- // $ret = $mem->hgetall(MemKey_User::FriendsOps_hash($zoneid, $uid));
- // } else {
- // $ret = $mem->hget(MemKey_User::FriendsOps_hash($zoneid, $uid), new enum_Friend_op($op));
- // }
- // if (is_null($ret)) {
- // $ret = ObjectInit();
- // }
- // return $ret;
- // }
- //
- // /**
- // * 回写好友异步操作队列
- // * @param CRedisUtil $mem
- // * @param string $uid
- // * @param int $zoneid
- // * @param mixed $data
- // * @param int $op
- // */
- // private static function saveOps($mem, $uid, $zoneid, $data, $op) {
- // $enop = new enum_Friend_op($op);
- // if (!$enop->isValidValue($op)) {
- // return ErrCode::paras_err;
- // }
- //
- // if ($op == enum_Friend_op::__default) { # 全部数据
- // $mem->hmset(MemKey_User::FriendsOps_hash($zoneid, $uid), $data);
- // } else {
- // if (is_array($data) && count($data) == 0) {
- // $data = "{}";
- // }
- // $mem->hset(MemKey_User::FriendsOps_hash($zoneid, $uid), $enop, $data);
- // }
- // return ErrCode::ok;
- // }
- //
- ////
- //// // </editor-fold>
- ////
- //}
- //
- //class initfriendInfoModel extends Object_ext {
- //
- // public $uid;
- // public $name;
- // public $level;
- // public $img;
- // public $imgBorderId;
- // public $guildName;
- // public $guildId;
- // public $cupScore;
- //
- // function __construct($tag, $uid, $name, $level, $img, $imgBorderId, $guildName, $guildId, $cupScore) {
- // if (1 == func_num_args() && $tag) { # 默认的Object初始化方法
- // parent::__construct($tag);
- // } else {
- // $this->uid = $uid;
- // $this->name = $name;
- // $this->level = $level;
- // $this->img = $img;
- // $this->imgBorderId = $imgBorderId;
- // $this->guildName = $guildName;
- // $this->guildId = $guildId;
- // $this->cupScore = $cupScore;
- // }
- // }
- //
- //}
|