Esempio n. 1
0
def main(args):
    with SampClient(*args) as client:
        if not client.is_online():
            print('Server {}:{} is offline'.format(*args))
            exit(1)
        server_info = client.get_server_info()
        print("""Connected to {info.hostname}. 
Currently {info.players}/{info.max_players} players online.

Select one of the options:

i. Server Info
r. Server Rules
c. Connected clients
d. Detailed clients
x. RCON
""".format(info=server_info, ))

        options = {
            'i': info,
            'r': rules,
            'c': clients,
            'd': details,
            'x': rcon,
        }
        option = input('Select option: ')
        if option in options: options[option](client)
        else: print('Unknown option, bye!')
Esempio n. 2
0
class RconClientTestCase(TestCase):
    def setUp(self):
        super(RconClientTestCase, self).setUp()
        self.client = SampClient(address='server.convoytrucking.net')
        self.client.connect()

    def tearDown(self):
        super(RconClientTestCase, self).tearDown()
        self.client.disconnect()

    def test_no_password(self):
        self.assertRaises(RconError, self.client.rcon_players)

    def test_incorrect_password(self):
        self.client.rcon_password = '******'
        self.assertRaises(InvalidRconPassword, self.client.rcon_players)
Esempio n. 3
0
	async def samp(self, ctx, arg, port=7777):
		""" Pobiera informacje dot. serwera SA:MP """
		with SampClient(address=arg, port=int(port)) as client:
			info = client.get_server_info()
			embed = discord.Embed(colour=ctx.me.top_role.colour)
			embed.add_field(name="Hostname", value=f"{info.hostname}", inline=True)
			embed.add_field(name="Ilość graczy", value=f" {info.players}/{info.max_players}", inline=True)
			embed.add_field(name="Gamemode", value=f"{info.gamemode}", inline=True)
			embed.add_field(name="Język", value=f"{info.language}", inline=True)
			await ctx.send(content=f"Informacje o serwerze **{arg}:{port}**", embed=embed)
Esempio n. 4
0
	def Start(self):
		try:
			with SampClient(address=str(self.Address), port=int(self.Port), rcon_password=self.Password) as client:
				self.Show_Status()
				if client.rcon_cmdlist() == []:
					raise InvalidRconPassword
				def Continuation():
					def wait():
						Exit()
						Continuation()
					Features()
					try:
						f = int(input("Give number of feature: "))
						flist = [self._0, self._1, self._2, self._3, self._4, self._5, self._6, self._7, self._8, self._9,self._10,self._11]
						if f > len(flist) or f < 0:
							raise IndexError
						flist[f]()
						wait()
					except IndexError:
						CJERROR()
						write("Invalid Number!\n")
						Continuation()
					except ValueError:
						CJERROR()
						write("Please enter number!")
						Continuation()

				Continuation()
		except ConnectionError:
			CJERROR()
			write("-Your internet is not connected or has a problem\n-The address and port you entered are incorrect\n-The server is offline\n")
			Exit()
			Samp().Start()
		except InvalidRconPassword:
			CJERROR()
			write("The rcon password you have entered is invalid, you can't use this features.\n")
			Exit()
			Samp().Start()
		except Exception as e:
			CJERROR()
			print(e)
			write("If you see a bug, raise it here\nhttps://github.com/TShoKT/SA-MP-PY-Control-Panel/issues")
			Continuation()
Esempio n. 5
0
	def Show_Status(self):
		with SampClient(address=str(self.Address), port=int(self.Port), rcon_password=str(self.Password)) as client:
			info = client.get_server_info()
			Rules = client.get_server_rules_dict()
			has_a_password = "******" if info.password else "No"
			write("[---------|Server Status|---------]\n", 0.02)
			write(f"""
|~	Address => {self.Address}:{self.Port}
|~  Hostname => {info.hostname}
|~	Players => {info.players}/{info.max_players}
|~	Mode => {info.gamemode}
|~	Language => {info.language}
|~	Has a password => {has_a_password}
			\n""",0.005)
			write("[---------|Server  Rules|---------]\n", 0.02)
			write(f"""
|~	Lagcomp => {Rules['lagcomp']}  
|~	Mapname => {Rules['mapname']}
|~	Version => {Rules['version']}
|~	Weather => {Rules['weather']}
|~	weburl => {Rules['weburl']}
|~	Worldtime => {Rules['worldtime']}
			\n""",0.005)
Esempio n. 6
0
		def wrapper(self):
			with SampClient(address=str(self.Address), port=int(self.Port), rcon_password=str(self.Password)) as client:
				func(self, client)
Esempio n. 7
0
def get_samp_data(ip: str, port: int):
    with SampClient(address=ip, port=port) as client:
        players = client.get_server_clients_detailed()
        server_info = client.get_server_info()
        return players, server_info
 def test_is_invalid_domain(self):
     client = SampClient(address='localhostinvalid', port=6666)
     self.assertRaises(ConnectionError, client.connect)
 def test_is_offline(self):
     # Will fail if there's a SA-MP server running on port 6666 on localhost
     with SampClient(address='localhost', port=6666) as client:
         self.assertFalse(client.is_online())
Esempio n. 10
0
 def setUp(self):
     super(ClientTestCase, self).setUp()
     # These tests depend on Convoy Trucking server being up
     # TODO: mock the server and hardcode fake responses
     self.client = SampClient(address='server.convoytrucking.net')
     self.client.connect()
Esempio n. 11
0
class ClientTestCase(TestCase):
    def setUp(self):
        super(ClientTestCase, self).setUp()
        # These tests depend on Convoy Trucking server being up
        # TODO: mock the server and hardcode fake responses
        self.client = SampClient(address='server.convoytrucking.net')
        self.client.connect()

    def tearDown(self):
        super(ClientTestCase, self).tearDown()
        self.client.disconnect()

    def test_server_ip(self):
        # Server address should be changed to ip address
        self.assertNotEqual('server.convoytrucking.net', self.client.address)
        self.assertEqual('51.254.130.14', self.client.address)

    def test_server_info(self):
        info = self.client.get_server_info()
        self.assertIsNotNone(info)
        self.assertIsInstance(info, ServerInfo)
        self.assertIsInstance(info.password, bool)
        self.assertIsInstance(info.players, int)
        self.assertIsInstance(info.max_players, int)
        self.assertIsInstance(info.hostname, str)
        self.assertIsInstance(info.gamemode, str)
        self.assertIsInstance(info.language, str)

        self.assertTrue(info.max_players)
        self.assertTrue(info.hostname)
        self.assertTrue(info.gamemode)
        self.assertTrue(info.language)

    def test_server_rules(self):
        rules = list(self.client.get_server_rules())
        self.assertEqual(6, len(rules))
        self.assertIsNotNone(rules)
        self.assertIsInstance(rules[0], Rule)

    def test_server_rules_dict(self):
        rules = self.client.get_server_rules_dict()
        self.assertIsNotNone(rules)
        self.assertIsInstance(rules, dict)
        self.assertIn('worldtime', rules)
        self.assertIn('mapname', rules)
        self.assertIn('version', rules)
        self.assertIn('weather', rules)

    def test_server_clients(self):
        for client in self.client.get_server_clients():
            self.assertIsInstance(client, Client)
            self.assertIsInstance(client.name, str)
            self.assertIsInstance(client.score, int)
            return  # only need to test first yielded client

    def test_server_clients_detailed(self):
        for client in self.client.get_server_clients_detailed():
            self.assertIsInstance(client, ClientDetail)
            self.assertIsInstance(client.name, str)
            self.assertIsInstance(client.score, int)
            self.assertIsInstance(client.ping, int)
            self.assertIsInstance(client.id, int)
            return  # only need to test first yielded client

    def test_probe_server_unicode(self):
        self.assertEqual(b'test', self.client.probe_server(u'test'))

    def test_probe_server_bytestring(self):
        self.assertEqual(b'test', self.client.probe_server(b'test'))

    def test_is_online(self):
        self.assertTrue(self.client.is_online())

    def test_is_offline(self):
        # Will fail if there's a SA-MP server running on port 6666 on localhost
        with SampClient(address='localhost', port=6666) as client:
            self.assertFalse(client.is_online())

    def test_is_invalid_domain(self):
        client = SampClient(address='localhostinvalid', port=6666)
        self.assertRaises(ConnectionError, client.connect)
Esempio n. 12
0
def Message():
    lst = []
    with SampClient(address='203.248.21.223', port=7777) as client:
        info = client.get_server_clients_detailed()
        players = client.get_server_info()
        for i in info:
            lst.append(i[1] + "\n")

        ## 최종 결과
        result = ','
        string = result.join(lst)
        string = string.replace(',', '')

    content = request.get_json()
    content = content['userRequest']
    content = content['utterance']

    round_info = ''
    if players.gamemode == 'Att-Def v1.23 (r)':
        round_info = "라운드 진행중이 아닙니다."
    else:
        round_info = f"라운드 {players.gamemode}가 진행중입니다!"

    if content == u"안녕":
        dataSend = {
            "version": "2.0",
            "template": {
                "outputs": [{
                    "carousel": {
                        "type": "basicCard",
                        "items": [{
                            "title": "",
                            "description": "인원"
                        }]
                    }
                }]
            }
        }
    else:
        dataSend = {
            "version": "2.0",
            "template": {
                "outputs": [{
                    "simpleText": {
                        "text":
                        f"현재 서버 인원은 {players.players}명입니다!\n" + "\n" +
                        "<플레이어 목록>\n" + f"{string}\n" + f"{round_info}"
                    }
                }],
                "quickReplies": [{
                    "label": "인원",
                    "action": "message",
                    "messageText": "인원"
                }, {
                    "label": "도움말",
                    "action": "message",
                    "messageText": "도움말"
                }, {
                    "label": "기능",
                    "action": "message",
                    "messageText": "기능"
                }]
            }
        }
    return jsonify(dataSend)
Esempio n. 13
0
 def setUp(self):
     super(ClientTestCase, self).setUp()
     # These tests depend on Convoy Trucking server being up
     self.client = SampClient(address='server.convoytrucking.net')
     self.client.socket_cls = MockSocket
     self.client.connect()
Esempio n. 14
0
 def setUp(self):
     super(RconClientTestCase, self).setUp()
     self.client = SampClient(address='server.convoytrucking.net')
     self.client.connect()
Esempio n. 15
0
class RconClientTestCase(TestCase):
    VAR_LIST = [
        ServerVar(name='ackslimit', value=3000, read_only=False),
        ServerVar(name='announce', value=False, read_only=False),
        ServerVar(name='bind', value='', read_only=True),
        ServerVar(name='chatlogging', value=1, read_only=False),
        ServerVar(name='conncookies', value=1, read_only=False),
        ServerVar(name='connseedtime', value=300000, read_only=False),
        ServerVar(name='cookielogging', value=0, read_only=False),
        ServerVar(name='db_log_queries', value=0, read_only=False),
        ServerVar(name='db_logging', value=0, read_only=False),
        ServerVar(name='filterscripts',
                  value='WeatherStreamer',
                  read_only=True),
        ServerVar(name='gamemode0', value='convoy', read_only=False),
        ServerVar(name='gamemode1', value='', read_only=False),
        ServerVar(name='gamemode10', value='', read_only=False),
        ServerVar(name='gamemode11', value='', read_only=False),
        ServerVar(name='gamemode12', value='', read_only=False),
        ServerVar(name='gamemode13', value='', read_only=False),
        ServerVar(name='gamemode14', value='', read_only=False),
        ServerVar(name='gamemode15', value='', read_only=False),
        ServerVar(name='gamemode2', value='', read_only=False),
        ServerVar(name='gamemode3', value='', read_only=False),
        ServerVar(name='gamemode4', value='', read_only=False),
        ServerVar(name='gamemode5', value='', read_only=False),
        ServerVar(name='gamemode6', value='', read_only=False),
        ServerVar(name='gamemode7', value='', read_only=False),
        ServerVar(name='gamemode8', value='', read_only=False),
        ServerVar(name='gamemode9', value='', read_only=False),
        ServerVar(name='gamemodetext',
                  value='Convoy Trucking DEV',
                  read_only=False),
        ServerVar(name='gravity', value='0.008', read_only=False),
        ServerVar(name='hostname', value='Convoy Trucking', read_only=False),
        ServerVar(name='incar_rate', value=40, read_only=True),
        ServerVar(name='lagcomp', value='On', read_only=True),
        ServerVar(name='lagcompmode', value=1, read_only=True),
        ServerVar(name='language', value='English', read_only=False),
        ServerVar(name='lanmode', value=False, read_only=False),
        ServerVar(name='logqueries', value=False, read_only=False),
        ServerVar(name='logtimeformat',
                  value='[%d %b %H:%M:%S]',
                  read_only=True),
        ServerVar(name='mapname', value='San Andreas', read_only=False),
        ServerVar(name='maxnpc', value=0, read_only=False),
        ServerVar(name='maxplayers', value=10, read_only=True),
        ServerVar(name='messageholelimit', value=3000, read_only=False),
        ServerVar(name='messageslimit', value=500, read_only=False),
        ServerVar(name='minconnectiontime', value=0, read_only=False),
        ServerVar(name='myriad', value=False, read_only=False),
        ServerVar(name='nosign', value='', read_only=True),
        ServerVar(name='onfoot_rate', value=40, read_only=True),
        ServerVar(name='output', value=False, read_only=False),
        ServerVar(name='password', value='', read_only=False),
        ServerVar(name='playertimeout', value=10000, read_only=False),
        ServerVar(name='plugins', value='CVector.so', read_only=True),
        ServerVar(name='port', value=7777, read_only=True),
        ServerVar(name='query', value=True, read_only=False),
        ServerVar(name='rcon', value=True, read_only=False),
        ServerVar(name='rcon_password', value='password', read_only=False),
        ServerVar(name='sleep', value=5, read_only=False),
        ServerVar(name='stream_distance', value=300.0, read_only=False),
        ServerVar(name='stream_rate', value=1000, read_only=False),
        ServerVar(name='timestamp', value=True, read_only=False),
        ServerVar(name='version', value='0.3.7-R2', read_only=True),
        ServerVar(name='weapon_rate', value=40, read_only=True),
        ServerVar(name='weather', value='10', read_only=False),
        ServerVar(name='weburl', value='localhost:8000', read_only=False),
        ServerVar(name='worldtime', value='12:00', read_only=False),
    ]

    def setUp(self):
        super(RconClientTestCase, self).setUp()
        self.client = SampClient(address='localhost', rcon_password='******')
        self.client.socket_cls = MockSocket
        self.client.connect()

    def tearDown(self):
        super(RconClientTestCase, self).tearDown()
        self.client.disconnect()

    def test_no_password(self):
        self.client.rcon_password = None
        self.assertRaises(RconError, self.client.rcon_players)

    def test_incorrect_password(self):
        self.client.rcon_password = '******'
        self.assertRaises(InvalidRconPassword, self.client.rcon_players)

    def test_rcon_password_bytes(self):
        self.client.rcon_password = '******'
        self.assertEqual(
            self.client.rcon_password_bytes,
            b'\x08\x00password',
        )

    def test_rcon_cmdlist(self):
        response = self.client.rcon_cmdlist()
        self.assertEqual(response, [
            'echo',
            'exec',
            'cmdlist',
            'varlist',
            'exit',
            'kick',
            'ban',
            'gmx',
            'changemode',
            'say',
            'reloadbans',
            'reloadlog',
            'players',
            'banip',
            'unbanip',
            'gravity',
            'weather',
            'loadfs',
            'unloadfs',
            'reloadfs',
        ])

    def test_rcon_varlist(self):
        varlist = self.client.rcon_varlist()
        self.assertEqual(varlist, self.VAR_LIST)

    def test_rcon_varlist_dict(self):
        vardict = self.client.rcon_varlist_dict()
        expected_dict = {var.name: var.value for var in self.VAR_LIST}
        self.assertEqual(vardict, expected_dict)

    def test_rcon_exit(self):
        response = self.client.rcon_exit()
        self.assertIsNone(response)

    def test_rcon_echo(self):
        response = self.client.rcon_echo('Hello')
        self.assertEqual(response, 'Hello')

    def test_rcon_set_hostname(self):
        response = self.client.rcon_set_hostname('test hostname')
        self.assertIsNone(response)
        self.client.rcon_set_hostname('Convoy Trucking')

    def test_rcon_get_hostname(self):
        hostname = self.client.rcon_get_hostname()
        self.assertEqual(hostname,
                         ServerVar('hostname', 'Convoy Trucking', False))

    def test_rcon_set_gamemodetext(self):
        response = self.client.rcon_set_gamemodetext('New Gamemode')
        self.assertIsNone(response)
        response = self.client.rcon_set_gamemodetext('Convoy Trucking DEV')

    def test_rcon_get_gamemodetext(self):
        var = self.client.rcon_get_gamemodetext()
        self.assertEqual(
            var, ServerVar('gamemodetext', 'Convoy Trucking DEV', False))

    def test_rcon_set_mapname(self):
        response = self.client.rcon_set_mapname('Convoy map')
        self.assertIsNone(response)
        self.client.rcon_set_mapname('San Andreas')

    def test_rcon_get_mapname(self):
        response = self.client.rcon_get_mapname()
        self.assertEqual(
            response,
            ServerVar(name='mapname', value='San Andreas', read_only=False))

    def test_rcon_exec(self):
        response = self.client.rcon_exec('server')
        self.assertEqual(response, [
            'bind = ""  (string, read-only)', 'password = ""  (string)',
            'maxplayers = 10  (int, read-only)',
            'port = 7777  (int, read-only)',
            'filterscripts = "WeatherStreamer"  (string, read-only)',
            'plugins = "CVector.so"  (string, read-only)',
            'onfoot_rate = 40  (int, read-only)',
            'incar_rate = 40  (int, read-only)',
            'weapon_rate = 40  (int, read-only)',
            'logtimeformat = "[%d %b %H:%M:%S]"  (string, read-only)'
        ])

    def test_rcon_exec__invalid(self):
        with self.assertRaises(SampError):
            self.client.rcon_exec('invalid')

    def test_rcon_kick(self):
        response = self.client.rcon_kick(0)
        self.assertEqual(response, [
            'mick88 <#0 - 172.19.0.1> has been kicked.',
            'Logged time spent online for mick88: 0 min',
            'mick88 left the server (Kicked)',
            'wanted level set to 0',
            '[part] mick88 has left the server (0:2)',
        ])

    def test_rcon_kick__invalidid(self):
        response = self.client.rcon_kick(999)
        self.assertEqual(response, [])

    def test_rcon_ban(self):
        response = self.client.rcon_ban(0)
        self.assertEqual(response, [
            'mick88 <#0 - 172.19.0.1> has been banned.',
            'Logged time spent online for mick88: 0 min',
            'mick88 left the server (Kicked)',
            'wanted level set to 0',
            '[part] mick88 has left the server (0:2)',
        ])

    def test_rcon_ban__invalid(self):
        response = self.client.rcon_ban(999)
        self.assertEqual(response, [])

    def test_rcon_banip(self):
        response = self.client.rcon_banip('192.168.1.1')
        self.assertEqual(response, ['IP 192.168.1.1 has been banned.'])

    def test_rcon_unbanip(self):
        response = self.client.rcon_unbanip('192.168.1.1')
        self.assertEqual(response, [])

    def test_rcon_changemode(self):
        response = self.client.rcon_changemode('convoy')
        self.assertEqual(response, [])

    def test_rcon_changemode__invalid(self):
        response = self.client.rcon_changemode('invalid')
        self.assertEqual(response, [])

    def test_rcon_gmx(self):
        response = self.client.rcon_gmx()
        self.assertEqual(response, [])

    def test_rcon_reloadbans(self):
        response = self.client.rcon_reloadbans()
        self.assertEqual(response, [])

    def test_rcon_reloadlog(self):
        response = self.client.rcon_reloadlog()
        self.assertEqual(response, [])

    def test_rcon_say(self):
        response = self.client.rcon_say('Hello')
        self.assertEqual(response, [])

    def test_rcon_players(self):
        response = self.client.rcon_players()
        self.assertEqual(
            response,
            [RConPlayer(id=0, name='mick88', ping=15, ip='172.19.0.1')])

    def test_rcon_gravity(self):
        response = self.client.rcon_gravity(0.008)
        self.assertEqual(response, [])

    def test_rcon_weather(self):
        response = self.client.rcon_weather(1)
        self.assertEqual(response, [])

    def test_rcon_loadfs(self):
        response = self.client.rcon_loadfs('WeatherStreamer')
        self.assertEqual(response,
                         "Filterscript 'WeatherStreamer.amx' loaded.")

    def test_rcon_loadfs__invalid(self):
        with self.assertRaises(SampError):
            self.client.rcon_loadfs('invalid')

    def test_rcon_unloadfs(self):
        response = self.client.rcon_unloadfs('WeatherStreamer')
        self.assertEqual(response,
                         "Filterscript 'WeatherStreamer.amx' unloaded.")

    def test_rcon_reloadfs(self):
        response = self.client.rcon_reloadfs('WeatherStreamer')
        self.assertEqual(response, [
            "Filterscript 'WeatherStreamer.amx' unloaded.",
            "Filterscript 'WeatherStreamer.amx' loaded.",
        ])

    def test_rcon_get_weburl(self):
        response = self.client.rcon_get_weburl()
        self.assertEqual(
            response,
            ServerVar(name='weburl', value='localhost:8000', read_only=False))

    def test_rcon_set_weburl(self):
        response = self.client.rcon_set_weburl('convoytrucking.net')
        self.assertEqual(response, [])

    def test_rcon_set_rcon_password(self):
        response = self.client.rcon_set_rcon_password('newpass')
        self.assertIsNone(response)
        self.assertEqual(self.client.rcon_password, 'newpass')

    def test_rcon_get_rcon_password(self):
        response = self.client.rcon_get_rcon_password()
        self.assertEqual(
            response,
            ServerVar(name='rcon_password', value='password', read_only=False))

    def test_rcon_get_password(self):
        response = self.client.rcon_get_password()
        # Server has no password
        self.assertEqual(response,
                         ServerVar(name='password', value='', read_only=False))

    def test_rcon_set_password(self):
        response = self.client.rcon_set_password('pass')
        self.assertEqual(response, 'Setting server password to: "pass"')

    def test_rcon_get_messageslimit(self):
        response = self.client.rcon_get_messageslimit()
        self.assertEqual(
            response,
            ServerVar(name='messageslimit', value=500, read_only=False))

    def test_rcon_set_messageslimit(self):
        response = self.client.rcon_set_messageslimit(200)
        self.assertIsNone(response)

    def test_rcon_get_ackslimit(self):
        response = self.client.rcon_get_ackslimit()
        self.assertEqual(
            response, ServerVar(name='ackslimit', value=3000, read_only=False))

    def test_rcon_set_ackslimit(self):
        response = self.client.rcon_set_ackslimit(1000)
        self.assertIsNone(response)

    def test_rcon_get_messageholelimit(self):
        response = self.client.rcon_get_messageholelimit()
        self.assertEqual(
            response,
            ServerVar(name='messageholelimit', value=3000, read_only=False))

    def test_rcon_set_messageholelimit(self):
        response = self.client.rcon_set_messageholelimit(1000)
        self.assertIsNone(response)

    def test_rcon_get_playertimeout(self):
        response = self.client.rcon_get_playertimeout()
        self.assertEqual(
            response,
            ServerVar(name='playertimeout', value=10000, read_only=False))

    def test_rcon_set_playertimeout(self):
        response = self.client.rcon_set_playertimeout(1000)
        self.assertIsNone(response)

    def test_rcon_get_language(self):
        response = self.client.rcon_get_language()
        self.assertEqual(
            response,
            ServerVar(name='language', value='English', read_only=False))

    def test_rcon_set_language(self):
        response = self.client.rcon_set_language('Polish')
        self.assertIsNone(response)
Esempio n. 16
0
 def setUp(self):
     super(RconClientTestCase, self).setUp()
     self.client = SampClient(address='localhost', rcon_password='******')
     self.client.socket_cls = MockSocket
     self.client.connect()