• gmsv_gsapi - Game Server API
    9 replies, posted
  • Avatar of VoiDeD
  • To continue with the trend of Steamworks game server related APIs, this module opens the door to various bits of server knowledge and information gathering methods. For example, this module allows you to check your game server's reputation to the backend server. Servers can potentially be banned from the master server list if the reputation goes too low, although I've never witnessed this myself. [lua] hook.Add( "GSReputation", "GMTRep", function( eResult, repScore, isBanned, bannedInfo ) Msg( "Got GSReputation!\n" ) Msg( "EResult: ", eResult, "\n" ) if ( eResult != EResultOK ) then return end Msg( "Reputation: ", repScore, "\n" ) Msg( "Is Banned: ", isBanned, "\n" ) PrintTable( bannedInfo ) Msg( "\n\n" ) end ) [/lua][cpp]lua_run gameserver.GetReputation() > gameserver.GetReputation()... Got GSReputation! EResult: 1 Reputation: 3410 Is Banned: false BannedAddress = 0.0.0.0:0 BanExpires = 0 BannedGame: AppID = 0 IsMod = false ModID = 0 IsValid = false IsShortcut = false IsSteamApp = true IsP2PFile = false [/cpp] Additionally, you can query certain server statistics that are stored on Valve's backend servers. [lua] hook.Add( "GSGameStats", "GMTGameStats", function( eResult, rank, totalConnects, totalMinsPlayed ) Msg( "Got GSGameStats!\n" ) Msg( "EResult: ", eResult, "\n" ) if ( eResult != EResultOK ) then return end Msg( "Rank: ", rank, "\n" ) Msg( "Total Connects: ", totalConnects, "\n" ) Msg( "Total Mins Played: ", totalMinsPlayed, "\n\n" ) end )[/lua][cpp] lua_run gameserver.GetGameplayStats() > gameserver.GetGameplayStats()... Got GSGameStats! EResult: 1 Rank: 924 Total Connects: 300 Total Mins Played: 9074 [/cpp] An additional aspect allowed by this module is to query client achievement and stats information. [lua] hook.Add( "GSStatsReceived", "GMTUserStats", function( eResult, steamid ) Msg( "Got GSStatsReceived!\n" ) Msg( "EResult: ", eResult, "\n" ) if ( eResult != EResultOK ) then return end Msg( "SteamID: ", steamid, "\n" ) local bSuccess, bAchieved = gameserverstats.GetUserAchievement( steamid, "GMA_PLAYWITH_GARRY" ) if ( !bSuccess ) then return end if ( bAchieved ) then Msg( steamid, " has played with garry!\n\n" ) end end ) [/lua][cpp] lua_run gameserverstats.RequestUserStats( "STEAM_0:0:4491990" ) > gameserverstats.RequestUserStats( "STEAM_0:0:4491990" )... Got GSStatsReceived! EResult: 1 SteamID: STEAM_0:0:4491990 STEAM_0:0:4491990 has played with garry! [/cpp] The functions currently exposed are as follows [b]gameserver[/b] - general gameserver access [list] [*]bool IsLoggedOn() [*]bool IsSecure() [*]string GetSteamID() [*]string GetPublicIP() [*]bool UpdateUserData( string steamID, string playerName, int score ) [*]bool SetType( int serverFlag, int gameIp, int gamePort, int specPort, int qeryPort, string gameDirectory, string version, bool lanMode ) [*]void UpdateStatus( int playerCount, int botCount, string serverName, string specServerName, mapName ) [*]void SetGameTags( string gameTags ) [*]bool GetReputation() - results returned in "GSReputation" hook [*]bool GetGameplayStats() - results returned in "GSGameStats" hook [/list] [b]gameserverstats[/b] - stat/achievement info [list] [*]bool RequestUserStats( string steamID ) - results returned "GSStatsReceived" [*]bool, int GetUserStatInt( string steamID, string statName ) [*]bool, float GetUserStatFloat( string steamID, string statName ) [*]bool, bool GetUserAchievement( string steamID, string achievementName ) [/list] [b]Hooks[/b] [cpp] // Called when server reputation is requested GSReputation ( EResult eResult, int repScore, bool isBanned, table bannedInfo ) // Called when server gameplay stats are requested GSGameStats ( EResult eResult, int rank, int totalConnects, int totalMinsPlayed ) // Called when stats are requested for a client GSStatsReceived( EResult eResult, string steamID ) // Called when the server unloads a client's stats. // you must request the stats again in order to get them. GSStatsUnloaded( string steamID ) [/cpp] A list of all known [url=http://voided.pastebin.com/g1HEzu6p]EResults is available here.[/url] [release] [b]Download[/b] (Windows): [url]http://code.google.com/p/gmodmodules/source/browse/trunk/gmsv_gsapi/bin/gmsv_gsapi.dll[/url] [b]Download[/b] (Linux, thanks to ComWalk): -none- [b]Source[/b]: [url]http://code.google.com/p/gmodmodules/source/browse/trunk/gmsv_gsapi/gmsv_gsapi/[/url] [/release] I'll be expanding this module and adding more things to it as I deem them useful. Suggestions are always welcome. If you're familiar with the Steamworks SDK and you want a specific function exposed, let me know!
  • Avatar of ComWalk
  • Linux compile: [url=http://dl.dropbox.com/u/38225/gmsv_gsapi_linux.zip]here[/url]
  • Avatar of CombineGuru
  • a very useful module thank you very much voidybear i was very disappointed to see the name wasn't as good as your previous release though
  • Avatar of Python1320
  • [QUOTE=LuaStoned;24680021]Awesome! :D[/QUOTE] but now borken :( Lasted for a year at least, lol.
  • Avatar of Ruzza
  • This would be amazing to have, could someone (Voided) look into recompiling it?
  • Avatar of VoiDeD
  • All fixed up. [url]http://code.google.com/p/gmodmodules/source/browse/trunk/gmsv_gsapi/bin/gmsv_gsapi.dll[/url] You can now find the code in that repo as well. [editline]20th December 2011[/editline] As for a linux build, you're on your own. Windows is the best OS.
  • Avatar of Python1320
  • [QUOTE=VoiDeD;33808837]As for a linux build, you're on your own. Windows is the best OS.[/QUOTE] [lua]srcds Cruth ~/developement/gmsv_gsapi> cp ~/developement/gmsv_gatekeeper/src/Makefile . srcds Cruth ~/developement/gmsv_gsapi> ls Makefile srcds Cruth ~/developement/gmsv_gsapi> svn checkout [url]http://gmodmodules.googlecode.com/svn/trunk/gmsv_gsapi/[/url] . A gmsv_gsapi A gmsv_gsapi/GSContext.cpp --snip-- A bin/gmsv_gsapi.dll Checked out revision 175. srcds Cruth ~/developement/gmsv_gsapi> ls bin gmsv_gsapi Makefile srcds Cruth ~/developement/gmsv_gsapi> mv Makefile gmsv_gsapi/ srcds Cruth ~/developement/gmsv_gsapi> cd gmsv_gsapi/ srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> ls common GSContext.cpp GSContext.h main.cpp Makefile steam srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> nano Makefile srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> make -s main.cpp:8: error: ‘dllexport’ was not declared in this scope main.cpp:8: error: expected ‘,’ or ‘;’ before ‘gmod_open’ main.cpp:8: error: redefinition of ‘int __declspec’ main.cpp:8: error: ‘int __declspec’ previously defined here main.cpp:8: error: ‘dllexport’ was not declared in this scope make: *** [Release/main.o] Error 1 srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> nano main.cpp srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> ls common GSContext.cpp GSContext.h main.cpp Makefile Release steam srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> rm common/ -rf srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> ln -s ~/developement/GarrysModSDK/ common srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> make -s srcds Cruth ~/developement/gmsv_gsapi/gmsv_gsapi> [/lua] nou [editline]20th December 2011[/editline] [code]lua_run require'gsapi' ; lua_run print(gameserver.GetPublicIP()) ; lua_run print(LINUX) > require'gsapi' ... > print(gameserver.GetPublicIP()) ... 88.191.111.120 > print(LINUX)... true[/code]