public function postPoke(Request $req, CouchService $cs)
 {
     $user = Auth::user()['name'];
     $cs->setDb('games');
     $wargame = urldecode($req->session()->get("wargame"));
     $x = (int) Input::get('x', FALSE);
     $y = (int) Input::get('y', FALSE);
     $event = (int) Input::get('event', FALSE);
     $id = Input::get('id', FALSE);
     //        $this->load->model("wargame/wargame_model");
     /*  @var  Wargame_model */
     $cs->setDb('games');
     $doc = $cs->get(urldecode($wargame));
     $ter = false;
     if (!empty($doc->wargame->terrainName)) {
         try {
             $ter = $cs->get($doc->wargame->terrainName);
         } catch (\GuzzleHttp\Exception\BadResponseException $e) {
             var_dump($e->getMessage());
         }
         $doc->wargame->terrain = $ter->terrain;
     }
     //        $this->load->library("battle");
     $game = !empty($doc->gameName) ? $doc->gameName : '';
     $emsg = false;
     $click = $doc->_rev;
     $matches = array();
     preg_match("/^([0-9]+)-/", $click, $matches);
     $click = $matches[1];
     try {
         $battle = Battle::battleFromDoc($doc);
         $isGameOver = $battle->victory->gameOver;
         //            $battle = Battle::getBattle($game, $doc->wargame, $doc->wargame->arg, false, $doc->className);
         $doSave = $battle->poke($event, $id, $x, $y, $user, $click);
         $gameOver = $battle->victory->gameOver;
         if (!$isGameOver && $gameOver) {
             event(new \App\Events\Analytics\RecordGameEvent(['docId' => $doc->_id, 'winner' => $battle->victory->winner, 'type' => 'game-victory', 'className' => $doc->className, 'scenario' => $battle->scenario, 'arg' => $battle->arg, 'time' => time()]));
         }
         $success = false;
         if ($doSave) {
             $doc->wargame = $battle->save();
             $cs->put($doc->_id, $doc);
             $success = true;
         }
         if ($doSave === 0) {
             $success = true;
         }
     } catch (Exception $e) {
         $emsg = $e->getMessage() . " \nFile: " . $e->getFile() . " \nLine: " . $e->getLine() . " \nCode: " . $e->getCode();
         $success = false;
     }
     if (!$success) {
         header("HTTP/1.1 404 Not Found");
     }
     return compact('success', "emsg");
 }
 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 addGame(CouchService $cs, $games)
 {
     $isProduction = config('app.env') === 'production';
     $prevDb = $cs->setDb('users');
     $doc = $cs->get("gnuGamesAvail");
     if ($doc->docType == "gnuGamesAvail") {
         foreach ($games as $name => $game) {
             if (!empty($game->disabled) === true) {
                 continue;
             }
             if ($isProduction && empty($game->production)) {
                 continue;
             }
             $doc->games->{$name} = $game;
         }
     }
     $cs->put($doc->_id, $doc);
     $cs->setDb($prevDb);
 }