Exemple #1
0
 /**
  * 在线状态下客户端发来的日结消息引发的函数。农场清算里面的:大厅生产文化(增加),果仓水果(减少),金库金币(减少)。
  * 函数名:eod = end of day
  * 注意,客户端发来的消息自然是强制要求服务器端做一次日结。此时,服务器端
  * 1:可能还没有走到日结的时间。(比如,日结的时间是10分钟一次)
  * 2:可能已经走过了日结的时间。
  * 服务器端要检查自己的时间离日结时间的秒数偏差,如果差太大,那么属于错误,返回APP_SYNC_FAIL。如果偏差小,那么就直接做eod结算
  * 
  *
  */
 private function eodFarm()
 {
     //求出日结个数
     $day_long = FarmConfig::getWorldConfig('DayLong');
     $time_dif = time() - $this->days_gone * $day_long;
     $time_dif = abs($time_dif);
     if ($time_dif > FarmConfig::getMaxNetDelay()) {
         return 'eod sync error: time diff is ' . $time_dif;
     } else {
         $farm_data =& $this->farm_data;
         $hall_count = count($farm_data['halls']);
         for ($i = 0; $i < $hall_count; $i++) {
             $farm_data['halls'][$i] = $this->eodHall($i, 1)->toArray();
         }
         $fooder_count = count($farm_data['fooders']);
         for ($i = 0; $i < $hall_count; $i++) {
             $farm_data['fooders'][$i] = $this->eodFooder($i, 1)->toArray();
         }
         $golder_count = count($farm_data['golders']);
         for ($i = 0; $i < $golder_count; $i++) {
             $farm_data['goldders'][$i] = $this->eodGolder($i, 1)->toArray();
         }
         $this->mongoUpdate($this->query, array('days_gone' => $this->days_gone + 1));
         return 'ok';
     }
 }
Exemple #2
0
 private function apply_farm($user_id)
 {
     $newfarm = FarmLayout::$farmlayout[0];
     $farm_id_exist = true;
     /*		while($farm_id_exist)
     		{
     			//$fid = rand(1,100000);
     			$fid = 1;
     			$farm_id_exist = $this->mongo_db->where(array("fid"=>$fid))->get('farm');
     		}
      */
     $fid = 1;
     $newfarm['fid'] = $fid;
     $day_long = FarmConfig::getWorldConfig('DayLong');
     //此处一定要把它整数化,否则客户端会解析Json出错
     $newfarm['days_gone'] = intval(time() / $day_long);
     $this->mongo_db->insert('farm', $newfarm);
     $this->mongo_db->insert('player', array("user_id" => $user_id, "fid" => $fid));
     //mongoDB在插入的时候会把key="_id"的key-value pair插入到newfarm中。所以此处要去掉这个key
     unset($newfarm['_id']);
     return $newfarm;
 }