Guest User

Untitled

a guest
Jun 22nd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. class GamersAllianceRPC {
  4. // Not actual details
  5. protected $api_id = "1@gamersalliance.net.au";
  6. protected $api_key = "c2543fff3bfa6f144c2f06a7de6cd10c0b650cae"
  7.  
  8. // XMLRPC Connection
  9. protected $connection = null;
  10.  
  11. // Session ID returned by the server
  12. protected $sessionid = null;
  13.  
  14. public function __construct() {
  15. $this->connection = new xmlrpc_client("/RPC2", "gamersalliance.net.au", 443, 'https');
  16.  
  17. $response = $this->connection->send(new xmlrpcmsg('login', array(php_xmlrpc_encode($api_id), php_xmlrpc_encode($api_key)));
  18.  
  19. if(!$response->faultCode()) {
  20. $this->sessionid = $response->value()->scalarVal();
  21. } else {
  22. throw new Exception("XMLRPC Error: " . $response->faultString());
  23. }
  24. }
  25.  
  26. // Checks to see if the user $username identified by $password exists. Returns Array
  27. // On Success: array(True, array(string $userid, string $username, string $firstname, string $lastname))
  28. // On Failure: array(False, array(string $reason))
  29. // Throws Exception on XMLRPC failure
  30. public function checkAuth($username, $password) {
  31. $response = $this->connection->send(new xmlrpcmsg('checkAuth', array(php_xmlrpc_encode($sessionid), php_xmlrpc_encode($username), php_xmlrpc_encode($password)));
  32.  
  33. if(!$response->faultCode()) {
  34. return $this->nativeise($response->value());
  35. } else {
  36. throw new Exception("XMLRPC Error: " . $response->faultString());
  37. }
  38. }
  39.  
  40. // Converts and XMLRPC response to a native type
  41. public function nativeise($xmlrpcobj) {
  42. if($xmlrpcobj->kindOf() == "scalar") {
  43. return $xmlrpcobj->scalarVal();
  44. } else if($xmlrpcobj->kindOf() == "array") {
  45. $out = array();
  46. for ($i = 0; $i < $xmlrpcobj->arraySize(); $i++) {
  47. $v = $xmlrpcobj->arrayMem($i);
  48. $out[] = $this->nativeise($v);
  49. }
  50. return $out;
  51. } else if($xmlrpcobj->kindOf() == "struct") {
  52. $out = array();
  53. while (list($key, $v) = $xmlrpcobj->structEach()) {
  54. $out[$key] = $this->nativeise($v);
  55. }
  56. return $out;
  57. } else {
  58. return $xmlrpcobj;
  59. }
  60. }
  61. }
Add Comment
Please, Sign In to add comment