void PrivateMessageSend()
{
try
{
//Create new packet reader for reading packet data
PacketReader Reader = new PacketReader(PacketInformation.buffer);
//Read lenght of charactername we send the message to
short ToCharacterLen = Reader.Int16();
//Read the name of the character we send the message to
string ToCharacter = Reader.String(ToCharacterLen);
//Read lenght of message characters
short MessageLen = Reader.Int16();
//Read message
string Message = Reader.String(MessageLen);
//Close packet reader
Reader.Close();
//Create new mssql query for sending and checking
MsSQL ms = new MsSQL("SELECT * FROM character WHERE name='" + ToCharacter + "'");
//Check if the player exists
int PlayerExists = ms.Count();
//If the player exists
if (PlayerExists > 0)
{
//First get details of the player we send the message to.
Systems sys = GetPlayerName(ToCharacter);
//Make sure we dont get a null error
if (sys.Character != null)
{
//Check how many messages the player has if inbox is full or not
int TargetMessageCount = MsSQL.GetRowsCount("SELECT * FROM message WHERE receiver='" + sys.Character.Information.CharacterID + "'");
//If less then 50 we continue
if (TargetMessageCount < 50)
{
//Set temp int to character data for new message order
sys.Character.Information.MessageCount = TargetMessageCount;
//Insert new message into the database
MsSQL.InsertData("INSERT INTO message (sender, receiver, message, status, time) VALUES ('" + Character.Information.Name + "','" + ToCharacter + "','" + Message + "','0','" + DateTime.Now + "')");
//Send packet message has been send to our client
client.Send(PrivateMessageRespond(2));
//Send packet to receiver information new message has arrived
sys.Send(Packet.FriendData(sys.Character.Information.UniqueID, 5, ToCharacter, Character, false));
}
//If inbox is full
else
{
//Send message to sender and receiver inbox full
client.Send(PrivateMessageRespond(3));
sys.client.Send(PrivateMessageRespond(3));
}
}
}
//If player doesn't exist
else
{
//Send packet message failed to send to our client.
client.Send(PrivateMessageRespond(1));
}
}
//Catch any bad exception errors
catch (Exception ex)
{
//Write information to the console
Console.WriteLine("Error sending messages : {0}" + ex);
//Write info to the debug logger.
Systems.Debugger.Write(ex);
}
}