Skip to content

Commit

Permalink
DISCORD: added discord support
Browse files Browse the repository at this point in the history
this allows us to publish messages to discord if the cvar discord_webhook_url is set properly

this can be done async or sync

currently only a message is sent when a new user connects to the server - and on map finish
but maybe we want other messages to be sent on frags or round ends with the winner

some performance checks should maybe also be done with the easy interface of curl vs the
multi interface of curl for the async requests

a new automated tests framework was added, too

the discord requests are made with a more general http request interface and could get used
for other stuff, too.
  • Loading branch information
mgerhardy committed Oct 28, 2023
1 parent 068af69 commit 9160d8a
Show file tree
Hide file tree
Showing 31 changed files with 1,107 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ profile
*.dylib

/wop.*
/woptest*
/wopded.*
/libSDL2*
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Version: 1.7.0 (tba.)

- ADDED
- 32bit binaries to support Windows and Linux systems
- Discord webhook support for dedicated servers. discord_webhook_url cvar should get set to a webhook url like https://discord.com/api/webhooks/xxx/yyy (can be done by exporting an env var called WOP_DISCORD_WEBHOOK_URL due to the // in the url)
- 32bit binaries to support Windows and Linux systems
- Freeze Tag (FT) game mode and related assets like ice cold weapon effects
- Catch the Killerduck (CTKD) game mode
- PElvis (PadElvis) skin, glow skin and bot for the PADMAN player model
Expand All @@ -30,8 +31,8 @@
- Option to enable/disable Limit Frame Rate to Display page of System menu to limit the frame rate when game window is minimized or out of focus
- Option to select Screenshot Format (TGA, JPG, PNG) to Display page of System menu, PNG is default
- Option to select Screenshot Quality, only when JPG format is selected to Display page of System menu
- Option to select magenta-green anaglyph 3D mode from the list in Display page of System menu
- Option to enable/disable Swap Colors to Display page of System menu to swap colors of anaglyph 3D modes
- Option to select magenta-green anaglyph 3D mode from the list in Display page of System menu
- Option to enable/disable Swap Colors to Display page of System menu to swap colors of anaglyph 3D modes
- Option to enable/disable Doppler Effect to Sound page of System menu
- Option to enable/disable Auto Mute to Sound page of System menu to mute the sound when game window is minimized or out of focus
- Options to select sound Output and Input Devices to Sound page of System menu
Expand Down Expand Up @@ -79,11 +80,11 @@
- Title of the game uniformly to `World of PADMAN` everywhere
- Location of assets where useful (folder and filing cleanup)
- Pad-Anthem credits song moved to music folder (credits.ogg)
- Map selection/preview to cycle three ingame pictures via shader animation
- Map selection/preview to cycle three ingame pictures via shader animation
- Graphics Settings option on Graphics page of System menu to provide a template list with useful and updated settings
- Geometric Detail option in Graphics menu to be split into Curves Detail and Models Detail to be able to set `r_subdivisions [20|12|4|2]` in 4 steps now (new default is 4)
- Anisotropy option to be merged with Texture Filter option into a single menu entry on Graphics page of System menu
- Name of Fullscreen option on Graphics page of Setup menu to Window Mode, also supporting new borderless window mode and moved to Display page of System menu
- Name of Fullscreen option on Graphics page of Setup menu to Window Mode, also supporting new borderless window mode and moved to Display page of System menu
- Anaglyph 3D modes on Display page of System menu to list the modes 1 to 4, modes 5 to 8 are enabled by enabling the new Color Swap option
- Name of Network page of System menu to Net/VoIP and moved all VoIP related options from Sound page of System menu to Net/VoIP
- Net/VoIP and Sound options to hide not necessary options depending on selected VoIP Support or Sound System (instead of showing them greyed)
Expand All @@ -102,7 +103,7 @@
- Headline of Team ingame menu changed to Start like listed in ingame main menu
- Headline of Voice ingame menu changed to Voice Chat like listed in ingame main menu
- Default keyboard mapping in a few spots: `Q`/`MOUSE3` for gesture (was undefined); `E`/`ENTER` for use item; `F`/`BACKSPACE` for drop item (cartridge/lolly); `HOME`/`KP5` for 3rd person view (was `U`); `X`/`MOUSE2` for scope/zoom (was `MOUSE3`); `Y`/`Z` for chat team (was undefined); `U` chat target (was undefined); `I` for chat attacker (was undefined); `F12` for taking a screenshot (was `F11`).
- Dynamic flares to be enabled by default `r_flares [1|0]`
- Dynamic flares to be enabled by default `r_flares [1|0]`
- Team names to Blue Noses and Red Pads everywhere in the game
- Scoreboard to show personal scores in team based games again
- Game type list in Create menu to list FFA game types first and FFA being default (was SYC)
Expand Down Expand Up @@ -475,7 +476,7 @@
- Maps: All old maps overhauled
- Menu: Start menu Sigle and Multi replaced by Create and Join
- Menu: All levelshots overhauled and resized
- Menu: Menu background pictures overhauled
- Menu: Menu background pictures overhauled
- Menu: Bot menu, only default bots selectable, additional selection of default/red/blue in list
- Menu: Game options menu expanded
- Menu: New game play hints while the loading screen is shown
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(DEFAULT_BASEDIR "" "")
option(BUILD_CLIENT "" ON)
option(BUILD_SERVER "" ON)
option(BUILD_TESTS "" ON)
option(BUILD_RENDERER_OPENGL2 "" ON)
option(BUILD_RENDERER_VULKAN "" OFF)

Expand Down
5 changes: 4 additions & 1 deletion code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function(add_asm TARGET)
enable_language(ASM_MASM)
set(ASM_SRCS)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND ASM_SRCS ${CODE_DIR}/asm/vm_x86_64.asm)
list(APPEND ASM_SRCS ${CODE_DIR}/asm/vm_x86_64.asm)
endif()
list(APPEND ASM_SRCS ${CODE_DIR}/asm/snapvector.asm ${CODE_DIR}/asm/ftola.asm)
foreach(_file ${ASM_SRCS})
Expand Down Expand Up @@ -329,3 +329,6 @@ endif()
if (BUILD_SERVER)
add_subdirectory(server)
endif()
if (BUILD_TESTS AND UNIX)
add_subdirectory(tests)
endif()
6 changes: 4 additions & 2 deletions code/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ set(SRCS
../server/sv_bot.c
../server/sv_ccmds.c
../server/sv_client.c
../server/sv_discord.c
../server/sv_http.c
../server/sv_game.c
../server/sv_init.c
../server/sv_main.c
Expand Down Expand Up @@ -90,9 +92,9 @@ endif()
add_botlib(${PROJECT_NAME})
add_dependencies(${PROJECT_NAME} cgame qagame ui ${RENDERER_LIST})
set(CLIENT_DEFINES)
set(LIBS opusfile opus vorbis theora zlib openal SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS})
set(LIBS curl opusfile opus vorbis theora zlib openal SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS})
if (MSVC)
list(APPEND LIBS ws2_32 winmm psapi gdi32 ole32)
list(APPEND LIBS ws2_32 winmm psapi gdi32 ole32 winhttp)
elseif (APPLE)
set(FRAMEWORKS Cocoa Security IOKit)
foreach (_framework ${FRAMEWORKS})
Expand Down
42 changes: 42 additions & 0 deletions code/client/cl_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef USE_CURL
#include "client.h"

#ifdef USE_CURL_DLOPEN
extern char *(*qcurl_version)(void);

extern CURL *(*qcurl_easy_init)(void);
extern CURLcode (*qcurl_easy_setopt)(CURL *curl, CURLoption option, ...);
extern CURLcode (*qcurl_easy_perform)(CURL *curl);
extern void (*qcurl_easy_cleanup)(CURL *curl);
extern CURLcode (*qcurl_easy_getinfo)(CURL *curl, CURLINFO info, ...);
extern void (*qcurl_easy_reset)(CURL *curl);
extern const char *(*qcurl_easy_strerror)(CURLcode);

extern CURLM *(*qcurl_multi_init)(void);
extern CURLMcode (*qcurl_multi_add_handle)(CURLM *multi_handle, CURL *curl_handle);
extern CURLMcode (*qcurl_multi_remove_handle)(CURLM *multi_handle, CURL *curl_handle);
extern CURLMcode (*qcurl_multi_fdset)(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set,
fd_set *exc_fd_set, int *max_fd);
extern CURLMcode (*qcurl_multi_perform)(CURLM *multi_handle, int *running_handles);
extern CURLMcode (*qcurl_multi_cleanup)(CURLM *multi_handle);
extern CURLMsg *(*qcurl_multi_info_read)(CURLM *multi_handle, int *msgs_in_queue);
extern const char *(*qcurl_multi_strerror)(CURLMcode);
#else
#define qcurl_version curl_version

#define qcurl_easy_init curl_easy_init
#define qcurl_easy_setopt curl_easy_setopt
#define qcurl_easy_perform curl_easy_perform
#define qcurl_easy_cleanup curl_easy_cleanup
#define qcurl_easy_getinfo curl_easy_getinfo
#define qcurl_easy_duphandle curl_easy_duphandle
#define qcurl_easy_reset curl_easy_reset
#define qcurl_easy_strerror curl_easy_strerror

#define qcurl_multi_init curl_multi_init
#define qcurl_multi_add_handle curl_multi_add_handle
#define qcurl_multi_remove_handle curl_multi_remove_handle
#define qcurl_multi_fdset curl_multi_fdset
#define qcurl_multi_perform curl_multi_perform
#define qcurl_multi_cleanup curl_multi_cleanup
#define qcurl_multi_info_read curl_multi_info_read
#define qcurl_multi_strerror curl_multi_strerror
#endif

#ifdef USE_CURL_DLOPEN
#include "../sys/sys_loadlib.h"

Expand Down
40 changes: 0 additions & 40 deletions code/client/cl_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,46 +44,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#endif

extern cvar_t *cl_cURLLib;

extern char *(*qcurl_version)(void);

extern CURL *(*qcurl_easy_init)(void);
extern CURLcode (*qcurl_easy_setopt)(CURL *curl, CURLoption option, ...);
extern CURLcode (*qcurl_easy_perform)(CURL *curl);
extern void (*qcurl_easy_cleanup)(CURL *curl);
extern CURLcode (*qcurl_easy_getinfo)(CURL *curl, CURLINFO info, ...);
extern void (*qcurl_easy_reset)(CURL *curl);
extern const char *(*qcurl_easy_strerror)(CURLcode);

extern CURLM *(*qcurl_multi_init)(void);
extern CURLMcode (*qcurl_multi_add_handle)(CURLM *multi_handle, CURL *curl_handle);
extern CURLMcode (*qcurl_multi_remove_handle)(CURLM *multi_handle, CURL *curl_handle);
extern CURLMcode (*qcurl_multi_fdset)(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set,
fd_set *exc_fd_set, int *max_fd);
extern CURLMcode (*qcurl_multi_perform)(CURLM *multi_handle, int *running_handles);
extern CURLMcode (*qcurl_multi_cleanup)(CURLM *multi_handle);
extern CURLMsg *(*qcurl_multi_info_read)(CURLM *multi_handle, int *msgs_in_queue);
extern const char *(*qcurl_multi_strerror)(CURLMcode);
#else
#define qcurl_version curl_version

#define qcurl_easy_init curl_easy_init
#define qcurl_easy_setopt curl_easy_setopt
#define qcurl_easy_perform curl_easy_perform
#define qcurl_easy_cleanup curl_easy_cleanup
#define qcurl_easy_getinfo curl_easy_getinfo
#define qcurl_easy_duphandle curl_easy_duphandle
#define qcurl_easy_reset curl_easy_reset
#define qcurl_easy_strerror curl_easy_strerror

#define qcurl_multi_init curl_multi_init
#define qcurl_multi_add_handle curl_multi_add_handle
#define qcurl_multi_remove_handle curl_multi_remove_handle
#define qcurl_multi_fdset curl_multi_fdset
#define qcurl_multi_perform curl_multi_perform
#define qcurl_multi_cleanup curl_multi_cleanup
#define qcurl_multi_info_read curl_multi_info_read
#define qcurl_multi_strerror curl_multi_strerror
#endif

qboolean CL_cURL_Init(void);
Expand Down
4 changes: 3 additions & 1 deletion code/game/g_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ to the server machine, but qfalse on map changes and tournement
restarts.
============
*/
char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {
const char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {
const char *value;
// const char *areabits;
gclient_t *client;
Expand Down Expand Up @@ -954,6 +954,8 @@ char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {
if (!G_BotConnect(clientNum, !firstTime)) {
return "BotConnectfailed";
}
} else if (firstTime) {
trap_GlobalMessage(Info_ValueForKey(userinfo, "name"), "Joined the server");
}

// get and distribute relevant parameters
Expand Down
4 changes: 3 additions & 1 deletion code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ void QDECL G_Error(const char *fmt, ...) __attribute__((noreturn, format(printf,
//
// g_client.c
//
char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot);
const char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot);
void ClientUserinfoChanged(int clientNum);
void ClientDisconnect(int clientNum);
void ClientBegin(int clientNum);
Expand Down Expand Up @@ -952,6 +952,8 @@ extern vmCvar_t g_modInstagib_WeaponJump;

extern vmCvar_t g_logDamage;

// allows you to send messages to discord
void trap_GlobalMessage(const char *user, const char *msg);
void trap_Print(const char *fmt);
void trap_Error(const char *fmt) Q_NORETURN;
int trap_Milliseconds(void);
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ void LogExit(const char *string) {
}

G_LogPrintf("Score: %i %i\n", level.sortedClients[i], cl->ps.persistant[PERS_SCORE]);
trap_GlobalMessage(cl->pers.netname, va("Score: %i", cl->ps.persistant[PERS_SCORE]));
}
}

Expand Down Expand Up @@ -1682,7 +1683,6 @@ static void CheckTournament(void) {
}

if (g_gametype.integer == GT_TOURNAMENT) {

// pull in a spectator if needed
if (level.numPlayingClients < 2) {
AddTournamentPlayer();
Expand Down
2 changes: 2 additions & 0 deletions code/game/g_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ typedef enum {
// 1.32
G_FS_SEEK,

G_GLOBALMESSAGE, // (const char *user, const char *msg)

BOTLIB_SETUP = 200, // ( void );
BOTLIB_SHUTDOWN, // ( void );
BOTLIB_LIBVAR_SET,
Expand Down
3 changes: 2 additions & 1 deletion code/game/g_syscalls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ equ trap_SnapVector -43
equ trap_TraceCapsule -44
equ trap_EntityContactCapsule -45
equ trap_FS_Seek -46
equ trap_GlobalMessage -47

equ memset -101
equ memcpy -102
Expand Down Expand Up @@ -223,4 +224,4 @@ equ trap_BotLibFreeSource -580
equ trap_BotLibReadToken -581
equ trap_BotLibSourceFileAndLine -582
equ trap_AAS_BestReachableArea -583

4 changes: 4 additions & 0 deletions code/game/g_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static int PASSFLOAT(float x) {
return *(int *)&floatTemp;
}

void trap_GlobalMessage(const char *user, const char *msg) {
syscall(G_GLOBALMESSAGE, user, msg);
}

void trap_Print(const char *text) {
syscall(G_PRINT, text);
}
Expand Down
4 changes: 4 additions & 0 deletions code/null/null_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void Sys_SigHandler(int signal) {
exit(signal);
}

const char *Sys_DefaultAppPath(void) {
return "";
}

const char *Sys_DefaultInstallPath(void) {
return ".";
}
Expand Down
4 changes: 4 additions & 0 deletions code/qcommon/net_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ typedef int socklen_t;
typedef unsigned short sa_family_t;
#endif

#undef EAGAIN
#define EAGAIN WSAEWOULDBLOCK
#undef EADDRNOTAVAIL
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#undef EAFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#undef ECONNRESET
#define ECONNRESET WSAECONNRESET
typedef u_long ioctlarg_t;
#define socketError WSAGetLastError()
Expand Down
6 changes: 4 additions & 2 deletions code/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set(SRCS
sv_bot.c
sv_ccmds.c
sv_client.c
sv_discord.c
sv_http.c
sv_game.c
sv_init.c
sv_main.c
Expand Down Expand Up @@ -50,9 +52,9 @@ add_asm(${PROJECT_NAME})
add_botlib(${PROJECT_NAME})
add_dependencies(${PROJECT_NAME} qagame)
set(SERVER_DEFINES DEDICATED)
set(LIBS zlib ${CMAKE_DL_LIBS})
set(LIBS curl zlib SDL2::SDL2 SDL2::SDL2main ${CMAKE_DL_LIBS})
if (MSVC)
list(APPEND LIBS ws2_32 winmm psapi)
list(APPEND LIBS ws2_32 winmm psapi winhttp)
elseif (APPLE)
set(FRAMEWORKS Cocoa)
foreach (_framework ${FRAMEWORKS})
Expand Down
2 changes: 1 addition & 1 deletion code/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void SV_SetUserinfo(int index, const char *val);
void SV_GetUserinfo(int index, char *buffer, int bufferSize);

void SV_ChangeMaxClients(void);
void SV_SpawnServer(char *server, qboolean killBots);
void SV_SpawnServer(const char *server, qboolean killBots);

//
// sv_client.c
Expand Down
6 changes: 0 additions & 6 deletions code/server/sv_ccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ SV_DelBanEntryFromList
Remove a ban or an exception from the list.
==================
*/

static qboolean SV_DelBanEntryFromList(int index) {
if (index == serverBansCount - 1)
serverBansCount--;
Expand All @@ -648,7 +647,6 @@ SV_ParseCIDRNotation
Parse a CIDR notation type string and return a netadr_t and suffix by reference
==================
*/

static qboolean SV_ParseCIDRNotation(netadr_t *dest, int *mask, const char *adrstr) {
char *suffix;

Expand Down Expand Up @@ -686,7 +684,6 @@ SV_AddBanToList
Ban a user from being able to play on this server based on his ip address.
==================
*/

static void SV_AddBanToList(qboolean isexception) {
const char *banstring;
char addy2[NET_ADDRSTRMAXLEN];
Expand Down Expand Up @@ -808,7 +805,6 @@ SV_DelBanFromList
Remove a ban or an exception from the list.
==================
*/

static void SV_DelBanFromList(qboolean isexception) {
int index, count = 0, todel, mask;
netadr_t ip;
Expand Down Expand Up @@ -883,7 +879,6 @@ SV_ListBans_f
List all bans and exceptions on console
==================
*/

static void SV_ListBans_f(void) {
int index, count;
serverBan_t *ban;
Expand Down Expand Up @@ -921,7 +916,6 @@ SV_FlushBans_f
Delete all bans and exceptions.
==================
*/

static void SV_FlushBans_f(void) {
// make sure server is running
if (!com_sv_running->integer) {
Expand Down
Loading

0 comments on commit 9160d8a

Please sign in to comment.