IpDrv
Class ClientBeaconReceiver

source: C:\XIII\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	    // Useless to broadcast now, since a lot is yet to be done before the level is running ! 
00039	    // (it avoids an annoying flick in join lan game menu (server appears-disappears-appears while loading))
00040		/*
00041	    Addr.Addr = BroadcastAddr;
00042		Addr.Port = ServerBeaconPort;
00043	
00044		BroadcastBeacon(Addr);
00045	    */
00046	}
00047	
00048	function Destroyed()
00049	{
00050		//log( "ClientBeaconReceiver finished." );
00051	}
00052	
00053	function Timer()
00054	{
00055		local int i, j;
00056	    local IpAddr Addr;
00057	
00058		for( i=0; i<arraycount(Beacons); i++ )
00059			if
00060			(	Beacons[i].Addr.Addr!=0
00061			&&	Level.TimeSeconds-Beacons[i].Time<BeaconTimeout )
00062				Beacons[j++] = Beacons[i];
00063		for( j=j; j<arraycount(Beacons); j++ )
00064			Beacons[j].Addr.Addr=0;
00065	
00066		Addr.Addr = BroadcastAddr;
00067		Addr.Port = ServerBeaconPort;
00068		BroadcastBeacon(Addr);
00069	}
00070	
00071	function BroadcastBeacon(IpAddr Addr)
00072	{
00073		SendText( Addr, "REPORT" );	
00074	}
00075	
00076	event ReceivedText( IpAddr Addr, string Text )
00077	{
00078		local int i, n;
00079		
00080		n = len(BeaconProduct);
00081		if( left(Text,n+1) ~= (BeaconProduct$" ") )
00082		{
00083			Text = mid(Text,n+1);
00084			Addr.Port = int(Text);
00085			for( i=0; i<arraycount(Beacons); i++ )
00086				if( Beacons[i].Addr==Addr )
00087					break;
00088			if( i==arraycount(Beacons) )
00089				for( i=0; i<arraycount(Beacons); i++ )
00090					if( Beacons[i].Addr.Addr==0 )
00091						break;
00092			if( i==arraycount(Beacons) )
00093				return;
00094			Beacons[i].Addr      = Addr;
00095			Beacons[i].Time      = Level.TimeSeconds;
00096			Beacons[i].Text      = mid(Text,InStr(Text," ")+1);
00097		}
00098	}
00099	
00100	defaultproperties
00101	{
00102	    ParseOption=
00103	}

End Source Code