Esempio n. 1
0
 public function join()
 {
     $data = Input::only(['name', 'room_id']);
     print_r($data);
     $room = Room::find($data['room_id']);
     if (!$room) {
         return Redirect::action('PrepareController@room');
     }
     if ($room->state !== 'open') {
         throw new BadRequestHttpException('既にゲームは開始しています。');
     }
     if ($room->mates->count() >= $room->member_number) {
         throw new BadRequestHttpException('全ユーザーが揃っています');
     }
     if (!isset($data['name']) || $data['name'] == '') {
         //名前指定していない場合
         return Redirect::action('PrepareController@rooms');
     }
     $i = 0;
     do {
         $hash = sha1(date("Y/m/d H:i:s.u") . 'zCeZu12X' . $data['name'] . $data['room_id']);
         $hashed_mate = Mate::where('hash', $hash)->select('hash')->first();
         $i++;
         if ($i > 50) {
             throw new InternalErrorException('ユーザー作成に失敗しました hash衝突しまくり');
         }
     } while ($hashed_mate && $i < 100);
     $mate = Mate::create(['name' => $data['name'], 'last_state' => 'open', 'hash' => $hash, 'cast_id' => 0, 'room_id' => $data['room_id'], 'select_user_id' => '', 'is_alive' => 1]);
     if (!$mate) {
         throw new InternalErrorException('ユーザー作成に失敗しました');
     }
     $room->touch();
     return Redirect::action('PlayController@index', ['hash' => $hash]);
 }