Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: Doom_Kill3R on March 5th, 2019, 05:39 AM

Title: Discord
Post by: Doom_Kill3R on March 5th, 2019, 05:39 AM
This is a discord plugin that I've made just to practice myself over C++ and ofcourse since IRC is a dead meme at this point as well it was cool to have a nice VCMP server-discord communication system.

There is a Read Me file that has instructions and explains the config settings. I'll put the Read Me here as well for quick look:
Code: [Select]
IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

* Place libDDiscord64 inside your plugins folder

* Enlist libDDiscord64 in your Server.cfg

* WINDOWS USERS: Place libcurl.dll, LIBEAY32.dll, SSLEAY.dll, zlib1.dll and settings.json inside server directory
* LINUX USERS: Place settings.json inside server directory. If the plugin doesn't load, install SSL; apt-get install libssl-dev

-----------------------------------------------------------------------------------------------------------------------

* Plugin provided events:
- SQ_onDiscordConnect
- SQ_onDiscordServer
- SQ_onDiscordChannel
- SQ_onDiscordChannelMessage
- SQ_onDiscordQuit
- SQ_onDiscordDisconnect

* Plugin provided functions:
- Discord_SendMessage("Message")
- Discord_SendMesageToChannel(channel_id, "Message")
- Discord_SendMesageToChannelName("Channel-Name", "Message")
- Discord_SetStatus("New Status")

-----------------------------------------------------------------------------------------------------------------------

* Configure settings.json according to your needs, following is explanation for each setting:

- prefix :: The prefix to use for commands, ! means commands start with ! for example: !bot
- token :: This is your bot token
- status :: Sets the status of the bot. Which is the "Currently playing ..." message.

- specialNicks :: If a user has special symbols which VCMP does not support ingame on chat, should these users be allowed to send messages ingame?
- specialMessages :: If a user's message has symbols that VCMP chat does not support, should they be blocked?

- defaultMessages :: This plugin has the following events handled inside:
 -> onPlayerJoin
 -> onPlayerPart
 -> onPlayerDeath
 -> onPlayerKill
 -> onPlayerChat

if you want to manually handle these events with your own messages, you can set this to false and do it inside squirrel events.

- defaultCommands :: The plugin comes with a few built-in commands if this is true:
 -> !say - Sends a message from discord to server
 -> !players - Displays the list of players ingame

- channels :: This is an array of channel IDs the plugin will load and send messages to when global messages are sent.

"channels" : [channel_id]

-> channel_id is the id of the channel to load, you can enable Developer Mode on discord, and then right click on channels to get their ID and palce them here.

- Multiple channels can be simply listed by a comma separation:
"channels" : [channel_1_id, channel_2_id]

# Note :: Its fair to just use 1 main channel to send messages to instead of multiple channels at multiple servers to avoid request flood.

This plugin is not the best! I made this personally for myself for very basic tasks like just simply logging out basic player join/quits, chats and kill logs. It was never meant to be very advanced. However I will prefer this any day over the current methods people are using (mysql queries to simulate server messages back and forth, ew!)

This plugin can be as easy as just download, place, config json and you have most of the simple stuff already done and handled, but if you want, you can disable the in-built ones and just do them all yourself squirrel side, both ways can serve.



* IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

- Functions:
Code: [Select]
Discord_SendMessage("message"); // Sends a message to all the channels listed in settings.json
Discord_SendMessageToChannel(channel_id, "message"); // Send message to the specific channel
Discord_SetStatus("Status"); // Set Bot's game status

- Events:
Code: [Select]
SQ_onDiscordConnect(string jsonFormattedData)
SQ_onDiscordServer(string jsonFormattedData)
SQ_onDiscordChannel(string jsonFormattedData)
SQ_onDiscordChannelMessage(int serverID, int channelID, int userID, string userName, string message)
SQ_onDiscordQuit()
SQ_onDiscordDisconnect()

- A sample script that implements a custom SQ_onDiscordCommand function/event
Code: [Select]
function SQ_onDiscordChannelMessage(serverID, channelID, userID, userName, message) {
if(message.slice(0, 1) == "!") {
local noprefixMessage = message.slice(1, message.len());
local str = split(noprefixMessage, " ");
local command = str[0];
local msg = null;
if(str.len() > 1) {
msg = "";
for(local i = 1; i < str.len(); i++) {
msg += str[i];
if(i < str.len()-1)
msg += " ";
}
}
SQ_onDiscordCommand(serverID, channelID, userID, userName, command, msg);
}
}

function SQ_onDiscordCommand(serverID, channelID, userID, username, cmd, msg) {
if(cmd == "t")
Discord_SendMessageToChannel(channelID, "test works");
}



NOTE: Binaries will only be available for x64

- Windows:
(http://files.thijn.ovh/img/4261d65641abaa3ce020e30f5b38a9ba/libDDiscord64 Windows.zip)(http://files.thijn.ovh/download/4261d65641abaa3ce020e30f5b38a9ba/libDDiscord64 Windows.zip)

Install OpenSSL(https://slproweb.com/products/Win32OpenSSL.html) for Windows

- Linux:
(http://files.thijn.ovh/img/81b62a23ca3d403be13c1eada2080b67/libDDiscord64 Linux.zip)(http://files.thijn.ovh/download/81b62a23ca3d403be13c1eada2080b67/libDDiscord64 Linux.zip)

Install OpenSSL for Linux
Code: [Select]
sudo apt-get install libssl-dev


- @Kirollos - I learned how to handle squirrel vm and stacks from his RCON plugin
- @. (SLC) - Ofcourse this bad boy has to be everywhere, no surprise at all
- @Luckshya - Helped me in some API issues and used his CMake files to easily generate binaries for Linux
Title: Re: Discord
Post by: Mursaleen5544 on March 7th, 2019, 06:30 PM
Can yOu Make a Video tutorial for that please dude .. Understanding of this is dificult for those whom were waiting for this.
Title: Re: Discord
Post by: Doom_Kill3R on March 8th, 2019, 06:40 AM
You first have to get your bot connected to your server, you can google search and see how that is done afterwards you take the bot token and place it inside the settings.conf file, run the server and the bot should be getting online.
Title: Re: Discord
Post by: Mitasubiszi on March 8th, 2019, 11:24 AM
On linux

Code: [Select]
Plugin error >> dlopen() 'plugins/DDiscord64.so' failed: plugins/DDiscord64.so: only ET_DYN and ET_EXEC can be loaded

help
Title: Re: Discord
Post by: AroliS^ on March 8th, 2019, 10:48 PM
a simple guide for making the token and it show how to create a bot to run this plugin - https://github.com/Chikachi/DiscordIntegration/wiki/How-to-get-a-token-and-channel-ID-for-Discord
Title: Re: Discord
Post by: DarkRaZoR^ on March 12th, 2019, 01:42 AM
Doom_Kill3R, excellent work. :)
Would be great if it can output a message to Discord that the bot disconnected.
Title: Re: Discord
Post by: Doom_Kill3R on March 12th, 2019, 05:42 AM
Hi DarkRazor, I'm working on a better plugin over sleepy-discord library (Because before I had issues getting it to compile but now those are fixed) so I'll probably get that plugin to have more events and functionalities, gotta wait abit though ;)
Title: Re: Discord
Post by: DarkRaZoR^ on March 13th, 2019, 04:26 PM
Quote from Doom_Kill3R on March 12th, 05:42 AM
Hi DarkRazor, I'm working on a better plugin over sleepy-discord library (Because before I had issues getting it to compile but now those are fixed) so I'll probably get that plugin to have more events and functionalities, gotta wait abit though ;)
Thanks man, you're the best! :)
Title: Re: Discord
Post by: Doom_Kill3R on March 14th, 2019, 06:21 PM

Binaries updated on first post, new sample script also updated.
Special thanks to @Luckshya for a great helping hand, first post credits for more information.
Title: Re: Discord
Post by: DarkRaZoR^ on March 14th, 2019, 08:13 PM
@Doom_Kill3R , what's the OpenSLL for?
Title: Re: Discord
Post by: Doom_Kill3R on March 15th, 2019, 04:56 AM
It is used for network communication
Title: Re: Discord
Post by: Mursaleen Qureshi on March 22nd, 2019, 02:07 AM
Can you make this For 32bit servers too ?
Title: Re: Discord
Post by: Athanatos on March 22nd, 2019, 05:30 PM
Quote from Mursaleen Qureshi on March 22nd, 02:07 AM
Can you make this For 32bit servers too ?
Stop using ancient hardware.
Title: Re: Discord
Post by: Doom_Kill3R on March 23rd, 2019, 05:37 AM

Updated binaries download on first post.
Title: Re: Discord
Post by: Athanatos on April 23rd, 2019, 09:24 PM
I gotta say, great work dude!
Title: Re: Discord
Post by: Athanatos on May 3rd, 2019, 04:31 PM
Guess what, I need the 32 bit version for a VPS my friend has :/
Title: Re: Discord
Post by: dracc on May 3rd, 2019, 07:56 PM
Quote from Athanatos on March 22nd, 05:30 PM
Quote from Athanatos on May 3rd, 04:31 PM
Guess what, I need the 32 bit version for a VPS my friend has :/
Stop using ancient hardware.
*Mic drop*
Title: Re: Discord
Post by: Markhoz on July 4th, 2019, 03:30 AM
Do you think it would be possible for them to also make 32bit versions?