Jump to content

Sending mail items via php ?


Recommended Posts

Posted

Anyone developed a system to send an item to a player via PHP ? I know one of the WoW blizzlike webpages for mangos had that system, buy was working crappy, some times the items was sent to the players, other times the player recived in his mail weird items.

I am looking for a simple php to do this, any idea what mysql query I must create to do this action ?

Posted
function send_ingame_mail($to, $from, $subject, $body, $gold = 0, $item = 0, $stack = 1){

$sql_0->connect($characters_db[$realm_id]['addr'], $characters_db[$realm_id]['user'], $characters_db[$realm_id]['pass'], $characters_db[$realm_id]['name']);

$result = $sql_0->query("SELECT MAX(`id`) FROM item_text");

$item_page_id = ($sql_0->result($result, 0)) + 1;

$result = $sql_0->query("INSERT INTO item_text (id, text) VALUES

($item_page_id,'$body')");

$result = $sql_0->query("SELECT MAX(`id`) FROM mail");

$mail_id = ($sql_0->result($result, 0)) + 1;

$item_guid = ($item) ? gen_item_instance($to, $item, $stack) : 0;

if ($item == 0) {

$has_items = 0;

} else {

$has_items = 1;

}

$result = $sql_0->query("INSERT INTO mail (id,messageType,stationery,mailTemplateId,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked)

VALUES

($mail_id, 0, 61, 0, '$from', '$to', '$subject', '$item_page_id', '$has_items', '".(time() + (30*24*3600))."','".(time()+5)."', '$gold', 0, 0)");

if ($has_items) {

$result = $sql_0->query("INSERT INTO mail_items (mail_id,item_guid,item_template,receiver)

VALUES

($mail_id, '$item_guid', '$item', '$to')");

}

if ($result) {

$sql_0->close();

return $mail_id;

} else {

$sql_0->close();

return 0;

}

}

$sql->connect($characters_db[$realm_id]['addr'], $characters_db[$realm_id]['user'], $characters_db[$realm_id]['pass'], $characters_db[$realm_id]['name']);

if($to){ //single Recipient

$result = $sql->query("SELECT guid FROM `characters` WHERE name ='$to'");

if ($sql->num_rows($result) == 1) {

$receiver = $sql->result($result, 0, 'guid');

$result = $sql->query("SELECT guid FROM `characters` WHERE name ='$user_name'");

$sender = 0;

//if ($sql->num_rows($result) == 1) {

// $sender = $sql->result($result, 0, 'guid');

//};

// we need the id of a character, account username is provided atm

send_ingame_mail($receiver, $sender, $subject, $body, $att_gold, $att_item, $att_stack);

} else {

$sql->close();

echo "error";

}

$sql->close();

echo "error";

Try opimise this on your site. it's from other project

  • 11 months later...
Posted

Hm i tested your Code but if i send an item i get nothing.

############ mail_items ############

mail_id --- item_guid --- item_template --- receiver

3 ------------ 386 ------------ 38237 ------------ 2

############ mail ############

id messageType stationery mailTemplateId sender receiver subject itemTextId has_items expire_time deliver_time money cod checked

3 0 61 0 0 2 Voting Reward 3 1 1261014009 1258422010 0 0

############ item_text ############

id ------------------------------ text

3 - Thank you for voting for our server. Here is your ..

What is wrong here ? By the way what is item_guid in mail_items

(i know these colors are *** :P made that to make more overview

Posted

You shouldn't modify this information when the server is running and the character is logged in. Better to do a check when sending it to see if the character is logged in than risk crashing the server or erasing mail.

  • 4 months later...
Posted

Need to enable soap first

Need to convert for your site

<?php


   function convert_charset($item)
   {
       if ($unserialize = unserialize($item))
       {
           foreach ($unserialize as $key => $value)
           {
               $unserialize[$key] = @iconv('windows-1256', 'UTF-8', $value);
           }
           $serialize = serialize($unserialize);
           return $serialize;
       }
       else
       {
           return @iconv('windows-1256', 'UTF-8', $item);
       }
   } 



function SoapExecute($command,$host,$soapport,$username,$password)
{
$client = new SoapClient(NULL,
array(
   "location" => "http://$host:$soapport/",
   "uri" => "urn:MaNGOS",
   "style" => SOAP_RPC,
   'login' => $user,
   'password' => $pass
));

try {
   $result = $client->executeCommand(new SoapParam(convert_charset($command), "command"));

   echo "Command succeeded! Output:
\\n";
   echo $result;
}
catch (Exception $e)
{
   echo "Command failed! Reason:
\\n";
   echo $e->getMessage();
}    
}

$command = 'send item '.$result_data["name"].' "Server Gift Item" "Enjoy!!" 90000:1';
SoapExecute($command,$host,$soapport,$username,$password);

$command = 'send money '.$result_data["name"].' "Server Gift Money" "Enjoy!!" 50000000';
SoapExecute($command,$host,$soapport,$username,$password);


?>

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use