} } if ($queueSpot) { echo 'Open spot - proceed'; // Creatre the data for the new character $charTemplateFile = fopen($scnPath . '/charTemplates.dat', 'rb'); $newChar = new character($postVals[2] * 4, $charTemplateFile); fclose($charTemplateFile); // Save character with stats into game if (flock($unitFile, LOCK_EX)) { fseek($unitFile, 0, SEEK_END); $size = ftell($unitFile); $newID = $size / $defaultBlockSize; //fseek($unitFile, $newID*$defaultBlockSize); //fwrite($unitFile, $charDat); $newChar->changeID($newID); flock($unitFile, LOCK_UN); } // Add game specific infomrationf /// Record locations, controller, etc $newChar->charData[1] = $bldgDat[1]; $newChar->charData[2] = $bldgDat[2]; $newChar->charData[4] = 4; $newChar->charData[18] = 0; $newChar->charData[19] = 500; // Save the new character $newChar->save($unitFile); // Add the unit to the building slot echo 'Save unit ' . $newID . ' in building #' . $postVals[1] . ' queue spot ' . $queueSpot; fseek($unitFile, $postVals[1] * $defaultBlockSize + 4 * ($queueSpot - 1)); fwrite($unitFile, pack('i', $newID));