Report post Posted June 26, 2017 (edited) Hello all, This is just a fun small project I've been working on to see how to get Discord webhooks working, nothing too serious and I kind of don't recommend using it on heavily populated servers. What does it do? It sends live notifications to your Discord when someone signs in - you can build off this and create bigger and better things. What do you need? - PHP 7 - CURL - Kitsune AS2/AS3 Preview How to add First you need to create a webhook on your Discord server. Go to your server settings, and then webhooks. Click on "Create Webhook" and enter a name for your bot and also select the channel you want it in, you can also add an avatar for it (webhook icon). Copy the webhook url and save it somewhere. Now we need to go to your source and go to /Kitsune/Kitsune/ClubPenguin/Login.php Find Quote public function __construct() { parent::__construct(); Logger::Fine("Login server is online"); } After it add the following Quote public function discordwebhook($content) { $curl = curl_init("REPLACE WITH YOUR DISCORD WEB HOOK LINK"); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_USERAGENT => 'Mozilla/5.0 (+https://flash.moe)', CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($content), ]); curl_exec($curl); } Where REPLACE WITH YOUR DISCORD WEB HOOK LINK is, add the webhook link. Now find Quote $penguin->send("%xt%l%-1%{$penguinData["ID"]}|{$penguinData["SWID"]}|{$penguinData["Username"]}|$encryptedPassword|1|45|2|false|true|$loginTime%$confirmationHash%$friendsKey%101,1%{$penguinData["Email"]}%"); After it add the following Quote print_r($this->discordwebhook(['embeds' => [ [ 'title' => 'CP Reborn Server', 'description' => $penguinData["Username"].' has signed into CP Reborn and is on the island', 'url' => 'https://play.clubpenguinreborn.pro/', 'timestamp' => gmdate("Y-m-d\TH:i:s.u\Z", strtotime("now")), ], ]])); You can now save this file and launch your server. It should work great and you should then see your bot put live notifications for when someone logins. Have some fun with it, you can do all types of things with this - let it be a starter to create bigger and better things with it. Thanks to @Jad for helping me fix a few errors with it, life saver. Edited June 26, 2017 by Jamie 2 Share this post Link to post Share on other sites
Report post Posted June 27, 2017 6 hours ago, Jamie said: Thanks to @Jad for helping me fix a few errors with it, life saver. I'm amazing, I know. 1 Share this post Link to post Share on other sites
Report post Posted June 27, 2017 Unfortunately, because curl_exec is a blocking call, your server will actually hang whenever a post is made to the Discord webhook API. I did this a few weeks ago, and even with two users online, the effect on performance was noticeable, and this could very easily be abused by creating bots which login to the server repeatedly. PHP is able to execute multiple curl requests at once, but there isn't a way (as far as I know), to carry on with your socket server loop before the requests are complete, not without using an extension which brings real multithreading to PHP, like pthreads. A nice idea, and it works, to a degree, don't use this if your server has many players. :) 1 Share this post Link to post Share on other sites
Report post Posted June 27, 2017 56 minutes ago, Ben said: Unfortunately, because curl_exec is a blocking call, your server will actually hang whenever a post is made to the Discord webhook API. I did this a few weeks ago, and even with two users online, the effect on performance was noticeable, and this could very easily be abused by creating bots which login to the server repeatedly. PHP is able to execute multiple curl requests at once, but there isn't a way (as far as I know), to carry on with your socket server loop before the requests are complete, not without using an extension which brings real multithreading to PHP, like pthreads. A nice idea, and it works, to a degree, don't use this if your server has many players. :) Tested this for several hours and effect on performance isn't' really noticeable at the moment, working on it even more, just a test for now - as I stated in thread it isn't wise to use this with many players. Share this post Link to post Share on other sites
Report post Posted June 29, 2017 On 6/27/2017 at 1:19 PM, Ben said: Unfortunately, because curl_exec is a blocking call, your server will actually hang whenever a post is made to the Discord webhook API. I did this a few weeks ago, and even with two users online, the effect on performance was noticeable, and this could very easily be abused by creating bots which login to the server repeatedly. PHP is able to execute multiple curl requests at once, but there isn't a way (as far as I know), to carry on with your socket server loop before the requests are complete, not without using an extension which brings real multithreading to PHP, like pthreads. A nice idea, and it works, to a degree, don't use this if your server has many players. :) Just wanted to say the same thing, whenever Discord's API would act up or have high latency, Club Penguin Rewritten would freeze up entirely. Use it for minor things. Share this post Link to post Share on other sites
Report post Posted June 29, 2017 It seems this library actually lets you carry out other work whilst a request is in progress, perhaps a solution? https://github.com/stil/curl-easy You could even make use of Kitsune's event timing system to get the response from Discord. 2 Share this post Link to post Share on other sites