diff --git a/html/js/menu/control.Menu.js b/html/js/menu/control.Menu.js index 6368b92..95dd2cf 100644 --- a/html/js/menu/control.Menu.js +++ b/html/js/menu/control.Menu.js @@ -51,7 +51,7 @@ 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(); } @@ -59,7 +59,7 @@ function MenuController( $scope, $rootScope ) $scope.SelectLanguage = function ( lang ) { $rootScope.Language = lang; - lua.Run( "RunConsoleCommand( \"gmod_language\", \"" + lang + "\" )" ) + lua.Run( "RunConsoleCommand( \"gmod_language\", \"" + lang + "\" )" ); $( '.language_list' ).hide(); } @@ -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 + " )" ); } // @@ -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 = [] @@ -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 ); } @@ -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" ); } ); \ No newline at end of file diff --git a/html/js/menu/control.Servers.js b/html/js/menu/control.Servers.js index 9fceb4a..346b52a 100644 --- a/html/js/menu/control.Servers.js +++ b/html/js/menu/control.Servers.js @@ -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 ) { @@ -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(); } @@ -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 ) @@ -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; @@ -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 }; @@ -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; @@ -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 ); @@ -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 ); + } +} diff --git a/html/js/menu/menuApp.js b/html/js/menu/menuApp.js index 278ec1f..dc935d1 100644 --- a/html/js/menu/menuApp.js +++ b/html/js/menu/menuApp.js @@ -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; @@ -37,4 +56,4 @@ App.filter( 'startFrom', function () start = +start; //parse to int return input.slice( start ); } -} ); +} ); \ No newline at end of file diff --git a/html/template/servers.html b/html/template/servers.html index 91a1353..71ae145 100644 --- a/html/template/servers.html +++ b/html/template/servers.html @@ -32,7 +32,7 @@

-
+
@@ -75,7 +75,8 @@

-
+
diff --git a/lua/menu/mainmenu.lua b/lua/menu/mainmenu.lua index 3d0cec9..411149a 100644 --- a/lua/menu/mainmenu.lua +++ b/lua/menu/mainmenu.lua @@ -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 @@ -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