Projet simple mais nul en réseau

svincent9 Messages postés 1 Date d'inscription jeudi 5 juin 2003 Statut Membre Dernière intervention 1 juin 2004 - 1 juin 2004 à 11:51
gnienfo Messages postés 8 Date d'inscription lundi 12 juillet 2004 Statut Membre Dernière intervention 3 mai 2005 - 13 juil. 2004 à 11:03
Etant plutôt débutant en programmation (je ne connais que le C "de base") et totalement ignorant en programmation réseau, j'ai pensé faire appel à vous pour un petit projet perso où il est question de protocole UDP, liaison et port réseau.

Je vous explique : le récent simulateur de vol IL2 Forgotten Battles dipsose de la capacié d'exporter les paramètres de vol de l'avion piloté par le joueur. Il les exporte via un protocole UDP sur un port spécifié. Je voudrais savoir comment récupérer ces données.

Voici un extrait du readme.txt du jeu :
<<
The DeviceLink interface is meant to provide the third-party software with the
current condition of the player's aircraft as well as allow an unified method of
connecting alternative operating controls.

DeviceLink utilizes the UDP protocol to transfer the data. In this network, IL2
plays a part of the server. The external application sends a query packet, in
reply, IL2 sends back one (or several) packets containing the query result.
Proposing using the protocol within a single computer, ar a local network, no
data encoding is used and data integrity CRC-checks are not taken. Packets do
contain only symbolic information, the allowed range is (0x21-0x7e). A query
packet is preceded with an 'R' symbol, the resulting packed is preceded with an
'A'; followed by one or several "key"/"value" pairs. The "key" is the number
identifying a parameter. The "value" may be omitted or consist of a number of
copies. The semantics of the "value" depends on the parameter itself. The "keys"
are preceded with a '/', the "values" are preceded with a '\'. If a "value" is
to contain one of these symbols, it is preceded with a '\'. There are two types
of "keys" - (get) requiring to return the value of the given parameter, and
(set) setting the given parameter. The (get) keys are even while the latter ones
are odd. "Get-keys" may contain values for the specified parameter, the answer
packet returns the "value" with the "get-key". "Set-keys" may contain values for
the parameter, but with these the reply contains none.

Ex.:

key 40 - altimeter
key 81 - power
Query packet - R/40/81\1.6e-1
Return the aircraft altitude, and set the power to 1.6e-1.
Reply (answer) packet - A/40\534.3
Returns the current altitude 534.3 meters MSL.

The DeviceLink interface is activated if the [DeviceLink] section is found in the
conf.ini file. Within this section, "port" specifies the number of UDP port for
data transfer.
Using "host" parameter one can specify the address of the network interface in
use.
The "IPS" parameter restricts the allowed client IP addresses. If the "IPS"
parameter is not found in the section, any IP address is allowed to connect.

Ex.:

[DeviceLink]
port=10000
IPS=10.1.1.3 10.1.1.8

Port number is 10000, allowed clients are 10.1.1.3 and 10.1.1.8.
..........
(suite du readme.txt)
..........

Parameters - instruments readings.

speedometer_indicated
30 get()
return: float [km/h] +0.00 +inf

altimeter
40 get()
return: float [m] +0.00 +inf
>>

Ce que j'aimerais faire, c'est avoir un programme qui tourne en parallèle du jeu sur la même machine et qui récupère certaines données. Par exemple, on va dire que ce programme devrait interroger le jeu 1 fois par seconde pour connaitre la vitesse (résultat de speedometer_indicated ci-dessus) et l'altitude (résultat de altimeter ci-dessus), lire les réponses exportées par le jeu, et les inscrire dans un fichier texte.

Est-ce-que quelqu'un sait comment réaliser un tel programme en C (pour que je puisse le comprendre et ensuite l'adapter) ? Merci d'avance.

1 réponse

gnienfo Messages postés 8 Date d'inscription lundi 12 juillet 2004 Statut Membre Dernière intervention 3 mai 2005
13 juil. 2004 à 11:03
salut,

je pense que tu as moyen d'utiliser la libpcap ou winPcap (zindoz) qui est une librairie de fonctions pour recuperer tes paquets. Ensuite vu que tu as ton paquet dans un buffer, tu peux aller chercher les champs qui t'interressent (speedometer etc...)

la voila un tuto pas mal pour se familiariser avec les paquets et les sockets:
http://freecodz.net/articles/SocketTuto.html

la un tuto sur la libpcap pour comprendre les fonctions:
http://coding.romainl.com/article52.html

sinon un dernier tuto pour programmer un sniffer de paquet:
http://coding.romainl.com/article67.html

apres avoir recuperer tes paquets, il va falloir que tu cherches dedans pour savoir ou sont les infos qui t'interressent, enfin ca ce n'est pas le plus complique je pense...

voila je pense que tu as pas mal de lecture.
bon courage!
0
Rejoignez-nous