Browse Source

Server side testing created

master
Jeffery R 6 years ago
parent
commit
aaf5fc709c
5 changed files with 74 additions and 22 deletions
  1. +6
    -0
      README.md
  2. +5
    -0
      googletrendsgame/package.json
  3. +20
    -0
      googletrendsgame/server/index.html
  4. +29
    -20
      googletrendsgame/server/server.js
  5. +14
    -2
      googletrendsgame/server/sql.js

+ 6
- 0
README.md View File

@ -18,6 +18,8 @@ npm install promise
##Database Construction
create database googleTrends;
use googleTrends;
create table users(
user_id mediumint unsigned not null AUTO_INCREMENT,
name varchar(30) not null,
@ -28,5 +30,9 @@ create table data(
data_id mediumint unsigned not null AUTO_INCREMENT,
user_id mediumint unsigned not null,
word varchar(100) not null,
score mediumint not null,
primary key(data_id)
);
grant all on googleTrends.* to trendingUser@localhost identified by "password";

+ 5
- 0
googletrendsgame/package.json View File

@ -3,9 +3,14 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"express": "^4.16.2",
"google-trends-api": "^4.4.0",
"mysql": "^2.15.0",
"promise": "^8.0.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.0",
"sanitizer": "^0.1.3",
"socket.io": "^2.0.4",
"socket.io-client": "^2.0.4"
},

+ 20
- 0
googletrendsgame/server/index.html View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello world</title>
</head>
<script src = "../../socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.emit('register', 'jeffery');
socket.on('sendRooms', function(data)
{
console.log("got rooms");
console.log(data);
document.write(data);
});
</script>
<body>Hello world</body>
</html>

+ 29
- 20
googletrendsgame/server/server.js View File

@ -71,25 +71,25 @@ var room = function(capacityP, pass, owner)
var countInner = 0;
var countSwap = 0;
var swapped;
do
{
countOuter++;
swapped = false;
for(var i = 0; i < result.users.length; i++)
{
countInner++;
if(result.users[i].score && result.users[i + 1].score &&
result.users[i].score > result.users[i + 1].score)
{
countSwap++;
var temp = result.users[i];
result.users[i] = result.users[j];
result.users[j] = temp;
swapped = true;
}
}
} while(swapped);
// var swapped;
// do
// {
// countOuter++;
// swapped = false;
// for(var i = 0; i < result.users.length; i++)
// {
// countInner++;
// if(result.users[i].score && result.users[i + 1].score &&
// result.users[i].score > result.users[i + 1].score)
// {
// countSwap++;
// var temp = result.users[i];
// result.users[i] = result.users[j];
// result.users[j] = temp;
// swapped = true;
// }
// }
// } while(swapped);
result.gameState = this.state;
@ -120,6 +120,7 @@ var room = function(capacityP, pass, owner)
var message = this.generateRoomUpdate();
this.users.forEach(function(u)
{
console.log("room update called");
u.socket.emit('roomUpdate', message);
console.log(message);
});
@ -307,6 +308,8 @@ var player = function(s)
result.name = this.name;
result.score = this.score;
result.word = this.sumbission;
return result;
}
/**
@ -385,6 +388,12 @@ var io = require('socket.io')(http);
const port = 3000;
app.get('/', function(req, res)
{
console.log("err");
res.sendfile('index.html');
});
//Whenever someone connects this gets executed
io.on('connection', function(socket)
{
@ -489,4 +498,4 @@ io.on('connection', function(socket)
http.listen(port, function() {
console.log('listening on *:3000');
});
});

+ 14
- 2
googletrendsgame/server/sql.js View File

@ -1,9 +1,9 @@
//
const mysql = require('mysql');
const sanitizer = require('sanitizer');
var Promise = require('promise');
module.exports=
{
/**
@ -28,5 +28,17 @@ module.exports=
resolve(result.insertId);
});
})
},
/**
* Insert all of the user's data into the sql database
* @param player
*/
insertData : function(player)
{
return new Promise(function(resolve, reject)
{
var q = "";
})
}
};

Loading…
Cancel
Save