Giter Club home page Giter Club logo

Comments (2)

Pok4 avatar Pok4 commented on September 24, 2024

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.

BattlefieldDuck avatar BattlefieldDuck commented on September 24, 2024

@Pok4 This is a good suggestion!

I will implement that in the next release.

from opengsq-python.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.