function cloneFile(CouchService $client, $stuff)
 {
     $client->setDb('rest');
     $doc = $client->get($stuff);
     if ($doc->docType == "hexMapData") {
         unset($doc->_id);
         unset($doc->_rev);
         $hexStr = $doc->map->hexStr;
         $doc->map->hexStr = "";
         $ret = $client->post($doc);
         $mapId = $ret->id;
         $mapRev = $ret->rev;
         if ($ret->ok === true) {
             echo "good ";
             if ($hexStr) {
                 echo "better '";
                 $hexDoc = $client->get($hexStr);
                 unset($hexDoc->_id);
                 unset($hexDoc->_rev);
                 $hexDoc->hexStr->map = $mapId;
                 $hexRet = $client->post($hexDoc);
                 if ($hexRet->ok) {
                     echo "Best";
                     $doc->_id = $mapId;
                     $doc->_rev = $mapRev;
                     $doc->map->hexStr = $hexRet->id;
                     $client->put($doc->_id, $doc);
                     echo "BFF forever ";
                 }
             }
         }
     }
 }
 public function getUnitInit(Request $req, CouchService $cs, AdminService $ad, $game, $arg = false)
 {
     $user = Auth::user()['name'];
     $wargame = urldecode($req->session()->get("wargame"));
     $chat = Input::get('chat', TRUE);
     $cs->setDb('games');
     $doc = $cs->get(urldecode($wargame));
     if ($user != $doc->createUser) {
         return redirect("wargame/play");
     }
     $opts = [];
     foreach ($_GET as $k => $v) {
         $opts[] = $k;
     }
     //        $this->load->model('users/users_model');
     $battle = Battle::battleFromName($game, $arg, $opts);
     $opts = [];
     foreach ($_GET as $k => $v) {
         $opts[] = $k;
     }
     //        $battle = $this->battle->getBattle($game, null, $arg, $opts);
     $cs->setDb('games');
     if (method_exists($battle, 'terrainInit')) {
         try {
             $terrainName = "terrain-{$game}.{$arg}";
             $terrainDoc = $cs->get($terrainName);
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
         }
         if (empty($terrainDoc)) {
             try {
                 $terrainName = "terrain-{$game}";
                 $terrainDoc = $cs->get($terrainName);
             } catch (\GuzzleHttp\Exception\BadResponseException $e) {
                 var_dump($e->getMessage());
             }
         }
         $battle->terrainName = $terrainName;
         $battle->terrainInit($terrainDoc);
     }
     if (method_exists($battle, 'init')) {
         $battle->init();
     }
     $doc->wargame = $battle->save();
     $click = $doc->_rev;
     $matches = array();
     preg_match("/^([0-9]+)-/", $click, $matches);
     $click = $matches[1];
     $doc->wargame->gameRules->phaseClicks[] = $click + 1;
     /* should probably get rid of this old code for genTerrain */
     if (isset($doc->wargame->genTerrain)) {
         try {
             $ter = $cs->get($doc->wargame->terrainName);
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
         }
         if (empty($ter)) {
             $data = array("_id" => $doc->wargame->terrainName, "docType" => "terrain", "terrain" => $doc->wargame->terrain);
             $cs->post($data);
         } else {
             $data = array("_id" => $doc->wargame->terrainName, "docType" => "terrain", "terrain" => $doc->wargame->terrain);
             /* totally throw the old one away */
             $cs->delete($doc->wargame->terrainName, $ter->_rev);
             $cs->post($data);
         }
         unset($doc->wargame->terrain);
         $doc->wargame->genTerrain = false;
     }
     $className = $doc->className = get_class($battle);
     $doc->chats = array();
     $doc->gameName = $game;
     $doc = $cs->put($doc->_id, $doc);
     event(new \App\Events\Analytics\RecordGameEvent(['docId' => $doc->id, 'type' => 'game-created', 'className' => $className, 'scenario' => $battle->scenario, 'arg' => $battle->arg, 'time' => time()]));
     return redirect("wargame/play-as/{$game}");
 }