Compare commits

...

5 Commits

7 changed files with 148 additions and 6 deletions

View File

@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef WIN32
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
@@ -26,8 +26,9 @@ namespace jscore {
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
int sock;
struct sockaddr_in client;
int PORT = 9911;
const char *HOST = "jaildoctor.duckdns.org";
string HOST = "jaildoctor.duckdns.org";
#ifdef WIN32
WSADATA WsaData;
@@ -36,6 +37,11 @@ namespace jscore {
bool jscore_error = false;
string error_message;
void init(std::string host, const int port) {
PORT = port;
HOST = host;
}
void setErrorMessage(string message) {
jscore_error = true;
error_message = message;
@@ -46,7 +52,7 @@ namespace jscore {
int ret = WSAStartup(0x101,&WsaData);
if (ret != 0) return 0;
#endif
struct hostent * host = gethostbyname(HOST);
struct hostent * host = gethostbyname(HOST.c_str());
if ( (host == NULL) || (host->h_addr == NULL) ) {
setErrorMessage("Error retrieving DNS information.\n");
@@ -120,9 +126,11 @@ namespace jscore {
return score.size();
}
string getUserName(const int index) {
if (score.size()==0 || index >= score.size()) return "";
return score[index].name;
}
const int getPoints(const int index) {
if (score.size()==0 || index >= score.size()) return 0;
return score[index].points;
}

View File

@@ -2,6 +2,7 @@
#include <string>
namespace jscore {
void init(std::string host, const int port);
const bool initOnlineScore(std::string game);
const int getNumUsers();
std::string getUserName(const int index);

24
server/deleteuserdata.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$user = "";
if (isset($_GET['user'])) $user = $_GET['user'];
$query = "DELETE FROM userdata WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
$bd->exec($query);
echo("OK");
?>

44
server/getalluserdata.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$query = "SELECT * FROM userdata";
$resultado = $bd->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>ÍCARO</title>
<meta http-equiv="Cache-Control" content="no-cache ,must-revalidate" />
</head>
<body>
<table>
<tr><th>game</th><th>user</th><th>data</th></tr>
<?php
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
while ($fila) {
?>
<tr>
<td><?=$fila['game']?></td>
<td><?=$fila['user']?></td>
<td><?=$fila['data']?></td>
</tr>
<?php
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
}
?>
</table>
</body>
</html>

30
server/getusers.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$query = "SELECT user FROM userdata WHERE game LIKE '".$game."'";
$resultado = $bd->query($query);
$res = "";
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
while ($fila) {
$res = $res.$fila['user'];
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
if ($fila) $res = $res.",";
}
echo($res);
?>

View File

@@ -16,7 +16,7 @@ $bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$query = "SELECT user, points FROM scores WHERE game LIKE '".$game."' ORDER BY points DESC LIMIT 10";
$query = "SELECT user, points FROM scores WHERE game LIKE '".$game."' ORDER BY points DESC";
$resultado = $bd->query($query);
$res = "";

View File

@@ -37,7 +37,7 @@ bool is_valid_move() {
}
void stack_piece() {
if (piece_pos.y==0) exit(0);
if (piece_pos.y==0) { state=STATE_ENNERYORNEIM; return; };
int x = piece_pos.x+3, y = piece_pos.y+3;
Uint16 piece = tetromino[current_piece].figure;
for (int i=0; i<16; i++) {
@@ -128,7 +128,7 @@ void doGame() {
void doMenu() {
while(SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
if (sdlEvent.type == SDL_KEYDOWN) {
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
level=score=lines=0;
current_piece = starting[rand()%7];
next_piece = starting[rand()%7];
@@ -162,6 +162,40 @@ void doMenu() {
SDL_RenderPresent(sdlRenderer);
}
char initials[4]={"AAA"};
int pos =0;
void doEnd() {
while(SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
if (sdlEvent.key.keysym.scancode>=SDL_SCANCODE_A && sdlEvent.key.keysym.scancode<=SDL_SCANCODE_0) {
if (sdlEvent.key.keysym.scancode<=SDL_SCANCODE_Z) {
initials[pos] = sdlEvent.key.keysym.scancode+61;
} else if (sdlEvent.key.keysym.scancode<SDL_SCANCODE_0) {
initials[pos] = sdlEvent.key.keysym.scancode+19;
} else {
initials[pos] = '0';
}
pos++; if (pos==3) pos=0;
} else if (sdlEvent.key.keysym.scancode==SDL_SCANCODE_RETURN) {
state=STATE_MENU;
}
}
}
//SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
//SDL_RenderClear(sdlRenderer);
print(90, 100, "GAME OVER", 7);
if (score>0 && (jscore::getNumUsers()<10 || score>jscore::getPoints(jscore::getNumUsers()-1))) {
print(40, 150, "CONGRATULATIONS", 1);
print(40, 180, "ENTER YOU NAME", 2);
print(40, 250, initials, 3);
}
SDL_RenderPresent(sdlRenderer);
}
int main(int argc, char* argv[]) {
srand(time(NULL));
current_piece = starting[rand()%7];
@@ -181,6 +215,7 @@ int main(int argc, char* argv[]) {
doGame();
break;
case STATE_ENNERYORNEIM:
doEnd();
break;
};
}