Jump to content

Querying a MTA Server


Recommended Posts

Hello Guys,

I'm looking for a working MTA server query for a very long time. I didnt find any. Isn't there a basic script that shows IP, Players, Map? Like the one on gamemonitor, but i don't wanna use that, coz it's branded.

Don't rape me if there is an existing one, i used search, google, etc.

In the Development wiki are several http functions, i guess, they are necessary for querying a server. Problem is: Lua is my first and only scripting language :|

Ah, and btw. If this is the wrong forum: Kill me, delete my posts and do whatever you want with my corpse. Or i will never learn to post in the right one 8)

Link to comment

It really isn't that hard. All you have to do is tell MTA the exported server function is accepting HTTP requests and use any language of your taste that supports HTTP requests. AJAX for example has the XMLHttpRequest object but you can also use sockets in C++. I know MTA DM has HTTP interface classes that you can use (PHP and AJAX). Just search the wiki or look at this very basic example.

HTTPExample.lua

  
function getServerPortEx() 
  return getServerPort() 
end 
  

meta.xml

  
<meta> 
  <export function="getServerPortEx" http="true" /> 
</meta> 
  

HTTPExample.js

  
var xhr = false; 
  
try 
  { 
    xhr = new XMLHttpRequest(); 
  } 
  catch (e) 
  { 
    try 
    { 
      xhr = new ActiveXObject("Msxml2.XMLHTTP"); 
    } 
    catch (e) 
    { 
      try 
      { 
        xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
      catch (e) 
      { 
        alert("Foo"); 
      } 
    } 
  } 
  
xhr.onreadystatechange = function () 
{ 
  if (xhr.readyState == 4) 
  { 
    try 
    { 
      alert("Server Port: " + xhr.responseText); 
    } 
    catch (err) 
    { 
    } 
  } 
} 
  
function getServerPort() 
{ 
  xhr.open("POST", "http://localhost:[port]/[resource]/call/getServerPortEx", true, "user", "pass"); 
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
  xhr.send(null); 
} 
  

index.html

  
<html> 
  <head> 
    <script src="./HTTPExample.js" type="text/javascript"></script> 
  </head> 
  <body> 
    <button onclick="getServerPort(); return false;">Get Server Port</button> 
  </body> 
</html> 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...