Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopefully fix wildcard check again #1550

Merged
merged 15 commits into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions .github/actions/validate-manifest/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import requests
from sys import exit as sys_exit
from re import fullmatch as re_match

REQUIRED_KEYS = ['server_name', 'nice_name', 'direct_ip']
USERNAME_SOCIAL_KEYS = ['twitter', 'tiktok', 'facebook', 'instagram', 'teamspeak']
Expand Down Expand Up @@ -45,16 +46,22 @@ def main():
error += '- One of the **required values** is missing\n'
continue

if data['direct_ip'] in ['', '-']:
error += f'- Direct IP is required\n'
if data['nice_name'] in ['', '-']:
error += f'- Nice name is required and cannot be empty!\n'

server_directory = manifest_file.replace('minecraft_servers/', '').replace('/manifest.json', '')
if server_directory != data['server_name']:
error += '**Servername has to be directory name!**\n'
error += '**Servername has to be directory name!** (all lowercase)\n'

# Validate wildcards
if 'server_wildcards' in data:
for wildcard in data['server_wildcards']:
if not wildcard.startswith('%.'):
wildcard_stop = True
error += '- Invalid wildcard entry. Each entry must start with **%.**. Further information here: https://en.wikipedia.org/wiki/Wildcard_DNS_record (`server_wildcards`)\n'
print(f'Found valid wildcard entry: {wildcard}')

check_server_online_state(
data['direct_ip'],
Expand Down Expand Up @@ -108,16 +115,21 @@ def main():
except ValueError:
error += f'- Please use a **numeric** value for your server id (`discord.server_id`)\n'
if 'rename_to_minecraft_name' in data['discord'] and data['discord']['rename_to_minecraft_name'] == True:
comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`. If you are a partner, please ignore this message.\n'
comment += f'- `discord.rename_to_minecraft_name` is reserved for LabyMod Partners. Change it to `false`.' \
'If you are a partner, please ignore this message.\n'


if 'location' in data:
if 'city' in data['location'] and data['location']['city'] in ['', '-']:
error += f'- Please remove the empty key **city** or fill in information.\n'

if 'location' in data and 'country_code' in data['location']:
country_code = data['location']['country_code']
if len(country_code) > 2 or len(country_code) <= 1:
error += '- Use valid format (ISO 3166-1 alpha-2) for country code. (`location.country_code`)\n'
if 'country_code' in data['location']:
country_code = data['location']['country_code']
if len(country_code) > 2 or len(country_code) <= 1:
error += '- Use valid format (ISO 3166-1 alpha-2) for country code. (`location.country_code`)\n'

if not country_code.isupper():
error += '- Use upper-case for country code. (`location.country_code`)\n'
if not country_code.isupper():
error += '- Use upper-case for country code. (`location.country_code`)\n'

# check hex codes
if 'brand' in data:
Expand All @@ -135,9 +147,10 @@ def main():
if '://laby.net/' in stats_url:
error += f'- Please use **your own page**, not LABY.net (`user_stats`)\n'

if 'message_formats' in data['chat']:
if 'chat' in data and 'message_formats' in data['chat']:
message_format = data['chat']['message_formats']
if message_format == '^§[a-f0-9](?<level>\\d+)( \\||§8 \\|) §[a-f0-9](?<sender>[a-zA-Z0-9_]{2,16})§r§7: §f(?<message>.*)$':
template_regex = r'^§[a-f0-9](?<level>\\d+)( \\||§8 \\|) §[a-f0-9](?<sender>[a-zA-Z0-9_]{2,16})§r§7: §f(?<message>.*)$'
if re_match(template_regex, message_format):
comment += f'- It seems you\'re using the **template regex** for chat message! Please make sure it is the right regex for **your server**!'
if message_format in ('', '-'):
error += f'- Please remove the empty key **message_formats** or fill in information.\n'
Expand All @@ -158,8 +171,10 @@ def main():


if create_comment:
post_comment(error, True)
post_comment(comment, False)
if error != '':
post_comment(error, True)
if comment != '':
post_comment(comment, False)

if error != '':
# Make job fail
Expand Down Expand Up @@ -187,7 +202,7 @@ def get_changed_manifest_files():


def post_comment(comment: str, error: bool, request_type: str = 'reviews'):
if not error:
if not error and request_type != 'comment':
print('No error found.')
return

Expand Down Expand Up @@ -243,6 +258,7 @@ def check_server_online_state(ip: str, wildcards: list):
wildcard_string = '*Just as an information*:\n'
wildcard_comment = False
for wildcard in wildcards:
print(f'Checking wildcard "{wildcard}"')
wildcard_ip = str.replace(wildcard, '%', 'testingstringwildcard')
request = requests.get(f'https://api.mcsrvstat.us/2/{wildcard_ip}')

Expand All @@ -253,9 +269,11 @@ def check_server_online_state(ip: str, wildcards: list):
continue

if not response['online']:
print(f'Wildcard "{wildcard}" is offline')
wildcard_string += f'- Wildcard {wildcard} seems to be invalid. Server is offline with testing wildcard.\n'
wildcard_comment = True
else:
print(f'Wildcard "{wildcard}" is online')
if response['ip'] != server_ip:
wildcard_string += f'- Wildcard do not resolve the same ip address: *{wildcard}* => *{response["ip"]}*\n'
wildcard_comment = True
Expand Down
Loading