public function history($match_id) { $since = Request::input('since', 0); $full = Request::input('full', false) === 'true'; $match = Match::findOrFail($match_id); $events = $match->events()->with(['game.beatmap.beatmapset', 'game.scores' => function ($query) { $query->with('game')->default(); }])->where('event_id', '>', $since); if ($full) { $events->default(); } else { $events->orderBy('event_id', 'desc')->take(config('osu.mp-history.event-count')); } $events = $events->get(); if (!$full) { $events = $events->reverse(); } $userIds = []; foreach ($events as $event) { if ($event->user_id) { $userIds[] = $event->user_id; } if ($event->game) { foreach ($event->game->scores as $score) { $userIds[] = $score->user_id; } } } $users = User::with('country')->whereIn('user_id', array_unique($userIds))->get(); $users = json_collection($users, new UserCompactTransformer(), 'country'); $events = json_collection($events, new EventTransformer(), ['game.beatmap.beatmapset', 'game.scores']); return ['events' => $events, 'users' => $users, 'all_events_count' => $match->events()->count()]; }
public function getMatch() { $match_id = Request::input('mp'); if (present($match_id)) { $match = Match::with('games.scores')->where('match_id', $match_id)->get(); if (!$match->isEmpty()) { return Response::json(json_collection($match, new MatchTransformer(), 'games.scores')[0]); } } // match existing api return Response::json(['match' => 0, 'games' => []]); }
public function checkChatChannelRead($user, $channel) { $prefix = 'chat.channel.read.'; switch (strtolower($channel->type)) { case 'public': return 'ok'; case 'private': $commonGroupIds = array_intersect($user->groupIds(), $channel->allowed_groups); if (count($commonGroupIds) > 0) { return 'ok'; } break; case 'spectator': case 'multiplayer': case 'temporary': // this and the comparisons below are needed until bancho is updated to use the new channel types if (starts_with($channel->name, '#spect_')) { return 'ok'; } if (starts_with($channel->name, '#mp_')) { $matchId = intval(str_replace('#mp_', '', $channel->name)); if (in_array($user->user_id, MultiplayerMatch::findOrFail($matchId)->currentPlayers(), true)) { return 'ok'; } } break; } return $prefix . 'no_access'; }
public function includeEvents(Match $match) { return $this->collection($match->events()->default()->get(), new EventTransformer()); }