public function add() { global $db; $recipient = new user(); if ($recipient->get('name', $this->data['recipient']) == 'done') { $sender = new user(); if ($sender->get('name', $this->data['sender']) == 'done') { if (!$sender->isBlocked($recipient->data['id'])) { $this->data['id'] = misc::newId('messages'); $sent = strftime('%Y-%m-%d %H:%M:%S', time()); $db->query('insert into messages (id, sender, recipient, subject, body, sent, viewed) values ("' . $this->data['id'] . '", "' . $sender->data['id'] . '", "' . $recipient->data['id'] . '", "' . $this->data['subject'] . '", "' . $this->data['body'] . '", "' . $sent . '", "' . $this->data['viewed'] . '")'); if ($db->affected_rows() > -1) { $status = 'done'; } else { $status = 'error'; } } else { $status = 'blocked'; } } else { $status = 'noSender'; } } else { $status = 'noRecipient'; } return $status; }
public function add($nodeId) { global $db, $game; $alliance = new alliance(); if ($alliance->get('name', $this->data['name']) == 'noAlliance') { $node = new node(); if ($node->get('id', $nodeId) == 'done') { $node->checkResources(time()); $addCost = $game['factions'][$node->data['faction']]['costs']['alliance']; $addCostData = $node->checkCost($addCost, 'alliance'); if ($addCostData['ok']) { $ok = 1; foreach ($addCost as $cost) { $node->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['alliance']; $db->query('update resources set value="' . $node->resources[$cost['resource']]['value'] . '" where node="' . $node->data['id'] . '" and id="' . $cost['resource'] . '"'); if ($db->affected_rows() == -1) { $ok = 0; } } $this->data['id'] = misc::newId('alliances'); $db->query('insert into alliances (id, user, name) values ("' . $this->data['id'] . '", "' . $node->data['user'] . '", "' . $this->data['name'] . '")'); if ($db->affected_rows() == -1) { $ok = 0; } $db->query('update users set alliance="' . $this->data['id'] . '" where id="' . $this->data['user'] . '"'); if ($db->affected_rows() == -1) { $ok = 0; } if ($ok) { $status = 'done'; } else { $status = 'error'; } } else { $status = 'notEnoughResources'; } } else { $status = 'noNode'; } } else { $status = 'nameTaken'; } return $status; }
public function add() { global $db, $game; $user = new user(); if ($user->get('name', $this->data['name']) == 'noUser') { if ($user->get('email', $this->data['email']) == 'noUser') { if (!blacklist::check('ip', $this->data['ip'])) { if (!blacklist::check('email', $this->data['email'])) { $ok = 1; $this->data['id'] = misc::newId('users'); $db->query('insert into users (id, name, password, email, level, joined, lastVisit, ip, template, locale) values ("' . $this->data['id'] . '", "' . $this->data['name'] . '", "' . $this->data['password'] . '", "' . $this->data['email'] . '", "' . $this->data['level'] . '", "' . $this->data['joined'] . '", "' . $this->data['lastVisit'] . '", "' . $this->data['ip'] . '", "' . $this->data['template'] . '", "' . $this->data['locale'] . '")'); if ($db->affected_rows() == -1) { $ok = 0; } $preferences = array(); foreach ($game['users']['preferences'] as $key => $preference) { $preferences[] = '("' . $this->data['id'] . '", "' . $key . '", "' . $preference . '")'; } $preferences = implode(', ', $preferences); $db->query('insert into preferences (user, name, value) values ' . $preferences); if ($db->affected_rows() == -1) { $ok = 0; } if ($ok) { $status = 'done'; } else { $status = 'error'; } } else { $status = 'emailBanned'; } } else { $status = 'ipBanned'; } } else { $status = 'emailInUse'; } } else { $status = 'nameTaken'; } return $status; }
public function addCombat($nodeId, $data) { global $db, $game; $this->getResources(); $this->getUnits(); $this->getLocation(); $node = new node(); $okUnits = 1; $army = array(); foreach ($data['input']['attacker']['groups'] as $group) { if (isset($army[$group['unitId']])) { $army[$group['unitId']] += $group['quantity']; } else { $army[$group['unitId']] = $group['quantity']; } } $speed = 999999999; foreach ($this->units as $key => $group) { if (isset($army[$key])) { if ($army[$key] > $group['value']) { $okUnits = 0; } if ($game['units'][$this->data['faction']][$key]['speed'] < $speed) { $speed = $game['units'][$this->data['faction']][$key]['speed']; } } } $combatCost = $game['factions'][$this->data['id']]['costs']['combat']; $okCombatCost = $this->checkCost($combatCost, 'combat'); if ($okUnits) { if ($okCombatCost['ok']) { if ($node->get('id', $nodeId) == 'done') { $node->getLocation(); $distance = sqrt(pow(abs($this->location['x'] - $node->location['x']), 2) + pow(abs($this->location['y'] - $node->location['y']), 2)); $duration = $distance / ($speed * $game['users']['speed']['combat']); $combatId = misc::newId('combat'); $ok = 1; $cuBuffer = array(); foreach ($army as $key => $value) { $cuBuffer[] = '("' . $combatId . '", "' . $key . '", "' . $value . '")'; $this->units[$key]['value'] -= $value; $db->query('update units set value="' . $this->units[$key]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $key . '"'); if ($db->affected_rows() == -1) { $ok = 0; } $upkeepResource = $game['units'][$this->data['faction']][$key]['upkeepResource']; $upkeep = $game['units'][$this->data['faction']][$key]['upkeep']; $this->resources[$upkeepResource]['value'] += $upkeep * $value; $db->query('update resources set value="' . $this->resources[$upkeepResource]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $upkeepResource . '"'); if ($db->affected_rows() == -1) { $ok = 0; } } foreach ($combatCost as $cost) { $this->resources[$cost['resource']]['value'] -= $cost['value'] * $game['users']['cost']['combat']; $db->query('update resources set value="' . $this->resources[$cost['resource']]['value'] . '" where node="' . $this->data['id'] . '" and id="' . $cost['resource'] . '"'); if ($db->affected_rows() == -1) { $ok = 0; } } $db->query('insert into combat (id, sender, recipient, focus, stage, start, duration) values ("' . $combatId . '", "' . $this->data['id'] . '", "' . $node->data['id'] . '", "' . $data['input']['attacker']['focus'] . '", "0", "' . strftime('%Y-%m-%d %H:%M:%S', time()) . '", "' . $duration . '")'); if ($db->affected_rows() == -1) { $ok = 0; } $db->query('insert into combat_units (combat, id, value) values ' . implode(', ', $cuBuffer)); if ($db->affected_rows() == -1) { $ok = 0; } if ($ok) { $status = 'done'; } else { $status = 'error'; } } else { $status = 'noNode'; } } else { $status = 'notEnoughResources'; } } else { $status = 'notEnoughUnits'; } return $status; }