diff --git a/auth_server.py b/auth_server.py index 163c185..e194856 100644 --- a/auth_server.py +++ b/auth_server.py @@ -1,4 +1,3 @@ -import logging from datetime import datetime, timezone from quarry.net.server import ServerFactory, ServerProtocol @@ -31,7 +30,8 @@ class AuthProtocol(ServerProtocol): connect_port = self.connect_port - self.logger.info("[AUTH SERVER] {} ({}) connected to address {}:{}".format(display_name, uuid, ip_addr, connect_port)) + self.logger.info("[AUTH SERVER] {} ({}) connected to address {}:{}".format( + display_name, uuid, ip_addr, connect_port)) try: connection_token = ip_addr.split(".")[0] session = database_session.get_session() @@ -48,8 +48,10 @@ class AuthProtocol(ServerProtocol): if datetime.utcnow() < token.expiry: # Check if they already have a linked account and are re-linking if discord_account.minecraft_account_id != None: - existing_account = session.query(MinecraftAccount).filter_by(id=discord_account.minecraft_account_id).first() - self.logger.info("[AUTH SERVER] unlinking existing {} account and replacing it with {}".format(existing_account.minecraft_uuid, str(uuid))) + existing_account = session.query(MinecraftAccount).filter_by( + id=discord_account.minecraft_account_id).first() + self.logger.info("[AUTH SERVER] unlinking existing {} account and replacing it with {}".format( + existing_account.minecraft_uuid, str(uuid))) session.delete(existing_account) mc_account = MinecraftAccount(str(uuid), discord_account.id) discord_account.minecraft_account = mc_account @@ -63,18 +65,18 @@ class AuthProtocol(ServerProtocol): session.delete(token) session.commit() session.close() - self.close("You have connected with an expired token! Please run the mc!register command again to get a new token.") + self.close("You have connected with an expired token! " + "Please run the mc!register command again to get a new token.") return except Exception as e: self.logger.error(e) session.close() - # Kick the player. self.close("This shouldn't happen!") class AuthFactory(ServerFactory): protocol = AuthProtocol - motd = "Auth Server" \ No newline at end of file + motd = "Auth Server" diff --git a/config.py b/config.py index 54c4cdd..7011000 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,6 @@ import json + class Configuration(object): def __init__(self, path): try: @@ -24,4 +25,4 @@ class Configuration(object): exit(1) except IOError: print("error reading config") - exit(1) \ No newline at end of file + exit(1) diff --git a/database.py b/database.py index b8cd4ee..0dff660 100644 --- a/database.py +++ b/database.py @@ -5,6 +5,7 @@ from sqlalchemy.orm import relationship from database_session import Base + class DiscordChannel(Base): __tablename__ = 'discord_channels' @@ -51,8 +52,10 @@ class DiscordAccount(Base): discord_id = Column(Integer) link_token_id = Column(Integer, ForeignKey('account_link_tokens.id')) minecraft_account_id = Column(Integer, ForeignKey('minecraft_accounts.id')) - link_token = relationship("AccountLinkToken", uselist=False, foreign_keys=[link_token_id], back_populates="discord_account") - minecraft_account = relationship("MinecraftAccount", uselist=False, foreign_keys=[minecraft_account_id], back_populates="discord_account") + link_token = relationship( + "AccountLinkToken", uselist=False, foreign_keys=[link_token_id], back_populates="discord_account") + minecraft_account = relationship( + "MinecraftAccount", uselist=False, foreign_keys=[minecraft_account_id], back_populates="discord_account") def __init__(self, discord_id): - self.discord_id = discord_id \ No newline at end of file + self.discord_id = discord_id diff --git a/database_session.py b/database_session.py index 3388913..d6b80c6 100644 --- a/database_session.py +++ b/database_session.py @@ -5,12 +5,14 @@ from sqlalchemy.orm import sessionmaker _engine = None Base = declarative_base() + def initialize(config): global _engine _connection_string = config.database_connection_string _engine = create_engine(_connection_string) Base.metadata.create_all(_engine) + def get_session(): Session = sessionmaker(bind=_engine)() - return Session \ No newline at end of file + return Session