
A few days ago the news appeared on Habré:
Settlers is now online !
The game is written in flex, therefore, it will work on almost any modern platform. But the beta-version of the game leaves its mark - much has not been finalized, but something is just unstable. The interface is also completely user friendly.
No economic strategy is complete without trade. In the future, it is possible to create mono-villages, extracting one type of resource, exchanging the rest through the market. For a slight simplification of trading, as well as proof of concept, I decided to write the simplest utility possible.
So how does the customer know about the assortment on the market?
The easiest way to find out is to put a sniffer and see what happens between the client and the server. After testing several paid, but absolutely not justifying its cost programs, I returned to the proven free
Wireshark . He will allow to see what is hidden.
Installing Wireshark does not cause problems, let's start sniffing right away. To do this, simply select the interface in the settings through which the communication takes place. To do this, you can use the Ctrl + I combination, or the Capture menu item -> Interfaces.
')

You do not need to make any additional settings at this stage, click Start opposite the active interface.
Something like this appears in the main window:

Of course, most of this information is absolutely not necessary for us, since the activity of torrents, downloaders, and other living creatures is displayed here. Filter out the packets in which the ip matches the ip of the xmpp server of the game (both chat and trading are based on this protocol, with some changes):

Of all the packages, we are interested in HTTP / XML, from which Wireshark allows us to immediately extract information, at the same time we remove outgoing packets, which in this case contain no interesting information for us. To do this, change the filter to “ip.src == 87.119.203.13 and xml”:

Now, looking through any of these packages, we will see something like (the brackets are changed to display correctly):
eXtensible Markup Language
[body xmlns='http://jabber.org/protocol/httpbind']
[message xmlns="jabber:client" to="dim0n@87.119.203.13/xiff-bosh" id="m_3115" type="groupchat" from="trade@conference.87.119.203.13/pimo"]
[body]Coin|1|Stone|200[/body]
[bbmsg xmlns="bbmsg" playername="Pimo" playerid="85153"/]
[/message]
[/body]
From this message it is clear that for 1 coin (Coin | 1) the player wants to receive 200 stones (Stone | 200). Not the best deal, but not the essence. In this format, all trade messages are transmitted. In general, they can be described by the regular expression \ w + \ | \ w + \ | \ w + \ | \ w +.
So, we are almost at the finish line. We have learned how to receive trade messages and can display them beautifully. But any information is good when it is relevant. The Wirecark software package includes the dumpcap.exe utility. It will allow us to write the necessary packets without, in fact, running Wireshark itself. I will not describe the arguments for the launch, you can learn about them from the help, I also got the string
-i \ Device \ NPF_ {4DC422B9-3A2E-4899-9775-2DD89AF02FDD} -f "host 87.119.203.13" -w C: \ Users \ Dim0N \ Desktop \ 323232my . Packages will be added to the 323232my file (no, I don’t have a justification for the name).
I will process the received information in C #. To do this, create a DataGridView with the columns “Purchase”, “Purchase price”, “Sale”, “Sale price”. On a timer, every 5 seconds we check new packages from a file.
public Form1()
{
InitializeComponent();
timer1.Start();
timer1.Interval = 5000;
Process.Start( @"C:\Users\Dim0N\Desktop\2\WiresharkPortable\App\Wireshark\dumpcap.exe" ,
"-i \\Device\\NPF_{4DC422B9-3A2E-4899-9775-2DD89AF02FDD} -f \"host 87.119.203.13\" -w C:\\Users\\Dim0N\\Desktop\\323232my" ); // dumpcap .
}
* This source code was highlighted with Source Code Highlighter .
Every 5 seconds the following code is executed:
private void timer1_Tick( object sender, EventArgs e)
{
File .Copy( @"C:\Users\Dim0N\Desktop\323232my" , @"C:\Users\Dim0N\Desktop\323232mycopy" , true ); // , , dumpcamp
var streamReader = new StreamReader( @"C:\Users\Dim0N\Desktop\323232mycopy" );
string str = streamReader.ReadToEnd(); //
streamReader.Close();
int i = 0;
dataGridView1.Rows.Clear(); // ,
foreach ( var match in Regex.Matches(str, @"\w+\|\w+\|\w+\|\w+" )) //
{
string matchstr = match.ToString(); //
dataGridView1.Rows.Add(matchstr.Split( '|' )[0], matchstr.Split( '|' )[1], matchstr.Split( '|' )[2], matchstr.Split( '|' )[3]); // ,
if ((matchstr.Split( '|' )[0] == matchstr.Split( '|' )[2]) && ( Convert .ToInt32(matchstr.Split( '|' )[1]) < Convert .ToInt32(matchstr.Split( '|' )[3]))) // , , ( 100 10 )
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red; //
}
i += 1;
}
* This source code was highlighted with Source Code Highlighter .
As a result, we have a table that allows us to sort, select the most advantageous offers and process information as we like:
