IpDrv
Class ClientBeaconReceiver

source: e:\games\UnrealTournament\IpDrv\Classes\ClientBeaconReceiver.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Info
         |
         +--Engine.InternetInfo
            |
            +--IpDrv.InternetLink
               |
               +--IpDrv.UdpLink
                  |
                  +--IpDrv.UdpBeacon
                     |
                     +--IpDrv.ClientBeaconReceiver
Direct Known Subclasses:None

class ClientBeaconReceiver
extends IpDrv.UdpBeacon

//============================================================================= // ClientBeaconReceiver: Receives LAN beacons from servers. //=============================================================================
Variables
 struct BeaconInfo


Function Summary
 void BeginPlay()
 void BroadcastBeacon(IpAddr Addr)
 void Destroyed()
 string GetBeaconAddress(int i)
 string GetBeaconText(int i)
 void Timer()



Source Code


00001	//=============================================================================
00002	// ClientBeaconReceiver: Receives LAN beacons from servers.
00003	//=============================================================================
00004	class ClientBeaconReceiver extends UdpBeacon
00005		transient;
00006	
00007	var struct BeaconInfo
00008	{
00009		var IpAddr      Addr;
00010		var float       Time;
00011		var string      Text;
00012	} Beacons[32];
00013	
00014	function string GetBeaconAddress( int i )
00015	{
00016		return IpAddrToString(Beacons[i].Addr);
00017	}
00018	
00019	function string GetBeaconText(int i)
00020	{
00021		return Beacons[i].Text;
00022	}
00023	
00024	function BeginPlay()
00025	{
00026		local IpAddr Addr;
00027	
00028		if( BindPort( BeaconPort, true ) > 0 )
00029		{
00030			SetTimer( 1.0, true );
00031			log( "ClientBeaconReceiver initialized." );
00032		}
00033		else
00034		{
00035			log( "ClientBeaconReceiver failed: Beacon port in use." );
00036		}
00037	
00038		Addr.Addr = BroadcastAddr;
00039		Addr.Port = ServerBeaconPort;
00040	
00041		BroadcastBeacon(Addr);
00042	}
00043	
00044	function Destroyed()
00045	{
00046		log( "ClientBeaconReceiver finished." );
00047	}
00048	
00049	function Timer()
00050	{
00051		local int i, j;
00052		for( i=0; i<arraycount(Beacons); i++ )
00053			if
00054			(	Beacons[i].Addr.Addr!=0
00055			&&	Level.TimeSeconds-Beacons[i].Time<BeaconTimeout )
00056				Beacons[j++] = Beacons[i];
00057		for( j=j; j<arraycount(Beacons); j++ )
00058			Beacons[j].Addr.Addr=0;
00059	}
00060	
00061	function BroadcastBeacon(IpAddr Addr)
00062	{
00063		SendText( Addr, "REPORT" );	
00064	}
00065	
00066	event ReceivedText( IpAddr Addr, string Text )
00067	{
00068		local int i, n;
00069		
00070		n = len(BeaconProduct);
00071		if( left(Text,n+1) ~= (BeaconProduct$" ") )
00072		{
00073			Text = mid(Text,n+1);
00074			Addr.Port = int(Text);
00075			for( i=0; i<arraycount(Beacons); i++ )
00076				if( Beacons[i].Addr==Addr )
00077					break;
00078			if( i==arraycount(Beacons) )
00079				for( i=0; i<arraycount(Beacons); i++ )
00080					if( Beacons[i].Addr.Addr==0 )
00081						break;
00082			if( i==arraycount(Beacons) )
00083				return;
00084			Beacons[i].Addr      = Addr;
00085			Beacons[i].Time      = Level.TimeSeconds;
00086			Beacons[i].Text      = mid(Text,InStr(Text," ")+1);
00087		}
00088	}
00089	
00090	defaultproperties
00091	{
00092	}

End Source Code