예제 #1
0
 function checkServerTimeDiff($overview_string)
 {
     date_default_timezone_set('Asia/Taipei');
     $config = ConfigManager::declareConfigValue();
     $now_time = date('H:i:s', time());
     //每次取得新session時 檢測本機時間 與 伺服器時間的差距
     $ogame_clock = GlobalFunc::getOGameServerTime($overview_string);
     $diff_in_sec = GlobalFunc::timeDiffInSecond($now_time, $ogame_clock);
     echo "\n============================================================================\n";
     echo "ogame_clock : {$ogame_clock}\n";
     echo "\nLoginManager: This computer is " . $diff_in_sec . " sec different from server.\n";
     //write time log to time.log file
     if ($ogame_clock !== false) {
         $time_log = iconv("UTF-8", "big5", date('l jS \\of F Y h:i:s A') . " | 外掛時間:{$now_time} | OGame網頁時間:{$ogame_clock} | 時間差: " . $diff_in_sec . " 秒\n");
         file_put_contents($config['TimeLog'], $time_log, FILE_APPEND | LOCK_EX);
     } else {
         echo "ogame_clock === false, don't write to time.log.\n";
     }
     if ($diff_in_sec > 0) {
         echo "Our System time is faster than OGame Server.\n";
     } else {
         if ($diff_in_sec < 0) {
             echo "Our System time is slower than OGame Server.\n";
         }
     }
     if (abs($diff_in_sec) >= 20) {
         //時間差超過3秒
         echo "Time difference is too large, synchronize host time with server.\n";
         system("cmd.exe /c ./../Timer.bat");
     }
     echo "\n============================================================================\n";
 }