Skip to content

Commit

Permalink
Merge branch 'master' into updating
Browse files Browse the repository at this point in the history
  • Loading branch information
nekoraw committed Dec 13, 2023
2 parents 3742cf9 + ec89b75 commit 74c150d
Show file tree
Hide file tree
Showing 24 changed files with 1,256 additions and 492 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ DEBUG=False
# redirect beatmaps, beatmapsets, and forum
# pages of maps to the official osu! website
REDIRECT_OSU_URLS=True
DISABLE_INGAME_REGISTRATION=True

PP_CACHED_ACCS=90,95,98,99,100

DISALLOWED_NAMES=mrekk,vaxei,btmc,cookiezi
DISALLOWED_PASSWORDS=password,abc123
DISALLOW_OLD_CLIENTS=True
KEY_BASED_LOGIN=True

DISCORD_AUDIT_LOG_WEBHOOK=
DISCORD_BANCHO_UPDATES_WEBHOOK=

# automatically share information with the primary
# developer of bancho.py (https://github.com/cmyui)
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/require-checklist.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ ext/nginx.conf
tools/cf_records.txt
/.db-data/
/.redis-data/
tools/temp
tools/temp/*
1 change: 1 addition & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from . import packets
from . import state
from . import utils
from . import pycord
102 changes: 65 additions & 37 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
from app.objects.match import MatchWinConditions
from app.objects.match import Slot
from app.objects.match import SlotStatus
from app.objects.match import multiplayer_change_host_event, multiplayer_close_lobby_event, multiplayer_event, multiplayer_join_leave_event
from app.objects.player import Action
from app.objects.player import ClientDetails
from app.objects.player import LeaveMatchEnum
from app.objects.player import OsuStream
from app.objects.player import OsuVersion
from app.objects.player import Player
Expand Down Expand Up @@ -195,7 +197,7 @@ async def bancho_handler(
# tell their client to reconnect immediately.
return Response(
content=(
app.packets.notification("Server has restarted.")
app.packets.notification("Reconectou-se ao servidor.")
+ app.packets.restart_server(0) # ms until reconnection
),
)
Expand Down Expand Up @@ -344,7 +346,7 @@ async def handle(self, player: Player) -> None:
msg = f"{msg[:2000]}... (truncated)"
player.enqueue(
app.packets.notification(
"Your message was truncated\n(exceeded 2000 characters).",
"Sua mensagem foi truncada\n(passou de 2000 caracteres).",
),
)

Expand Down Expand Up @@ -438,26 +440,26 @@ async def handle(self, player: Player) -> None:
# TODO: these should probably be moved to the config.
WELCOME_MSG = "\n".join(
(
f"Welcome to {BASE_DOMAIN}.",
"To see a list of commands, use !help.",
"We have a public (Discord)[https://discord.gg/ShEQgUx]!",
"Enjoy the server!",
f"Bem-vindo a {BASE_DOMAIN}.",
"Para ver a lista de comandos, use !help.",
"Nós temos um (Discord)[https://discord.gg/nmu4hYWE4n] público!",
"Aproveite o servidor!",
),
)

RESTRICTED_MSG = (
"Your account is currently in restricted mode. "
"If you believe this is a mistake, or have waited a period "
"greater than 3 months, you may appeal via the form on the site."
"Sua conta está atualmente no modo restrito. "
"Caso você ache que isso é um erro, ou esperou um período maior "
"do que 3 meses, você pode se justificar com o formulário no site."
)

WELCOME_NOTIFICATION = app.packets.notification(
f"Welcome back to {BASE_DOMAIN}!\nRunning bancho.py v{app.settings.VERSION}.",
f"Bem-vindo ao {BASE_DOMAIN}!\nRodando bancho.py v{app.settings.VERSION}.",
)

OFFLINE_NOTIFICATION = app.packets.notification(
"The server is currently running in offline mode; "
"some features will be unavailable.",
"O servidor está rodando em modo offline; "
"alguns recursos estarão indisponíveis.",
)


Expand Down Expand Up @@ -610,7 +612,7 @@ async def login(
"osu_token": "empty-adapters",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("Please restart your osu! and try again.")
+ app.packets.notification("Por favor, reinicie o seu osu! e tente novamente.")
),
}

Expand All @@ -628,7 +630,7 @@ async def login(
"osu_token": "user-already-logged-in",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("User already logged in.")
+ app.packets.notification("Usuário já está conectado.")
),
}
else:
Expand All @@ -646,7 +648,7 @@ async def login(
return {
"osu_token": "unknown-username",
"response_body": (
app.packets.notification(f"{BASE_DOMAIN}: Unknown username")
app.packets.notification(f"{BASE_DOMAIN}: Nome de usuário desconhecido.")
+ app.packets.user_id(-1)
),
}
Expand All @@ -672,7 +674,7 @@ async def login(
return {
"osu_token": "incorrect-password",
"response_body": (
app.packets.notification(f"{BASE_DOMAIN}: Incorrect password")
app.packets.notification(f"{BASE_DOMAIN}: Faça login novamente. Caso não funcionar, suas credenciais estão incorretas.")
+ app.packets.user_id(-1)
),
}
Expand All @@ -681,7 +683,7 @@ async def login(
return {
"osu_token": "incorrect-password",
"response_body": (
app.packets.notification(f"{BASE_DOMAIN}: Incorrect password")
app.packets.notification(f"{BASE_DOMAIN}: Faça login novamente. Caso não funcionar, suas credenciais estão incorretas.")
+ app.packets.user_id(-1)
),
}
Expand Down Expand Up @@ -753,7 +755,7 @@ async def login(
"osu_token": "contact-staff",
"response_body": (
app.packets.notification(
"Please contact staff directly to create an account.",
"Multi-contas detectado. Não será possível efetuar login no fubi.ca.",
)
+ app.packets.user_id(-1)
),
Expand All @@ -768,7 +770,7 @@ async def login(
clan = app.state.sessions.clans.get(id=user_info["clan_id"])
clan_priv = ClanPrivileges(user_info["clan_priv"])

db_country = user_info["country"]
db_country = user_info.get("country")

geoloc = await app.state.services.fetch_geoloc(ip, headers)

Expand Down Expand Up @@ -951,6 +953,8 @@ async def login(
| Privileges.DONATOR
| Privileges.ALUMNI,
)
elif player.id >= 3:
await player.add_privs(Privileges.SUPPORTER)

data += app.packets.send_message(
sender=app.state.sessions.bot.name,
Expand Down Expand Up @@ -1151,10 +1155,10 @@ async def handle(self, player: Player) -> None:
# limit message length to 2k chars
# perhaps this could be dangerous with !py..?
if len(msg) > 2000:
msg = f"{msg[:2000]}... (truncated)"
msg = f"{msg[:2000]}... (truncado)"
player.enqueue(
app.packets.notification(
"Your message was truncated\n(exceeded 2000 characters).",
"Sua mensagem foi truncada\n(passou de 2000 caracteres).",
),
)

Expand All @@ -1171,8 +1175,8 @@ async def handle(self, player: Player) -> None:
# will receive the mail @ next login.
player.enqueue(
app.packets.notification(
f"{target.name} is currently offline, but will "
"receive your messsage on their next login.",
f"{target.name} está offline, mas vai receber "
"sua mensagem no próximo login",
),
)

Expand Down Expand Up @@ -1305,7 +1309,7 @@ async def handle(self, player: Player) -> None:
player.enqueue(
app.packets.match_join_fail()
+ app.packets.notification(
"Multiplayer is not available while restricted.",
"Multijogador não está disponível enquanto restrito.",
),
)
return
Expand All @@ -1314,7 +1318,7 @@ async def handle(self, player: Player) -> None:
player.enqueue(
app.packets.match_join_fail()
+ app.packets.notification(
"Multiplayer is not available while silenced.",
"Multijogador não está disponível enquanto silenciado.",
),
)
return
Expand All @@ -1323,7 +1327,7 @@ async def handle(self, player: Player) -> None:

if match_id is None:
# failed to create match (match slots full).
player.send_bot("Failed to create match (no slots available).")
player.send_bot("Incapaz de criar partida (sem vagas disponíveis).")
player.enqueue(app.packets.match_join_fail())
return

Expand Down Expand Up @@ -1358,11 +1362,21 @@ async def handle(self, player: Player) -> None:
app.state.sessions.matches[match_id] = match
app.state.sessions.channels.append(chat_channel)
match.chat = chat_channel

query = f"""INSERT INTO multiplayer_matches (name, creation_time) VALUES (:name, UNIX_TIMESTAMP())"""
params = {
"name": match.name
}
rec_id = await app.state.services.database.execute(query, params)
match.db_match_id = rec_id

player.update_latest_activity_soon()
player.join_match(match, self.match_data.passwd)
if player.join_match(match, self.match_data.passwd):
rec_id = await multiplayer_join_leave_event(match, player, True)
await multiplayer_event(match.db_match_id, join_leave_event=rec_id)


match.chat.send_bot(f"Match created by {player.name}.")
match.chat.send_bot(f"Partida criada por {player.name}.")
log(f"{player} created a new multiplayer match.")


Expand All @@ -1383,7 +1397,7 @@ async def handle(self, player: Player) -> None:
player.enqueue(
app.packets.match_join_fail()
+ app.packets.notification(
"Multiplayer is not available while restricted.",
"Multijogador não está disponível enquanto restrito.",
),
)
return
Expand All @@ -1392,20 +1406,30 @@ async def handle(self, player: Player) -> None:
player.enqueue(
app.packets.match_join_fail()
+ app.packets.notification(
"Multiplayer is not available while silenced.",
"Multijogador não está disponível enquanto silenciado..",
),
)
return


player.update_latest_activity_soon()
player.join_match(match, self.match_passwd)
if player.join_match(match, self.match_passwd):
rec_id = await multiplayer_join_leave_event(match, player, True)
await multiplayer_event(match.db_match_id, join_leave_event=rec_id)


@register(ClientPackets.PART_MATCH)
class MatchPart(BasePacket):
async def handle(self, player: Player) -> None:
lobby = player.match
player.update_latest_activity_soon()
player.leave_match()
leave_result = player.leave_match()
if leave_result != LeaveMatchEnum.Failed:
rec_id = await multiplayer_join_leave_event(lobby, player, False)
await multiplayer_event(lobby.db_match_id, join_leave_event=rec_id)
if leave_result == LeaveMatchEnum.CloseLobby:
rec_id = await multiplayer_close_lobby_event(lobby)
await multiplayer_event(lobby.db_match_id, close_event=rec_id)


@register(ClientPackets.MATCH_CHANGE_SLOT)
Expand Down Expand Up @@ -1542,7 +1566,7 @@ async def handle(self, player: Player) -> None:
f"https://osu.{app.settings.DOMAIN}/b/{self.match_data.map_id}"
)
map_embed = f"[{map_url} {self.match_data.map_name}]"
player.match.chat.send_bot(f"Selected: {map_embed}.")
player.match.chat.send_bot(f"Selecionado: {map_embed}.")

# use our serverside version if we have it, but
# still allow for users to pick unknown maps.
Expand All @@ -1568,9 +1592,9 @@ async def handle(self, player: Player) -> None:
]

msg = (
"Changing team type while scrimming will reset "
"the overall score - to do so, please use the "
f"!mp teams {_team} command."
"Mudar o tipo de time durante o amistoso vai redefinir "
"a pontuação total - para fazer isso, por favor use o comando "
f"!mp teams {_team}."
)
player.match.chat.send_bot(msg)
else:
Expand Down Expand Up @@ -1684,6 +1708,8 @@ async def handle(self, player: Player) -> None:
immune=not_playing,
)
player.match.enqueue_state()

asyncio.create_task(player.match.await_submissions(was_playing, save_to_mp_link=True))

if player.match.is_scrimming:
# determine winner, update match points & inform players.
Expand Down Expand Up @@ -1856,6 +1882,8 @@ async def handle(self, player: Player) -> None:
player.match.host_id = target.id
player.match.host.enqueue(app.packets.match_transfer_host())
player.match.enqueue_state()
rec_id = await multiplayer_change_host_event(player.match, player, target)
await multiplayer_event(player.match.db_match_id, change_host_event=rec_id)


@register(ClientPackets.TOURNAMENT_MATCH_INFO_REQUEST)
Expand Down Expand Up @@ -2063,7 +2091,7 @@ async def handle(self, player: Player) -> None:
return

if target is app.state.sessions.bot:
player.send_bot("I'm too busy!")
player.send_bot("Estou muito ocupado!")
return

target.enqueue(app.packets.match_invite(player, target.name))
Expand Down
Loading

0 comments on commit 74c150d

Please sign in to comment.