2 require_once('../tools/validate_cookie.php');
3 include_once('../login/config.php');
4 include_once('../tools/domain_info.php');
5 include_once('ring_session_manager_itf.php');
7 class JoinShardCb
extends CRingSessionManagerWeb
10 * Join the specified shard
12 function joinSessionResult($userId, $sessionId, $result, $shardAddr, $participantStatus)
14 global $JoinSessionResultCode, $JoinSessionResultMsg;
15 $JoinSessionResultCode = $result;
16 $JoinSessionResultMsg = $shardAddr;
19 global $FSHostLuaMode, $FSHostResult, $FSHostResultStr;
21 $FSHostResultStr = "Error ".$result." : '".$shardAddr."' while trying to join a shard";
24 echo $FSHostResultStr;
25 echo '<p><p><a href="web_start.php">Back to menu</a>';
30 // ok, we have the info to connect !
31 // generate the lua script
32 $cookie=convertCookieForActionHandler($_COOKIE["ryzomId"]);
33 global $FSHostLuaMode, $FSHostResult, $FSHostResultStr;
35 $FSHostResultStr = $shardAddr;
38 $luaScript='runAH(nil, "on_connect_to_shard", "cookie='.$cookie.'|fsAddr='.$shardAddr.'")';
39 //echo 'luaScript : '.$luaScript.'<br>';
40 echo '<lua>'.$luaScript.'</lua>';
43 echo '<br>Teleporting to shard<br>';
49 * Receive the result of the shard list, then call the global $getShardListCallback with the associative array as argument
51 function getShardsResult($userId, $resultStr)
53 global $getShardListCallback;
55 $onlineShardsBySessionId = array();
56 $resultArray = explode(';', $resultStr);
57 foreach ($resultArray as $shardInfo)
59 $shardAttr = explode(',', $shardInfo);
60 if (isset($shardAttr[1]))
61 $onlineShardsBySessionId[$shardAttr[0]] = $shardAttr[1];
63 $getShardListCallback($onlineShardsBySessionId);
68 $FSHostLuaMode = false;
75 // THE ABOVE DECLARATIONS ARE NEEDED FOR ALL CODE BELOW THIS LINE
76 if (isset($_POST["ml"]))
78 if (isset($_POST["destSessionId"]))
79 joinShardFromIdPost($_POST["destSessionId"]);
82 * Authenticate and request to join a mainland shard
84 function joinMainlandPost()
86 global $FSHostLuaMode;
87 $FSHostLuaMode = true;
89 if (!validateCookie($userId, $domainId, $charId))
91 echo "Invalid cookie !";
96 joinMainland($userId, $domainId);
101 * Authenticate and request to join the specified shard
103 function joinShardFromIdPost( $destSessionId )
106 if (!validateCookie($userId, $domainId, $charId))
108 echo "Invalid cookie !";
113 joinShardFromId($userId, $domainId, $destSessionId);
118 * Request to join the specified shard
120 function joinShardFromId( $userId, $domainId, $destSessionId )
122 $domainInfo = getDomainInfo($domainId);
123 $addr = explode(":", $domainInfo["session_manager_address"]);
127 // request join to the session manager
128 $joinShard = new JoinShardCb
;
130 $joinShard->connect($RSMHost, $RSMPort, $res);
131 $charSlot = getCharSlot(); // if ingame (!=15), the RSM can check if this character has the right to connect to the specified shard
132 $charId = ($userId<<4) +
$charSlot;
133 echo "Requesting teleportation of $charId/$userId to shard session ".$destSessionId."...<br>";
134 $joinShard->joinSession($charId, $destSessionId, $domainInfo["domain_name"]);
136 // wait the the return message
137 if ($joinShard->waitCallback() == false)
139 // Note: the answer is a joinSessionResult message
140 echo "No response from server, joinShard failed<br>";
146 * Request to get the shard list
148 function getShardList($userId, $domainId)
150 $domainInfo = getDomainInfo($domainId);
151 $addr = explode(":", $domainInfo["session_manager_address"]);
155 // request get to the session manager
156 $joinShard = new JoinShardCb
;
158 $joinShard->connect($RSMHost, $RSMPort, $res);
160 $charId = ($userId<<4)+
15;
161 echo "Retrieving online shards for $charId...<br>";
162 $joinShard->getShards($charId);
164 // wait the the return message
165 if ($joinShard->waitCallback() == false)
167 echo "No response from server, getShards failed<br>";
173 * Display the list of mainland shards
174 * This is a candidate to the callback $getShardListCallback
176 function displayAllShards(&$onlineShardsBySessionId)
178 // Get the userId and domainId back
180 if (!validateCookie($userId, $domainId, $charId))
182 echo "Invalid cookie !";
186 // List all shards of the domain, including offline ones
187 global $DBName, $DBHost, $DBUserName, $DBPassword;
188 $link = mysqli_connect($DBHost, $DBUserName, $DBPassword) or die("Can't connect to nel database");
189 mysqli_select_db($link, $DBName) or die ("Can't access to the db dbname:$DBName");
191 $domainId = (int) $domainId;
192 $query = "select * from shard where domain_id = $domainId";
193 $resShards = mysqli_query($link, $query) or die ("Can't execute the query: ".$query." ".mysqli_error($link));
195 echo "Select a shard to join:<br>";
196 //echo "<form name='far_tp' action='join_shard.php' method='post'>";
197 while ($rowShard = mysqli_fetch_assoc($resShards))
199 $mainlandSessionId = $rowShard['FixedSessionId'];
200 $isOnline = isset($onlineShardsBySessionId[$mainlandSessionId]);
201 // Radio button not supported by Client's html component. Instead: one form (button) per shard.
202 //echo "<input type='radio' name='destSessionId' value='".$mainlandSessionId."' ".($isOnline?"":"disabled ")."/>".$rowShard['Name']." (".($isOnline?"online with $nbOnlinePlayers players":"offline").", version ".$rowShard['Version'].")<br>";
203 echo "<form name='far_tp_".$rowShard['ShardId']."' action='join_shard.php' method='post'>";
204 echo "<input type='hidden' name='destSessionId' value='".$mainlandSessionId."' />";
205 echo "<input type='hidden' name='charSlot' value='".getCharSlot()."'>";
206 echo " ".$rowShard['Name']." ".$rowShard['ShardId']." (".($isOnline ?
$onlineShardsBySessionId[$mainlandSessionId]." online)" : "offline)");
208 echo "<input type='submit' name='button' value='Teleport' />";
212 //echo "<input type='submit' name='button' value='Teleport' />";
213 //echo "</form></font>";
220 * Returns true in case of success, and the FSHost address in $FSHostResultStr.
221 * Returns false in case of error, and an explanatory string in $FSHostResultStr.
223 function joinMainland($userId, $domainId)
225 $domainInfo = getDomainInfo($domainId);
226 $addr = explode(":", $domainInfo["session_manager_address"]);
230 // request get to the session manager
231 $joinsShard = new JoinShardCb
;
233 $joinsShard->connect($RSMHost, $RSMPort, $res);
235 // set the shard Id to allow any character (by using the special value '15')
236 $charId = ($userId<<4)+
15;
237 global $FSHostLuaMode, $verbose;
238 if ($FSHostLuaMode && $verbose)
239 echo "Joining a mainland shard for $charId...<br>";
240 $joinsShard->joinMainland($charId, $domainInfo["domain_name"]);
242 // wait the the return message
243 if ($joinsShard->waitCallback() == false)
245 global $FSHostResultStr;
246 $FSHostResultStr = "No response from server for joinMainland<br>";
249 global $FSHostResult;
250 return $FSHostResult;