2 include_once('../tools/validate_cookie.php');
3 include_once('ring_session_manager_itf.php');
4 include_once('../tools/domain_info.php');
5 include_once('../login/config.php');
7 function planEditSession($charId, $domainId, $sessionType, $title, $desc)
9 $domainInfo = getDomainInfo($domainId);
10 $addr = split(":", $domainInfo["session_manager_address"]);
14 $rsm = new ScheduleSessionCb();
16 $rsm->connect($RSMHost, $RSMPort, $res);
19 echo "Error connecting to session manager<br>";
20 echo '<a href="web_start.php">Return to start menu</a>';
24 // send the create session message
25 $rsm->scheduleSession(
35 0 // 0 inscription slots for edit session
39 // the rest of the work is done in the callback
44 $SessionToolsResult = false;
46 class ScheduleSessionCb
extends CRingSessionManagerWeb
48 function scheduleSessionResult($charId, $sessionId, $result, $resultString)
50 global $SessionId, $DomainId, $SessionToolsResult;
51 $SessionId = $sessionId;
52 // $DomainId = $domainId;
53 echo "Create session result :<br>";
56 $SessionToolsResult = true;
57 echo "Session $sessionId created for char $charId<br>";
58 echo "<h2>Your session has been planned, thank you<h2><br>";
62 $SessionToolsResult = false;
63 echo "Failed to create a session for char $charId with error $resultString <br>";
69 $callbackClient = false;
72 function startSession($charId, $domainId, $sessionId)
74 global $SessionId, $DomainId, $SessionToolsResult;
76 $domainInfo = getDomainInfo($domainId);
77 $addr = split(":", $domainInfo["session_manager_address"]);
81 $SessionId = $sessionId;
82 $DomainId = $domainId;
84 // ask to start the session
85 global $rsmProxy, $callbackClient, $rsmSkel;
86 $startSession = new StartSessionCb
;
88 $startSession->connect($RSMHost, $RSMPort, $res);
89 echo "Starting session for character ".$charId." in session ".$sessionId."<br>";
91 $SessionId = $sessionId;
92 $startSession->startSession($charId, $sessionId);
94 // wait the the return message
95 $startSession->waitCallback() or die("No reponse from session manager");
98 function inviteOwnerInSession($charId, $domainId, $sessionId)
100 global $SessionId, $DomainId, $SessionToolsResult;
102 // first, set the result to false
103 $SessionToolsResult = false;
105 $domainInfo = getDomainInfo($domainId);
106 $addr = split(":", $domainInfo["session_manager_address"]);
110 global $rsmProxy, $rsmSkel, $userId, $charId, $callbackClient, /*$SessionId,*/ $SessionToolsResult;
111 global $DBHost, $RingDBUserName, $RingDBPassword;
113 $SessionId = $sessionId;
114 $DomainId = $domainId;
116 $link = mysqli_connect($DBHost, $RingDBUserName, $RingDBPassword) or die("Can't connect to ring database");
117 mysqli_select_db($link, $domainInfo['ring_db_name']) or die ("Can't access to the db dbname:" . $domainInfo['ring_db_name']);
119 $sessionId = (int) $sessionId;
120 $query = "select session_type from sessions where session_id=".$sessionId;
121 $result = mysqli_query($link, $query) or die ("Can't execute the query: ".$query);
122 if (mysqli_num_rows($result) != 1)
124 echo "Can't find 1 row for ring session ".$sessionId."<br>";
127 $row = mysqli_fetch_row($result);
128 $session_type = $row[0];
129 $mode = ($session_type == "st_edit") ?
"sps_edit_invited" : "sps_anim_invited";
130 echo "Inviting character ".$charId." of user ".$userId." in session ".$sessionId."<br>";
132 $inviteOwner = new InviteOwnerCb
;
134 $inviteOwner->connect($RSMHost, $RSMPort, $res);
135 $inviteOwner->inviteCharacter($charId, $sessionId, $charId, $mode);
137 // wait the the return message
138 if ($inviteOwner->waitCallback() == false)
140 echo "No response from server, invite failed<br>";
145 class StartSessionCb
extends CRingSessionManagerWeb
147 function invokeResult($userId, $resultCode, $resultString)
149 global $rsmProxy, $rsmSkel, $userId, $charId, $callbackClient, $SessionId, $DomainId, $SessionToolsResult;
151 if ($resultCode != 0)
153 $SessionToolsResult = false;
154 echo "<h1>Error ".$resultCode." : '".$resultString."' while trying to start the session ".$SessionId."</h1>";
155 echo '<p><p><a href="web_start.php">Back to menu</a>';
159 // ok, the session is started, invite the session owner in the session
160 $SessionToolsResult = false;
162 echo "Start of session $SessionId success, now inviting character $charId in the sesison<br>";
164 inviteOwnerInSession($charId, $DomainId, $SessionId);
169 class InviteOwnerCb
extends CRingSessionManagerWeb
171 function invokeResult($userId, $resultCode, $resultString)
173 global $rsmProxy, $rsmSkel, $userId, $charId, $callbackClient, $SessionId, $DomainId, $SessionToolsResult;
175 // jump back to main page
176 echo "<h1>The session ".$SessionId." have been started</h1>";
177 if ($resultCode == 0)
179 $SessionToolsResult = true;
180 echo "<h1>You are automaticaly invited in the session</h1>";
184 $SessionToolsResult = false;
185 echo "<h1>Failed to invite you in the started session !</h1>";
186 echo "<h1>Error ".$resultCode." : '".$resultString."' while trying to join the session ".$SessionId."</h1>";
188 echo '<p><p><a href="web_start.php">Back to menu</a>';