From 896c438f04aa45c791689c9756b5d39259f7e6f4 Mon Sep 17 00:00:00 2001 From: Alexander Matthes Date: Thu, 12 Dec 2019 22:11:32 +0100 Subject: [PATCH] Ported the server to php7 and moved to different server per default --- ToDo | 1 - about.h | 3 +-- build/pandora/hase/PXML.xml | 12 +++++++++--- client.c | 1 + client.h | 4 ++-- hase_readme.txt | 10 ++++++++-- make_release_packages.sh | 2 +- options.c | 25 ++++++++++++++++++++++++- options.h | 2 ++ server/INIT_SERVER.php | 29 +++++++++++++++-------------- server/change_game.php | 14 ++++++-------- server/create_game.php | 15 +++++++-------- server/delete_game.php | 15 +++++++-------- server/get_game.php | 17 ++++++++--------- server/get_games.php | 25 ++++++++++++------------- server/heartbeat.php | 11 +++++------ server/join_game.php | 21 ++++++++++----------- server/kick.php | 17 ++++++++--------- server/leave_game.php | 21 ++++++++++----------- server/notify.php | 19 +++++++++---------- server/pull_game.php | 26 ++++++++++++++------------ server/push_game.php | 27 +++++++++++++-------------- server/set_level.php | 15 +++++++-------- server/set_status.php | 23 +++++++++++------------ server/utils.php | 4 ++-- 25 files changed, 192 insertions(+), 167 deletions(-) diff --git a/ToDo b/ToDo index 8b13789..e69de29 100644 --- a/ToDo +++ b/ToDo @@ -1 +0,0 @@ - diff --git a/about.h b/about.h index 77e5efe..54f0328 100644 --- a/about.h +++ b/about.h @@ -5,10 +5,9 @@ #include "client.h" #include "lobbyList.h" -#define VERSION "1.6.5" +#define VERSION "1.6.7" void start_about(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h )); void start_help(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h )); #endif - diff --git a/build/pandora/hase/PXML.xml b/build/pandora/hase/PXML.xml index 41feb69..fee98cd 100644 --- a/build/pandora/hase/PXML.xml +++ b/build/pandora/hase/PXML.xml @@ -1,7 +1,7 @@ - + @@ -17,6 +17,12 @@ The used fonts are Pixel Mania by HiBan (CC-BY-SA) and DejaVu Sans (Public Domai Changelog ========= +1.6.7: +- Ported the server to php7 and moved to different server per default + +1.6.6: +- Connecting to another IRC port of one is not working + 1.6.5: - Improved camera handling, especially for small device screens @@ -314,7 +320,7 @@ Changelog - health - more weapon points - mine - + 1.4.7.2 - Added button arrow images to sparrow3d and use them now in hase in the help @@ -384,7 +390,7 @@ Changelog </package> <application id="hase_prototype-hase_prototype-12345" appdata="hase_prototype"> <exec command="./hase.sh"/> -<version major="1" minor="6" release="5" build="0" type="release"/> +<version major="1" minor="6" release="7" build="0" type="release"/> <!--This program's version--> <osversion major="1" minor="0" release="0" build="0"/> <!--The minimum OS version required--> diff --git a/client.c b/client.c index 88f67f0..24a757e 100644 --- a/client.c +++ b/client.c @@ -192,6 +192,7 @@ pMessage sendMessage(pMessage message,char* binary_name,void* binary,int count,c spNetSendTCP(server_connection,buffer,length); int res = spNetReceiveHTTP(server_connection,buffer,buffer_size-1); buffer[res] = 0; + //printf("\n%s\n",buffer); spNetCloseTCP(server_connection); //HTTP error check + jumping to begin if ( diff --git a/client.h b/client.h index 2386161..91b8fc0 100644 --- a/client.h +++ b/client.h @@ -6,7 +6,7 @@ #include <sparrow3d.h> #include <string.h> -#define CLIENT_VERSION 17 +#define CLIENT_VERSION 18 #define TRACE_COUNT 16 @@ -100,7 +100,7 @@ typedef struct sHare int hops; int high_hops; int health; - spSpriteCollectionPointer hase; + spSpriteCollectionPointer hase; pHare before,next; int wp_x,wp_y; Sint32 cam_rotation; diff --git a/hase_readme.txt b/hase_readme.txt index 23fcb7c..d1101ce 100644 --- a/hase_readme.txt +++ b/hase_readme.txt @@ -1,4 +1,4 @@ -Hase +Hase ==== Hase is a game about hares in space. It is a bit like Worms or Artillery, but with gravitation. @@ -9,6 +9,12 @@ The music is from Kevin MacLeod (CC-BY-SA)\nwww.incompetech.com Changelog ========= +1.6.7: +- Ported the server to php7 and moved to different server per default + +1.6.6: +- Connecting to another IRC port of one is not working + 1.6.5: - Improved camera handling, especially for small device screens @@ -307,7 +313,7 @@ Changelog - health - more weapon points - mine - + 1.4.7.2 - Added button arrow images to sparrow3d and use them now in hase in the help diff --git a/make_release_packages.sh b/make_release_packages.sh index e1c2caa..8fe02c4 100755 --- a/make_release_packages.sh +++ b/make_release_packages.sh @@ -1,6 +1,6 @@ #!/bin/bash PROGRAM="hase" -VERSION="1.6.5" +VERSION="1.6.7" DEST=./build/* ZIP_CALL="7z a -t7z -m0=LZMA -mmt=on -mx=9 -md=256m -mfb=512 -ms=on upload.7z" RM_CALL="rm upload.7z" diff --git a/options.c b/options.c index d01afac..382ead7 100644 --- a/options.c +++ b/options.c @@ -21,6 +21,17 @@ int op_game_seconds = 45; int op_game_hares = 3; int op_first_game = 1; int op_sprite = 0; +int op_update_server = 0; + +void sop_update_server(int v) +{ + op_update_server = v; +} + +int gop_update_server() +{ + return op_update_server; +} int gop_first_game() { @@ -266,6 +277,8 @@ void load_options() sop_first_game(atoi(entry->value)); if (strcmp(entry->key,"sprite") == 0) sop_sprite(atoi(entry->value)); + if (strcmp(entry->key,"update_server") == 0) + sop_update_server(atoi(entry->value)); entry = entry->next; } spNetC4AProfilePointer profile; @@ -277,6 +290,15 @@ void load_options() sop_music_volume(gop_music_volume()); sop_sample_volume(gop_sample_volume()); spConfigFree(conf); + if (gop_update_server() == 0) + { + if ( strcmp( gop_server(), "ziz.gp2x.de/hase.php" ) == 0 ) + { + sop_update_server( 1 ); + sop_server("ziz.myftp.info/hase/hase.php"); + save_options(); + } + } } void save_options() @@ -298,6 +320,7 @@ void save_options() spConfigSetInt(conf,"game_hares",op_game_hares); spConfigSetInt(conf,"first_game",op_first_game); spConfigSetInt(conf,"sprite",op_sprite); + spConfigSetInt(conf,"update_server",op_update_server); spConfigWrite(conf); spConfigFree(conf); } @@ -485,7 +508,7 @@ int options_window(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ),in mapping_window(font,resize,0); } if (window->selection == 11 && res == 1) - ret = 1; + ret = 1; } delete_window(window); save_options(); diff --git a/options.h b/options.h index 619cfbd..f9a47a5 100644 --- a/options.h +++ b/options.h @@ -19,6 +19,7 @@ int gop_show_map(); int gop_global_chat(); int gop_first_game(); int gop_sprite(); +int gop_update_server(); void sop_zoom(int v); void sop_circle(int v); @@ -34,6 +35,7 @@ void sop_show_map(int v); void sop_global_chat(int v); void sop_first_game(int g); void sop_sprite(int v); +void sop_update_server(int v); Uint32* gop_game_options_ptr(); int* gop_game_hares_ptr(); diff --git a/server/INIT_SERVER.php b/server/INIT_SERVER.php index 08637fb..9b8e590 100644 --- a/server/INIT_SERVER.php +++ b/server/INIT_SERVER.php @@ -1,8 +1,7 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $query = "CREATE TABLE IF NOT EXISTS `".$mysql_prefix."data_list` (". " `game_id` int(11) NOT NULL,". @@ -10,7 +9,8 @@ " `second_of_player` int(11) NOT NULL,". " `data` mediumblob NOT NULL". ") ENGINE=InnoDB DEFAULT CHARSET=latin1;"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; + $query = "CREATE TABLE IF NOT EXISTS `".$mysql_prefix."game_list` (". "`game_id` int(11) NOT NULL,". " `game_name` varchar(32) NOT NULL,". @@ -22,7 +22,8 @@ " `level_string` varchar(512) NOT NULL,". " `hares_per_player` int(11) NOT NULL". ") ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; + $query = "CREATE TABLE IF NOT EXISTS `".$mysql_prefix."player_list` (". "`player_id` int(11) NOT NULL,". " `game_id` int(11) NOT NULL,". @@ -35,26 +36,26 @@ " `heartbeat_time` int(11) NOT NULL,". " `nr` int(11) NOT NULL". ") ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; $query = "ALTER TABLE `".$mysql_prefix."data_list`". " ADD PRIMARY KEY (`game_id`,`player_id`,`second_of_player`);"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; $query = "ALTER TABLE `".$mysql_prefix."game_list`". " ADD PRIMARY KEY (`game_id`), ADD UNIQUE KEY `game_id` (`game_id`);"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; $query = "ALTER TABLE `".$mysql_prefix."player_list`". " ADD PRIMARY KEY (`player_id`,`game_id`);"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; $query = "ALTER TABLE `".$mysql_prefix."game_list`". " MODIFY `game_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=0;"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; $query = "ALTER TABLE `".$mysql_prefix."player_list`". " MODIFY `player_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=0;"; -mysql_query($query) or die; +mysqli_query($connection, $query) or die; -mysql_close($connection); +mysqli_close($connection); -echo "Success!"; -echo "Delete this file now, you will not need it again!"; +echo "Success!", PHP_EOL; +echo "Delete this file now, you will not need it again!", PHP_EOL; ?> diff --git a/server/change_game.php b/server/change_game.php index a2f1c0e..797cbaa 100644 --- a/server/change_game.php +++ b/server/change_game.php @@ -1,9 +1,8 @@ -<?php +<?php include 'config.php'; include 'utils.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $admin_pw = (int)$_POST['admin_pw']; @@ -12,17 +11,16 @@ $hares_per_player = (int)$_POST['hares_per_player']; $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query($connection, $query) or die; -$row = mysql_fetch_array( $result ); +$row = mysqli_fetch_array( $result ); if ($row['admin_pw'] == $admin_pw) { $query = "UPDATE " . $mysql_prefix . "game_list SET options='$options', seconds_per_turn='$seconds_per_turn', hares_per_player='$hares_per_player' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> - diff --git a/server/create_game.php b/server/create_game.php index b711754..ffd45ac 100644 --- a/server/create_game.php +++ b/server/create_game.php @@ -1,12 +1,11 @@ -<?php +<?php include 'config.php'; include 'utils.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; -$game_name = escape_input($_POST['game_name']); -$level_string = escape_input($_POST['level_string']); +$game_name = escape_input( $connection, $_POST['game_name']); +$level_string = escape_input( $connection, $_POST['level_string']); $options = (int)$_POST['options']; $seconds_per_turn = (int)$_POST['seconds_per_turn']; try { @@ -22,10 +21,10 @@ $query = "INSERT INTO " . $mysql_prefix . "game_list (game_name, options, seconds_per_turn, admin_pw, create_date, status, level_string, hares_per_player) ". "VALUES ( '$game_name', '$options', '$seconds_per_turn', '$admin_pw', '$create_date', '0', '$level_string', '$hares_per_player')"; -mysql_query($query) or die; -$game_id = mysql_insert_id(); +mysqli_query( $connection, $query) or die; +$game_id = mysqli_insert_id( $connection ); echo "game_id: $game_id", PHP_EOL; echo "admin_pw: $admin_pw", PHP_EOL; echo "create_date: $create_date"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/delete_game.php b/server/delete_game.php index 54c4d3d..876c5f7 100644 --- a/server/delete_game.php +++ b/server/delete_game.php @@ -1,29 +1,28 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $admin_pw = (int)$_POST['admin_pw']; $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; -$row = mysql_fetch_array( $result ); +$row = mysqli_fetch_array( $result ); if ($row['admin_pw'] == $admin_pw) { if ($row['status'] == 1) //closing a running game { $query = "UPDATE " . $mysql_prefix . "game_list SET status='-1' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } else { $query = "UPDATE " . $mysql_prefix . "game_list SET status='-2' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } } echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/get_game.php b/server/get_game.php index 4a1c067..f4470c7 100644 --- a/server/get_game.php +++ b/server/get_game.php @@ -1,21 +1,20 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; //Loading game data $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id='$game_id'"; -$result = mysql_query($query) or die; -$game_row = mysql_fetch_assoc( $result ); +$result = mysqli_query( $connection, $query) or die; +$game_row = mysqli_fetch_assoc( $result ); //List of player names and IDs and count player $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; $i = 0; -while ($row = mysql_fetch_array( $result )) +while ($row = mysqli_fetch_array( $result )) { $now = time(); $heartbeat_diff = $now - $row['heartbeat_time']; @@ -23,7 +22,7 @@ { $player_id = $row['player_id']; $query = "DELETE FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } else { @@ -57,5 +56,5 @@ $status = $game_row['status']; echo "status: $status"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/get_games.php b/server/get_games.php index a8658b9..b0a4154 100644 --- a/server/get_games.php +++ b/server/get_games.php @@ -1,15 +1,14 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $now = time(); $query = "SELECT * FROM " . $mysql_prefix . "game_list"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; $i = 0; -while ($row = mysql_fetch_array( $result )) +while ($row = mysqli_fetch_array( $result )) { $game_id = $row['game_id']; $create_date = $row['create_date']; @@ -17,18 +16,18 @@ if ($create_date < $now-3600*24*8) //delete after 8 days { $query = "DELETE FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; $query = "DELETE FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; $query = "DELETE FROM " . $mysql_prefix . "data_list WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; continue; } else if ($create_date < $now-3600*24*7) //mark as deleted after 7 days { $query = "UPDATE " . $mysql_prefix . "game_list SET status='-2' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; continue; } else @@ -38,7 +37,7 @@ $query = "UPDATE " . $mysql_prefix . "game_list SET status='-2' WHERE game_id = '$game_id'"; else $query = "UPDATE " . $mysql_prefix . "game_list SET status='-1' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; continue; } if ($status == -2) @@ -48,8 +47,8 @@ $seconds_per_turn = $row['seconds_per_turn']; $hares_per_player = $row['hares_per_player']; //count player - $subresult = mysql_query("SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); - $subrow = mysql_fetch_assoc($subresult); + $subresult = mysqli_query( $connection, "SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); + $subrow = mysqli_fetch_assoc($subresult); $player_count = $subrow['total']; echo "player_count: $player_count", PHP_EOL; echo "create_date: $create_date", PHP_EOL; @@ -62,5 +61,5 @@ $i = $i + 1; } echo "game_count: $i"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/heartbeat.php b/server/heartbeat.php index 272aa34..f12e24a 100644 --- a/server/heartbeat.php +++ b/server/heartbeat.php @@ -1,8 +1,7 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $player_id = (int)$_POST['player_id']; @@ -10,13 +9,13 @@ //player heartbeat $query = "UPDATE " . $mysql_prefix . "player_list SET heartbeat_time='$now' WHERE game_id = '$game_id' AND player_id = '$player_id'"; -mysql_query($query) or die; +mysqli_query( $connection, $query) or die; //game heartbeat $query = "UPDATE " . $mysql_prefix . "game_list SET create_date='$now' WHERE game_id = '$game_id'"; -mysql_query($query) or die; +mysqli_query( $connection, $query) or die; echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/join_game.php b/server/join_game.php index fff601f..6da94c1 100644 --- a/server/join_game.php +++ b/server/join_game.php @@ -1,24 +1,23 @@ -<?php +<?php include 'config.php'; include 'utils.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; -$player_name = escape_input($_POST['player_name']); +$player_name = escape_input( $connection, $_POST['player_name']); $player_pw = rand(); $computer = (int)$_POST['computer']; $nr = (int)$_POST['nr']; //counting players -$result = mysql_query("SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); -$row = mysql_fetch_assoc($result); +$result = mysqli_query( $connection, "SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); +$row = mysqli_fetch_assoc($result); $player_count = $row['total']; //getting optionss -$result = mysql_query("SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id='$game_id'"); -$row = mysql_fetch_assoc($result); +$result = mysqli_query( $connection, "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id='$game_id'"); +$row = mysqli_fetch_assoc($result); $options = $row['options']; $status = $row['status']; @@ -32,11 +31,11 @@ $query = "INSERT INTO " . $mysql_prefix . "player_list (game_id, player_pw, player_name, position_in_game, computer, chat_get_time, status, heartbeat_time, nr) ". "VALUES ( '$game_id', '$player_pw', '$player_name', '0', '$computer', '0', '0', '$now', '$nr')"; - mysql_query($query) or die; - $player_id = mysql_insert_id(); + mysqli_query( $connection, $query) or die; + $player_id = mysqli_insert_id( $connection ); echo "player_id: $player_id", PHP_EOL; echo "player_pw: $player_pw", PHP_EOL; echo "error: 0"; } -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/kick.php b/server/kick.php index b0b1e24..f1a3dcc 100644 --- a/server/kick.php +++ b/server/kick.php @@ -1,30 +1,29 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $player_id = (int)$_POST['player_id']; $admin_pw = (int)$_POST['admin_pw']; $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; -$row = mysql_fetch_array( $result ); +$row = mysqli_fetch_array( $result ); if ($row['admin_pw'] == $admin_pw) { if ($row['status'] == 0) //Never started { $query = "DELETE FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } else { $query = "UPDATE " . $mysql_prefix . "player_list SET status='-1' WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; - } + mysqli_query( $connection, $query) or die; + } } echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/leave_game.php b/server/leave_game.php index a1c2261..44bb856 100644 --- a/server/leave_game.php +++ b/server/leave_game.php @@ -1,35 +1,34 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $player_id = (int)$_POST['player_id']; $player_pw = (int)$_POST['player_pw']; $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; -$row = mysql_fetch_assoc( $result ); +$row = mysqli_fetch_assoc( $result ); if ($row['player_pw'] == $player_pw) { $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; - $result = mysql_query($query) or die; - $row = mysql_fetch_array( $result ); + $result = mysqli_query( $connection, $query) or die; + $row = mysqli_fetch_array( $result ); if ($row['status'] == 0) //Never started { $query = "DELETE FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } else { $query = "UPDATE " . $mysql_prefix . "player_list SET status='-1' WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; - } + mysqli_query( $connection, $query) or die; + } } echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/notify.php b/server/notify.php index 82c9ea0..5e8084e 100644 --- a/server/notify.php +++ b/server/notify.php @@ -19,14 +19,13 @@ </script> <p>Games on server:</p> <ul> - <?php + <?php include 'config.php'; - $connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; - mysql_select_db($mysql_dbname) or die; + $connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $now = time(); $query = "SELECT * FROM " . $mysql_prefix . "game_list ORDER BY create_date DESC"; - $result = mysql_query($query) or die; - while ($row = mysql_fetch_array( $result )) + $result = mysqli_query($connection, $query) or die; + while ($row = mysqli_fetch_array( $result )) { $status = $row['status']; if ($status == -2) @@ -35,11 +34,11 @@ $game_name = $row['game_name']; switch ($status) { - case 0: - echo "<li><b>$game_name</b> Open</li>", PHP_EOL; + case 0: + echo "<li><b>$game_name</b> Open</li>", PHP_EOL; break; - case 1: - echo "<li><b>$game_name</b> Running</li>", PHP_EOL; + case 1: + echo "<li><b>$game_name</b> Running</li>", PHP_EOL; break; default: $diff = $now - $create_date; @@ -60,7 +59,7 @@ echo '</script>', PHP_EOL; } } - mysql_close($connection); + mysqli_close($connection); ?> </ul> </body> diff --git a/server/pull_game.php b/server/pull_game.php index bcf124a..46e0b38 100644 --- a/server/pull_game.php +++ b/server/pull_game.php @@ -1,8 +1,7 @@ -<?php +<?php //header("Content-type: fun"); include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $player_id = (int)$_POST['player_id']; @@ -10,29 +9,29 @@ $query = "SELECT data FROM " . $mysql_prefix . "data_list WHERE ". "game_id = '$game_id' AND player_id = '$player_id' AND second_of_player = '$second_of_player'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; $heartbeat_diff = 0; -if (mysql_num_rows($result) > 0) +if (mysqli_num_rows($result) > 0) { - $row = mysql_fetch_assoc( $result ); + $row = mysqli_fetch_assoc( $result ); header("Content-length: 1543"); echo 'ACK'; $data = $row['data']; echo $data; $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; - $result = mysql_query($query) or die; - $row = mysql_fetch_assoc( $result ); + $result = mysqli_query( $connection, $query) or die; + $row = mysqli_fetch_assoc( $result ); $now = time(); $heartbeat_diff = $now - $row['heartbeat_time']; } else { $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; - $result = mysql_query($query) or die; - $row = mysql_fetch_assoc( $result ); + $result = mysqli_query( $connection, $query) or die; + $row = mysqli_fetch_assoc( $result ); $now = time(); $heartbeat_diff = $now - $row['heartbeat_time']; @@ -48,7 +47,7 @@ if ($heartbeat_diff > 90) //one and a half minute no reaction { $query = "UPDATE " . $mysql_prefix . "player_list SET status='-2' WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; //this will work on next pull } header("Content-length: 7"); @@ -56,5 +55,8 @@ } } echo pack("l", $heartbeat_diff); -mysql_close($connection); +mysqli_close($connection); + +$time = date('l jS \of F Y H:i:s T ') . $_SERVER['REMOTE_ADDR'] . " (". $game_id . "," . $player_id . "," . $second_of_player . ")\n"; +file_put_contents('./pull_game_log.txt',$time,FILE_APPEND); ?> diff --git a/server/push_game.php b/server/push_game.php index e6add50..b555c86 100644 --- a/server/push_game.php +++ b/server/push_game.php @@ -1,23 +1,22 @@ -<?php +<?php include 'config.php'; include 'utils.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $player_id = (int)$_POST['player_id']; $player_pw = (int)$_POST['player_pw']; $second_of_player = (int)$_POST['second_of_player']; if (array_key_exists('gzip',$_POST)) - $data = escape_input(gzdecode($_POST['data'])); + $data = escape_input( $connection, gzdecode($_POST['data']) ); else - $data = escape_input($_POST['data']); + $data = escape_input( $connection, $_POST['data']); $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id = '$game_id' AND player_id = '$player_id'"; -$result = mysql_query($query) or die; -$row = mysql_fetch_assoc( $result ); +$result = mysqli_query( $connection, $query) or die; +$row = mysqli_fetch_assoc( $result ); if ($row['status'] == -2) //killed... echo "error: 1"; @@ -27,7 +26,7 @@ if ($row['heartbeat_time'] < $now-90) //killed... { $query = "UPDATE " . $mysql_prefix . "player_list SET status='-2' WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; echo "error: 1"; } else @@ -37,22 +36,22 @@ //saving push $query = "INSERT INTO " . $mysql_prefix . "data_list (game_id, player_id, second_of_player, data) ". "VALUES ( '$game_id', '$player_id', '$second_of_player', '$data' )"; - if (!mysql_query($query)) + if (!mysqli_query( $connection, $query)) { $query = "UPDATE " . $mysql_prefix . "data_list SET data='$data' WHERE game_id = '$game_id' AND player_id = '$player_id' AND second_of_player = '$second_of_player'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } //player heartbeat $query = "UPDATE " . $mysql_prefix . "player_list SET heartbeat_time='$now' WHERE game_id = '$game_id' AND player_id = '$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; //game heartbeat $query = "UPDATE " . $mysql_prefix . "game_list SET create_date='$now' WHERE game_id = '$game_id'"; - mysql_query($query) or die; - } + mysqli_query( $connection, $query) or die; + } echo "error: 0"; } } -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/set_level.php b/server/set_level.php index a4991a2..baa49eb 100644 --- a/server/set_level.php +++ b/server/set_level.php @@ -1,25 +1,24 @@ -<?php +<?php include 'config.php'; include 'utils.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $admin_pw = (int)$_POST['admin_pw']; -$level_string = escape_input($_POST['level_string']); +$level_string = escape_input( $connection, $_POST['level_string']); $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; -$row = mysql_fetch_array( $result ); +$row = mysqli_fetch_array( $result ); if ($row['admin_pw'] == $admin_pw) { $query = "UPDATE " . $mysql_prefix . "game_list SET level_string='$level_string' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } echo "error: 0"; -mysql_close($connection); +mysqli_close($connection); ?> diff --git a/server/set_status.php b/server/set_status.php index b5e734b..081ae17 100644 --- a/server/set_status.php +++ b/server/set_status.php @@ -1,24 +1,23 @@ -<?php +<?php include 'config.php'; -$connection = mysql_connect ($mysql_host, $mysql_username, $mysql_password) or die; -mysql_select_db($mysql_dbname) or die; +$connection = mysqli_connect ($mysql_host, $mysql_username, $mysql_password, $mysql_dbname) or die; $game_id = (int)$_POST['game_id']; $admin_pw = (int)$_POST['admin_pw']; $status = (int)$_POST['status']; $query = "SELECT * FROM " . $mysql_prefix . "game_list WHERE game_id = '$game_id'"; -$result = mysql_query($query) or die; +$result = mysqli_query( $connection, $query) or die; -$row = mysql_fetch_array( $result ); +$row = mysqli_fetch_array( $result ); if ($row['admin_pw'] == $admin_pw && $row['status'] != $status) { if ($status == 1) //game started, setting positions ingame { //count player - $result = mysql_query("SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); - $row = mysql_fetch_assoc($result); + $result = mysqli_query( $connection, "SELECT COUNT(*) AS total FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"); + $row = mysqli_fetch_assoc($result); $player_count = $row['total']; $positions = array_fill(0,$player_count,0); for ($i=0;$i<$player_count;$i++) @@ -36,20 +35,20 @@ } //Setting in db $query = "SELECT * FROM " . $mysql_prefix . "player_list WHERE game_id='$game_id'"; - $result = mysql_query($query) or die; + $result = mysqli_query( $connection, $query) or die; $i = 0; - while ($row = mysql_fetch_array( $result )) + while ($row = mysqli_fetch_array( $result )) { $player_id = $row['player_id']; $position = $positions[$i]; $query = "UPDATE " . $mysql_prefix . "player_list SET position_in_game='$position' WHERE game_id = '$game_id' AND player_id='$player_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; $i++; } } $query = "UPDATE " . $mysql_prefix . "game_list SET status='$status' WHERE game_id = '$game_id'"; - mysql_query($query) or die; + mysqli_query( $connection, $query) or die; } -mysql_close($connection); +mysqli_close($connection); echo "Everything: ok"; ?> diff --git a/server/utils.php b/server/utils.php index b7c6fc6..28e3d18 100644 --- a/server/utils.php +++ b/server/utils.php @@ -1,9 +1,9 @@ <?php -function escape_input($input) +function escape_input($connection, $input) { if (get_magic_quotes_gpc()) return $input; //Already escaped else - return mysql_real_escape_string($input); + return mysqli_real_escape_string($connection, $input); } ?>