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::query('select id from users where password=:password', ['password' => $request->getClientCertificate()->getFingerprint()])->fetchColumn(); 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::query('select id from villages order by id desc limit 1')->fetchColumn(); 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); } }