Optimized the API.
Version 1.5 is available on top post!
Printable View
Optimized the API.
Version 1.5 is available on top post!
I would appreciate some feedback on the new code.
If your inventory is full, you won't get the items (not via mail or relog [= sent via MSSQL table])
There should be a function to check for it.
Btw.: Checking the INVENTORY_TBL for the inventory being full won't help since it just reloads when you relog or when the server is doing the regular save.
If you would have a cool tipp on this issue, the api would be more than insanely good :D
For me the send via mssql if char isn't logging in is not working correctly its inserting it in the ITEM_SEND_TBL but with the wrong id and I don't know why if the char is logged in it's working fine
What ID should it insert and what is it inserting?
I noticed this myself. If the ID was greater than 0000007, then it would read it as 0. If I just put in 8, for example, then it would work contrary to putting in 0000008.
As example when I buy the item with ID 26455 (Gold Battery) than in the ITEM_SEND_TBL it's item ID 87 and this can't be send
And there is another bug if your character have full inventory like r3fl3x said
I will try to fix the thing with the item id wrong later but with the bug r3fl3x mentioned I have no idea about how to fix because I don't know anything about the billing function in the source so I don't know how to check if the char has full inventory EDIT: maybe it would be a good idea to send the items via postbox if inventory is full
EDIT2:
I got the think with mssql to work now only the think with full inventory is there to fix now
There are other ways (just as efficient ways/just as fast ways) to do the API without opening ports. Personally I find the socket part of this API not needed, but I suppose you have your reasons.
Although I like how you are packing the data to increase the speed of the API (smart).
Nice job.
The socket part of the API has to do with getting items to players that are logged in, instantly.
If you would've tried it, you would've known.
Anyways, v1.6 is up, fixed up the data formats on the procedure bindings as well as added documentation and better examples.
Thanks, I like the 1.6
Hi spikensbror, i've ported our code to the actual sqlsrv module because mssql functions are not supported in php 5.3
Here is the rewrite of our code(nice release :thumbup:):
billing.api.php:
config.php:PHP Code:<?php
/*************************************
* addBill-API (spikensbror) *
* API-rewrite and Port by *
* ZappeL 2011 *
*************************************/
function billing_send_item($adbill_object){
if(!socket_connect($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP), B_IP, B_PT) || !($mssql_socket = sqlsrv_connect(S_SRV, array("UID"=>S_UID, "PWD"=>S_PWD, "Database"=>S_DBF))))
return false;
if(!billing_internal_adbill_send($socket, $adbill_object))
billing_internal_mssql_send($mssql_socket, $adbill_object);
socket_close($socket);
sqlsrv_close($mssql_socket);
return true;
}
// Sends multiple items to a player.
function billing_send_items($adbill_objects){
if(!socket_connect($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP), B_IP, B_PT) || !($mssql_socket = sqlsrv_connect(S_SRV, array("UID"=>S_UID, "PWD"=>S_PWD, "Database"=>S_DBF))))
return false;
$user_online = true;
foreach($adbill_objects as $adbill_object){
if(!isset($scnd_loop)){
$scnd_loop = true;
if(!billing_internal_adbill_send($socket, $adbill_object)) $user_online = false;
else continue;
}
if($user_online) billing_internal_adbill_send($socket, $adbill_object);
else billing_internal_mssql_send($mssql_socket, $adbill_object);
}
socket_close($socket);
sqlsrv_close($mssql_socket);
return true;
}
// Creates an adbill item object.
function billing_create_item($server_index, $player_id, $item_id, $item_count){
return new AdbillObject($server_index, $player_id, $item_id, $item_count);
}
// Internal SEND_ITEM_TBL operation.
function billing_internal_mssql_send($mssql_socket, $adbill_object){
$procedure = '{CALL [dbo].[uspProvideItemToCharacter](?,?,?,?)}';
$params = array(
array(str_pad($adbill_object->player_id, 7, "0", STR_PAD_LEFT), SQLSRV_PARAM_IN),
array(str_pad($adbill_object->server_index, 2, "0", STR_PAD_LEFT), SQLSRV_PARAM_IN),
array($adbill_object->item_id, SQLSRV_PARAM_IN),
array($adbill_object->item_count, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_query($mssql_socket,$procedure,$params);
sqlsrv_free_stmt($stmt);
}
// Internal abill protocol operation.
function billing_internal_adbill_send($billing_socket, $adbill_object){
$packet = pack("VVVVV",
$adbill_object->server_index,
$adbill_object->player_id,
0000001,
$adbill_object->item_id,
$adbill_object->item_count)
. str_pad("", 24, ' ')
. pack("V", 0);
socket_write($billing_socket, $packet, 48);
$buffer = "";
if(!socket_recv($billing_socket, $buffer, 2048, MSG_WAITALL)) return false;
$return = unpack("V", substr($buffer, strlen($buffer) - 4));
return (bool)$return[1];
}
// Adbill item object.
class AdbillObject{
public $server_index = null;
public $player_id = null;
public $item_id = null;
public $item_count = null;
public function __construct($server_index, $player_id, $item_id, $item_count){
$this->server_index = $server_index;
$this->player_id = $player_id;
$this->item_id = $item_id;
$this->item_count = $item_count;
}
}
?>
test.php:PHP Code:<?php
/*************************************
* addBill-Config *
* API-rewrite and Port by *
* ZappeL 2011 *
*************************************/
define('B_PT', 29000); // BillingService-Port (can be defined in server sources)
define('B_IP', '127.0.0.1'); // BillingService-IP
define('S_SRV', 'xxxxxxxx\SQLEXPRESS'); // MSSQL server
define('S_UID', 'someuser'); // MSSQL username
define('S_PWD', '**********'); // MSSQL password
define('S_DBF', 'CHARACTER_01_DBF'); // MSSQL CHARACTER-table
?>
If u disagree with this post, let me know it. I'm not a leecher.. ;)PHP Code:<?php
include("config.php");
include("billing.api.php");
$billObj = billing_create_item(01, 0000001, 128, 1);
if(billing_send_item($billObj)) echo "success ;)";
else echo "error :(";
?>
But maybe you put this code-snippets in your main post.. ;)
But i've a little question: the socket command to provide the bill directly to the char is clear, but do you know if there is a command to remove an item from a char?
regards,
ZappeL
I got mssql functions running on PHP 5.3 as I developed and tested this using the PHP 5.3 API.
Yes, i on my linux machine it runs fine, but on winslow, i decided to use the M$ sql-functions.. because the php_mssql.dll is missing in the installers. If u re interested, here is the M$ link: MS-Downloadpage
Uhm, but the last question is still unanswerd.. ;) If there is a Command to remove items instantly (via socket) from the inventory..
Updated to 1.7.
New features:
- Mails the player the item if they are offline or if their inventory is full.
What exactly did you change in V1.7 so I could edit it manually in the api that I have already edited for my usage