Ejemplo n.º 1
0
def rcon(ip):
    try:
        if not request.cookies.get('rconpwd'):
            res = make_response("")
            res.set_cookie('rconpwd', 'NotSet', max_age=60 * 60)
        else:
            res = make_response("{}".format(request.cookies.get('rconpwd')))

        server_addr = next(gs.query_master(r'\appid\581320\gameaddr\%s' % ip))
        serverInfo = gs.a2s_info(server_addr)
        serverRules = gs.a2s_rules(server_addr)
        serverPlayers = gs.a2s_players(server_addr)
        return render_template('rcon.html',
                               addr=server_addr[0],
                               ip=ip,
                               data=serverInfo,
                               players=serverPlayers,
                               rules=serverRules,
                               quote=randomQuote(),
                               maplist=mapList)
    except StopIteration as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except socket.timeout as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except:  # noqa
        e = "Unknown error."
        return render_template('error.html', error=e)
Ejemplo n.º 2
0
def home():
    try:
        if "0.0.0.0" in os.environ["SERVERIP"]:
            return render_template('homedefault.html', version=__version__)

        server_addr = next(
            gs.query_master(r'\appid\581320\gameaddr\%s' %
                            os.environ["SERVERIP"]))
        serverInfo = gs.a2s_info(server_addr)
        serverRules = gs.a2s_rules(server_addr)
        serverPlayers = gs.a2s_players(server_addr)
        return render_template('home.html',
                               addr=server_addr,
                               ip=os.environ["SERVERIP"],
                               data=serverInfo,
                               players=serverPlayers,
                               rules=serverRules,
                               quote=randomQuote())
    except StopIteration as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except socket.timeout as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except:  # noqa
        e = "Unknown error."
        return render_template('error.html', error=e)
Ejemplo n.º 3
0
    def test_returns_rules_with_default_arguments(self, mock_socket_class):
        mock_socket = mock_socket_class.return_value
        mock_socket.recv.side_effect = [
            b"\xff\xff\xff\xffA\x01\x02\x03\x04",
            b"\xff\xff\xff\xffE\x03\0text\0b\x99r\0int\x0042\0float\x0021.12\0"
        ]

        rules = a2s_rules(("addr", 1234))

        self.assertEqual({
            "text": u"b\ufffdr",
            "int": 42,
            "float": 21.12
        }, rules)

        mock_socket_class.assert_called_once_with(socket.AF_INET,
                                                  socket.SOCK_DGRAM)

        mock_socket.connect.assert_called_once_with(("addr", 1234))
        mock_socket.settimeout.assert_called_once_with(2)

        self.assertEqual(2, mock_socket.send.call_count)
        mock_socket.send.assert_has_calls([
            mock.call(b"\xff\xff\xff\xffV\0\0\0\0"),
            mock.call(b"\xff\xff\xff\xffV\x01\x02\x03\x04")
        ])

        self.assertEqual(2, mock_socket.recv.call_count)
        mock_socket.recv.assert_has_calls([mock.call(512), mock.call(2048)])

        mock_socket.close.assert_called_once_with()
Ejemplo n.º 4
0
def getServerInfoSteam(ip, port):
    #print("getServerInfoSteam()")
    server = (ip, int(port))
    return {
        "info": gs.a2s_info(server),
        "players": gs.a2s_players(server),
        "rules": gs.a2s_rules(server)
    }
Ejemplo n.º 5
0
def banner(ip):
    try:
        server_addr = next(gs.query_master(r'\appid\581320\gameaddr\%s' % ip))
        serverInfo = gs.a2s_info(server_addr)
        serverRules = gs.a2s_rules(server_addr)
        serverPlayers = gs.a2s_players(server_addr)
        return render_template('banner.html',
                               addr=server_addr,
                               ip=ip,
                               data=serverInfo,
                               rules=serverRules,
                               players=serverPlayers)
    except:  # noqa
        e = "Unknown error."
        return render_template('bannererror.html', error=e)
Ejemplo n.º 6
0
def cmd_hlmaster_info(args):
    host, port = parse_host(args.server)

    flags = [args.info, args.players, args.rules].count(True)

    if args.info or flags == 0:
        if flags > 1:
            print('--- {:-<60}'.format("Server Info "))

        if args.short:
            print(get_info_short(host, port))
        else:
            try:
                data = gs.a2s_info((host, port))
            except Exception as exp:
                print("Error: {}".format(exp))
            else:
                for pair in sorted(data.items()):
                    print("{} = {}".format(*pair))

    if args.players:
        if flags > 1:
            print('--- {:-<60}'.format("Players "))

        try:
            plist = gs.a2s_players((host, port))
        except Exception as exp:
            print("Error: {}".format(exp))
        else:
            print_table([[
                player['name'],
                str(player['score']),
                fmt_duration(player['duration']),
                ] for player in plist],
                ['Name', '>Score', '>Duration'],
                )

    if args.rules:
        if flags > 1:
            print('--- {:-<60}'.format("Rules "))

        try:
            rules = gs.a2s_rules((host, port))
        except Exception as exp:
            print("Error: {}".format(exp))
        else:
            for rule in rules.items():
                print("{} = {}".format(*rule))
Ejemplo n.º 7
0
    def test_returns_rules_as_bytes_when_binary_is_true(
            self, mock_socket_class):
        mock_socket = mock_socket_class.return_value
        mock_socket.recv.side_effect = [
            b"\xff\xff\xff\xffA\x01\x02\x03\x04",
            b"\xff\xff\xff\xffE\x03\0text\0b\x99r\0int\x0042\0float\x0021.12\0"
        ]

        rules = a2s_rules(("addr", 1234), binary=True)

        self.assertEqual(
            {
                b"text": b"b\x99r",
                b"int": b"42",
                b"float": b"21.12"
            }, rules)
Ejemplo n.º 8
0
def remote(ip):
    try:
        server_addr = next(gs.query_master(r'\appid\581320\gameaddr\%s' % ip))
        serverInfo = gs.a2s_info(server_addr)
        serverRules = gs.a2s_rules(server_addr)
        serverPlayers = gs.a2s_players(server_addr)
        return render_template('remote.html',
                               addr=server_addr,
                               ip=ip,
                               data=serverInfo,
                               players=serverPlayers,
                               rules=serverRules,
                               quote=randomQuote())
    except StopIteration as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except socket.timeout as e:
        e = "Unable to resolve server ip."
        return render_template('error.html', error=e)
    except:  # noqa
        e = "Unknown error."
        return render_template('error.html', error=e)