I would like to request LAN support on this plugin if possible.
The following modifications should make it work for LAN environments while maintaining listenability for outside users. This is a crude modification but it works for me since I know very little about making plugins.
Add new variable to jukebox.cfg
jb_base_local_url = "" // put the local IP address of your jukebox install here.
Add IsLanIP()
Code:
//Thanks to Darkthrone (https://forums.alliedmods.net/member.php?u=54636)
bool:IsLanIP( String:src[16] )
{
decl String:ip4[4][4];
new ipnum;
if(ExplodeString(src, ".", ip4, 4, 4) == 4)
{
ipnum = StringToInt(ip4[0])*65536 + StringToInt(ip4[1])*256 + StringToInt(ip4[2]);
if((ipnum >= 655360 && ipnum < 655360+65535) || (ipnum >= 11276288 && ipnum < 11276288+4095) || (ipnum >= 12625920 && ipnum < 12625920+255))
{
return true;
}
}
return false;
}
Added new handle variable
Code:
//around line 70
new Handle:cv_base_local_url = INVALID_HANDLE;
Added the following on OnPluginStart()
Code:
public OnPluginStart() {
cv_base_local_url = CreateConVar("jb_base_local_url", "", "URL path to Jukebox's base folder if local", FCVAR_SPONLY|FCVAR_PRINTABLEONLY|FCVAR_PLUGIN);
}
Added the following on OnPluginEnd()
Code:
public OnPluginEnd() {
CloseHandle2(cv_base_local_url);
}
Added the following on OnConfigsExecuted()
*NOTE There is a slight bug here where the error messages were swapped.
Code:
public OnConfigsExecuted() {
decl String:base_local_url_test[128];
GetConVarString(cv_base_local_url, base_local_url_test, sizeof(base_local_url_test));
if(strlen(base_url_test) == 0) {
PrintToServer("[JB] WARNING - You must populate 'jb_base_url' in cfg/sourcemod/jukebox.cfg with the URL to Jukebox's base folder on your web server.");
}
if(strlen(leech_password_test) == 0) {
PrintToServer("[JB] WARNING - You must populate 'jb_leech_password' in cfg/sourcemod/jukebox.cfg with the anti-leech password specified in settings.php on your web server.");
}
//There is obviously a better way to do this but this is just temporary.
if(strlen(base_local_url_test) == 0) {
PrintToServer("[JB] WARNING - You must populate 'jb_base_local_url' in cfg/sourcemod/jukebox.cfg with the URL to Jukebox's base folder on your web server.");
}
}
Modified the AddClients() to look like this (I'm posting all the code for clarity)
Code:
AddClients(id, clients_list[], update_count, bool:lock=false) {
decl String:key[9], String:play_url[256];
new volume_target = FindOption("volume");
decl String:base_url[128];
new temp_volume;
new volume_min = GetConVarInt(cv_volume_min);
//SAUCE
decl String:ip[16];
new bool:bIsLanIp;
decl String:base_local_url[128];
GetConVarString(cv_base_local_url, base_local_url, sizeof(base_url));
//SAUCE
GetConVarString(cv_base_url, base_url, sizeof(base_url));
if(base_url[strlen(base_url)-1] != '/') {
Format(base_url, sizeof(base_url), "%s/", base_url);
}
//SAUCE
if(base_local_url[strlen(base_local_url)-1] != '/') {
Format(base_local_url, sizeof(base_local_url), "%s/", base_local_url);
}
//SAUCE
for(new i = 0; i < update_count; i++) {
AssignStreamToClient(clients_list[i], id);
play_lock[clients_list[i]] = lock;
}
GenerateKey(key, sizeof(key)); // Encrypts a time stamp into the URL to prevent leeching
for(new i = 0; i < update_count; i++) {
if(now_volume[clients_list[i]] < 0) {
StopMOTD(clients_list[i]);
} else {
if(now_volume[clients_list[i]] > 0) {
temp_volume = now_volume[clients_list[i]];
} else {
temp_volume = options[clients_list[i]][volume_target];
now_volume[clients_list[i]] = temp_volume;
}
if(temp_volume > 0) {
if(temp_volume < volume_min) {
temp_volume = volume_min;
}
//SAUCE
GetClientIP(clients_list[i], ip, sizeof(ip));
//detect LAN ip
bIsLanIp = IsLanIP( ip );
if(bIsLanIp) {
FormatEx(play_url, sizeof(play_url), "%squery.php?sid=%d&key=%s&vol=%d", base_local_url, id, key, temp_volume);
}
else {
FormatEx(play_url, sizeof(play_url), "%squery.php?sid=%d&key=%s&vol=%d", base_url, id, key, temp_volume);
}
//SAUCE
LoadMOTDPanelHidden(clients_list[i], "Jukebox - Source Engine Streaming Music System", play_url, MOTDPANEL_TYPE_URL);
// ShowMOTDPanel(clients_list[i], "Jukebox - Source Engine Streaming Music System", play_url, MOTDPANEL_TYPE_URL); // DEBUG
// PrintToConsole(clients_list[i], "Playing URL: %s", play_url); // DEBUG
}
}
}
return true;
}