Skip to content

Commit

Permalink
Blacklist hinzugefügt
Browse files Browse the repository at this point in the history
  • Loading branch information
bumseb1ene committed May 19, 2024
1 parent 20dca00 commit 630296f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
22 changes: 17 additions & 5 deletions api_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Importing necessary libraries
import requests
import os
from dotenv import load_dotenv
Expand Down Expand Up @@ -26,7 +25,6 @@ def is_logged_in(self):
response = self.session.get(check_url)
return response.json().get('result', False)


def do_perma_ban(self, player, steam_id_64, reason, by):
ban_url = f"{self.base_url}/api/do_perma_ban"
payload = {
Expand Down Expand Up @@ -60,8 +58,6 @@ def do_temp_ban(self, player, steam_id_64, duration_hours, reason, by):
print(f"Fehler beim Aufrufen von do_temp_ban: {e}")
return False



def do_unban(self, steam_id):
unban_url = f"{self.base_url}/api/do_unban"
response = self.session.post(unban_url, json={'steam_id_64': steam_id})
Expand All @@ -70,4 +66,20 @@ def do_unban(self, steam_id):
def unblacklist_player(self, steam_id):
unban_url = f"{self.base_url}/api/unblacklist_player"
response = self.session.post(unban_url, json={'steam_id_64': steam_id})
return response.ok
return response.ok

def do_blacklist_player(self, steam_id_64, name, reason, by):
blacklist_url = f"{self.base_url}/api/blacklist_player"
payload = {
'steam_id_64': steam_id_64,
'name': name,
'reason': reason,
'by': by
}
try:
response = self.session.post(blacklist_url, json=payload)
print(f"do_blacklist_player response: {response.status_code}, {response.text}")
return response.ok
except Exception as e:
print(f"Fehler beim Aufrufen von do_blacklist_player: {e}")
return False
15 changes: 11 additions & 4 deletions ban_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api_manager import APIClient
from dotenv import load_dotenv
import aio_pika
from aio_pika import IncomingMessage, connect_robust, ExchangeType
from aio_pika import connect_robust, ExchangeType
import aiohttp

# Konfigurieren des Loggings
Expand Down Expand Up @@ -48,7 +48,7 @@ async def connect_to_rabbitmq():
client_properties={'connection_name': 'my_connection'}
)
channel = await connection.channel()
exchange = await channel.declare_exchange('bans_fanout', aio_pika.ExchangeType.FANOUT, durable=True)
exchange = await channel.declare_exchange('bans_fanout', ExchangeType.FANOUT, durable=True)
queue = await channel.declare_queue('', exclusive=True)
await queue.bind(exchange)
logging.info("RabbitMQ Exchange und Queue deklariert und gebunden.")
Expand All @@ -64,6 +64,7 @@ async def consume_messages(connection, channel, queue, api_client):
ban_data = json.loads(message.body.decode())
logging.info(f"Empfangene Ban-Daten: {ban_data}")
for api_client in api_clients:
# Permanent Ban
if api_client.do_perma_ban(ban_data['player'], ban_data['steam_id_64'], ban_data['reason'], ban_data['by']):
data_to_send = {
'player': ban_data['player'],
Expand All @@ -81,6 +82,12 @@ async def consume_messages(connection, channel, queue, api_client):
if response.status != 200:
response_text = await response.text()
logging.error(f"Fehler beim Aktualisieren des Status von {ban_data['player']}: {response_text}")

# Blacklist Player
if api_client.do_blacklist_player(ban_data['steam_id_64'], ban_data['player'], ban_data['reason'], ban_data['by']):
logging.info(f"Player erfolgreich auf die Blacklist gesetzt: {ban_data['steam_id_64']}")
else:
logging.error(f"Fehler beim Setzen auf die Blacklist für: {ban_data['steam_id_64']}")
except json.JSONDecodeError:
logging.error("Fehler beim Parsen der JSON-Daten")
await message.nack(requeue=True) # Nachricht wird zur Wiederverarbeitung in die Queue zurückgestellt
Expand All @@ -97,7 +104,7 @@ async def connect_to_unban_rabbitmq():
client_properties={'connection_name': 'unban_connection'}
)
unban_channel = await unban_connection.channel()
unban_exchange = await unban_channel.declare_exchange('unbans_fanout', aio_pika.ExchangeType.FANOUT, durable=True)
unban_exchange = await unban_channel.declare_exchange('unbans_fanout', ExchangeType.FANOUT, durable=True)
unban_queue = await unban_channel.declare_queue('', exclusive=True)
await unban_queue.bind(unban_exchange)
logging.info("Unban RabbitMQ Exchange und Queue deklariert und gebunden.")
Expand Down Expand Up @@ -138,7 +145,7 @@ async def connect_to_tempban_rabbitmq():
client_properties={'connection_name': 'tempban_connection'}
)
tempban_channel = await tempban_connection.channel()
tempban_exchange = await tempban_channel.declare_exchange('tempbans_fanout', aio_pika.ExchangeType.FANOUT, durable=True)
tempban_exchange = await tempban_channel.declare_exchange('tempbans_fanout', ExchangeType.FANOUT, durable=True)
tempban_queue = await tempban_channel.declare_queue('', exclusive=True)
await tempban_queue.bind(tempban_exchange)
logging.info("Tempban RabbitMQ Exchange und Queue deklariert und gebunden.")
Expand Down

0 comments on commit 630296f

Please sign in to comment.