HallApiController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Game\GameCard;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Treasure\GameScoreLocker;
  6. use App\Util;
  7. use App\Utility\SetNXLock;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Redis;
  11. class HallApiController extends Controller
  12. {
  13. public function index()
  14. {
  15. }
  16. private function checkAuth(Request $request)
  17. {
  18. Util::WriteLog("hallapi","");
  19. return $request->input('pass','')=='24680.com';
  20. }
  21. public function SetIngameState(Request $request)
  22. {
  23. if(!$this->checkAuth($request))return;
  24. $UserID=$request->input('UserID')??null;
  25. $redisKey='SetIngameState_'.$UserID;
  26. $n=0;
  27. while (!SetNXLock::getExclusiveLock($redisKey)){
  28. sleep(1);
  29. $n++;
  30. if($n>3){
  31. break;
  32. }
  33. }
  34. $GlobalUID=$request->input('GlobalUID')??null;
  35. $ingame_state=$request->input('ingame_state')??"0";
  36. $ingame_state=intval($ingame_state);
  37. $key='ingame_state_'.$UserID;
  38. if($ingame_state!=-1) {
  39. Redis::set($key, $ingame_state);
  40. if($ingame_state>0){
  41. GameCard::$enableStateCheck=false;
  42. $game=GameCard::where('id',$ingame_state)->first();
  43. //ouro777的游戏,不管
  44. if(isset($game)&&!in_array($game->brand,['OURO777','PGSoft'])){
  45. // $ingame=GameScoreLocker::where('UserID',$UserID)->exists();
  46. GameScoreLocker::updateOrInsert(['UserID'=>$UserID],[
  47. 'UserID' => $UserID,
  48. 'KindID' => 0,
  49. 'ServerID' => $ingame_state,
  50. 'EnterID' => 0,
  51. 'EnterIP' => $request->input('ip') ?? '',
  52. 'ByHallServer' => 1
  53. ]);
  54. }
  55. }else{
  56. GameScoreLocker::where('ByHallServer',1)->where('UserID',$UserID)->delete();
  57. }
  58. }else{
  59. Redis::del($key);
  60. GameScoreLocker::where('ByHallServer',1)->where('UserID',$UserID)->delete();
  61. }
  62. SetNXLock::release($redisKey);
  63. exit("");
  64. }
  65. public function ClearLocker(Request $request)
  66. {
  67. if(!$this->checkAuth($request))return;
  68. GameScoreLocker::where('ByHallServer',1)->delete();
  69. exit("");
  70. }
  71. }