public function register_user(WebSocketTransportInterface $user, $data) { $tournament = Tournament::get($data->tournament); if ($tournament == null) { $user->sendString('{"msg": "Tournament not exist"}'); $this->say('Tournament ' . $data->tournament . ' not exist'); return false; } // Register itself $user->tournament = $tournament; $player = $tournament->get_player($user->player_id); if ($player == null) { $this->observer->say('Player ' . $user->player_id . ' not found in draft'); } else { $player->connect($this->type); $user->player = $player; if ($tournament->status == 3) { $booster = $tournament->get_booster($player->order); if ($booster == null) { $this->observer->say("Booster not found t {$this->tournament->id}" . " p {$this->player->order} n {$this->tournament->round}"); } else { $user->sendString(json_encode($booster)); } } $user->sendString(json_encode($tournament)); $user->sendString(json_encode($player->get_deck())); } }
public function register_user(WebSocketTransportInterface $user, $data) { $tournament = Tournament::get($data->tournament); if ($tournament == null) { $user->sendString('{"msg": "Tournament not exist"}'); $this->say('Tournament ' . $data->tournament . ' not exist'); return false; } $user->tournament = $tournament; $user->follow = null; if (property_exists($data, 'follow')) { $pid = $data->follow; $user->follow = $user->player_id; } else { $pid = $user->player_id; } $user->sendString(json_encode($tournament)); $player = $tournament->get_player($pid); if ($player == null) { $this->observer->say('Player ' . $user->player_id . ' not found in build'); } else { $player->connect($this->type); $user->player = $player; $user->sendString(json_encode($player->get_deck())); } }
public function __construct($obj, $type = '') { Game::$cache[] = $this; foreach ($this->fields as $field) { if (property_exists($obj, $field)) { $this->{$field} = $obj->{$field}; } else { $this->{$field} = ''; } } $this->spectators = new Spectators(); if (!isset($obj->id)) { $this->create(); } else { $this->getActions(); } if (isset($obj->type) && $obj->type != '') { $this->type = $obj->type; } else { $this->type = $type; } if (isset($this->creator_score) && $this->creator_score == '') { $this->creator_score = 0; } if (isset($this->joiner_score) && $this->joiner_score == '') { $this->joiner_score = 0; } $this->tournament_obj = Tournament::get($this->tournament, 'tournament'); }
public function register_user(WebSocketTransportInterface $user, $data) { // Get tournament $tournament = Tournament::get($data->tournament); if ($tournament == null) { $user->sendString('{"msg": "Tournament not exist"}'); $this->observer->say('Tournament ' . $data->tournament . ' not exist'); return false; } $user->tournament = $tournament; // Get player $i = $tournament->registered($user); if ($i !== false) { $player = $tournament->players[$i]; } else { $player = null; } // Player redirected from index if ($tournament->status == 2 && $player != null) { $tournament->players[$i]->set_ready(true); } $tournament->send(); if ($player == null) { $tournament->register_spectator($user); } else { $player->connect($this->type); $user->player = $player; // Redirect if ($tournament->status == 3 && !$this->observer->draft->is_connected($tournament, $user->player_id)) { $user->sendString('{"type": "redirect"}'); } if ($tournament->status == 4 && !$this->observer->build->is_connected($tournament, $user->player_id)) { $user->sendString('{"type": "redirect"}'); } if ($tournament->status == 5) { $game = $tournament->player_match($user->player_id); if ($game == null) { $this->observer->say('No game found'); } else { if ($game->joiner_id == '') { // Bye } else { if (!$this->observer->game->connected($user->player_id, $game) && $game->status < 7) { $user->sendString('{"type": "redirect", "game": ' . $game->id . '}'); } } } } } }
static function create($data, $user) { if (property_exists($data, 'id')) { $tournament = Tournament::get($data->id); if ($tournament != null) { return $tournament; } } $options = Tournament::check_create($data); if (is_string($options)) { return $options; } global $db; $data->status = 1; $data->data = $options; $data->min_players = intval($data->min_players); $data->id = $db->insert("INSERT INTO\n\t\t\t`tournament` ( `type`, `name`, `min_players`, `status`, `data` )\n\t\t\tVALUES ( '{$data->format}', '" . $db->escape($data->name) . "',\n\t\t\t{$data->min_players}, {$data->status},\n\t\t\t'" . $db->escape(json_encode($options)) . "' );"); $tournament = new Tournament($data); $tournament->log($user->player_id, 'create', $user->nick); return $tournament; }
public function run() { Eloquent::unguard(); $tournaments = Tournament::get(); $tournament = $tournaments[0]; $games = $tournament->games()->orderBy('id', 'ASC')->get(); $players = $tournament->players()->orderBy('id', 'ASC')->get(); DB::table('reports')->truncate(); DB::table('reports')->insert(array(array('game' => $games[0]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[0]->id, 'player' => $players[1]->id, 'victory' => 0, 'control' => 4, 'destruction' => 5), array('game' => $games[1]->id, 'player' => $players[2]->id, 'victory' => 1, 'control' => 2, 'destruction' => 22), array('game' => $games[1]->id, 'player' => $players[3]->id, 'victory' => 0, 'control' => 0, 'destruction' => 6), array('game' => $games[2]->id, 'player' => $players[4]->id, 'victory' => 1, 'control' => 5, 'destruction' => 21), array('game' => $games[2]->id, 'player' => $players[5]->id, 'victory' => 0, 'control' => 1, 'destruction' => 16), array('game' => $games[3]->id, 'player' => $players[6]->id, 'victory' => 1, 'control' => 0, 'destruction' => 16), array('game' => $games[3]->id, 'player' => $players[7]->id, 'victory' => 0, 'control' => 0, 'destruction' => 12), array('game' => $games[4]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[4]->id, 'player' => $players[2]->id, 'victory' => 0, 'control' => 4, 'destruction' => 5), array('game' => $games[5]->id, 'player' => $players[4]->id, 'victory' => 1, 'control' => 2, 'destruction' => 22), array('game' => $games[5]->id, 'player' => $players[6]->id, 'victory' => 0, 'control' => 0, 'destruction' => 6), array('game' => $games[6]->id, 'player' => $players[1]->id, 'victory' => 1, 'control' => 5, 'destruction' => 21), array('game' => $games[6]->id, 'player' => $players[3]->id, 'victory' => 0, 'control' => 1, 'destruction' => 16), array('game' => $games[7]->id, 'player' => $players[5]->id, 'victory' => 1, 'control' => 0, 'destruction' => 16), array('game' => $games[7]->id, 'player' => $players[7]->id, 'victory' => 0, 'control' => 0, 'destruction' => 12), array('game' => $games[8]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[8]->id, 'player' => $players[4]->id, 'victory' => 0, 'control' => 4, 'destruction' => 5), array('game' => $games[9]->id, 'player' => $players[1]->id, 'victory' => 1, 'control' => 2, 'destruction' => 22), array('game' => $games[9]->id, 'player' => $players[2]->id, 'victory' => 0, 'control' => 0, 'destruction' => 6), array('game' => $games[10]->id, 'player' => $players[5]->id, 'victory' => 1, 'control' => 5, 'destruction' => 21), array('game' => $games[10]->id, 'player' => $players[6]->id, 'victory' => 0, 'control' => 1, 'destruction' => 16), array('game' => $games[11]->id, 'player' => $players[3]->id, 'victory' => 1, 'control' => 0, 'destruction' => 16), array('game' => $games[11]->id, 'player' => $players[7]->id, 'victory' => 0, 'control' => 0, 'destruction' => 12))); $tournament = $tournaments[1]; $games = $tournament->games()->orderBy('id', 'ASC')->get(); $players = $tournament->players()->orderBy('id', 'ASC')->get(); DB::table('reports')->insert(array(array('game' => $games[0]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[0]->id, 'player' => $players[1]->id, 'victory' => 0, 'control' => 4, 'destruction' => 5), array('game' => $games[1]->id, 'player' => $players[2]->id, 'victory' => 1, 'control' => 2, 'destruction' => 22), array('game' => $games[1]->id, 'player' => $players[3]->id, 'victory' => 0, 'control' => 0, 'destruction' => 6), array('game' => $games[2]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[2]->id, 'player' => $players[2]->id, 'victory' => 0, 'control' => 2, 'destruction' => 21), array('game' => $games[3]->id, 'player' => $players[1]->id, 'victory' => 1, 'control' => 5, 'destruction' => 5), array('game' => $games[3]->id, 'player' => $players[3]->id, 'victory' => 0, 'control' => 3, 'destruction' => 16), array('game' => $games[4]->id, 'player' => $players[0]->id, 'victory' => 1, 'control' => 5, 'destruction' => 18), array('game' => $games[4]->id, 'player' => $players[3]->id, 'victory' => 0, 'control' => 2, 'destruction' => 21), array('game' => $games[5]->id, 'player' => $players[1]->id, 'victory' => 1, 'control' => 5, 'destruction' => 5), array('game' => $games[5]->id, 'player' => $players[2]->id, 'victory' => 0, 'control' => 3, 'destruction' => 16))); foreach ($tournaments as $tournament) { $players = $tournament->players()->get(); foreach ($players as $player) { $player->updateScore($tournament); } foreach ($players as $player) { $opponents = $player->opponents($tournament)->get(); foreach ($opponents as $opponent) { $opponent->updateSos($tournament); } } } }
public function onDisconnect(WebSocketTransportInterface $user) { if (!isset($user->player_id)) { // Unregistered user $this->observer->say('Disconnection from unregistered user'); return false; } if (!$this->connected($user->player_id, $user->game)) { // Last connexion on this game from that user // Send disconnection to game $this->broadcast('{"type": "unregister", "sender": "' . $user->player_id . '"}', $user->game); // Update player status $field = $user->game->which($user->player_id); if ($field != '') { $field .= '_status'; if ($user->game->{$field} > 0) { $user->game->{$field} = 0; } } // Update tournament player status if ($user->game->tournament > 0) { $tournament = Tournament::get($user->game->tournament); $tournament->player_disconnect($user->player_id, 'game_' . $user->game->id); } else { // Update / remove from index if (!$this->displayed($user->game)) { $this->observer->index->broadcast('{"type": "duelcancel", "id": "' . $user->game->id . '"}'); } else { if ($field != '') { $this->observer->index->broadcast(json_encode($user->game)); } } // Clean duel if it has no players connected to $connexions = $this->getConnections(); $connected = false; foreach ($connexions as $cnx) { if ($cnx->game->id == $user->game->id) { $connected = true; break; } } if (!$connected) { $this->observer->clean_duel($user->game); } } } }
public function import_mogg() { $this->say("\tBegin MOGG import"); $this->bans = new Bans($this); $this->say("\t\t" . count($this->bans->list) . ' bans imported'); global $db; // Running games $this->joined_duels = array(); foreach ($db->select("SELECT id FROM `round`\n\t\t\tWHERE\n\t\t\t\t`status` = '3' AND `tournament` = '0'\n\t\t\t\tAND TIMESTAMPDIFF(MINUTE, `last_update_date`, NOW()) < 10\n\t\t\tORDER BY `id` ASC") as $duel) { $g = Game::get($duel->id); if ($g != null) { $g->type = 'joineduel'; // JSON communication $this->joined_duels[] = $g; } } $this->say("\t\t" . count($this->joined_duels) . ' running duels imported'); // Running tournaments foreach ($db->select("SELECT `id` FROM `tournament`\n\t\t\tWHERE `status` > '1' AND `status` < '6'\tORDER BY `id` ASC") as $tournament) { $t = Tournament::get($tournament->id, 'running_tournament'); if ($t) { $this->running_tournaments[] = $t; } } $this->say("\t\t" . count($this->running_tournaments) . ' running tournaments imported'); $this->say("\tEnd MOGG import"); }
public function recieve(WebSocketTransportInterface $user, $data) { switch ($data->type) { case 'tournament_set': $t = Tournament::get($data->id); if ($t == null) { $user->sendString('{"type": "msg", "msg": "No tournament ' . $data->id . '"}'); } else { foreach ($data as $field => $value) { if ($field != 'type' && $field != 'id') { if (!property_exists($t, $field)) { $this->say('Updating non existing field ' . $field); continue; } $this->say('Admin setting "' . $field . '" to "' . $value . '"'); if ($field == 'due_time') { // Have to relaunch timer, using dedicated func // Go on $left = strtotime($value) - time(); if ($left > 0) { // Some time left in current tournament step $t->timer_goon($left); } else { $user->sendString('{"type": "msg", "msg": "Can\'t set due to past time"}'); } } else { $t->{$field} = $value; $t->commit($field); } } } $t->send(); } break; case 'refresh_mtg_data': $this->observer->import_mtg(); $this->refresh($user); break; case 'kick': if (property_exists($data, 'handler') && property_exists($data, 'id')) { if (property_exists($this->observer, $data->handler)) { $handler = $this->observer->{$data->handler}; $kicked = array(); foreach ($handler->getConnections() as $cnx) { if (isset($cnx->player_id) && $cnx->player_id == $data->id) { $cnx->close('Kicked'); $kicked[] = $cnx->nick; } } if (count($kicked) == 0) { $this->say('No players with id ' . $data->id . ' to kick'); } else { $this->say(implode($kicked) . ' kicked'); $this->refresh($user); } } else { $this->say('Trying to kick from unexisting handler ' . $data->handler); } } break; case 'ban': if (property_exists($data, 'id') && property_exists($data, 'reason')) { $this->observer->bans->add($data->reason, null, $data->id); $this->refresh($user); } break; case 'unban': if (property_exists($data, 'id')) { $this->observer->bans->del($data->id); $this->refresh($user); } break; default: $this->say('Unknown type : ' . $data->type); print_r($data); } }