PHP–based Neverwinter gateway bot — daemon service to get data from Neverwinter gateway.
Taking companions using nwogatewaybot:
$StickerBook = $gateway-> get('Client_RequestStickerBook', array(
'id' => 'Companion',
'params' => array(),
), 'Proxy_StickerBook');- PHP at
/usr/bin/php - crontab*
- Gmail account at
@gmail.com - Neverwinter account at
@gmail.com
* crontab is recommended to copying tasks, but can be eventually replaced.
Pull the following files into their responding directories:
/etc/init.d/nwogatewaybotbash init script/usr/bin/nwogatewaybot/Curl.phpphp-curl-classsrc/Curl/Curl.php3.4.4 used tosocket.iomore friendly/usr/bin/nwogatewaybot/gateway.cckcookie file/usr/bin/nwogatewaybot/gateway.cfgconfig file/usr/bin/nwogatewaybot/gateway.phpgatewayclass — bot engine/usr/bin/nwogatewaybot/nwogatewaybot.phpbot daemon/usr/bin/nwogatewaybot/tasksfolder tasks container/var/log/nwogatewaybot/loglog file/var/log/nwogatewaybot/errorerror log file
edit /usr/bin/nwogatewaybot/gateway.cfg configuration file.
service nwogatewaybot start|stop|restartstart|stop|restart the nwogatewaybotservice nwogatewaybot statusshow if bot is running and how many tasks are in queueservice nwogatewaybot clearclear all tasks
- Bot itself works as a daemon run from
/etc/init.d/nwogatewaybot, with/var/run/nwogatewaybot.pidpid, as a/usr/bin/nwogatewaybot/nwogatewaybot.php. - Bot uses
/usr/bin/nwogatewaybot/gateway.phpclass and initializessocket.ioconnection with gateway address from/usr/bin/nwogatewaybot/gateway.cfg$nwo_addressat$nwo_character@$nwo_accountaccount using$nwo_passwordpassword. - If Account Guard asks for a pin, login to
$gmail_login@gmail.comoccurs with$gmail_passwordpassword to the{imap.gmail.com:993/imap/ssl}INBOXimap and pin is automatically red and submitted. - Finally, bot loops, refreshing connection every 20 seconds and sending
Client_Heartbeatevery 60s to keepsocket.ioconnection up. Every second, all/usr/bin/nwogatewaybot/tasks/*tasks are executed if correct, and then always deleted, even if broken.
Tasks should be made every rational time interval. It is strongly recommended not to execute tasks too often and copy task files from crontab.
Let's assume our tasks source directory is /home/nwostatus.
Task files will be named *.task.php to differ them easy from other php files.
Let's make a /home/nwostatus/foo.task.php file.
To crontab the task, cp /path/to/source/TASKNAME.task.php to the /usr/bin/nwogatewaybot/tasks, renaming the task to the ddd-taskname where ddd is a prioroty number and taskname is a name of task.
The lower ddd number, the higher prioroty, because tasks are executed ASCII alphabetically.
It is strongly recommended to follow the ddd-taskname markup and to use the priority reasonably.
Ex. important, weekly task should remain low numbered (like 001-weekly or so), dailies should remain about 100+, hourlies 300+ and minuties 600+. It is also recommended not to overwrite any task until its done.
Example for foo.task.php being executed 27 minutes past every hour with a 950 priority:
27 * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/foo.task.php ] || cp /home/nwostatus/foo.task.php tasks/950-foo)
It is recommended to edit crontab using crontab -e.
Let's check if the file is executed internally, we don't wont any additional user–side task requests, only the crontab ones.
<?php
if(!defined('STDIN')){
die();
}Let's add information about when the last update was made to the upcomming HTML cache file:
$O = '<h5 class="text-muted text-left">Update: <span class=text-info>__UPDATE__</span></h5>';Now, we will need a Client_REQUESTID that is made in the socket.io, we can track it using browser network console.
Ex. Entering
http://gateway.playneverwinter.com/#char(name@account)/exchange-sellzen
we shall see the
5:::{"name":"Client_RequestExchangeAccountData","args":[{"id":"ACCOUNTID","params":{}}]}
request payload, where ACCOUNTID is an account id.
With the following response:
5:::{name: "Proxy_ExchangeAccountData", args: [{id: "ACCOUNTID",…}]}
Let's expand it:
args
0
container
forsaleescrow
globaldata
buyprices
0
price: 500
quantity: 4180126
1
2
3
4
enabled: 1
maxmtcprice: 500
maxplayeropenorders: 5
maxquantityperorder: 5000
minmtcprice: 50
minquantityperorder: 1
sellprices: []
logentries
openorders
readytoclaimescrow
readytoclaimmtc
id: "ACCOUNTID"
status: "online"
name: "Proxy_ExchangeAccountData"
In this case, Client_REQUESTID is a Client_RequestExchangeAccountData, SUBREQID is an account id and Proxy_RESPONSEID is a Proxy_ExchangeAccountData.
Then, we add the following bot request:
$data = $gateway-> get('Client_REQUESTID', array(
'id' => 'SUBREQID',
'params' => array(),
), 'Proxy_RESPONSEID');In our case, this will be a
$data = $gateway-> get('Client_RequestExchangeAccountData', array(
'id' => 'ACCOUNTID',
'params' => array(),
), 'Proxy_ExchangeAccountData');And thus, $data->container->globaldata->buyprices will contain the full list of exchange: sell ZEN data.
And zeroth entry's price will contain current ZEN buy price and its quantity contains the amount of ZEN to buy in queue.
This said, we add the following code to our task file:
foreach($data->container->globaldata->buyprices as $buyrecords_id => $buyrecords){
$O .= 'ZEN buy price: ' .$buyrecords->price .'<br>';
$O .= 'Quantity: ' .$buyrecords->quantity .'<br>';
break;
}Finally, we replace the header update time with current time:
$O = str_replace('__UPDATE__', date('d.m.Y H:i'), $O);and save the cache file to a chosen path:
file_put_contents('/path/to/file.cch', $O);
?>That's all.
Full example foo.task.php file:
<?php
if(!defined('STDIN')){
die();
}
$O = '<h5 class="text-muted text-left">Update: <span class=text-info>__UPDATE__</span></h5>';
$data = $gateway-> get('Client_RequestExchangeAccountData', array(
'id' => 'ACCOUNTID',
'params' => array(),
), 'Proxy_ExchangeAccountData');
foreach($data->container->globaldata->buyprices as $buyrecords_id => $buyrecords){
$O .= 'ZEN buy price: ' .$buyrecords->price .'<br>';
$O .= 'Quantity: ' .$buyrecords->quantity .'<br>';
break;
}
$O = str_replace('__UPDATE__', date('d.m.Y H:i'), $O);
file_put_contents('/path/to/file.cch', $O);
?>To show the ZAX info, just simply:
echo file_get_contents('/path/to/file.cch');in another PHP, stable file.
All examples are assumed to be placed in /home/nwostatus.
If you wish to pull them, remember to change all /home/nwostatus paths to your real ones.
Creates simple table that shows guild members online.
- Change
GUILDNAMEto your guild name in line 27 of Guild_status.task.php - Change
/home/nwostatusto your real path in line 64 of Guild_status.task.php - Add task to crontab, changing
/home/nwostatusto your real path:
* * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/Guild_status.task.php ] || cp /home/nwostatus/Guild_status.task.php tasks/611-Guild_status)Show the full information site about guild.
- Change
GUILDNAMEto your guild name in line 92 of Guild_status.task.php - Change
/home/nwostatusto your real path in line 384 of Guild_status.task.php - Add task to crontab, changing
/home/nwostatusto your real path:
*/2 * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/Guild_members.task.php ] || cp /home/nwostatus/Guild_members.task.php tasks/601-Guild_members)Advanced example.
Info.php includes three task caches:
Info_companions.cchInfo_enchants.cchInfo_zenshop.cch
Info_companions.task.php collects information about companions from collections. Then shows it in a simple table.
Info_enchants.task.php collects information about available enchantments and runestones, finally showing it in the correspondending tabs.
Info_zenshop.task.php collects information about products in Zen Shop, making a grid–like rich presentation of available products.
All those tasks makes a subrequests to get the tooltips for their items.
Tooltips are saved inside /home/nwostatus/tooltip folder with their corresponding key name.
All tooltips are also cached to lower the request quantity.
- Change all occurencies of
/home/nwostatusto your real path in all above listed files. - Add task to crontab, changing
/home/nwostatusto your real path:
17 * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/Info_companions.task.php ] || cp /home/nwostatus/Info_companions.task.php tasks/271-Info_companions)
27 * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/Info_enchants.task.php ] || cp /home/nwostatus/Info_enchants.task.php tasks/272-Info_enchants)
37 * * * * cd /usr/bin/nwogatewaybot && ([ -e tasks/Info_zenshop.task.php ] || cp /home/nwostatus/Info_zenshop.task.php tasks/273-Info_zenshop)Note that you can simply replace the header resources that corresponds to my current hopepage: //Benio.me.
However, it is important to attach /home/nwostatus/tooltip.js file to the final Info.php so tooltips can be showed correctly.
Task files are syntax checked before execution. Disable syntax checking if neccesary.
Task files are eval('?>' .file_get_contents($task))ed to make the daemon running even if task crashed upon executing. To enable deep debugging, change eval to include.
If some task lasts infinitelly:
service nwogatewaybot stopservice nwogatewaybot clearto clear the tasks (including the corrupted one)- fix the task, eventually manually copying them to execute immediately after bot starts
service nwogatewaybot start
Trace your log files:
/var/log/nwogatewaybot/log
/var/log/nwogatewaybot/error
See if everything works fine.
CURLOPT_SSLVERSION used to get changed a several times already (SSL issues).
Enable V3 if, and only if necessary.
After some maintenances, removing cookie cache will be necessary. Type simple:
cat <<< "" > /usr/bin/nwogatewaybot/gateway.cck
service nwogatewaybot restart









