Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: DizzasTeR on Mar 05, 2019, 05:39 AM

Title: Discord
Post by: DizzasTeR on Mar 05, 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:
IMPORTANT NOTE: Its significantly better to load the Discord plugin first in the plugin list, even before squirrel plugin

* Place DDiscord.dll inside your plugins folder
* Place all DLLs in the dll zip file next to server.exe
* Place settings.json next to server.exe and configure as needed
* Enlist DDiscord in your server.cfg

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

* Plugin provided events:
- SQ_onDiscordConnect
- SQ_onDiscordServer
- 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?

- defaultMode :: Toggles defaultMessages, defaultCommands and whether squirrel events are triggered or not.

- 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 defaultMode to false and do it inside squirrel events.

- defaultCommands :: The plugin comes with a few built-in commands if defaultMode is ON:
 -> !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.


- Functions:
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_SendMessageToChannelName("my-channel", "my message"); // Send message to all channels matching this name
Discord_SetStatus("Status"); // Set Bot's game status

- Events:
SQ_onDiscordConnect(string jsonFormattedData)
SQ_onDiscordServer(string jsonFormattedData)
SQ_onDiscordChannelMessage(int serverID, int channelID, int userID, string userName, string message)
SQ_onMemberEdit(string jsonFormattedData, string emptyStringForCompatibility)
SQ_onDiscordQuit()
SQ_onDiscordDisconnect()

- A sample script that implements a custom SQ_onDiscordCommand function/event
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");
}


https://github.com/DizzasTeR/sleepy-discord-vcmp-client/releases

* Do read the release notes to be aware of any important changes to the plugin!

Install OpenSSL for Linux
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: DizzasTeR on Mar 08, 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 Mar 08, 2019, 11:24 AM
On linux

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 Mar 08, 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: D4rkR420R on Mar 12, 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: DizzasTeR on Mar 12, 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: D4rkR420R on Mar 13, 2019, 04:26 PM
Quote from: Doom_Kill3R on Mar 12, 2019, 05:42 AMHi 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: DizzasTeR on Mar 14, 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: D4rkR420R on Mar 14, 2019, 08:13 PM
@Doom_Kill3R , what's the OpenSLL for?
Title: Re: Discord
Post by: DizzasTeR on Mar 15, 2019, 04:56 AM
It is used for network communication
Title: Re: Discord
Post by: Mursaleen Qureshi on Mar 22, 2019, 02:07 AM
Can you make this For 32bit servers too ?
Title: Re: Discord
Post by: NicusorN5 on Mar 22, 2019, 05:30 PM
Quote from: Mursaleen Qureshi on Mar 22, 2019, 02:07 AMCan you make this For 32bit servers too ?
Stop using ancient hardware.
Title: Re: Discord
Post by: DizzasTeR on Mar 23, 2019, 05:37 AM

Updated binaries download on first post.
Title: Re: Discord
Post by: NicusorN5 on Apr 23, 2019, 08:24 PM
I gotta say, great work dude!
Title: Re: Discord
Post by: NicusorN5 on May 03, 2019, 03:31 PM
Guess what, I need the 32 bit version for a VPS my friend has :/
Title: Re: Discord
Post by: dracc on May 03, 2019, 06:56 PM
Quote from: Athanatos on Mar 22, 2019, 05:30 PM
Quote from: Athanatos on May 03, 2019, 03:31 PMGuess what, I need the 32 bit version for a VPS my friend has :/
Stop using ancient hardware.

*Mic drop*
Title: Re: Discord
Post by: !RELOADED¡ on Jul 04, 2019, 02:30 AM
Do you think it would be possible for them to also make 32bit versions?
Title: Re: Discord
Post by: Alecu Madalin on Sep 22, 2019, 04:28 PM
help

(https://i.imgur.com/hnnAmpu.png)
Title: Re: Discord
Post by: DizzasTeR on Sep 22, 2019, 05:17 PM
This plugin only works for x64, make sure you are not running it on x32/x86
Title: Re: Discord
Post by: Alecu Madalin on Sep 22, 2019, 05:53 PM
Quote from: Doom_Kill3R on Sep 22, 2019, 05:17 PMThis plugin only works for x64, make sure you are not running it on x32/x86

mine is x64

nvm im retarded
i placed libcurl.dll, LIBEAY32.dll, SSLEAY32.dll, SSLEAY32.dll and settings.json into the root and works now

(https://i.imgur.com/x1fUz89.png)
Title: Re: Discord
Post by: D4rkR420R on Dec 15, 2019, 07:06 PM
[2019-12-15 12:18:20] [connect] WebSocket Connection 162.159.135.234:443 v-2 "WebSocket++/0.8.1" /?v=6 101
[2019-12-15 12:18:26] [error] handle_read_frame error: asio.ssl:335544539 (short read)
[2019-12-15 12:18:26] [info] asio async_shutdown error: asio.ssl:335544539 (short read)
Close 4000 Unknown error.
Error 4000: unknown error - We're not sure what went wrong. Try reconnecting?
[2019-12-15 12:18:26] [disconnect] Disconnect close local:[1006,short read] remote:[4000,Unknown error.]
[2019-12-15 12:18:26] [connect] Successful connection
[2019-12-15 12:18:26] [connect] WebSocket Connection 162.159.135.234:443 v-2 "WebSocket++/0.8.1" /?v=6 101

The bot seems to lag, not only the bot itself but the server, after frequent messages sending back and forth. Any clue? This error triggers when I launch the server terminal using a batch file (which opens up if the server terminal closes)
Title: Re: Discord
Post by: DizzasTeR on Dec 17, 2019, 02:23 PM
This is an API related thing after alot of messages are sent, could either be discord sided or the library itself however a workaround as told by Luckshya on discord is to send multiple messages concatenated via \n in intervals rather than individually to reduce the chances of this happening.
Title: Re: Discord
Post by: Razor. on Apr 21, 2020, 01:15 AM
@DizzasTeR, this plugin can work in Linux CentOS?

Plugin error >> dlopen() 'plugins/libDDiscord64.so' failed: libssl.so.1.1: cannot open shared object file: No such file or directory

Failed to load plugin: libDDiscord64

Used:
apt-get install libssl-dev
Title: Re: Discord
Post by: DizzasTeR on Apr 21, 2020, 06:56 AM
Should work, it seems to not be able to find libssl 1.1, check if you have a newer/older version and try to get the 1.1 version if possible then try again
Title: Re: Discord
Post by: DizzasTeR on May 10, 2020, 06:44 PM
Released v1.1


Empty settings.json file attached (Thanks Xmair) with the post.

Binaries download link in first post.

I would still recommend using Luckshya's plugin if you are going to do some serious work with the discord bot, but if you just want a normal casual bot, that logs out player join/quits/chats, then yeah this can do the job.
Title: Re: Discord
Post by: DizzasTeR on Aug 07, 2022, 09:57 AM
Released v2.0

Both x64 and x86 builds are available for download at:

https://github.com/DizzasTeR/discord-vcmp-client/releases/tag/v2.0

Linux build will eventually get added but it should be fairly easy to build the plugin on linux

Changes:

Again, the purpose of this plugin is just to have echo like we used to in IRC days, I can add more events or simple functions if very severely requested but that is about it.

Please note that now you have to copy and paste DLLs into your server directory on windows when using this plugin, they are provided at GitHub release page
Title: Re: Discord
Post by: Pun1sh3r on Oct 05, 2022, 06:19 PM
Works perfect on Windows, wanted to compile the Plugin on Linux but I get this error back:

QuoteScanning dependencies of target DDiscord
[ 50%] Building CXX object bot/CMakeFiles/DDiscord.dir/discord-client.cpp.o
[100%] Linking CXX shared library libDDiscord.so
/usr/bin/ld: cannot find -ldpp32.lib
collect2: error: ld returned 1 exit status
make[2]: *** [bot/CMakeFiles/DDiscord.dir/build.make:103: bot/libDDiscord.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:113: bot/CMakeFiles/DDiscord.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

Would be nice if you can compile it for Linux or help with the Problem?
Title: Re: Discord
Post by: DizzasTeR on Oct 07, 2022, 12:43 PM
Quote from: Pun1sh3r on Oct 05, 2022, 06:19 PMWould be nice if you can compile it for Linux or help with the Problem?

Have you cloned the plugin repository recursively? Because it has DPP as a submodule added to it, so cmake will build DPP for you hence you shouldn't be getting the link error. If you still cannot figure it out you could also get pre-build dpp linux binaries from here (https://github.com/brainboxdotcc/DPP/releases) and look into that.

If you still cannot figure it out, you'll have to wait for weekend and hopefully I can look into it or provide you with linux binaries