Formatted all files

feature/embed-uploads
Tristan Gosselin-Hane 7 years ago
parent d8b152576c
commit fdabf8c00e
  1. 14
      auth_server.py
  2. 1
      config.py
  3. 7
      database.py
  4. 2
      database_session.py

@ -1,4 +1,3 @@
import logging
from datetime import datetime, timezone from datetime import datetime, timezone
from quarry.net.server import ServerFactory, ServerProtocol from quarry.net.server import ServerFactory, ServerProtocol
@ -31,7 +30,8 @@ class AuthProtocol(ServerProtocol):
connect_port = self.connect_port 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: try:
connection_token = ip_addr.split(".")[0] connection_token = ip_addr.split(".")[0]
session = database_session.get_session() session = database_session.get_session()
@ -48,8 +48,10 @@ class AuthProtocol(ServerProtocol):
if datetime.utcnow() < token.expiry: if datetime.utcnow() < token.expiry:
# Check if they already have a linked account and are re-linking # Check if they already have a linked account and are re-linking
if discord_account.minecraft_account_id != None: if discord_account.minecraft_account_id != None:
existing_account = session.query(MinecraftAccount).filter_by(id=discord_account.minecraft_account_id).first() existing_account = session.query(MinecraftAccount).filter_by(
self.logger.info("[AUTH SERVER] unlinking existing {} account and replacing it with {}".format(existing_account.minecraft_uuid, str(uuid))) 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) session.delete(existing_account)
mc_account = MinecraftAccount(str(uuid), discord_account.id) mc_account = MinecraftAccount(str(uuid), discord_account.id)
discord_account.minecraft_account = mc_account discord_account.minecraft_account = mc_account
@ -63,14 +65,14 @@ class AuthProtocol(ServerProtocol):
session.delete(token) session.delete(token)
session.commit() session.commit()
session.close() 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 return
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
session.close() session.close()
# Kick the player. # Kick the player.
self.close("This shouldn't happen!") self.close("This shouldn't happen!")

@ -1,5 +1,6 @@
import json import json
class Configuration(object): class Configuration(object):
def __init__(self, path): def __init__(self, path):
try: try:

@ -5,6 +5,7 @@ from sqlalchemy.orm import relationship
from database_session import Base from database_session import Base
class DiscordChannel(Base): class DiscordChannel(Base):
__tablename__ = 'discord_channels' __tablename__ = 'discord_channels'
@ -51,8 +52,10 @@ class DiscordAccount(Base):
discord_id = Column(Integer) discord_id = Column(Integer)
link_token_id = Column(Integer, ForeignKey('account_link_tokens.id')) link_token_id = Column(Integer, ForeignKey('account_link_tokens.id'))
minecraft_account_id = Column(Integer, ForeignKey('minecraft_accounts.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") link_token = relationship(
minecraft_account = relationship("MinecraftAccount", uselist=False, foreign_keys=[minecraft_account_id], back_populates="discord_account") "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): def __init__(self, discord_id):
self.discord_id = discord_id self.discord_id = discord_id

@ -5,12 +5,14 @@ from sqlalchemy.orm import sessionmaker
_engine = None _engine = None
Base = declarative_base() Base = declarative_base()
def initialize(config): def initialize(config):
global _engine global _engine
_connection_string = config.database_connection_string _connection_string = config.database_connection_string
_engine = create_engine(_connection_string) _engine = create_engine(_connection_string)
Base.metadata.create_all(_engine) Base.metadata.create_all(_engine)
def get_session(): def get_session():
Session = sessionmaker(bind=_engine)() Session = sessionmaker(bind=_engine)()
return Session return Session
Loading…
Cancel
Save