Skip to content

Commit

Permalink
Merge pull request owenashurst#471 from flaminggenius/master
Browse files Browse the repository at this point in the history
Database integration
  • Loading branch information
huytd authored Mar 23, 2017
2 parents bfa0418 + cc31472 commit b2603e4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
11 changes: 10 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"host": "0.0.0.0",
"port": 3000,
"logpath": "logger.php",
"foodMass": 1,
"fireFood": 20,
"limitSplit": 16,
Expand Down Expand Up @@ -30,5 +31,13 @@
"newPlayerInitialPosition": "farthest",
"massLossRate": 1,
"minMassLoss": 50,
"mergeTimer": 15
"mergeTimer": 15,
"sqlinfo":{
"connectionLimit": 100,
"host": "localhost",
"user": "root",
"password": "DEFAULT",
"database": "DEFAULT",
"debug": false
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"socket.io-client": "^1.4.6",
"sync-request": "^3.0.1",
"webpack": "^1.13.1",
"webpack-stream": "^3.2.0"
"webpack-stream": "^3.2.0",
"mysql": "^2.5.5"
}
}
13 changes: 13 additions & 0 deletions src/client/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ div {
width: 100px;
height: 100px;
padding: 5px;
border: none;
}

#feed {
Expand All @@ -37,6 +38,7 @@ div {
width: 100px;
height: 100px;
padding: 5px;
border: none;
}

#status {
Expand Down Expand Up @@ -267,3 +269,14 @@ display: none;
display: none;
}
}

input [type="image"]:focus{
border:none;
outline: 1px solid transparent;
border-style: none;
}

*:focus {
outline: 1px solid transparent;
border-style: none;
}
6 changes: 4 additions & 2 deletions src/client/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!doctype html>
<!doctype html>
<html lang="en">
<head>
<!-- Meta Properties -->
<meta charset="UTF-8">
<title>Agar.IO Clone</title>
<title>Open Agar</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<!-- CSS -->
<link rel="stylesheet" href="css/main.css" />
Expand Down Expand Up @@ -43,6 +43,7 @@ <h3>Settings</h3>
<label><input id="continuity" type="checkbox">Continue moving when mouse is off-screen</label>
<br />
<label><input id="roundFood" type="checkbox" checked>Rounded food</label>
<label><input id="darkMode" type="checkbox">Toggle Dark Mode</label>
</ul>
</div>
<div id="instructions">
Expand All @@ -57,6 +58,7 @@ <h3>Gameplay</h3>
</div>
</div>
<!-- JS -->
<!-- <script src="virtualjoystick.js"></script>-->
<script src="//code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="js/app.js"></script>
</body>
Expand Down
23 changes: 21 additions & 2 deletions src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var SAT = require('sat');
var sql = require ("mysql");

// Import game settings.
var c = require('../../config.json');
Expand All @@ -16,6 +17,9 @@ var util = require('./lib/util');
// Import quadtree.
var quadtree = require('simple-quadtree');

//call sqlinfo
var s = c.sqlinfo;

var tree = quadtree(0, 0, c.gameWidth, c.gameHeight);

var users = [];
Expand All @@ -30,6 +34,19 @@ var leaderboardChanged = false;
var V = SAT.Vector;
var C = SAT.Circle;

var pool = sql.createConnection({
host: s.host,
user: s.user,
database: s.database
});

//log sql errors
pool.connect(function(err){
if (err){
console.log (err);
}
});

var initMassLog = util.log(c.defaultPlayerMass, c.slowBase);

app.use(express.static(__dirname + '/../client'));
Expand Down Expand Up @@ -340,9 +357,11 @@ io.on('connection', function (socket) {
socket.broadcast.emit('serverMSG', currentPlayer.name + ' just logged in as admin!');
currentPlayer.admin = true;
} else {
console.log('[ADMIN] ' + currentPlayer.name + ' attempted to log in with incorrect password.');
socket.emit('serverMSG', 'Password incorrect, attempt logged.');

// TODO: Actually log incorrect passwords.
console.log('[ADMIN] ' + currentPlayer.name + ' attempted to log in with incorrect password.');
socket.emit('serverMSG', 'Password incorrect, attempt logged.');
pool.query('INSERT INTO logging SET name=' + currentPlayer.name + ', reason="Invalid login attempt as admin"');
}
});

Expand Down

0 comments on commit b2603e4

Please sign in to comment.