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 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,14 +65,14 @@ 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!")

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

@ -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

@ -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
Loading…
Cancel
Save