<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AUDP_Based_Advert_System</id>
	<title>Scripts:UDP Based Advert System - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AUDP_Based_Advert_System"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:UDP_Based_Advert_System&amp;action=history"/>
	<updated>2026-08-06T00:35:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:UDP_Based_Advert_System&amp;diff=128&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__ == Introduction ==  There are many ways to implement an advert system in BF2. A good way would probably be to use the RCON interface. But another one that might be wor...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:UDP_Based_Advert_System&amp;diff=128&amp;oldid=prev"/>
		<updated>2018-06-22T15:36:09Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ == Introduction ==  There are many ways to implement an advert system in BF2. A good way would probably be to use the RCON interface. But another one that might be wor...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
There are many ways to implement an advert system in BF2. A good way would probably be to use the RCON interface. But another one that might be worth playing around with, is a solution where you create a dedicated &amp;#039;&amp;#039;advert port&amp;#039;&amp;#039; on the server, and send messages to it at will, using a suitable client.&lt;br /&gt;
&lt;br /&gt;
== Server Code == &lt;br /&gt;
&lt;br /&gt;
The idea is to let the server listen on a port bound to the &amp;#039;localhost&amp;#039; interface, and read messages off that port, and post them to the players. The socket does of course need to be non-blocking, or it will interfere with the server. But I have no idea if the solution is to use a timer, like this code does. But this at least shows the consept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import socket&lt;br /&gt;
import host&lt;br /&gt;
import bf2&lt;br /&gt;
&lt;br /&gt;
port = 29600&lt;br /&gt;
addr = (&amp;#039;localhost&amp;#039;,port)&lt;br /&gt;
bufsize = 1024&lt;br /&gt;
&lt;br /&gt;
s = None&lt;br /&gt;
msgtimer = None&lt;br /&gt;
&lt;br /&gt;
def init():&lt;br /&gt;
   global s, msgtimer&lt;br /&gt;
   print &amp;quot;Initializing the &amp;#039;advert client&amp;#039; script.&amp;quot;&lt;br /&gt;
   s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)&lt;br /&gt;
   s.setblocking(0)&lt;br /&gt;
   s.bind(addr)&lt;br /&gt;
   msgtimer = bf2.Timer(read,1,1)&lt;br /&gt;
   msgtimer.setRecurring(1)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def read(data):&lt;br /&gt;
   if not s: return&lt;br /&gt;
   try:&lt;br /&gt;
      msg, client = s.recvfrom(bufsize)&lt;br /&gt;
   except:&lt;br /&gt;
      return False&lt;br /&gt;
   if msg:&lt;br /&gt;
      host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;&amp;quot; + str(msg) + &amp;quot;\&amp;quot;&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== Client Code ==&lt;br /&gt;
&lt;br /&gt;
The client can be as easy or complex as anyone wish. This is the simplest possible client:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python import socket  HOST = &amp;#039;localhost&amp;#039; PORT = 29600  print &amp;quot;Creating client socket.&amp;quot; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print &amp;quot;Sending data to server.&amp;quot; s.sendto(&amp;quot;Hi. I&amp;#039;m an advert client sending data to the server.&amp;quot;, (HOST,PORT)) print &amp;quot;Closing socket.&amp;quot; s.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>