/** * Function to enable SSO (it runs before user_login() is called) * If a valid CHOCOLATECHIP cookie is not found, the user will be forced to the * master bakery login page where have to authenticate the user. * * @return logged in USER */ function loginpage_hook() { global $CFG, $USER, $DB; global $key, $cookieDomain, $slaveURL, $masterURL, $defaultCountry; $key = $this->config->skey; $cookieDomain = $this->config->cookiedomain; $masterURL = $this->config->masterurl; $slaveURL = $this->config->slaveurl; $defaultCountry = $this->config->defaultcountry; $mdBakery['slave'] = validateCookie(); if (!empty($mdBakery['slave'])) { $username = $mdBakery['slave']['name']; $user = authenticate_user_login($username, null); if ($user) { complete_user_login($user); $urltogo = $CFG->wwwroot . '/'; $userMail = $USER->email; // If dummie change init url through edit user form $userInit = $USER->idnumber; // Don't check for username because of user freedom for Firstname and Lastname display if ($userMail != $mdBakery['slave']['mail'] || $userInit != $mdBakery['slave']['init']) { $emptyString = " "; // Or just "default" string $user->idnumber = $mdBakery['slave']['init']; $fName = ucfirst($mdBakery['slave']['name']); $user->firstname = $fName; $user->lastname = $emptyString; $user->email = $mdBakery['slave']['mail']; $user->city = $emptyString; $user->country = $defaultCountry; $DB->update_record('user', $user); } redirect($urltogo); } } else { if (isloggedin() && !isguestuser()) { require_logout(); } else { // $master_redirect = $masterURL . 'user/login?return_dest=' . urlencode($slaveURL . 'login/index.php'); // header('Location: ' . $master_redirect); } } }
/** * Request to join the specified shard */ function joinSessionFromId($userId, $domainId, $destSessionId) { $domainId = -1; if (!validateCookie($userId, $domainId, $charId)) { echo "Invalid cookie !"; die; } else { echo "Welcome user {$userId}<BR>"; $domainInfo = getDomainInfo($domainId); $addr = split(":", $domainInfo["session_manager_address"]); $RSMHost = $addr[0]; $RSMPort = $addr[1]; // ask join to the session manager $joinSession = new JoinSessionCb(); $res = ""; $joinSession->connect($RSMHost, $RSMPort, $res); // $rsmProxy = new CRingSessionManagerWebProxy; // $charSlot = getCharSlot(); // if ingame (!=15), the RSM will check if this character has the right to connect to the specified session // $charId = ($userId<<4) + $charSlot; echo $charId . " of user " . $userId . " joigning session " . $destSessionId . "<br>"; $joinSession->joinSession($charId, $destSessionId, $domainInfo["domain_name"]); // wait the the return message // $rsmSkel = new CRingSessionManagerWebSkel; if ($joinSession->waitCallback() == false) { echo "No response from server, joinSession failed<br>"; } die; } }
function estAuthentifier() { if (isset($_SESSION['connexion']) or isset($_COOKIE['connexion']) && validateCookie($_COOKIE['connexion'])) { global $currentJoueur; $currentJoueur = new Joueur($_SESSION['idJoueur']); $currentJoueur->save(); return true; } else { return false; } }
{ function invokeResult($userId, $resultCode, $resultString) { global $step, $rsmProxy, $rsmSkel, $userId, $callbackClient; if ($resultCode != 0) { echo "<h1>Error " . $resultCode . " : '" . $resultString . "' will trying to close the session " . $_POST["sessionId"] . "</h1>"; echo '<p><p><a href="web_start.php">Back to menu</a>'; } else { // ok, the session is closed (or almost to close) echo "<h1>Session " . $_POST["sessionId"] . " is begin closed</h1>"; echo '<p><a href="web_start.php">Return to main</a> </p>'; } } } $domainId = -1; if (!validateCookie($userId, $domainId, $charId)) { echo "Invalid cookie !"; die; } else { $domainInfo = getDomainInfo($domainId); $addr = split(":", $domainInfo["session_manager_address"]); $RSMHost = $addr[0]; $RSMPort = $addr[1]; // ask to start the session $closeSession = new CloseSessionCb(); $res = ""; $closeSession->connect($RSMHost, $RSMPort, $res); // $rsmProxy = new CRingSessionManagerWebProxy; $closeSession->closeSession($charId, $_POST["sessionId"]); // wait the the return message // $rsmSkel = new CRingSessionManagerWebSkel;
* * Returns: * success / failure */ $addTopic = function ($sql) { $_POST = json_decode(file_get_contents('php://input'), true); /* Parameters */ $expected = array("title", "text"); $params = fetchPostParams($expected); /* Check all parameters were included and set */ foreach ($expected as $expect) { if (!isset($params[$expect])) { die("Error: {$expect} parameter was not set."); } } $cookie = validateCookie(); if (!$cookie) { header('HTTP/1.1 401 Unauthorized'); die("Invalid cookie"); } $posted_by = $cookie["id"]; $title = $params["title"]; $text = $params["text"]; /* Sql escaping */ db_escape($posted_by, $sql); db_escape($title, $sql); db_escape($text, $sql); /* Specify query */ $query = "insert into forum_topics values (default, {$posted_by}, '{$title}', now());"; $result = db_update($query, $sql); $id = mysqli_insert_id($sql);
/** * Display the list of mainland shards * This is a candidate to the callback $getShardListCallback */ function displayAllShards(&$onlineShardsBySessionId) { // Get the userId and domainId back $domainId = -1; if (!validateCookie($userId, $domainId, $charId)) { echo "Invalid cookie !"; die; } // List all shards of the domain, including offline ones global $DBName; mysql_select_db($DBName) or die("Can't access to the db dbname:{$DBName}"); $query = "select * from shard where domain_id = {$domainId}"; $resShards = mysql_query($query) or die("Can't execute the query: " . $query . " " . mysql_error()); echo "Select a shard to join:<br>"; //echo "<form name='far_tp' action='join_shard.php' method='post'>"; while ($rowShard = mysql_fetch_array($resShards)) { $mainlandSessionId = $rowShard['FixedSessionId']; $isOnline = isset($onlineShardsBySessionId[$mainlandSessionId]); // Radio button not supported by Client's html component. Instead: one form (button) per shard. //echo "<input type='radio' name='destSessionId' value='".$mainlandSessionId."' ".($isOnline?"":"disabled ")."/>".$rowShard['Name']." (".($isOnline?"online with $nbOnlinePlayers players":"offline").", version ".$rowShard['Version'].")<br>"; echo "<form name='far_tp_" . $rowShard['ShardId'] . "' action='join_shard.php' method='post'>"; echo "<input type='hidden' name='destSessionId' value='" . $mainlandSessionId . "' />"; echo "<input type='hidden' name='charSlot' value='" . getCharSlot() . "'>"; echo " " . $rowShard['Name'] . " " . $rowShard['ShardId'] . " (" . ($isOnline ? $onlineShardsBySessionId[$mainlandSessionId] . " online)" : "offline)"); if ($isOnline) { echo "<input type='submit' name='button' value='Teleport' />"; } echo "</form><br>"; } //echo "<input type='submit' name='button' value='Teleport' />"; //echo "</form></font>"; exit; }
function isAllowedUserForListing($listing_id) { //first we need to check if the user exists at all (if the credentials stored in cookie are valid) if (!validateCookie()) { return false; } //check if user has admin priviledges if (isAdmin(getEmail(), getPassword())) { return true; } //if the user has valid credentials but is just a regular user //then we have to check if the listing belongs to him global $wpdb; $sql = "SELECT * FROM " . $wpdb->prefix . "kallababy_listing where user_id='" . getEmail() . "' and id='" . $listing_id . "'"; $result = $wpdb->query($sql); if ($wpdb->num_rows > 0) { return true; } return false; }