Skip to content

Commit

Permalink
mirroring garrysmod repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Yogpod committed May 8, 2020
1 parent 48120f6 commit 1b96609
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 77 deletions.
67 changes: 6 additions & 61 deletions html/js/menu/control.Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ function MenuController( $scope, $rootScope )
{
$scope.Gamemode = gm.name;
$scope.GamemodeTitle = gm.title;
lua.Run( "RunConsoleCommand( \"gamemode\", \""+gm.name+"\" )" )
lua.Run( "RunConsoleCommand( \"gamemode\", \"" + gm.name + "\" )" );

$( '.gamemode_list' ).hide();
}

$scope.SelectLanguage = function ( lang )
{
$rootScope.Language = lang;
lua.Run( "RunConsoleCommand( \"gmod_language\", \"" + lang + "\" )" )
lua.Run( "RunConsoleCommand( \"gmod_language\", \"" + lang + "\" )" );

$( '.language_list' ).hide();
}
Expand Down Expand Up @@ -93,7 +93,7 @@ function MenuController( $scope, $rootScope )
//
$scope.GameMountChanged = function( mount )
{
lua.Run( "engine.SetMounted( "+mount.depot+", "+mount.mounted+" )" );
lua.Run( "engine.SetMounted( " + mount.depot + ", " + mount.mounted + " )" );
}

//
Expand Down Expand Up @@ -237,61 +237,6 @@ function GetGamemodeInfo( name )
return GamemodeDetails[name];
}

function GetHighestKey( obj )
{
var h = 0;
var v = "";

for ( k in obj )
{
if ( obj[k] > h )
{
h = obj[k];
v = k;
}
}

return v;
}

//
// Updates information about gamemodes we don't have using server info
//
function UpdateGamemodeInfo( server )
{
gi = GetGamemodeInfo( server.gamemode )

//
// Use the most common title
//
if ( !gi.titles ) gi.titles = {}

// First try to see if we have a capitalized version already (i.e. sandbox should be Sandbox)
if ( server.desc == server.gamemode.toLowerCase() ) {
var names = Object.keys( gi.titles );
for ( var i = 0; i < names.length; i++ ) {
var name = names[ i ];
if ( name != name.toLowerCase() && name.toLowerCase() == server.gamemode.toLowerCase() ) {
server.desc = name;
break;
}
}
}

if ( !gi.titles[ server.desc ] ) { gi.titles[ server.desc ] = 1; } else { gi.titles[ server.desc ]++; }
gi.title = GetHighestKey( gi.titles );

//
// Use the most common workshop id
//
//if ( server.workshopid != "" )
{
if ( !gi.wsid ) gi.wsid = {}
if ( !gi.wsid[ server.workshopid ] ) { gi.wsid[ server.workshopid ] = 1; } else { gi.wsid[ server.workshopid ]++; }
gi.workshopid = GetHighestKey( gi.wsid );
}
}

function UpdateMaps( inmaps )
{
var mapList = []
Expand Down Expand Up @@ -361,8 +306,8 @@ function UpdateGames( games )

function UpdateVersion( version, branch )
{
gScope.Version = version;
gScope.Branch = branch;
gScope.Version = version;
gScope.Branch = branch;

UpdateDigest( gScope, 100 );
}
Expand All @@ -375,4 +320,4 @@ $(document).on( "click", ".options a", function () { lua.PlaySound( "garrysmo
$(document).on( "mouseenter", ".noisy", function () { lua.PlaySound( "garrysmod/ui_hover.wav" ); } );
$(document).on( "click", ".noisy", function () { lua.PlaySound( "garrysmod/ui_click.wav" ); } );
$(document).on( "mouseenter", ".ui_sound_return", function () { lua.PlaySound( "garrysmod/ui_hover.wav" ); } );
$(document).on( "click", ".ui_sound_return", function () { lua.PlaySound( "garrysmod/ui_return.wav" ); } );
$(document).on( "click", ".ui_sound_return", function () { lua.PlaySound( "garrysmod/ui_return.wav" ); } );
88 changes: 78 additions & 10 deletions html/js/menu/control.Servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,27 @@ function ControllerServers( $scope, $element, $rootScope, $location )
//
// Get the server list from the engine
//
lua.Run( "GetServers( '"+Scope.ServerType+"', '"+RequestNum[Scope.ServerType ]+"' )" );
lua.Run( "GetServers( '" + Scope.ServerType + "', '" + RequestNum[ Scope.ServerType ] + "' )" );

Scope.Refreshing[Scope.ServerType] = "true";
Scope.Refreshing[ Scope.ServerType] = "true";
UpdateDigest( Scope, 50 );
}

$scope.SelectServer = function( server )
$scope.SelectServer = function( server, event )
{
if ( event && event.which != 1 )
{
lua.Run( "SetClipboardText( '" + server.name.replace( "'", "\\'") + " @ " + server.address + " - " + server.steamID + " (Anon:" + server.isAnon + ")' )" );
event.preventDefault();
return;
}

Scope.CurrentGamemode.Selected = server;

if ( !IN_ENGINE )
SetPlayerList( server.address, { "1": { "time": 3037.74, "score": 5, "name": "Sethxi" }, "2": { "time": 2029.34, "score": 0, "name": "RedDragon124" }, "3": { "time": 1405.02, "score": 0, "name": "Joke (0_0)" }, "4": { "time": 462.15, "score": 0, "name": "TheAimBot" }, "5": { "time": 301.32, "score": 0, "name": "DesanPL"} } );

lua.Run( "GetPlayerList( '"+server.address+"' )" );
lua.Run( "GetPlayerList( '" + server.address + "' )" );

if ( server.DoubleClick )
{
Expand Down Expand Up @@ -118,12 +125,12 @@ function ControllerServers( $scope, $element, $rootScope, $location )
return gm.name;
}

$scope.JoinServer = function ( gm )
$scope.JoinServer = function ( srv )
{
if ( gm.password )
lua.Run( "RunConsoleCommand( \"password\", \"" + gm.password + "\" )" )
if ( srv.password )
lua.Run( "RunConsoleCommand( \"password\", \"" + srv.password + "\" )" )

lua.Run( "JoinServer( \"" + gm.address + "\" )" )
lua.Run( "JoinServer( \"" + srv.address + "\" )" )
$scope.DoStopRefresh();
}

Expand Down Expand Up @@ -211,6 +218,7 @@ function GetGamemode( name, type )
servers: [],
num_servers: 0,
num_players: 0,
sort_players: 0,
OrderByMain: 'recommended',
OrderBy: ['recommended', 'ping', 'address'],
info: GetGamemodeInfo( name )
Expand All @@ -221,7 +229,7 @@ function GetGamemode( name, type )
return ServerTypes[type].gamemodes[name];
}

function AddServer( type, id, ping, name, desc, map, players, maxplayers, botplayers, pass, lastplayed, address, gamemode, workshopid )
function AddServer( type, id, ping, name, desc, map, players, maxplayers, botplayers, pass, lastplayed, address, gamemode, workshopid, isAnon, steamID )
{
if ( id != RequestNum[ type ] ) return;

Expand All @@ -243,6 +251,8 @@ function AddServer( type, id, ping, name, desc, map, players, maxplayers, botpla
gamemode: gamemode,
password: '',
workshopid: workshopid,
isAnon: isAnon,
steamID: steamID,
favorite: false // This needs to be set properly
};

Expand All @@ -256,6 +266,7 @@ function AddServer( type, id, ping, name, desc, map, players, maxplayers, botpla
if ( data.players == 0 ) data.recommended += 75; // Server is empty
if ( data.players >= data.maxplayers ) data.recommended += 100; // Server is full, can't join it
if ( data.pass ) data.recommended += 300; // Password protected, can't join it
if ( data.isAnon ) data.recommended += 1000; // Anonymous server

// The first few bunches of players reduce the impact of the server's ping on the ranking a little
if ( data.players >= 4 ) data.recommended -= 10;
Expand All @@ -275,11 +286,13 @@ function AddServer( type, id, ping, name, desc, map, players, maxplayers, botpla
gm.num_servers += 1;
gm.num_players += data.players

if ( !data.isAnon ) gm.sort_players += data.players

gm.element_class = "";
if ( gm.num_players == 0 ) gm.element_class = "noplayers";
if ( gm.num_players > 50 ) gm.element_class = "lotsofplayers";

gm.order = gm.num_players + Math.random();
gm.order = gm.sort_players; // + Math.random();

UpdateDigest( Scope, 50 );

Expand All @@ -304,3 +317,58 @@ function SetPlayerList( serverip, players )

UpdateDigest( Scope, 50 );
}

function GetHighestKey( obj )
{
var h = 0;
var v = "";

for ( k in obj )
{
if ( obj[k] > h )
{
h = obj[k];
v = k;
}
}

return v;
}

//
// Updates information about gamemodes we don't have using server info
//
function UpdateGamemodeInfo( server )
{
gi = GetGamemodeInfo( server.gamemode )

//
// Use the most common title
//
if ( !gi.titles ) gi.titles = {}

// First try to see if we have a capitalized version already (i.e. sandbox should be Sandbox)
if ( server.desc == server.gamemode.toLowerCase() ) {
var names = Object.keys( gi.titles );
for ( var i = 0; i < names.length; i++ ) {
var name = names[ i ];
if ( name != name.toLowerCase() && name.toLowerCase() == server.gamemode.toLowerCase() ) {
server.desc = name;
break;
}
}
}

if ( !gi.titles[ server.desc ] ) { gi.titles[ server.desc ] = 1; } else { gi.titles[ server.desc ]++; }
gi.title = GetHighestKey( gi.titles );

//
// Use the most common workshop id
//
//if ( server.workshopid != "" )
{
if ( !gi.wsid ) gi.wsid = {}
if ( !gi.wsid[ server.workshopid ] ) { gi.wsid[ server.workshopid ] = 1; } else { gi.wsid[ server.workshopid ]++; }
gi.workshopid = GetHighestKey( gi.wsid );
}
}
21 changes: 20 additions & 1 deletion html/js/menu/menuApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ App.config(function ( $routeProvider, $locationProvider )
$routeProvider.when('/dupes/', { templateUrl: 'template/dupes.html' } );
} );

// This is a bit silly
App.filter( 'gamemodeFilter', function() {
return function( inputs, searchText ) {
if ( !searchText ) return inputs;
searchText = searchText.toLowerCase();

var output = [];
angular.forEach( inputs, function( input ) {
var found = false;

if ( input.name.toLowerCase().indexOf( searchText ) != -1 ) found = true;
if ( !found && input.info && input.info.title.toLowerCase().indexOf( searchText ) != -1 ) found = true;

if ( found ) output.push( input );
} );
return output;
};
} );

function UpdateDigest( scope, timeout )
{
if ( !scope ) return;
Expand All @@ -37,4 +56,4 @@ App.filter( 'startFrom', function ()
start = +start; //parse to int
return input.slice( start );
}
} );
} );
5 changes: 3 additions & 2 deletions html/template/servers.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1 class="menuheader">

<div class='server_gamemodes whiterounded scrollable'>

<div class='gamemode {{gamemode.element_class}}' ng-repeat="gamemode in GamemodeList|filter:Search|orderBy:'-(order)'" ng-click="SelectGamemode( gamemode )">
<div class='gamemode {{gamemode.element_class}}' ng-repeat="gamemode in GamemodeList|gamemodeFilter:GMSearch|orderBy:['-(order)', '-(num_players)', 'name' ]" ng-click="SelectGamemode( gamemode )">

<img ng-src='../gamemodes/{{gamemode.name}}/icon24.png' onerror="MissingGamemodeIcon(this)"/>

Expand Down Expand Up @@ -75,7 +75,8 @@ <h1 class="menuheader">

<div class='body scrollable'>

<div ng-repeat="server in CurrentGamemode.servers|filter:CurrentGamemode.Search|orderBy:CurrentGamemode.OrderBy:CurrentGamemode.OrderReverse|limitTo:256" class="server {{ServerClass(server)}} {{IfElse( CurrentGamemode.Selected == server, 'activeserver', '' )}}" ng-click="SelectServer( server )">
<div ng-repeat="server in CurrentGamemode.servers|filter:CurrentGamemode.Search|orderBy:CurrentGamemode.OrderBy:CurrentGamemode.OrderReverse|limitTo:256"
class="server {{ServerClass(server)}} {{IfElse( CurrentGamemode.Selected == server, 'activeserver', '' )}}" ng-mouseup="SelectServer( server, $event )" >
<name>
<a class='unfavbutton {{IfElse( !server.favorite, "removed", "" )}}' ng-show="ServerType == 'favorite'" ng-click="ToggleFavorite( server );$event.stopPropagation();"></a>
<img src='img/server-passworded.png' style="margin-right: 8px;" ng-show="server.pass"/>
Expand Down
6 changes: 3 additions & 3 deletions lua/menu/mainmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function GetServers( category, id )
Servers[ category ] = {}

local data = {
Callback = function( ping, name, desc, map, players, maxplayers, botplayers, pass, lastplayed, address, gm, workshopid )
Callback = function( ping, name, desc, map, players, maxplayers, botplayers, pass, lastplayed, address, gm, workshopid, isAnon, steamID64 )

if Servers[ category ] && Servers[ category ][ address ] then print( "Server Browser Error!", address, category ) return end
Servers[ category ][ address ] = true
Expand All @@ -327,8 +327,8 @@ function GetServers( category, id )
gm = string.JavascriptSafe( gm )
workshopid = string.JavascriptSafe( workshopid )

pnlMainMenu:Call( string.format( 'AddServer( "%s", "%s", %i, "%s", "%s", "%s", %i, %i, %i, %s, %i, "%s", "%s", "%s" );',
category, id, ping, name, desc, map, players, maxplayers, botplayers, tostring( pass ), lastplayed, address, gm, workshopid ) )
pnlMainMenu:Call( string.format( 'AddServer( "%s", "%s", %i, "%s", "%s", "%s", %i, %i, %i, %s, %i, "%s", "%s", "%s", %s, "%s" );',
category, id, ping, name, desc, map, players, maxplayers, botplayers, tostring( pass ), lastplayed, address, gm, workshopid, tostring( isAnon ), steamID64 ) )

else

Expand Down

0 comments on commit 1b96609

Please sign in to comment.