void RenamePet()
{
try
{
//Start reading packet data
PacketReader Reader = new PacketReader(PacketInformation.buffer);
//Pet id
int petid = Reader.Int32();
//Pet name lenght
short petnamel = Reader.Int16();
//Pet name
string petname = Reader.String(petnamel);
//Check availability for pet name.
int nameavailable = MsSQL.GetRowsCount("SELECT pet_name FROM pets WHERE pet_name='" + petname + "'");
//If available (Row count is zero).
if (nameavailable == 0)
{
//Create the query we will use
MsSQL ms = new MsSQL("SELECT * FROM pets WHERE playerid='" + Character.Information.CharacterID + "' AND pet_unique='" + petid + "'");
//Open our data reader
using (SqlDataReader reader = ms.Read())
{
//While the reader is reading from database
while (reader.Read())
{
//First we check the lenght of the name.
if (petnamel < 3)
{
client.Send(Packet.IngameMessages(SERVER_PET_RENAME_MSG, IngameMessages.UIIT_MSG_COSPETERR_PETNAME_NOTPUT));
}
//Check if renamed allready. (Should not be needed just extra check)
if (Character.Grabpet.Details != null)
{
if (petid == Character.Grabpet.Details.UniqueID)
{
if (Character.Grabpet.Details.Petname == "No name")
{
//Update name in database
MsSQL.UpdateData("UPDATE pets SET pet_state='2',pet_name='" + petname + "' WHERE pet_unique='" + petid + "' AND playerid='" + Character.Information.CharacterID + "'");
//Send needed packets to update name (Official sends 2 times)...
client.Send(Packet.PetSpawn(petid, 2, Character.Grabpet.Details));
//Send to all currently in spawn range
Send(Packet.PetSpawn(petid, 2, Character.Grabpet.Details));
}
}
}
//Check if renamed allready. (Should not be needed just extra check)
if (Character.Attackpet.Details != null)
{
if (petid == Character.Attackpet.Details.UniqueID)
{
if (Character.Attackpet.Details.Petname == "No name")
{
//Update name in database
MsSQL.UpdateData("UPDATE pets SET pet_state='2',pet_name='" + petname + "' WHERE pet_unique='" + petid + "' AND playerid='" + Character.Information.CharacterID + "'");
//Send needed packets to update name (Official sends 2 times)...
client.Send(Packet.PetSpawn(petid, 2, Character.Attackpet.Details));
//Send to all currently in spawn range
Send(Packet.PetSpawn(petid, 2, Character.Attackpet.Details));
}
}
}
}
}
}
//If name has been taken
else
{
//Not sure if correct msg.
client.Send(Packet.IngameMessages(SERVER_PET_RENAME_MSG, IngameMessages.UIIT_MSG_COSPETERR_PETNAME_NOTPUT));
}
}
catch (Exception ex)
{
Console.WriteLine("Grab pet renaming error : " + ex);
}
}