getClientCertificate() === null) { return false; } return DB::query( << $request->getClientCertificate()->getFingerprint()] )->fetch(); } public function create(Request $request): array|bool { DB::query( 'insert into users (username, password, email) values (:username, :fingerprint, :email)', [ 'username' => md5($request->getClientCertificate()->getFingerprint()), 'fingerprint' => $request->getClientCertificate()->getFingerprint(), 'email' => '(no email)', ] ); $userId = DB::$connection->lastInsertId(); DB::query( 'insert into users_gemini (certificate, user_id) values (:fingerprint, :userId)', ['fingerprint' => $request->getClientCertificate()->getFingerprint(), 'userId' => $userId] ); // also insert new village at random free coordinates DB::query( 'insert into villages (name, x, y, wood, clay, iron, food, satisfaction) values (:name, :x, :y, :wood, :clay, :iron, :food, :satisfaction)', [ 'name' => substr(md5(rand()), 0, 6), 'x' => rand(0, 100), 'y' => rand(0, 100), 'wood' => 500, 'clay' => 500, 'iron' => 500, 'food' => 500, 'satisfaction' => 100, ] ); $villageId = DB::$connection->lastInsertId(); DB::query( 'insert into user_villages (user_id, village_id) values (:userId, :villageId)', ['userId' => $userId, 'villageId' => $villageId] ); // insert base buildings DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'TownHall', 'villageId' => $villageId] ); DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'Storage', 'villageId' => $villageId] ); DB::query( 'insert into village_storage_config (wood, clay, iron, food, village_id) values (:wood, :clay, :iron, :food, :villageId)', ['wood' => 25, 'clay' => 25, 'iron' => 25, 'food' => 25, 'villageId' => $villageId] ); DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'WoodCutter', 'villageId' => $villageId] ); DB::query( 'insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id) values (:amount, :type, false, :villageId, :villageId)', ['amount' => 1, 'type' => 'WoodCutter', 'villageId' => $villageId] ); DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'ClayPit', 'villageId' => $villageId] ); DB::query( 'insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id) values (:amount, :type, false, :villageId, :villageId)', ['amount' => 1, 'type' => 'PitWorker', 'villageId' => $villageId] ); DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'IronMine', 'villageId' => $villageId] ); DB::query( 'insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id) values (:amount, :type, false, :villageId, :villageId)', ['amount' => 1, 'type' => 'Miner', 'villageId' => $villageId] ); DB::query( 'insert into village_buildings (level, type, village_id) values (:level, :type, :villageId)', ['level' => 1, 'type' => 'Farm', 'villageId' => $villageId] ); DB::query( 'insert into village_units (amount, type, is_traveling, home_village_id, residence_village_id) values (:amount, :type, false, :villageId, :villageId)', ['amount' => 1, 'type' => 'Farmer', 'villageId' => $villageId] ); return $this->get($request); } public function account(Request $request): Response { $user = $this->get($request); return new Response(body: View::render('account.twig', [ 'user' => $user, ])); } public function accountUsername(Request $request): Response { $input = $request->get('input'); if (empty($input)) { return new Response(statusCode: Status::INPUT, meta: 'Username'); } $user = $this->get($request); DB::query('update users set username=:username where id=:id', ['username' => urldecode($input), 'id' => $user['id']]); return new Response( statusCode: Status::REDIRECT_TEMPORARY, meta: '/account' ); } public function accountEmail(Request $request): Response { $input = $request->get('input'); if (empty($input)) { return new Response(statusCode: Status::INPUT, meta: 'E-Mail'); } $user = $this->get($request); DB::query('update users set email=:email where id=:id', ['email' => urldecode($input), 'id' => $user['id']]); return new Response( statusCode: Status::REDIRECT_TEMPORARY, meta: '/account' ); } public function accountPassword(Request $request): Response { $input = $request->get('input'); if (empty($input)) { return new Response(statusCode: Status::SENSITIVE_INPUT, meta: 'Password'); } $password = password_hash(urldecode($input), PASSWORD_DEFAULT); $user = $this->get($request); DB::query('update users set password=:password where id=:id', ['password' => $password, 'id' => $user['id']]); return new Response( statusCode: Status::REDIRECT_TEMPORARY, meta: '/account' ); } }