IBroadCastServer.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. require_once( PATH_LIB . 'cserver/ESPacket.php' );
  3. require_once( PATH_LIB . 'cserver/NetUtil.php' );
  4. class IBroadCastServer {
  5. /** 广播协议命令字 START **/
  6. const NEW_BROADSERVER_TO_All = 0x7852; //php进行全服广播 ( PHP->B )
  7. const NEW_BROADSERVER_TO_USER = 0x7600; //php进行特定用户单播( PHP->B )
  8. const MONEYCHANGE = 0x1007; //用户属性相关
  9. const PROPSCHANGE = 0x1008; //活动道具相关
  10. const NEWSCHANGE = 0x1009; //消息相关
  11. const TASKACHCHANGE = 0x1010; //任务成就
  12. const INVITEFRIPLAYING = 0x1011; //好友邀请打牌
  13. const BROAD_CAST_PAY_SUCC = 0x100D; //支付成功
  14. const MATCH_USERREWARD = 0x2001; //比赛场: 玩家领奖通知
  15. const BROADSERVER_TO_ALL = 0x2006; //大喇叭
  16. const BROADWCUPPOOLCHIPS_TO_ALL = 0x2007; //世界杯奖金池
  17. const BROADPOKER_RWD = 0x1013; //玩牌领奖通知
  18. const BROADUSER_HEADIMG = 0x1014; //修改头像通知
  19. /** 广播协议命令字 END **/
  20. public function __construct() {
  21. }
  22. /** php进行特定用户单播( PHP->B )
  23. * uid : int(用户ID)
  24. * info : array(用户个人数据)
  25. * 新广播server接口
  26. * */
  27. static function newBroadToUser($uid, $type, $info = array()) {
  28. if (empty($type)) { // 空广播不发
  29. return true;
  30. }
  31. $packet = new ESPacket();
  32. $packet->WriteBegin(self::NEW_BROADSERVER_TO_USER);
  33. $packet->WriteInt($uid);
  34. $packet->WriteInt($type);
  35. $packet->WriteString(json_encode($info));
  36. $packet->WriteEnd();
  37. $request = $packet->GetPacketBuffer();
  38. !PRODUCTION_SERVER && oo::logs()->debug2($uid.'|'.oo::$config['BroadServer'][0].'|'. oo::$config['BroadServer'][1] . "|" .$type.'|'. json_encode($info), 'newBroadToUser.log');
  39. NetUtil::tcpLongCmd(oo::$config['BroadServer'][0], oo::$config['BroadServer'][1], $request, 2, 2, 0, "\0", false);
  40. return 0;
  41. }
  42. /** php进行特定用户单播( PHP->B )
  43. * uid : int(用户ID)
  44. * info : array(用户个人数据)
  45. * 新广播server接口
  46. * */
  47. static function broadToUser($uid, $type, $info = '') {
  48. if (empty($type)) { // 空广播不发
  49. return true;
  50. }
  51. $packet = new ESPacket();
  52. $packet->WriteBegin(self::NEW_BROADSERVER_TO_USER);
  53. $packet->WriteInt($uid);
  54. $packet->WriteInt($type);
  55. $packet->WriteString($info);
  56. $packet->WriteEnd();
  57. $request = $packet->GetPacketBuffer();
  58. !PRODUCTION_SERVER && oo::logs()->debug2($uid.'|'.oo::$config['BroadServer'][0].'|'. oo::$config['BroadServer'][1] . "|" .$type.'|'. json_encode($info), 'newBroadToUser.log');
  59. NetUtil::tcpLongCmd(oo::$config['BroadServer'][0], oo::$config['BroadServer'][1], $request, 2, 2, 0, "\0", false);
  60. return 0;
  61. }
  62. /**
  63. * php进行全服广播 ( PHP->B )
  64. * msg : string 内容
  65. */
  66. static function newBroadToAll($msg) {
  67. if (empty($msg)) { // 空广播不发
  68. return true;
  69. }
  70. $packet = new ESPacket();
  71. $packet->WriteBegin(self::NEW_BROADSERVER_TO_All);
  72. $packet->WriteString("");
  73. $packet->WriteString($msg);
  74. $packet->WriteString("");
  75. $packet->WriteString("");
  76. $packet->WriteEnd();
  77. $request = $packet->GetPacketBuffer();
  78. NetUtil::tcpLongCmd(oo::$config['BroadServer'][0], oo::$config['BroadServer'][1], $request, 2, 2, 0, "\0", false);
  79. return 0;
  80. }
  81. /* notifySeatExp */
  82. /**
  83. * 通知用户坐下加经验
  84. * @param uid 游戏uid
  85. * @param experience 需要增加的经验 > 0
  86. */
  87. public function notifySeatExp($uid, $exp = 0) {
  88. $type = 0x5001; //通知用户坐下加经验
  89. $arr['exp'] = $exp;
  90. self::newBroadToUser($uid, $type, $arr);
  91. return 0;
  92. }
  93. /**
  94. * 用户属性变化, 包括金币,经验,钻石等
  95. * 该方法目前只通知金币变化的广播通知
  96. */
  97. static public function notifyPropertyChange($uid, $array = array() ) {
  98. self::newBroadToUser($uid, self::MONEYCHANGE, $array);
  99. return 0;
  100. }
  101. /**
  102. * 玩家道具变化通知
  103. * array( id => count ) 道具ID => 改变的数量
  104. */
  105. static public function notifyPropsChange($uid, $array = array() )
  106. {
  107. self::newBroadToUser($uid, self::PROPSCHANGE, $array);
  108. return 0;
  109. }
  110. /**
  111. * 大转盘
  112. */
  113. static public function notifyBigwheel($uid, $array = array() )
  114. {
  115. }
  116. /**
  117. * 支付成功
  118. */
  119. static public function notifyPaysucc($uid, $array = array() )
  120. {
  121. self::newBroadToUser($uid, self::BROAD_CAST_PAY_SUCC, $array);
  122. return 0;
  123. }
  124. /**
  125. * 消息相关
  126. */
  127. static public function notifyNews($uid, $array = array())
  128. {
  129. self::newBroadToUser($uid, self::NEWSCHANGE, $array);
  130. return 0;
  131. }
  132. /**
  133. * 成就和任务相关
  134. */
  135. static public function notifyTaskAch($uid, $array = array())
  136. {
  137. self::newBroadToUser($uid, self::TASKACHCHANGE, $array);
  138. return 0;
  139. }
  140. /**
  141. * 比赛场 玩家领奖
  142. */
  143. static public function notifyMatchUserReward($uid, $array = array())
  144. {
  145. self::newBroadToUser($uid, self::MATCH_USERREWARD, $array);
  146. return 0;
  147. }
  148. /**
  149. * 喇叭
  150. */
  151. static public function sendSpeaker($msg, $uid = 0, $nick = 'System')
  152. {
  153. $data['type'] = self::BROADSERVER_TO_ALL;
  154. $data['uid'] = $uid;
  155. $data['nick'] = $nick;
  156. $data['msg'] = $msg;
  157. $json = json_encode($data);
  158. self::newBroadToAll($json);
  159. return 0;
  160. }
  161. /**
  162. * 世界杯活动奖金池通知
  163. */
  164. static public function noticeWCupPoolChip($list = [])
  165. {
  166. if(empty($list) || !is_array($list)) {
  167. return false;
  168. }
  169. $data['type'] = self::BROADWCUPPOOLCHIPS_TO_ALL;
  170. $data['data'] = $list;
  171. $json = json_encode($data);
  172. self::newBroadToAll($json);
  173. return true;
  174. }
  175. /**
  176. * 玩牌活动领奖通知
  177. */
  178. static public function noticePokerRWD($uid, $array = [])
  179. {
  180. self::newBroadToUser($uid, self::BROADPOKER_RWD, $array);
  181. return 0;
  182. }
  183. /**
  184. * 玩牌活动领奖通知
  185. */
  186. static public function noticeUserHeadImg($uid, $array = [])
  187. {
  188. if(empty($array)){
  189. return false;
  190. }
  191. self::newBroadToUser($uid, self::BROADUSER_HEADIMG, $array);
  192. return 0;
  193. }
  194. /**
  195. * 邀请好友打牌广播
  196. */
  197. static public function notifyInviteFriPlaying($uid, $str)
  198. {
  199. self::broadToUser($uid, self::INVITEFRIPLAYING, $str);
  200. return 0;
  201. }
  202. }