mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
Implement DB updates for player. Cleaned up DB calls. No longer track slot, it's ordered by index id (no concept of slots anyway in client).
This commit is contained in:
parent
76f073d85f
commit
bc95c139de
@ -1225,7 +1225,6 @@ namespace FFXIVClassic_Map_Server
|
|||||||
serverItemId,
|
serverItemId,
|
||||||
itemId,
|
itemId,
|
||||||
quantity,
|
quantity,
|
||||||
slot,
|
|
||||||
itemType,
|
itemType,
|
||||||
quality,
|
quality,
|
||||||
durability,
|
durability,
|
||||||
@ -1237,36 +1236,36 @@ namespace FFXIVClassic_Map_Server
|
|||||||
materia5
|
materia5
|
||||||
FROM characters_inventory
|
FROM characters_inventory
|
||||||
INNER JOIN server_items ON serverItemId = server_items.id
|
INNER JOIN server_items ON serverItemId = server_items.id
|
||||||
WHERE characterId = @charId AND inventoryType = @type AND slot >= @slot ORDER BY slot";
|
WHERE characterId = @charId AND inventoryType = @type";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||||
cmd.Parameters.AddWithValue("@slot", slotOffset);
|
|
||||||
cmd.Parameters.AddWithValue("@type", type);
|
cmd.Parameters.AddWithValue("@type", type);
|
||||||
|
|
||||||
|
ushort slot = 0;
|
||||||
using (MySqlDataReader reader = cmd.ExecuteReader())
|
using (MySqlDataReader reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
uint uniqueId = reader.GetUInt32(0);
|
uint uniqueId = reader.GetUInt32("serverItemId");
|
||||||
uint itemId = reader.GetUInt32(1);
|
uint itemId = reader.GetUInt32("itemId");
|
||||||
int quantity = reader.GetInt32(2);
|
int quantity = reader.GetInt32("quantity");
|
||||||
ushort slot = reader.GetUInt16(3);
|
|
||||||
|
|
||||||
byte itemType = reader.GetByte(4);
|
byte itemType = reader.GetByte("itemType");
|
||||||
byte qualityNumber = reader.GetByte(5);
|
byte qualityNumber = reader.GetByte("quality");
|
||||||
|
|
||||||
int durability = reader.GetInt32(6);
|
int durability = reader.GetInt32("durability");
|
||||||
ushort spiritBind = reader.GetUInt16(7);
|
ushort spiritBind = reader.GetUInt16("spiritBind");
|
||||||
|
|
||||||
byte materia1 = reader.GetByte(8);
|
byte materia1 = reader.GetByte("materia1");
|
||||||
byte materia2 = reader.GetByte(9);
|
byte materia2 = reader.GetByte("materia2");
|
||||||
byte materia3 = reader.GetByte(10);
|
byte materia3 = reader.GetByte("materia3");
|
||||||
byte materia4 = reader.GetByte(11);
|
byte materia4 = reader.GetByte("materia4");
|
||||||
byte materia5 = reader.GetByte(12);
|
byte materia5 = reader.GetByte("materia5");
|
||||||
|
|
||||||
InventoryItem item = new InventoryItem(uniqueId, itemId, quantity, itemType, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5);
|
InventoryItem item = new InventoryItem(uniqueId, itemId, quantity, itemType, qualityNumber, durability, spiritBind, materia1, materia2, materia3, materia4, materia5);
|
||||||
item.slot = slot;
|
item.slot = slot;
|
||||||
|
slot++;
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1327,10 +1326,8 @@ namespace FFXIVClassic_Map_Server
|
|||||||
return insertedItem;
|
return insertedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InventoryItem AddItem(Player player, InventoryItem addedItem, uint type)
|
public static void AddItem(Player player, InventoryItem addedItem, uint type)
|
||||||
{
|
{
|
||||||
InventoryItem insertedItem = null;
|
|
||||||
|
|
||||||
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -1339,8 +1336,8 @@ namespace FFXIVClassic_Map_Server
|
|||||||
|
|
||||||
string query = @"
|
string query = @"
|
||||||
INSERT INTO characters_inventory
|
INSERT INTO characters_inventory
|
||||||
(characterId, slot, inventoryType, serverItemId, quantity)
|
(characterId, inventoryType, serverItemId, quantity)
|
||||||
SELECT @charId, IFNULL(MAX(SLOT)+1, 0), @inventoryType, @uid, @quantity FROM characters_inventory WHERE characterId = @charId AND inventoryType = @inventoryType;
|
SELECT @charId, @inventoryType, @uid, @quantity FROM characters_inventory WHERE characterId = @charId AND inventoryType = @inventoryType;
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
@ -1348,7 +1345,7 @@ namespace FFXIVClassic_Map_Server
|
|||||||
cmd.Parameters.AddWithValue("@uid", addedItem.uniqueId);
|
cmd.Parameters.AddWithValue("@uid", addedItem.uniqueId);
|
||||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||||
cmd.Parameters.AddWithValue("@inventoryType", type);
|
cmd.Parameters.AddWithValue("@inventoryType", type);
|
||||||
cmd.Parameters.AddWithValue("@quantity", insertedItem.quantity);
|
cmd.Parameters.AddWithValue("@quantity", addedItem.quantity);
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
@ -1361,11 +1358,9 @@ namespace FFXIVClassic_Map_Server
|
|||||||
conn.Dispose();
|
conn.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return insertedItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetQuantity(Player player, uint slot, ushort type, int quantity)
|
public static void SetQuantity(Player player, ulong serverItemId, int quantity)
|
||||||
{
|
{
|
||||||
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
||||||
{
|
{
|
||||||
@ -1376,54 +1371,13 @@ namespace FFXIVClassic_Map_Server
|
|||||||
string query = @"
|
string query = @"
|
||||||
UPDATE characters_inventory
|
UPDATE characters_inventory
|
||||||
SET quantity = @quantity
|
SET quantity = @quantity
|
||||||
WHERE characterId = @charId AND slot = @slot AND inventoryType = @type;
|
WHERE characterId = @charId and serverItemId = @serverItemId;
|
||||||
";
|
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
|
||||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
|
||||||
cmd.Parameters.AddWithValue("@quantity", quantity);
|
|
||||||
cmd.Parameters.AddWithValue("@slot", slot);
|
|
||||||
cmd.Parameters.AddWithValue("@type", type);
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (MySqlException e)
|
|
||||||
{
|
|
||||||
Program.Log.Error(e.ToString());
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
conn.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemoveItem(Player player, ulong serverItemId, ushort type)
|
|
||||||
{
|
|
||||||
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}; Allow User Variables=True", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
conn.Open();
|
|
||||||
|
|
||||||
string query = @"
|
|
||||||
SELECT slot INTO @slotToDelete FROM characters_inventory WHERE serverItemId = @serverItemId;
|
|
||||||
UPDATE characters_inventory
|
|
||||||
SET slot = slot - 1
|
|
||||||
WHERE characterId = @charId AND slot > @slotToDelete AND inventoryType = @type;
|
|
||||||
|
|
||||||
DELETE FROM characters_inventory
|
|
||||||
WHERE serverItemId = @serverItemId AND inventoryType = @type;
|
|
||||||
|
|
||||||
DELETE FROM server_items
|
|
||||||
WHERE id = @serverItemId;
|
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||||
cmd.Parameters.AddWithValue("@serverItemId", serverItemId);
|
cmd.Parameters.AddWithValue("@serverItemId", serverItemId);
|
||||||
cmd.Parameters.AddWithValue("@type", type);
|
cmd.Parameters.AddWithValue("@quantity", quantity);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1439,7 +1393,7 @@ namespace FFXIVClassic_Map_Server
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveItem(Player player, ushort slot, ushort type)
|
public static void RemoveItem(Player player, ulong serverItemId)
|
||||||
{
|
{
|
||||||
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}; Allow User Variables=True", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
using (MySqlConnection conn = new MySqlConnection(String.Format("Server={0}; Port={1}; Database={2}; UID={3}; Password={4}; Allow User Variables=True", ConfigConstants.DATABASE_HOST, ConfigConstants.DATABASE_PORT, ConfigConstants.DATABASE_NAME, ConfigConstants.DATABASE_USERNAME, ConfigConstants.DATABASE_PASSWORD)))
|
||||||
{
|
{
|
||||||
@ -1448,23 +1402,13 @@ namespace FFXIVClassic_Map_Server
|
|||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
string query = @"
|
string query = @"
|
||||||
SELECT serverItemId INTO @serverItemId FROM characters_inventory WHERE characterId = @charId AND slot = @slot;
|
|
||||||
|
|
||||||
DELETE FROM characters_inventory
|
DELETE FROM characters_inventory
|
||||||
WHERE characterId = @charId AND slot = @slot AND inventoryType = @type;
|
WHERE characterId = @charId and serverItemId = @itemDBCode;
|
||||||
|
|
||||||
DELETE FROM server_items
|
|
||||||
WHERE id = @serverItemId;
|
|
||||||
|
|
||||||
UPDATE characters_inventory
|
|
||||||
SET slot = slot - 1
|
|
||||||
WHERE characterId = @charId AND slot > @slot AND inventoryType = @type;
|
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
cmd.Parameters.AddWithValue("@charId", player.actorId);
|
||||||
cmd.Parameters.AddWithValue("@slot", slot);
|
cmd.Parameters.AddWithValue("@serverItemId", serverItemId);
|
||||||
cmd.Parameters.AddWithValue("@type", type);
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,12 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack);
|
item.quantity = Math.Min(item.quantity + quantityCount, gItem.maxStack);
|
||||||
isDirty[i] = true;
|
isDirty[i] = true;
|
||||||
quantityCount -= (gItem.maxStack - oldQuantity);
|
quantityCount -= (gItem.maxStack - oldQuantity);
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
{
|
||||||
|
Database.SetQuantity((Player)owner, item.uniqueId, item.quantity);
|
||||||
|
}
|
||||||
|
|
||||||
if (quantityCount <= 0)
|
if (quantityCount <= 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -145,10 +151,17 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
isDirty[endOfListIndex] = true;
|
isDirty[endOfListIndex] = true;
|
||||||
list[endOfListIndex++] = addedItem;
|
list[endOfListIndex++] = addedItem;
|
||||||
quantityCount -= gItem.maxStack;
|
quantityCount -= gItem.maxStack;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
{
|
||||||
|
Database.AddItem((Player)owner, addedItem, inventoryCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
|
{
|
||||||
SendUpdatePackets((Player)owner);
|
SendUpdatePackets((Player)owner);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -178,10 +191,18 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
int oldQuantity = item.quantity;
|
int oldQuantity = item.quantity;
|
||||||
//Stack nomnomed
|
//Stack nomnomed
|
||||||
if (item.quantity - quantityCount <= 0)
|
if (item.quantity - quantityCount <= 0)
|
||||||
|
{
|
||||||
|
if (owner is Player)
|
||||||
|
Database.RemoveItem((Player)owner, list[i].uniqueId);
|
||||||
list[i] = null;
|
list[i] = null;
|
||||||
|
}
|
||||||
//Stack reduced
|
//Stack reduced
|
||||||
else
|
else
|
||||||
|
{
|
||||||
item.quantity -= quantityCount;
|
item.quantity -= quantityCount;
|
||||||
|
if (owner is Player)
|
||||||
|
Database.SetQuantity((Player)owner, list[i].uniqueId, list[i].quantity);
|
||||||
|
}
|
||||||
|
|
||||||
isDirty[i] = true;
|
isDirty[i] = true;
|
||||||
|
|
||||||
@ -215,6 +236,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
if (toDelete == null)
|
if (toDelete == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
Database.RemoveItem((Player)owner, toDelete.uniqueId);
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
doRealign();
|
doRealign();
|
||||||
@ -225,6 +249,9 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
if (slot >= endOfListIndex)
|
if (slot >= endOfListIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (owner is Player)
|
||||||
|
Database.RemoveItem((Player)owner, list[slot].uniqueId);
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
doRealign();
|
doRealign();
|
||||||
@ -243,9 +270,17 @@ namespace FFXIVClassic_Map_Server.actors.chara.player
|
|||||||
|
|
||||||
if (list[slot].quantity <= 0)
|
if (list[slot].quantity <= 0)
|
||||||
{
|
{
|
||||||
|
if (owner is Player)
|
||||||
|
Database.RemoveItem((Player)owner, list[slot].uniqueId);
|
||||||
|
|
||||||
list[slot] = null;
|
list[slot] = null;
|
||||||
doRealign();
|
doRealign();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (owner is Player)
|
||||||
|
Database.SetQuantity((Player)owner, list[slot].uniqueId, list[slot].quantity);
|
||||||
|
}
|
||||||
|
|
||||||
isDirty[slot] = true;
|
isDirty[slot] = true;
|
||||||
if (owner is Player)
|
if (owner is Player)
|
||||||
|
Loading…
Reference in New Issue
Block a user