gmsv_gsapi - Game Server API

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!

" )
Msg( "EResult: ", eResult, "
" )

if ( eResult != EResultOK ) then return end

Msg( "Reputation: ", repScore, "

" )
Msg( "Is Banned: ", isBanned, "
" )
PrintTable( bannedInfo )
Msg( "

" )

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!

" )
Msg( "EResult: ", eResult, "
" )

if ( eResult != EResultOK ) then return end

Msg( "Rank: ", rank, "

" )
Msg( "Total Connects: ", totalConnects, "
" )
Msg( "Total Mins Played: ", totalMinsPlayed, "

" )

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!

" )
Msg( "EResult: ", eResult, "
" )

if ( eResult != EResultOK ) then return end

Msg( "SteamID: ", steamid, "

" )

local bSuccess, bAchieved = gameserverstats.GetUserAchievement( steamid, "GMA_PLAYWITH_GARRY" )

if ( !bSuccess ) then return end

if ( bAchieved ) then
    Msg( steamid, " has played with garry!

" )
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

gameserver - general gameserver access
[ul]
[li]bool IsLoggedOn()[/li][li]bool IsSecure()[/li][li]string GetSteamID()[/li][li]string GetPublicIP()[/li][li]bool UpdateUserData( string steamID, string playerName, int score )[/li][li]bool SetType( int serverFlag, int gameIp, int gamePort, int specPort, int qeryPort, string gameDirectory, string version, bool lanMode )[/li][li]void UpdateStatus( int playerCount, int botCount, string serverName, string specServerName, mapName )[/li][li]void SetGameTags( string gameTags )[/li][li]bool GetReputation() - results returned in “GSReputation” hook[/li][li]bool GetGameplayStats() - results returned in “GSGameStats” hook[/li][/ul]

gameserverstats - stat/achievement info
[ul]
[li]bool RequestUserStats( string steamID ) - results returned “GSStatsReceived”[/li][li]bool, int GetUserStatInt( string steamID, string statName )[/li][li]bool, float GetUserStatFloat( string steamID, string statName )[/li][li]bool, bool GetUserAchievement( string steamID, string achievementName )[/li][/ul]

Hooks
[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 EResults is available here.

[release]
Download (Windows): http://code.google.com/p/gmodmodules/source/browse/trunk/gmsv_gsapi/bin/gmsv_gsapi.dll
Download (Linux, thanks to ComWalk): -none-

Source: http://code.google.com/p/gmodmodules/source/browse/trunk/gmsv_gsapi/gmsv_gsapi/
[/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!

Linux compile: here

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

That’s cool.

Awesome! :smiley:

but now borken :frowning:
Lasted for a year at least, lol.

This would be amazing to have, could someone (Voided) look into recompiling it?

I just am but meh, osw gives me troubles with some compiling errors.

All fixed up.

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.

[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 http://gmodmodules.googlecode.com/svn/trunk/gmsv_gsapi/ .
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]


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