Skip to content

Commit

Permalink
Merge pull request #5 from SouthernCrossGaming/1.0.1
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
Fraeven authored Oct 23, 2023
2 parents f782365 + 49e2127 commit 6ef4038
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 118 deletions.
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
A sourcemod plugin and extension that allows players to individually modify the voice volume of other players.
</br>
</br>
<h3>View Demo on YouTube
<h3><a href=https://youtu.be/5lFNonAkXDQ>View Demo on YouTube</a>
</br>
</br>

[![Demo](https://i3.ytimg.com/vi/5lFNonAkXDQ/maxresdefault.jpg)](https://youtu.be/5lFNonAkXDQ "Voice Manager Sourcemod Extension and Plugin Demo")
</h3>
</div>

## How to use
## How To Use
A player can type the command `/vm` into chat to display a menu that allows them to set volume overrides for players in the server. Overrides can be set for invidual players or globally for all players (individual overrides will take precedence).

![image](https://github.com/SouthernCrossGaming/voicemanager/assets/20617130/b882ee1c-3e8d-4ca4-94db-0448c03f876a)
Expand All @@ -23,39 +23,36 @@ There are currently 5 volume levels that can be selected:

![image](https://github.com/SouthernCrossGaming/voicemanager/assets/20617130/171bb8bf-4a6c-4e0b-a7eb-fb970ec07137)

## Compatible Games
## Requirements

### Compatible Games
- Team Fortress 2
- Open Fortress

## Supported Platforms
### Supported Platforms
- Linux

## Sourcemod
### Sourcemod
- Version 1.10+

## Supported Database Drivers
- sqlite
### Supported Database Drivers
- mysql
- sqlite

## Installation
Download the [latest release](https://github.com/SouthernCrossGaming/voicemanager/releases/latest/download/voicemanager.zip), unzip and copy to your `addons` directory.

Add a configuration for the voice manager database to your `addons/sourcemod/configs/databases.cfg` file.

For example:
```
"voicemanager"
{
"driver" "sqlite"
"database" "voicemanager"
}
```
Add a configuration for the voice manager database to your `addons/sourcemod/configs/databases.cfg` file. Note that voice manager will use the "default" configuration by default, but this can be configured via cvar, see below.

## Configuration
`vm_enabled` - Enables or disables voice manager (0/1, default 1)
`vm_database` - Database configuration to use from databases.cfg (default "voicemanager")
`vm_database` - Database configuration to use from databases.cfg (default is "default")
`vm_allow_self` - Allow players to override their own volume. This is recommended only for testing (0/1, default 0)

## Commands
`/vm` | `/voicemanager` - Opens the Voice Manager menu
`/vmclear` - Clears the player's overrides from the database

## Building

### Build Extension
Expand All @@ -65,7 +62,7 @@ For example:

<b>Windows</b>
```
$ .\build_ext.bat
> .\build_ext.bat
```

<b>Linux</b>
Expand All @@ -79,7 +76,7 @@ $ .\build_ext.sh

<b>Windows</b>
```
$ .\build_plugin.bat
> .\build_plugin.bat
```
<b>Linux</b>
```
Expand All @@ -90,7 +87,7 @@ $ .\build_plugin.sh

<b>Windows</b>
```
$ .\build.bat
> .\build.bat
```

<b>Linux</b>
Expand Down
2 changes: 0 additions & 2 deletions addons/sourcemod/scripting/include/voicemanager.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ native bool OnPlayerGlobalAdjust(int caller, int volume);

native bool RefreshActiveOverrides();

native bool AdminPrintVmStatus(int caller);

/**
* Clears all overrides a client has set
*
Expand Down
124 changes: 67 additions & 57 deletions addons/sourcemod/scripting/voicemanager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#include <sdktools>
#include <clientprefs>

#define PLUGIN_VERSION "1.0.0"
#define PLUGIN_VERSION "1.0.1"
#define VOICE_MANAGER_PREFIX "{green}[VOICE MANAGER]{default}"
#define TABLE_NAME "voicemanager"
#define STEAM_ID_BUF_SIZE 18

#pragma newdecls required

Expand Down Expand Up @@ -47,13 +48,12 @@ public Plugin myinfo =
public void OnPluginStart()
{
g_Cvar_VoiceEnable = FindConVar("vm_enable");
g_Cvar_Database = CreateConVar("vm_database", "voicemanager", "Database configuration to use from databases.cfg");
g_Cvar_Database = CreateConVar("vm_database", "default", "Database configuration to use from databases.cfg");
g_Cvar_AllowSelfOverride = CreateConVar("vm_allow_self", "0", "Allow players to override their own volume (recommended only for testing)");

RegConsoleCmd("sm_vm", CommandBaseMenu);
RegConsoleCmd("sm_voicemanager", CommandBaseMenu);
RegConsoleCmd("sm_vmclear", OnClearClientOverrides);
RegAdminCmd("sm_vmcheck", CommandAdminCheck, ADMFLAG_KICK, "Checks volume override levels");
RegConsoleCmd("sm_vmclear", Command_ClearClientOverrides);

HookConVarChange(g_Cvar_VoiceEnable, OnVoiceEnableChanged);

Expand Down Expand Up @@ -95,11 +95,20 @@ public void T_InitDatabase(Handle owner, Handle hndl, const char[] error, any da
SetFailState("Unsupported database driver %s", g_sDriver);
}

// Add voicemanager table
// Add voicemanager table if it does not exist
char szQuery[511];
Format(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%s` (adjuster VARCHAR(64), adjusted VARCHAR(64), level TINYINT, PRIMARY KEY (adjuster, adjusted))", TABLE_NAME);

SQL_TQuery(g_hDatabase, SQLErrorCheckCallback, szQuery);

for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client))
{
OnClientPostAdminCheck(client);
OnClientCookiesCached(client);
}
}
}

public void OnVoiceEnableChanged(ConVar convar, const char[] oldValue, const char[] newValue)
Expand All @@ -114,29 +123,20 @@ public void OnClientPostAdminCheck(int client)
return;
}

// Adding list from database
char szBuffer[255];
char szSteamID[18];

char szSteamID[STEAM_ID_BUF_SIZE];
GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID));
int buffer_len = strlen(szSteamID) * 2 + 1;
char[] steam_id = new char[buffer_len];

SQL_EscapeString(g_hDatabase, szSteamID, steam_id, buffer_len);

LogMessage("[VoiceManager] Adjuster: %s - %s", szSteamID, steam_id);

FormatEx(szBuffer, sizeof(szBuffer), "SELECT adjusted, level FROM %s WHERE adjuster = '%s'", TABLE_NAME, steam_id);
SQL_TQuery(g_hDatabase, T_LoadAdjustments, szBuffer, client);
// Load adjustments from database
char szQueryBuffer[255];
FormatEx(szQueryBuffer, sizeof(szQueryBuffer), "SELECT adjusted, level FROM `%s` WHERE adjuster = '%s'", TABLE_NAME, szSteamID);
SQL_TQuery(g_hDatabase, T_LoadAdjustments, szQueryBuffer, client);
}

public void T_LoadAdjustments(Handle owner, Handle hndl, const char[] error, int client)
{
LogMessage("[VoiceManager] Loading player adjustments");

if (hndl == INVALID_HANDLE)
if (hndl == INVALID_HANDLE || strlen(error) > 1)
{
LogError("Query failed! %s", error);
LogError("[VoiceManager] Failed to load adjustments: %s", error);
return;
}

Expand All @@ -145,12 +145,10 @@ public void T_LoadAdjustments(Handle owner, Handle hndl, const char[] error, int
while (SQL_FetchRow(hndl))
{
// Fetch adjusted steam ids with levels from SQL
char adjustedSteamId[18];
int level;
char adjustedSteamId[STEAM_ID_BUF_SIZE];
SQL_FetchString(hndl, 0, adjustedSteamId, sizeof(adjustedSteamId));
level = SQL_FetchInt(hndl, 1);

LogMessage("[VoiceManager] Adjust for %N: %s - %i", client, adjustedSteamId, level);
int level = SQL_FetchInt(hndl, 1);

LoadPlayerAdjustment(client, adjustedSteamId, level);
}
Expand Down Expand Up @@ -185,12 +183,6 @@ public void OnClientDisconnect(int client)
}
}

public Action CommandAdminCheck(int client, int args)
{
AdminPrintVmStatus(client);
return Plugin_Handled;
}

// Menus
public Action CommandBaseMenu(int client, int args)
{
Expand Down Expand Up @@ -322,17 +314,40 @@ public int BaseMenuHandler(Menu menu, MenuAction action, int client, int param2)
return 0;
}

public Action OnClearClientOverrides(int client, int args)
public Action Command_ClearClientOverrides(int client, int args)
{
if (!g_Cvar_VoiceEnable.BoolValue)
{
return Plugin_Handled;
}

char szSteamID[STEAM_ID_BUF_SIZE];
GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID));

char szQuery[511];
FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%s` WHERE adjuster = '%s'", TABLE_NAME, szSteamID);
SQL_TQuery(g_hDatabase, SQLErrorCheckCallback, szQuery);

ClearClientOverrides(client);

CPrintToChat(client, "%s You have cleared all of your voice overrides!", VOICE_MANAGER_PREFIX);

return Plugin_Handled;

}

public void OnClearClientOverrides(int client)
{
char szSteamID[STEAM_ID_BUF_SIZE];
GetClientAuthId(client, AuthId_SteamID64, szSteamID, sizeof(szSteamID));

char szQuery[511];
FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%s` WHERE adjuster = '%s'", TABLE_NAME, szSteamID);
SQL_TQuery(g_hDatabase, SQLErrorCheckCallback, szQuery);

ClearClientOverrides(client);

CPrintToChat(client, "%s You have cleared all of your voice overrides!", VOICE_MANAGER_PREFIX);
}

//Handlers
Expand Down Expand Up @@ -378,7 +393,7 @@ public int VoiceMenuHandler(Menu menu, MenuAction action, int param1, int param2
return 0;
}

public int ClearMenuHandler(Menu menu, MenuAction action, int param1, int param2)
public int ClearMenuHandler(Menu menu, MenuAction action, int client, int param2)
{
if (action == MenuAction_Select)
{
Expand All @@ -387,11 +402,11 @@ public int ClearMenuHandler(Menu menu, MenuAction action, int param1, int param2
int yes = StringToInt(info);
if (yes)
{
ClearClientOverrides(param1);
OnClearClientOverrides(client);
}
else
{
CommandBaseMenu(param1, 0);
CommandBaseMenu(client, 0);
}
}
else if (action == MenuAction_End)
Expand All @@ -402,7 +417,7 @@ public int ClearMenuHandler(Menu menu, MenuAction action, int param1, int param2
return 0;
}

public int VoiceVolumeHandler(Menu menu, MenuAction action, int param1, int param2)
public int VoiceVolumeHandler(Menu menu, MenuAction action, int client, int param2)
{
if (action == MenuAction_Select)
{
Expand All @@ -412,27 +427,23 @@ public int VoiceVolumeHandler(Menu menu, MenuAction action, int param1, int para
if (found)
{
int level = StringToInt(info);
if (!OnPlayerAdjustVolume(param1, g_iSelection[param1], level))
if (!OnPlayerAdjustVolume(client, g_iSelection[client], level))
{
CPrintToChat(param1, "%s Something went wrong, please try again soon!", VOICE_MANAGER_PREFIX);
CPrintToChat(client, "%s Something went wrong, please try again soon!", VOICE_MANAGER_PREFIX);
}
else
{
CPrintToChat(param1, "%s %N's level is now set to %s.", VOICE_MANAGER_PREFIX, g_iSelection[param1], setting);
CPrintToChat(client, "%s %N's level is now set to %s.", VOICE_MANAGER_PREFIX, g_iSelection[client], setting);
}

char adjuster[18], adjusted[18];
GetClientAuthId(param1, AuthId_SteamID64, adjuster, sizeof(adjuster));
GetClientAuthId(g_iSelection[param1], AuthId_SteamID64, adjusted, sizeof(adjusted));

SQL_EscapeString(g_hDatabase, adjuster, adjuster, sizeof(adjuster));
SQL_EscapeString(g_hDatabase, adjusted, adjusted, sizeof(adjusted));
char adjuster[STEAM_ID_BUF_SIZE], adjusted[STEAM_ID_BUF_SIZE];
GetClientAuthId(client, AuthId_SteamID64, adjuster, sizeof(adjuster));
GetClientAuthId(client, AuthId_SteamID64, adjusted, sizeof(adjusted));

char szQuery[511];

if (level == -1)
{
FormatEx(szQuery, sizeof(szQuery), "DELETE FROM %s WHERE adjuster = '%s' AND adjusted = '%s'", TABLE_NAME, adjuster, adjusted);
FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%s` WHERE adjuster = '%s' AND adjusted = '%s'", TABLE_NAME, adjuster, adjusted);
SQL_TQuery(g_hDatabase, SQLErrorCheckCallback, szQuery);
}
else
Expand Down Expand Up @@ -471,13 +482,13 @@ public int VoiceVolumeHandler(Menu menu, MenuAction action, int param1, int para

public void SQLErrorCheckCallback(Handle owner, Handle hndl, const char[] error, any data)
{
if (strlen(error) > 1)
if (hndl == INVALID_HANDLE || strlen(error) > 1)
{
LogMessage("[VoiceManager] SQL Error: %s", error);
LogError("[VoiceManager] SQL Error: %s", error);
}
}

public int GlobalVoiceVolumeHandler(Menu menu, MenuAction action, int param1, int param2)
public int GlobalVoiceVolumeHandler(Menu menu, MenuAction action, int client, int param2)
{
if (action == MenuAction_Select)
{
Expand All @@ -487,23 +498,23 @@ public int GlobalVoiceVolumeHandler(Menu menu, MenuAction action, int param1, in
if (found)
{
int volume = StringToInt(info);
if (!OnPlayerGlobalAdjust(param1, volume))
if (!OnPlayerGlobalAdjust(client, volume))
{
CPrintToChat(param1, "%s Something went wrong, please try again soon!", VOICE_MANAGER_PREFIX);
CPrintToChat(client, "%s Something went wrong, please try again soon!", VOICE_MANAGER_PREFIX);
}
else
{
CPrintToChat(param1, "%s Global voice volume is now set to %s.", VOICE_MANAGER_PREFIX, setting);
SetClientCookie(param1, g_Cookie_GlobalOverride, info);
g_iCookieSelection[param1] = volume;
CPrintToChat(client, "%s Global voice volume is now set to %s.", VOICE_MANAGER_PREFIX, setting);
SetClientCookie(client, g_Cookie_GlobalOverride, info);
g_iCookieSelection[client] = volume;
}
}
}
else if (action == MenuAction_Cancel)
{
if (param2 == MenuCancel_ExitBack)
{
CommandBaseMenu(param1, 0);
CommandBaseMenu(client, 0);
}
}
else if (action == MenuAction_End)
Expand All @@ -514,7 +525,6 @@ public int GlobalVoiceVolumeHandler(Menu menu, MenuAction action, int param1, in
return 0;
}


stock bool IsValidClient(int client)
{
if (!client || client > MaxClients || client < 1 || !IsClientInGame(client))
Expand Down
Loading

0 comments on commit 6ef4038

Please sign in to comment.