$message = $ui['accessDenied']; } } else { $message = $ui[$status]; } } else { $message = $ui['accessDenied']; } } else { $message = $ui['insufficientData']; } } break; case 'add': if ($status == 'noAlliance') { $nodes = node::getList($_SESSION[$shortTitle . 'User']['id']); if ($nodes) { $nodeList = ''; foreach ($nodes as $node) { $nodeList .= '<option value="' . $node->data['id'] . '">' . $node->data['name'] . '</option>'; } if (isset($_POST['nodeId'], $_POST['name'])) { if ($_POST['name'] != '') { $alliance = new alliance(); $node = new node(); $status = $node->get('id', $_POST['nodeId']); if ($status == 'done') { if ($node->data['user'] == $_SESSION[$shortTitle . 'User']['id']) { $alliance->data['name'] = $_POST['name']; $alliance->data['user'] = $_SESSION[$shortTitle . 'User']['id']; $status = $alliance->add($node->data['id']);
public function add($userId) { global $db, $game, $shortTitle; $sector = grid::getSector($this->location['x'], $this->location['y']); $node = new node(); $status = 0; if ($sector['type'] == 1) { if ($node->get('name', $this->data['name']) == 'noNode') { $nodes = node::getList($userId); if (count($nodes) < $game['users']['nodes']) { $ok = 1; $this->data['id'] = misc::newId('nodes'); $db->query('insert into nodes (id, faction, user, name, focus, lastCheck) values ("' . $this->data['id'] . '", "' . $this->data['faction'] . '", "' . $this->data['user'] . '", "' . $this->data['name'] . '", "hp", now())'); if ($db->affected_rows() == -1) { $ok = 0; } $db->query('update grid set type="2", id="' . $this->data['id'] . '" where x="' . $this->location['x'] . '" and y="' . $this->location['y'] . '"'); if ($db->affected_rows() == -1) { $ok = 0; } $query = array(); $nr = count($game['resources']); for ($i = 0; $i < $nr; $i++) { $query[$i] = '("' . $this->data['id'] . '", "' . $i . '", "' . $game['factions'][$this->data['faction']]['storage'][$i] . '")'; } $db->query('insert into resources (node, id, value) values ' . implode(', ', $query)); if ($db->affected_rows() == -1) { $ok = 0; } $query = array(); $nr = count($game['technologies'][$this->data['faction']]); for ($i = 0; $i < $nr; $i++) { $query[$i] = '("' . $this->data['id'] . '", "' . $i . '", "0")'; } $db->query('insert into technologies (node, id, value) values ' . implode(', ', $query)); if ($db->affected_rows() == -1) { $ok = 0; } $query = array(); for ($i = 0; $i < $game['factions'][$this->data['faction']]['modules']; $i++) { $query[$i] = '("' . $this->data['id'] . '", "' . $i . '", "-1", "0")'; } $db->query('insert into modules (node, slot, module, input) values ' . implode(', ', $query)); if ($db->affected_rows() == -1) { $ok = 0; } $query = array(); $nr = count($game['components'][$this->data['faction']]); for ($i = 0; $i < $nr; $i++) { $query[$i] = '("' . $this->data['id'] . '", "' . $i . '", "0")'; } $db->query('insert into components (node, id, value) values ' . implode(', ', $query)); if ($db->affected_rows() == -1) { $ok = 0; } $query = array(); $nr = count($game['units'][$this->data['faction']]); for ($i = 0; $i < $nr; $i++) { $query[$i] = '("' . $this->data['id'] . '", "' . $i . '", "0")'; } $db->query('insert into units (node, id, value) values ' . implode(', ', $query)); if ($db->affected_rows() == -1) { $ok = 0; } if ($ok) { $status = "done"; } else { $status = 'error'; } } else { $status = 'maxNodesReached'; } } else { $status = 'nameTaken'; } } else { $status = 'invalidGridSector'; } return $status; }