Jump to content

Recommended Posts

I need something that will add some functions to our forum (Same kind as this one) for an onlune game. I need it to connect to a web site and download a file, and update the mysql database with the information in the file every hour. I need it to add the ability for users to put [player]player name[/player] and it link the player name with their profile in the game, [village]coordinates[/village] and it link to the village, [ally]tribe tag[/ally] and link to the tribe's profile etc. I'm not sure if I'm doing it right and have no idea how to test it. I have done computer programming but not with this specifically. Here's what I have so far:

 

$lines = gzfile('http://tw4c.tribalwars.net/map/village.txt.gz', 'r');

if(!is_array($lines)) die("File could not be opened");

foreach($lines as $line) {

list($id, $name,$x, $y, $player, $points, $rank) = explode(',', $line);

$name = urldecode($name);

 

$name = addslashes($name);

mysql_query("INSERT INTO village SET id='$id', name='$name', x='$x', y='$y',

player='$player', points='$points', rank='$rank'");

}

 

Villages

$lines = gzfile('http://tw4c.tribalwars.net/map/tribe.txt.gz', 'r');

if(!is_array($lines)) die("File could not be opened");

foreach($lines as $line) {

list($id, $name, $ally, $villages, $points, $rank) = explode(',', $line);

$name = urldecode($name);

 

$name = addslashes($name);

mysql_query("INSERT INTO village SET id='$id', name='$name', ally='$ally', villages'$villages',

points='$points', rank='$rank'");

}

 

$lines = gzfile('http://tw4c.tribalwars.net/map/ally.txt.gz', 'r');

if(!is_array($lines)) die("File could not be opened");

foreach($lines as $line) {

list($id, $name,$tag, $members, $villages, $points, $all_points, $rank) = explode(',', $line);

$name = urldecode($name);

 

$name = addslashes($name);

mysql_query("INSERT INTO village SET id='$id', name='$name', tag='$tag', members='$members',

villages='$villages', points='$points', all_points=$all_points, rank='$rank'");

}

 

The web site with the files to download is here:

http://tw4c.tribalwars.net/staemme.php?village=37694&screen=overview

 

Here's what the game creator says on that page:

For the creation external statistics, we provide the most important world data for download. The attributes of the villages, tribes and players are offered for download regularly.

 

Please load the world statistics only as often as you really need to. Scripts which load the statistics more than once per hour in regular operation are not allowed. In this case try to cache the data to an external webserver. The world statistics are updated at regular intervals, which depend on the particular server.

 

The files are also available compressed as .txt.gz files. If possible, please do use these files.

 

There are three files available for download. Each file consists of an arbitrary number of lines separated by commas. The individual data are coded with the PHP function urlencode(), which means for example that a comma is represented by %2C.

/map/village.txt - /map/village.txt.gz

 

This file contains information about the villages. The data are available in the following order:

 

$id, $name, $x, $y, $tribe, $points, $rank

 

/map/tribe.txt - /map/tribe.txt.gz

 

This file contains information about the players. The data are available in the following order:

 

$id, $name, $ally, $villages, $points, $rank

 

/map/ally.txt - /map/ally.txt.gz

 

This file contains information about Tribal Wars. The data are sorted in the following order:

 

$id, $name, $tag, $members, $villages, $points, $all_points, $rank

 

Example

 

A simple example in PHP to write the villages and their names into a MySQL-database:

 

$lines = gzfile('http://ds1.die-staemme.de/map/village.txt.gz', 'r');

if(!is_array($lines)) die("File could not be opened");

foreach($lines as $line) {

list($id, $name,$x, $y, $player, $points, $rank) = explode(',', $line);

$name = urldecode($name);

 

$name = addslashes($name);

mysql_query("INSERT INTO village SET id='$id', name='$name', x='$x', y='$y',

player='$player', points='$points', rank='$rank'");

}

 

Please help.

Link to comment
https://forums.phpfreaks.com/topic/50098-new-to-this/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.