Comments (2)
Ok, i write it:
fivem.py:
import asyncio
import json
import httpx
from opengsq.protocol_base import ProtocolBase
class FiveM(ProtocolBase):
"""FiveM Protocol"""
full_name = 'FiveM Multiplayer Protocol'
async def make_request(self, url, headers):
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers)
if response.status_code == httpx.codes.OK:
return response.json()
print(f"HTTP request failed with status code: {response.status_code}")
return None
async def get_info(self):
url = f'http://{self._host}:{self._port}/dynamic.json'
headers = {'Content-Type': 'application/json'} # Set the Content-Type header
dynamic_data = await self.make_request(url, headers)
result = {
'hostname': dynamic_data.get('hostname', ''),
'players': dynamic_data.get('clients', 0),
'maxplayers': dynamic_data.get('sv_maxclients', 0),
'gametype': dynamic_data.get('gametype', ''),
'mapname': dynamic_data.get('mapname', '')
}
return result
`
it works with the command :
opengsq fivem --host 45.81.17.148 --port 30120 --function get_info
but i can make it work with
if game.strip() == "fivem":
fivem = FiveM(host=ip_real.strip(), port=port_real.strip())
info = await fivem.get_info()
return {
'hostname': info['hostname'] if info else hostname_untouch,
'players': info['players'] if info else 0,
'maxplayers': info['maxplayers'] if info else 0,
'mapname': info['mapname'] if info else 'unknown',
'bots': 0,
'status': 'online' if info else 'offline'
}
`
I get:
File "/usr/lib/python3/dist-packages/mysql/connector/network.py", line 133, in __del__
File "/usr/lib/python3/dist-packages/mysql/connector/network.py", line 121, in shutdown
TypeError: catching classes that do not inherit from BaseException is not allowed
Can you implement this in next release ? It works very well. Every fivem have builtin web server and this file is there... (http://45.81.17.148:30120/dynamic.json)
Ps: The script above needs:
pip install httpx
Thank you!
from opengsq-python.
@Pok4 This is a good suggestion!
I will implement that in the next release.
from opengsq-python.
Related Issues (10)
- Mordhau module does not show players HOT 3
- does it support the isle evrima server?
- Timeout error for no apparent reason. HOT 12
- Mordhau class missing useful server info HOT 7
- Satisfactory protocol changed with game v1.0 HOT 1
- Documented instructions do not seem to work HOT 2
- Is it possible in php? HOT 2
- EOS Query Credentials HOT 2
- Source.RemoteConsole not working with ASA HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opengsq-python.