DeveloperGuide/GameConnectionDetection

(DeveloperGuide/GameConnectionDetection@groupWiki:goim) 458 Hits - Changes: 3 - Last Change: 2006-07-16 11:27:01 by Herbert Poul (Kahless) - [ History ] [ Latest changes ]

To detect game connections there are currently two separate classes making use of the Java Native Interface to make calls to a small library programmed in C/C++.

Both of the native code is located in the net.sphene.goim.netstat project. It contains a .dev file for both projects. (a dev-C++ project file - see: http://www.bloodshed.net/devcpp.html)

Netstat

The first native class is a netstat like implementation - java class: net.sphene.goim.netstat.NetStat

It has two native methods:

the second one is deprecated and nowhere used.. and therefore i won't explain it.. it might even be removed when you read this ;)

the first one - private native void nativeGetUdpPortsApps(); will get called periodically and it's task is to retrieve all open UDP ports and for those UDP ports retrieve the full path of the executable which owns this port.

As soon as it has those two informations (port and executable) it has to call the java method:

to let the java class know which udp ports are bound. (for every call to 'nativeGetUdpPortsApps()' the native interface has to call the method addUdpPortApp(...) for EVERY open udp port.. no matter if it was already detected in an earlier run.. (ie. the native interface does not need to remember anything .. just retrieve all information on each run))

So the java application now knows which applications have which UDP ports. The missing information is to which server those applications are connected. This is the responsibility of the second class:

SniffUdpConns

As said before the responsibility of net.sphene.goim.sniffudpconns.SniffUdpConns is to sniff UDP packets which are sent or received on the local UDP port bound by a game.

This class has one native method:

this method will be called in a separate thread and should have an endless loop and never return. (the 'String' return value was just for testing purposes and not needed at all)

the method should sniff all outgoing UDP connections and compare them to the conns field of this class:

/**
 * List of all connections, a 2 dimensional array.
 * the elements for one connection are the 4 bytes of an IP plus the port 
 */
protected int[][] conns = new int[0][0];

if one outgoing packet matches this conns list.. it should call the method:

IP field will get decoded the following way:

byte ip[] = {
(ip >> 24) & 0xFF,
(ip >> 16) & 0xFF,
(ip >> 8)  & 0xFF,
ip         & 0xFF
};

Please Note: the native method has to reload the 'conns' array itself.. periodically (the current windows implementation fetches the conns array each time it sniffs a udp packet) - but.. while fetching this array make sure it is locked.. e.g.:

env->MonitorEnter( obj );
jobjectArray connsarray = (jobjectArray)env->GetObjectField(obj, fid_conns);
/* convert the java connsarray to a C++ int[][] */
env->MonitorExit( obj );


0 Comments
You need to be logged in to post a Comment !