]> jfr.im git - irc/gameservirc.git/commitdiff
finalizing the php scripts
authorkainazzzo <redacted>
Sat, 11 Mar 2006 02:38:26 +0000 (02:38 +0000)
committerkainazzzo <redacted>
Sat, 11 Mar 2006 02:38:26 +0000 (02:38 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@412 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/php/install.php
gameserv/php/mysql.php
gameserv/php/readdata.php [new file with mode: 0644]
gameserv/php/readitems.php [new file with mode: 0644]
gameserv/php/readplayers.php [new file with mode: 0644]

index 1f6a3245aa8a2cb7388c76871de0cb32629c8411..9f2e858d8d9fda6097b9443d14673309f246b3d7 100644 (file)
@@ -1,6 +1,19 @@
 <?php
-    include ('mysql.php');
+include ('mysql.php');
 
-$query = "CREATE Table `players` (`name` text, `level` int NOT NULL default 1, `exp` bigint NOT NULL default 0, `gold` bigint NOT NULL default 0, `bank` bigint NOT NULL default 0, `hp` int NOT NULL default 0, `maxhp` int NOT NULL default 0, `strength` int NOT NULL default 0, `defense` int NOT NULL default 0, `forestfights` int NOT NULL default 0, `playerfights` int NOT NULL default 0, `lastlogin` text, `weapon` text NOT NULL, `armor` text NOT NULL, PRIMARY KEY (`name`(255))) ENGINE=InnoDB DEFAULT CHARSET=latin1";
 
+$query = "CREATE Table `$itemtablename` (`id` bigint NOT NULL auto_increment, `name` text NOT NULL, `price` bigint NOT NULL default 0, `uses` int NOT NULL, `strengthmod` int NOT NULL default 0, `defensemod` int NOT NULL default 0, `maxhpmod` int NOT NULL default 0, `hpmod` int NOT NULL default 0, `forestfightsmod` int NOT NULL default 0, `playerfightsmod` int NOT NULL default 0, `goldmod` bigint NOT NULL default 0, `bankbalmod` bigint NOT NULL default 0, PRIMARY KEY (`id`)) ENGINE=InnoDB";
+
+mysql_query($query) or die("Couldn't create table $itemtablename: " . mysql_error());
+
+echo "Item table created.<br>";
+
+$query = "CREATE Table `$playertablename` (`name` text, `level` int NOT NULL default 1, `exp` bigint NOT NULL default 0, `gold` bigint NOT NULL default 0, `bank` bigint NOT NULL default 0, `hp` int NOT NULL default 0, `maxhp` int NOT NULL default 0, `strength` int NOT NULL default 0, `defense` int NOT NULL default 0, `forestfights` int NOT NULL default 0, `playerfights` int NOT NULL default 0, `lastlogin` text, `weaponID` bigint NOT NULL default 0, `armorID` bigint NOT NULL default 0, PRIMARY KEY (`name`(255)), KEY `weaponID` (`weaponID`), KEY `armorID` (`armorID`), CONSTRAINT `" . $playertablename . "_ibfk_1` FOREIGN KEY (`weaponID`) REFERENCES $itemtablename(`id`), CONSTRAINT `" . $playertablename . "_ibfk_2` FOREIGN KEY (`armorID`) REFERENCES $itemtablename(`id`)) ENGINE=InnoDB";
+
+echo "\n $query \n";
+mysql_query($query) or die("Couldn't create table $playertablename: " . mysql_error());
+
+echo "Player table created.<br>";
+
+echo '<a href="readdata.php">Click here to import the data into mysql</a>';
 ?>
\ No newline at end of file
index b46ca1629e6dbd75de8349f1fd9c946a16a23b34..961fb2892ef1b9238c48b05458eb867631e68f1c 100644 (file)
@@ -1,5 +1,5 @@
 <?php
     include ('config.php');
-    $link = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpassword") or die ('Couldn't connect: ' . mysql_error());
+    $link = mysql_connect("$mysqlhost", "$mysqluser", "$mysqlpassword") or die ("Couldn't connect: " . mysql_error());
     mysql_select_db("$mysqldatabase") or die ('Could not select database: ' . mysql_error());
 ?>
\ No newline at end of file
diff --git a/gameserv/php/readdata.php b/gameserv/php/readdata.php
new file mode 100644 (file)
index 0000000..0495a8b
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+include('readitems.php');
+include('readplayers.php');
+?>
\ No newline at end of file
diff --git a/gameserv/php/readitems.php b/gameserv/php/readitems.php
new file mode 100644 (file)
index 0000000..de5b831
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+$include ('mysql.php');
+// type~ID~name~price~uses~strengthmod~defensemod~maxhpmod~hpmod~forestfightsmod~playerfightsmod~goldmod~bankbalmod
+
+$handle = @fopen("$itemdata", "r");
+if ($handle) {
+  while (!feof($handle)) {
+       $buffer = fgets($handle, 4096);
+       $item = explode(" ", $buffer, 13);
+       $id = $item[1];
+       $name = $item[2];
+       $price = $item[3];
+       $uses = $item[4];
+       $strengthmod = $item[5];
+       $defensemod = $item[6];
+       $maxhpmod = $item[7];
+       $hpmod = $item[8];
+       $forestfightsmod = $item[9];
+       $playerfightsmod = $item[10];
+       $goldmod = $item[11];
+       $bankbalmod = $item[12];
+       $query = "insert into $itemtablename values ('$id', '$name', '$price', '$uses', '$strengthmod', '$defensemod', '$maxhpmod', '$hpmod', '$forestfightsmod', '$playerfightsmod', '$goldmod', '$bankbalmod')";
+       mysql_query($query);
+  }
+  mysql_close($link);
+  fclose($handle);
+}
+?>
\ No newline at end of file
diff --git a/gameserv/php/readplayers.php b/gameserv/php/readplayers.php
new file mode 100644 (file)
index 0000000..dd08722
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+$handle = @fopen("$playerdata", "r");
+if ($handle) {
+  while (!feof($handle)) {
+       $buffer = fgets($handle, 4096);
+       $player = explode(" ", $buffer, 16);
+       $player_name = $player[0];
+       $player_level = $player[1];
+       $player_exp = $player[2];
+       $player_gold = $player[3];
+       $player_bank = $player[4];
+       $player_hp = $player[5];
+       $player_maxhp = $player[6];
+       $player_strength = $player[7];
+       $player_defense = $player[8];
+       $player_forestfights = $player[9];
+       $player_playerfights = $player[10];
+       $player_lastlogin = $player[13];
+       $player_weaponnum = $player[14];
+       $player_armornum = $player[15];
+  }
+  fclose($handle);
+  mysql_close($link);
+}
+?>