Creating Your Own Travian Utilities in .NET
By Amgad Suliman
Travian the well known browser game has a downloadable file for developers in each of its servers that provides details of all the players of the server. The file contains a list of SQL INSERT statements, one for each player. Although the statement doesn't provide military or attack information, that can be used to cheat in the game, it provide enough information to draw your own maps and create analysis tools for the villages, players, and alliances. The file name is map.sql, for example the full URL of the file for the com4 server will be ‘http://s4.travian.com/map.sql’. By the way, the map files of the German servers used to be karte.sql, but they changed it to map.sql too. The following is an example of the contents (I inserted a line break before the VALUES clause for readability): view plaincopy to clipboardprint? 1. INSERT INTO `x_world` 2. VALUES (1517,315,399,3,181705,'New Remial',82126,'Tale',0,'',273); 3. INSERT INTO `x_world` 4. VALUES (67792,107,316,1,175829,'3.Clay',35440,'salvaje_jabali',0,'',244); 5. INSERT INTO `x_world` 6. VALUES (32790,349,360,1,189271,'Lumeria',9702,'Aquifel',90,'APE',20); 7. INSERT INTO `x_world` 8. VALUES (72449,-42,310,1,194313,'New village',2634,'paloc',0,'',24); 9. INSERT INTO `x_world` 10. VALUES (75669,-26,306,1,170802,'Yao Ming',2634,'paloc',0,'',330); INSERT INTO `x_world` VALUES (1517,315,399,3,181705,'New Remial',82126,'Tale',0,'',273); INSERT INTO `x_world` VALUES (67792,107,316,1,175829,'3.Clay',35440,'salvaje_jabali',0,'',244); INSERT INTO `x_world` VALUES (32790,349,360,1,189271,'Lumeria',9702,'Aquifel',90,'APE',20); INSERT INTO `x_world` VALUES (72449,-42,310,1,194313,'New village',2634,'paloc',0,'',24); INSERT INTO `x_world` VALUES (75669,-26,306,1,170802,'Yao Ming',2634,'paloc',0,'',330); The fields are: * ID: Number of the field, starts in the top left corner at the coordinate (-400|400) and ends in the bottom right corner at (400|-400). * X: X-Coordinate of the village. * Y: Y-Coordinate of the village. * TID: The tribe number. 1 = Roman, 2 = Teuton, 3 = Gaul, 4 = Nature and 5 = Natars * VID: Village number. The unique ID for the village. * Village: The name of the village. * UID: The player’s unique ID, also known as User-ID. * Player: The player name. * AID: The alliance’s unique ID. * Alliance: The alliance name. * Population: The village’s number of inhabitants without the troops. The SQL code needed to create the table to hold this data is: view plaincopy to clipboardprint? 1. CREATE TABLE [dbo].[x_world]( 2. [worldid] [tinyint] NULL, 3. [id] [int] NULL, 4. [x] [smallint] NULL, 5. [y] [smallint] NULL, 6. [tid] [tinyint] NULL, 7. [vid] [int] NULL, 8. [village] [nvarchar](50) NULL, 9. [uid] [int] NULL, 10. [player] [nvarchar](50) NULL, 11. [aid] [int] NULL, 12. [alliance] [nvarchar](20) NULL, 13. [population] [smallint] NULL 14. ) CREATE TABLE [dbo].[x_world]( [worldid] [tinyint] NULL, [id] [int] NULL, [x] [smallint] NULL, [y] [smallint] NULL, [tid] [tinyint] NULL, [vid] [int] NULL, [village] [nvarchar](50) NULL, [uid] [int] NULL, [player] [nvarchar](50) NULL, [aid] [int] NULL, [alliance] [nvarchar](20) NULL, [population] [smallint] NULL ) The following code downloads the map.sql file, opens it for reading, and runs each line as a separate INSERT statement. Although the code is ASP.NET, it can be changed to a Windows Forms app easily. view plaincopy to clipboardprint? 1. using System.Net; //to download the file 2. using System.Data.SqlClient; //to run the INSERT statement 3. using System.Configuration; //to read the connection string from web.config 4. using System.IO; //to open the downloaded file 5. 6. ... 7. 8. public partial class travian : System.Web.UI.Page 9. { 10. 11. ... 12. 13. private static void GetTravianMap() 14. { 15. //get the directory of the web app 16. string mapFile = HttpContext.Current.Request.PhysicalApplicationPath 17. + "\\map.sql"; 18. WebClient client = new WebClient(); 19. 20. //download the file to the specified location, using HTTP 21. client.DownloadFile("http://s4.travian.com/map.sql", mapFile); 22. 23. SqlConnection aspNetDb = new SqlConnection( 24. ConfigurationManager.ConnectionStrings["DBConStr"].ConnectionString); 25. SqlCommand cmd = new SqlCommand(); 26. cmd.Connection = aspNetDb; 27. aspNetDb.Open(); 28. 29. StreamReader sr = new StreamReader(mapFile); 30. 31. string line; 32. 33. //loop thru the lines in the file 34. while ((line = sr.ReadLine()) != null) 35. { 36. //Remove the back tick from the name of the table, because this only 37. //works with MySQL, in SQL Server this throws an error 38. line = line.Replace("`", ""); 39. 40. cmd.CommandText = line; 41. cmd.ExecuteNonQuery(); 42. } 43. 44. aspNetDb.Close(); 45. } 46. } using System.Net; //to download the file using System.Data.SqlClient; //to run the INSERT statement using System.Configuration; //to read the connection string from web.config using System.IO; //to open the downloaded file ... public partial class travian : System.Web.UI.Page { ... private static void GetTravianMap() { //get the directory of the web app string mapFile = HttpContext.Current.Request.PhysicalApplicationPath + "\\map.sql"; WebClient client = new WebClient(); //download the file to the specified location, using HTTP client.DownloadFile("http://s4.travian.com/map.sql", mapFile); SqlConnection aspNetDb = new SqlConnection( ConfigurationManager.ConnectionStrings["DBConStr"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = aspNetDb; aspNetDb.Open(); StreamReader sr = new StreamReader(mapFile); string line; //loop thru the lines in the file while ((line = sr.ReadLine()) != null) { //Remove the back tick from the name of the table, because this only //works with MySQL, in SQL Server this throws an error line = line.Replace("`", ""); cmd.CommandText = line; cmd.ExecuteNonQuery(); } aspNetDb.Close(); } } The GetTravianMap() function can be run in a regular interval to keep the data in the table current with the game. The DownloadFile() function replaces the local copy of the file without raising an error, so there is no need to check if a file exists and delete it. But the data downloaded previously should be deleted, or normalized because the a server can have more than 20,000 members and this could increase the database size drastically. To get more details about the servers, their update time, and examples in PHP follow this link to the Travian Help website: http://help.travian.com/index.php?type=faq&mod=230
This intel first appeared on: http://amgadhs.com/index.php/2008/10/creating-your-own-travian-util...
|