undef HALF_FREQUENCY_SENDING_TO_CLIENT
[ryzomcore.git] / web / public_php / ring / session_tools.php
blobe5f12763f9c921e2155d94ee9dc4783d0de0a433
1 <?php
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"]);
11 $RSMHost = $addr[0];
12 $RSMPort = $addr[1];
14 $rsm = new ScheduleSessionCb();
15 $res="";
16 $rsm->connect($RSMHost, $RSMPort, $res);
17 if ($res != "")
19 echo "Error connecting to session manager<br>";
20 echo '<a href="web_start.php">Return to start menu</a>';
21 die();
24 // send the create session message
25 $rsm->scheduleSession(
26 $charId,
27 $sessionType,
28 $title,
30 $desc,
31 "sl_a",
32 "at_public",
33 "rt_liberal",
34 "et_short",
35 0 // 0 inscription slots for edit session
38 $rsm->waitCallback();
39 // the rest of the work is done in the callback
42 $SessionId = 0;
43 $DomainId = 0;
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>";
54 if ($result == 0)
56 $SessionToolsResult = true;
57 echo "Session $sessionId created for char $charId<br>";
58 echo "<h2>Your session has been planned, thank you<h2><br>";
60 else
62 $SessionToolsResult = false;
63 echo "Failed to create a session for char $charId with error $resultString <br>";
68 $rsmProxy = false;
69 $callbackClient = false;
70 $rsmSkel = false;
72 function startSession($charId, $domainId, $sessionId)
74 global $SessionId, $DomainId, $SessionToolsResult;
76 $domainInfo = getDomainInfo($domainId);
77 $addr = split(":", $domainInfo["session_manager_address"]);
78 $RSMHost = $addr[0];
79 $RSMPort = $addr[1];
81 $SessionId = $sessionId;
82 $DomainId = $domainId;
84 // ask to start the session
85 global $rsmProxy, $callbackClient, $rsmSkel;
86 $startSession = new StartSessionCb;
87 $res = "";
88 $startSession->connect($RSMHost, $RSMPort, $res);
89 echo "Starting session for character ".$charId." in session ".$sessionId."<br>";
90 global $SessionId;
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"]);
107 $RSMHost = $addr[0];
108 $RSMPort = $addr[1];
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>";
125 die();
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;
133 $res = "";
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>";
141 die();
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>';
157 else
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>";
182 else
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>';