Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: TR1GG3R (http://www.houseofpain.tk)
- Resources:
- http://int64.org/docs/gamestat-protocols/gamespy2.html
- http://www.alexthissen.nl/wikis/gaming/gamespy-2.aspx
- http://wiki.beyondunreal.com/Legacy:UdpLink
- http://en.wikipedia.org/wiki/User_Datagram_Protocol#IPv4_Pseudo_Header
- */
- class AMGameSpyV2Query extends IPDrv.UDPLink;
- var int boundport;
- var int bytecount;
- var byte data[255];
- var() globalconfig int GameSpyV2QueryPort;
- function BeginPlay()
- {
- LinkMode = MODE_Binary;
- if ( GameSpyV2QueryPort == 0 )
- {
- Destroy();
- return;
- }
- boundport = BindPort( GameSpyV2QueryPort, true );
- if ( boundport == 0 )
- {
- log( "AMGameSpyV2Query: Could not bind a port" );
- Destroy();
- return;
- }
- log( "AMGameSpyV2Query: Listening on "$boundport );
- }
- event ReceivedBinary( IpAddr Addr, int Count, byte B[255] )
- {
- if ( IsGameSpy2Query( B ) )
- {
- SetHeader( B );
- // Server information and rules
- if ( B[23] == 0xFF )
- SendMain( Addr );
- // Player information
- if ( B[24] == 0xFF )
- SendPlayers( Addr );
- }
- }
- function AddData( byte B )
- {
- if ( bytecount < 255 )
- {
- data[bytecount] = B;
- bytecount++;
- }
- }
- function SendData( IpAddr Addr )
- {
- SendBinary( Addr, bytecount, data );
- bytecount = 0;
- }
- function AddNull()
- {
- AddData( 0x00 );
- }
- function SetHeader( byte B[255] )
- {
- local int i;
- AddNull(); // Delimiter
- // Unique identifier (4 bytes)
- for ( i = 19; i < 23; i++ )
- AddData( B[i] );
- }
- function AddString( string Str )
- {
- local int i, j;
- j = Len( Str );
- for ( i = 0; i < j; i++ )
- AddData( Asc( Mid( Str, i, 1 ) ) );
- AddNull(); // Delimiter
- }
- function bool IsGameSpy2Query( byte B[255] )
- {
- if ( B[16] == 0xFE && B[17] == 0xFD && B[18] == 0x00 )
- return true;
- return false;
- }
- function SendMain( IpAddr Addr )
- {
- local int i;
- local string keys[9], values[9];
- keys[0] = "hostname";
- values[0] = ServerSettings(Level.CurrentServerSettings).ServerName;
- keys[1] = "numplayers";
- values[1] = String(SwatGameInfo(Level.Game).NumberOfPlayersForServerBrowser());
- keys[2] = "maxplayers";
- values[2] = String(ServerSettings(Level.CurrentServerSettings).MaxPlayers);
- keys[3] = "gametype";
- values[3] = SwatGameInfo(Level.Game).GetGameModeName();
- keys[4] = "gamevariant";
- values[4] = Level.ModName;
- keys[5] = "mapname";
- values[5] = Level.Title;
- keys[6] = "hostport";
- values[6] = String(SwatGameInfo(Level.Game).GetServerPort());
- keys[7] = "password";
- values[7] = String(Level.Game.GameIsPasswordProtected());
- keys[8] = "gamever";
- values[8] = Level.BuildVersion;
- for ( i = 0; i < 9; i++ )
- {
- AddString( keys[i] ); // Key
- AddString( values[i] ); // Value
- }
- // Empty key/value (end of key/value pairs)
- AddNull();
- AddNull();
- if ( bytecount > 255 )
- {
- log( "AMGameSpyV2Query::SendMain() failed... data > 255 bytes" );
- return;
- }
- SendData( Addr );
- }
- function SendPlayers( IpAddr Addr )
- {
- local int i;
- local Array<string> keys;
- local Controller controller, theLocalPlayerController;
- local SwatGamePlayerController current;
- AddNull();
- AddData( SwatGameInfo(Level.Game).NumberOfPlayersForServerBrowser() ); // Player count
- keys[0] = "player_";
- keys[1] = "score_";
- keys[2] = "ping_";
- for ( i = 0; i < keys.Length; i++ )
- AddString(keys[i]);
- AddNull(); // Empty string (end of player info description)
- theLocalPlayerController = Level.GetLocalPlayerController();
- for ( controller = Level.ControllerList; controller != None; controller = controller.NextController )
- {
- current = SwatGamePlayerController( controller );
- if ( current != None && current != theLocalPlayerController )
- {
- AddString( SwatGameInfo(Level.Game).GetPlayerName( current ) );
- AddString( String(SwatGameInfo(Level.Game).GetPlayerScore( current )) );
- AddString( String(current.PlayerReplicationInfo.Ping) );
- }
- }
- if ( bytecount > 255 )
- {
- log( "AMGameSpyV2Query::SendPlayers() failed... data > 255 bytes" );
- return;
- }
- SendData( Addr );
- }
- defaultproperties
- {
- GameSpyV2QueryPort=10481
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement