예제 #1
0
	def sync_inventory_down(self):
		db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
		db.row_factory = sqlite3.Row
		dbcmd = db.cursor()
		query = "SELECT * FROM Inventory WHERE CharID = ?"
		dbcmd.execute(query, (self.id,))
		value = dbcmd.fetchall()
		self.inventory.clear()
		for item in value:
			newitem = {}
			newitem['ItemLOT'] = item['ItemLOT']
			newitem['Quantity'] = item['Quantity']
			newitem['IsEquipped'] = item['IsEquipped']
			newitem['IsLinked'] = item['IsLinked']
			newitem['Slot'] = item['Slot']
			newitem['ItemID'] = item['ItemID']

			db = sqlite3.connect(str(str(get_project_root()) + "/clientfiles/cdclient.sqlite"))
			dbcmd = db.cursor()
			query = "SELECT itemType FROM ItemComponent WHERE id = ?"
			dbcmd.execute(query, (item['ItemLOT'],))
			item_type = dbcmd.fetchall()

			newitem['Type'] = item_type[0][0]
			self.inventory.append(newitem)

		dbcmd.close()
예제 #2
0
    def create_character(self, character):
        db = sqlite3.connect(
            str(str(get_project_root()) + "/PikaChewniverse.sqlite"))
        db.row_factory = sqlite3.Row
        dbcmd = db.cursor()

        query = "SELECT CharID FROM Characters WHERE UnapprovedName = ?"
        dbcmd.execute(query, (character['UnapprovedName'], ))
        unapprovednameexists = dbcmd.fetchone()

        query = "SELECT CharID FROM Characters WHERE Name = ?"
        dbcmd.execute(query, (character['Name'], ))
        nameexists = dbcmd.fetchone()

        dbcmd.close()

        if unapprovednameexists is None:
            if nameexists is None:
                db = sqlite3.connect(
                    str(str(get_project_root()) + "/PikaChewniverse.sqlite"))
                db.row_factory = sqlite3.Row
                dbcmd = db.cursor()
                query = "INSERT INTO Characters (AccountID, ObjectID, Name, UnapprovedName, ShirtColor, ShirtStyle, PantsColor, HairStyle, HairColor, LeftHand, RightHand, Eyebrows, Eyes, Mouth) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
                dbcmd.execute(query, (
                    self.account_id,
                    character['ObjectID'],
                    character['Name'],
                    character['UnapprovedName'],
                    character['ShirtColor'],
                    character['ShirtStyle'],
                    character['PantsColor'],
                    character['HairStyle'],
                    character['HairColor'],
                    character['LeftHand'],
                    character['RightHand'],
                    character['Eyebrows'],
                    character['Eyes'],
                    character['Mouth'],
                ))
                db.commit()
                dbcmd.close()

                self.sync_characters_down()

                for char in self.characters:
                    if char.name == character['Name']:
                        self.current_character = char

                        dbcmd = db.cursor()
                        query = "INSERT INTO Stats (CharID) VALUES (?)"
                        dbcmd.execute(query, (char.id, ))
                        db.commit()
                        dbcmd.close()

                return 0x00  # Note: Success
            else:
                return 0x04  # Note: Custom name in use
        else:
            return 0x03  # Note: Unapproved name in use
예제 #3
0
    def __init__(self, zone_id):
        self._zone_id = zone_id

        config = ConfigParser()
        config.read(str(get_project_root()) + "/config.ini")
        self.path = str(get_project_root()) + config[self._zone_id]['LUZ']

        self.version = None
        self.version_control = None
        self.world_id = None

        self.zone = Zone()
예제 #4
0
	def add_item(self, item_data):
		self.sync_inventory_down()

		db = sqlite3.connect(str(str(get_project_root()) + "/clientfiles/cdclient.sqlite"))
		dbcmd = db.cursor()
		query = "SELECT stackSize FROM ItemComponent WHERE id = ?"
		dbcmd.execute(query, (item_data['ItemLOT'],))
		stack_size = dbcmd.fetchall()

		added = False

		for item in self.inventory:
			if item_data['ItemLOT'] == item['ItemLOT'] and item['Quantity'] < stack_size[0]:
				item['Quantity'] = item['Quantity'] + item_data['Quantity']

				db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
				db.row_factory = sqlite3.Row
				dbcmd = db.cursor()
				query = "UPDATE Inventory SET Quantity = ? WHERE ItemID = ?"
				dbcmd.execute(query, (item['Quantity'], item['ItemLOT'],))
				db.commit()
				dbcmd.close()
				added = True
				break

		db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
		dbcmd = db.cursor()
		query = "SELECT InventorySpace FROM Characters WHERE CharID = ?"
		dbcmd.execute(query, (self.id,))
		inventoy_space = dbcmd.fetchone()

		if len(self.inventory) < inventoy_space[0]:
			if added is False:
				db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
				db.row_factory = sqlite3.Row
				dbcmd = db.cursor()
				query = "INSERT INTO Inventory (CharID, ItemLOT, IsEquipped, IsLinked, Quantity, Slot, ItemID) VALUES (?, ?, ?, ?, ?, ?, ?)"
				dbcmd.execute(query, (
					self.id, item_data['ItemLOT'], item_data['IsEquipped'], item_data['IsLinked'],
					item_data['Quantity'],
					len(self.inventory) + 1, random.randrange(100000, 100000000),))
				db.commit()
				dbcmd.close()

				added = True

		self.sync_inventory_down()

		return added
예제 #5
0
    def sync_characters_down(self):
        db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
        db.row_factory = sqlite3.Row

        dbcmd = db.cursor()
        query = "SELECT * FROM Characters WHERE AccountID = ?"
        dbcmd.execute(query, (self.account_id, ))
        value = dbcmd.fetchall()
        dbcmd.close()
        self.characters.clear()
        if value is not None:
            for character in value:
                char = Character()
                char.account_id = character['AccountID']
                char.id = character['CharID']
                char.object_id = character['ObjectID']

                char.name = character['Name']
                char.unapproved_name = character['UnapprovedName']

                char.shirt_color = character['ShirtColor']
                char.shirt_style = character['ShirtStyle']

                char.pants_color = character['PantsColor']

                char.hair_style = character['HairStyle']
                char.hair_color = character['HairColor']

                char.left_hand = character['LeftHand']
                char.right_hand = character['RightHand']

                char.eyebrows = character['Eyebrows']
                char.eyes = character['Eyes']
                char.mouth = character['Mouth']

                char.last_zone = character['LastZone']

                char.health = character['Health']
                char.max_health = character['MaxHealth']

                char.armor = character['Armor']
                char.max_armor = character['MaxArmor']

                char.imagination = character['Imagination']
                char.max_imagination = character['MaxImagination']

                char.inventory_space = character['InventorySpace']
                char.u_score = character['UScore']
                char.gm_level = character['GMLevel']
                char.reputation = character['Reputation']
                char.level = character['Level']

                dbcmd = db.cursor()
                query = "SELECT * FROM Stats WHERE CharID = ?"
                dbcmd.execute(query, (char.id, ))
                char.stats = dbcmd.fetchone()
                dbcmd.close()

                char.sync_inventory_down()
                self.characters.append(char)
예제 #6
0
def getAccountFromID(ID):  # Template insert (1)
	try:
		db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
		cursor = db.cursor()
		query = "select * from Accounts where id = ?"
		cursor.execute(query, (ID,))
		data = cursor.fetchall()
		for row in data:
			id = row[0]
			Username = row[1]
			Email = row[2]
			Password = row[3]
			SessionKey = row[4]
			FirstLogin = row[5]
			Banned = row[6]
			Admin = row[7]
			CurrentCharacterID = row[8]

			jsonData = '''{"ID": id, "Username": Username, "Email": Email, "Password": Password, "SessionKey": SessionKey,
						"FirstLogin": FirstLogin,
						"Banned": Banned, "Admin": Admin, "CurrentCharacterID": CurrentCharacterID, "Status": "Success"}'''
			return jsonData
		cursor.close()
	except:
		return '{"Status": "Fail", "Reason": "Account doesn\'t exist"}'
예제 #7
0
    def get_spawners(self):
        config = ConfigParser()
        config.read(str(get_project_root()) + "/config.ini")
        path = str(get_project_root()) + config[self.zone_id]['LVL']

        with open(path + self.file_name, "rb") as lvl:
            data = lvl.read()
            luz_len = len(data)
            stream = ReadStream(data, unlocked=True)

        header = stream.read(bytes, length=4)

        stream.read_offset = 0
        if header == b"CHNK":
            while not stream.all_read():
                assert stream.read_offset // 8 % 16 == 0  # seems everything is aligned like this?
                start_pos = stream.read_offset // 8
                stream.read(bytes, length=4)  # b"CHNK"

                self.chunk_type = stream.read(c_uint)

                stream.read(c_ushort)
                stream.read(c_ushort)

                self.chunk_length = stream.read(c_uint)

                data_pos = stream.read(c_uint)
                stream.read_offset = data_pos * 8

                assert stream.read_offset // 8 % 16 == 0

                if self.chunk_type == 1000:
                    pass
                elif self.chunk_type == 2000:
                    pass
                elif self.chunk_type == 2001:
                    self.parse_2001(stream)
                elif self.chunk_type == 2002:
                    pass
                stream.read_offset = (
                    start_pos + self.chunk_length) * 8  # go to the next CHNK
        else:
            self.parse_old_lvl(stream)
            self.parse_2001(stream)
예제 #8
0
	def set_last_zone(self, zone_id):
		self.last_zone = zone_id

		db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
		db.row_factory = sqlite3.Row
		dbcmd = db.cursor()
		query = "UPDATE Characters SET LastZone = ? WHERE CharID = ?"
		dbcmd.execute(query, (zone_id, self.id,))
		db.commit()
		dbcmd.close()
예제 #9
0
    def set_current_character_id(self, charid):
        self.current_character_id = charid

        db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
        db.row_factory = sqlite3.Row
        dbcmd = db.cursor()
        query = "UPDATE Accounts SET CurrentCharacterID = ? WHERE Username = ?"
        dbcmd.execute(query, (
            charid,
            self.username,
        ))
        db.commit()
        dbcmd.close()
예제 #10
0
    def set_session_key(self, key):
        self.session_key = key

        db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
        db.row_factory = sqlite3.Row
        dbcmd = db.cursor()
        query = "UPDATE Accounts SET SessionKey = ? WHERE Username = ?"
        dbcmd.execute(query, (
            key,
            self.username,
        ))
        db.commit()
        dbcmd.close()
예제 #11
0
	def set_position(self, position, rotation):
		self.x_pos = position.x
		self.y_pos = position.y
		self.z_pos = position.z

		self.x_rot = rotation.x
		self.y_rot = rotation.y
		self.z_rot = rotation.z
		self.w_rot = rotation.w

		db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
		db.row_factory = sqlite3.Row
		dbcmd = db.cursor()
		query = "UPDATE Characters SET X = ?, Y = ?, Z = ? WHERE CharID = ?"
		dbcmd.execute(query, (self.x_pos, self.y_pos, self.z_pos, self.id,))
		db.commit()
		dbcmd.close()
예제 #12
0
    def sync_account_values_down(self):
        db = sqlite3.connect(str(str(get_project_root()) + "/Garmadon.sqlite"))
        db.row_factory = sqlite3.Row

        dbcmd = db.cursor()
        query = "SELECT * FROM Accounts WHERE Username = ?"
        dbcmd.execute(query, (self.temp_username, ))
        value = dbcmd.fetchone()
        dbcmd.close()
        if value is not None:
            self.account_id = value['id']
            self.username = value['Username']
            self.email = value['Email']
            self.password = value['Password']
            self.session_key = value['SessionKey']
            self.first_login = value['FirstLogin']
            self.is_banned = value['Banned']
            self.is_admin = value['Admin']
            self.current_character_id = value['CurrentCharacterID']
예제 #13
0
def getSpecificAccountData(Username, value):  # Template insert ("Player", "id")
	if (getAccountFromUsername(Username)):
		def switchcase(value):
			switcher = {
				"id": 0,
				"username": 1,
				"email": 2,
				"password": 3,
				"sessionKey": 4,
				"firstLogin": 5,
				"banned": 6,
				"admin": 7,
				"currentcharacterid": 8
			}
			return switcher.get(value, "Error")

		def switchcase2(value):
			switcher = {
				0: "ID",
				1: "Username",
				2: "Email",
				3: "Password",
				4: "SessionKey",
				5: "FirstLogin",
				6: "Banned",
				7: "Admin",
				8: "CurrentCharacterID"
			}
			return switcher.get(value, "Error")

		db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
		cursor = db.cursor()
		query = "select * from Accounts where Username = ?"
		cursor.execute(query, (Username,))
		data = cursor.fetchall()
		for row in data:
			if switchcase(value) == "Error":
				return '{"Status": "Fail", "Reason": "Data unreachable"}'
			else:
				return '''{"Username": Username, switchcase2(switchcase(value)): row[switchcase(value)],
						"Status": "Success"}'''
	else:
		return '{"Status": "Fail", "Reason": "Account doesn\'t exist"}'
예제 #14
0
def createAccount(Username, Email, Password):  # Template insert ("Encry", "*****@*****.**", "password")
	if (getAccountFromUsername(Username)):
		return '{"Status": "Fail", "Reason": "Account already exists"}'
	else:
		try:
			db = sqlite3.connect(str(get_project_root()) + "/Garmadon.sqlite")
			db.row_factory = sqlite3.Row
			dbcmd = db.cursor()
			temp = Password.encode('utf-8')

			hashedPassword = bcrypt.hashpw(temp, bcrypt.gensalt())

			query = "INSERT INTO Accounts (Username, Email, Password, SessionKey, FirstLogin, Banned, Admin, CurrentCharacterID) VALUES (?,?,?,?,?,?,?,?)"
			dbcmd.execute(query, (Username, Email, hashedPassword, None, "1", "0", "1", "1"))
			db.commit()
			dbcmd.close()
			return '{"Status": "Success"}'
		except:
			return '{"Status": "Fail", "Reason": "Unknown"}'
예제 #15
0
    def sync_inventory_down(self):
        db = sqlite3.connect(
            str(str(get_project_root()) + "/PikaChewniverse.sqlite"))
        db.row_factory = sqlite3.Row
        dbcmd = db.cursor()
        query = "SELECT * FROM Inventory WHERE CharID = ?"
        dbcmd.execute(query, (self.character.id, ))
        value = dbcmd.fetchall()
        self.items.clear()
        for item in value:
            newitem = Item()
            newitem.item_lot = item['ItemLOT']
            newitem.quantity = item['Quantity']
            newitem.is_equipped = item['IsEquipped']
            newitem.is_linked = item['IsLinked']
            newitem.slot = len(self.items) + 1
            newitem.item_id = item['ItemID']
            newitem.type = item['Type']
            self.items.append(newitem)

        dbcmd.close()
예제 #16
0
    def get_components(self):
        db = sqlite3.connect(
            str(str(get_project_root()) + "/clientfiles/cdclient.sqlite"))
        dbcmd = db.cursor()

        query = "SELECT component_type, component_id FROM ComponentsRegistry WHERE id = ?"
        dbcmd.execute(query, (self.lot, ))
        object_components = dbcmd.fetchall()

        for component in network_components:
            for _ in object_components:
                if component == _[0]:
                    if component not in non_networked:
                        self.component_ids.append(_)

        for component in self.component_ids:
            if component[0] in available_components:
                pass
            else:
                self.is_constructable = False
                break
예제 #17
0
    def create(self):
        for component in self.component_ids:
            if component[0] == 3:
                simple_physics_dict = {
                    'HasPosition': True,
                    'PosX': self.position_x,
                    'PosY': self.position_y,
                    'PosZ': self.position_z,
                    'RotX': self.rotation_x,
                    'RotY': self.rotation_y,
                    'RotZ': self.rotation_z,
                    'RotW': self.rotation_w
                }
                simple_physics_dict['HasVelocity'] = False
                simple_physics_dict['LVelocityX'] = 0
                simple_physics_dict['LVelocityY'] = 0
                simple_physics_dict['LVelocityZ'] = 0

                simple_physics_dict['AVelocityX'] = 0
                simple_physics_dict['AVelocityY'] = 0
                simple_physics_dict['AVelocityZ'] = 0

                self.components.append(
                    SimplePhysics.SimplePhysics(
                        simple_physics_dict=simple_physics_dict))

            if component[0] == 40:
                phantom_physics_dict = {
                    'HasPosition': True,
                    'PosX': self.position_x,
                    'PosY': self.position_y,
                    'PosZ': self.position_z,
                    'RotX': self.rotation_x,
                    'RotY': self.rotation_y,
                    'RotZ': self.rotation_z,
                    'RotW': self.rotation_w
                }
                self.components.append(
                    PhantomPhysics.PhantomPhysics(
                        phantom_physics_dict=phantom_physics_dict))

            if component[0] == 7:
                destructible_dict = {}
                stats_dict = {}
                stats_dict['HasStats'] = False

                self.components.append(
                    Destructible.Destructible(
                        destructible_dict=destructible_dict))
                self.components.append(Stats.Stats(stats_dict=stats_dict))

            if component[0] == 17:
                inventory_dict = {}

                db = sqlite3.connect(
                    str(
                        str(get_project_root()) +
                        "/clientfiles/cdclient.sqlite"))
                dbcmd = db.cursor()
                query = "SELECT itemid, count, equip FROM InventoryComponent WHERE id = ?"
                dbcmd.execute(query, (component[1], ))
                items = dbcmd.fetchall()

                inventory = []

                for item in items:
                    itm = {}
                    itm['ItemID'] = random.randrange(0, 10000000)
                    itm['ItemLOT'] = item[0]
                    itm['Quantity'] = item[1]
                    itm['IsEquipped'] = item[2]
                    itm['Slot'] = items.index(item)

                    db = sqlite3.connect(
                        str(
                            str(get_project_root()) +
                            "/clientfiles/cdclient.sqlite"))
                    dbcmd = db.cursor()
                    query = "SELECT itemType FROM ItemComponent WHERE id = ?"
                    dbcmd.execute(query, (itm['ItemLOT'], ))
                    item_type = dbcmd.fetchall()

                    try:
                        itm['Type'] = item_type[0][0]
                    except Exception:
                        itm['Type'] = 0

                    inventory.append(itm)

                inventory_dict['HasInventory'] = True
                inventory_dict['Inventory'] = inventory

                self.components.append(
                    Inventory.Inventory(inventory_dict=inventory_dict))

            if component[0] == 5:
                db = sqlite3.connect(
                    str(
                        str(get_project_root()) +
                        "/clientfiles/cdclient.sqlite"))
                dbcmd = db.cursor()
                query = "SELECT client_script_name FROM ScriptComponent WHERE id = ?"
                dbcmd.execute(query, (component[1], ))
                script = dbcmd.fetchone()

                try:
                    if script[0] is not None:
                        self.is_constructable = False
                        pass
                    else:
                        pass  # log(LOGGINGLEVEL.ERROR, "LOT: " + self.spawn_lot + " Has No Script")
                except Exception:
                    self.is_constructable = False
                    log(LOGGINGLEVEL.ERROR,
                        "LOT: " + str(self.lot) + " No script database entry")

                if self.is_constructable is True:
                    script_dict = {}
                    self.components.append(
                        Script.Script(script_dict=script_dict))

            if component[0] == 9:
                skill_dict = {}

                self.components.append(Skill.Skill(skill_dict=skill_dict))

            if component[0] == 16:
                vendor_dict = {}

                self.components.append(Vendor.Vendor(vendor_dict=vendor_dict))

            if component[0] == 2:
                render_dict = {}

                self.components.append(Render.Render(render_dict=render_dict))

            if component[0] == 107:
                component107_dict = {}
                self.components.append(
                    Component107.Component107(
                        component107_dict=component107_dict))

        self.server._rep_man.construct(obj=self,
                                       new=True,
                                       reliability=Reliability.ReliableOrdered)
예제 #18
0
from Utils.GetProjectRoot import get_project_root
import configparser
from APIServer import app
import ctypes
from Logger import *

config = configparser.ConfigParser()
path = str(get_project_root()) + '/config.ini'
config.read(path)


def flaskThread():
    log(LOGGINGLEVEL.WEBSERVER, (" Server Started"))
    app.debug = False
    app.run(config['API']['IP'], int(config['API']['PORT']))
예제 #19
0
    def create(self):
        id = LWOOBJID().generateobject()
        obj = Object(object_id=id, lot=int(self.spawn_lot), name="")

        for component in self.components:
            if component[0] == 3:
                simple_physics_dict = {
                    'HasPosition': True,
                    'PosX': self.pos_x,
                    'PosY': self.pos_y,
                    'PosZ': self.pos_z,
                    'RotX': self.rot_x,
                    'RotY': self.rot_y,
                    'RotZ': self.rot_z,
                    'RotW': self.rot_w
                }
                simple_physics_dict['HasVelocity'] = False
                simple_physics_dict['LVelocityX'] = 0
                simple_physics_dict['LVelocityY'] = 0
                simple_physics_dict['LVelocityZ'] = 0

                simple_physics_dict['AVelocityX'] = 0
                simple_physics_dict['AVelocityY'] = 0
                simple_physics_dict['AVelocityZ'] = 0

                obj.components.append(
                    SimplePhysics.SimplePhysics(
                        simple_physics_dict=simple_physics_dict))

            if component[0] == 40:
                phantom_physics_dict = {
                    'HasPosition': True,
                    'PosX': self.pos_x,
                    'PosY': self.pos_y,
                    'PosZ': self.pos_z,
                    'RotX': self.rot_x,
                    'RotY': self.rot_y,
                    'RotZ': self.rot_z,
                    'RotW': self.rot_w
                }
                obj.components.append(
                    PhantomPhysics.PhantomPhysics(
                        phantom_physics_dict=phantom_physics_dict))

            if component[0] == 7:
                destructible_dict = {}
                stats_dict = {}
                stats_dict['HasStats'] = False

                obj.components.append(
                    Destructible.Destructible(
                        destructible_dict=destructible_dict))
                obj.components.append(Stats.Stats(stats_dict=stats_dict))

            if component[0] == 17:
                inventory_dict = {}

                db = sqlite3.connect(
                    str(
                        str(get_project_root()) +
                        "/clientfiles/cdclient.sqlite"))
                dbcmd = db.cursor()
                query = "SELECT itemid, count, equip FROM InventoryComponent WHERE id = ?"
                dbcmd.execute(query, (component[1], ))
                items = dbcmd.fetchall()

                inventory = typeinv(character=None)

                for item in items:
                    itm = Item()
                    itm.item_id = random.randrange(0, 10000000)
                    itm.item_lot = item[0]
                    itm.quantity = item[1]
                    itm.is_equipped = item[2]
                    itm.slot = items.index(item)
                    itm.type = 0
                    inventory.items.append(itm)

                inventory_dict['HasInventory'] = True
                inventory_dict['Inventory'] = inventory

                obj.components.append(
                    Inventory.Inventory(inventory_dict=inventory_dict))
                print(self.spawn_lot)

            if component[0] == 9:
                skill_dict = {}

                obj.components.append(Skill.Skill(skill_dict=skill_dict))

            if component[0] == 16:
                vendor_dict = {}

                obj.components.append(Vendor.Vendor(vendor_dict=vendor_dict))

            if component[0] == 2:
                render_dict = {}

                obj.components.append(Render.Render(render_dict=render_dict))

            if component[0] == 107:
                component107_dict = {}
                obj.components.append(
                    Component107.Component107(
                        component107_dict=component107_dict))

        self.server._rep_man.construct(obj, True)
예제 #20
0
    def add_item(self, item_data):
        self.sync_inventory_down()
        if item_data['Type'] == 0:
            if len(self.items) > 0:
                for item in self.items:
                    if int(item.item_lot) == int(item_data['ItemLOT']):
                        print("Same")
                        item.quantity = item.quantity + item_data['Quantity']

                        db = sqlite3.connect(
                            str(
                                str(get_project_root()) +
                                "/PikaChewniverse.sqlite"))
                        db.row_factory = sqlite3.Row
                        dbcmd = db.cursor()
                        query = "UPDATE Inventory SET Quantity = ? WHERE ItemID = ?"
                        dbcmd.execute(query, (
                            item.quantity,
                            item.item_id,
                        ))
                        db.commit()
                        dbcmd.close()
                        break

                    elif len(self.items) < self.character.inventory_space:
                        newitem = Item()
                        newitem.item_lot = item_data['ItemLOT']
                        newitem.quantity = item_data['Quantity']
                        newitem.is_equipped = item_data['IsEquipped']
                        newitem.is_linked = item_data['IsLinked']
                        newitem.slot = len(self.items) + 1
                        newitem.item_id = item_data['ItemID']
                        newitem.type = item_data['Type']
                        self.items.append(newitem)

                        db = sqlite3.connect(
                            str(
                                str(get_project_root()) +
                                "/PikaChewniverse.sqlite"))
                        db.row_factory = sqlite3.Row
                        dbcmd = db.cursor()
                        query = "INSERT INTO Inventory (CharID, ItemLOT, IsEquipped, IsLinked, Quantity, Slot, ItemID, Type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
                        dbcmd.execute(query, (
                            self.character.id,
                            newitem.item_lot,
                            newitem.is_equipped,
                            newitem.is_linked,
                            newitem.quantity,
                            newitem.slot,
                            newitem.item_id,
                            newitem.type,
                        ))
                        db.commit()
                        dbcmd.close()
                        break
            else:
                newitem = Item()
                newitem.item_lot = item_data['ItemLOT']
                newitem.quantity = item_data['Quantity']
                newitem.is_equipped = item_data['IsEquipped']
                newitem.is_linked = item_data['IsLinked']
                newitem.slot = len(self.items) + 1
                newitem.item_id = item_data['ItemID']
                newitem.type = item_data['Type']
                self.items.append(newitem)

                db = sqlite3.connect(
                    str(str(get_project_root()) + "/PikaChewniverse.sqlite"))
                db.row_factory = sqlite3.Row
                dbcmd = db.cursor()
                query = "INSERT INTO Inventory (CharID, ItemLOT, IsEquipped, IsLinked, Quantity, Slot, ItemID, Type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
                dbcmd.execute(query, (
                    self.character.id,
                    newitem.item_lot,
                    newitem.is_equipped,
                    newitem.is_linked,
                    newitem.quantity,
                    newitem.slot,
                    newitem.item_id,
                    newitem.type,
                ))
                db.commit()
                dbcmd.close()

                del newitem
        else:
            print("Type not supported: " + str(item_data['Type']))
        self.sync_inventory_down()