Code:
using System;
using DriftCity.Server.Structures;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DriftCity.Server.Core;
namespace DriftCity.Server.Packets.Game
{
public static class Shop
{
[DriftCityPacket(405, DriftCityServer.ServerType.Game)]
public static void BuyItem(DriftCityPacket packet)
{
int id = packet.Reader.ReadInt32();
int quantity = packet.Reader.ReadInt32();
DbConnection dbconn_d = Database.GetConnection();
DbCommand items = dbconn_d.CreateCommand();
items.CommandText = @"SELECT price FROM items WHERE id = '" + id + "'";
DbDataReader itemdata = items.ExecuteReader();
if( itemdata.HasRows )
{
while( itemdata.Read() )
{
// By SdfSdf
Log.WriteLine("Shop Buy - ItemID: {0} Quantity: {1} Price: {2}", id, quantity, (itemdata.GetInt32(0)));
var ack = new DriftCityPacket(406);
ack.Writer.Write(id);
ack.Writer.Write(quantity);
ack.Writer.Write(itemdata.GetInt32(0) * quantity);
packet.Sender.Send(ack);
break;
}
}
else
{
packet.Sender.Error( "Add item id = {0} to the database!", id );
}
itemdata.Close();
}
}
}
Credits: By SdfSdf