-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
70 lines (52 loc) · 1.57 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//create server
var express = require('express');
var app = express();
app.use(express.static("public")); //static files go to public folder
//set view engine to ejs
app.set('view engine', 'ejs');
//express form data from server side
var bodyParser = require('body-parser');
//urlencoded
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
//default ID that the bot will use to login
var ID = require('./userID.js').ID;
//create bot
var communication = require('./communication');
var bot = new communication.Bot();
//Later this should be put together in a game object -> neater
var battleformat ='';
var userID ='';
var password = '';
app.listen(process.env.app_port || 8080);
bot.initializeBot();
//index
app.get('/', function(req, res) {
res.render('pages/index');
});
app.post('/confirminput', function (req, res) {
userID = req.body.userID;
password = req.body.password;
battleformat = req.body.battleformat;
//console.log(req.body);
console.log('Logging in');
//login to server
if (userID != null && password != null) {
bot.setID(userID, password, battleformat);
}
});
app.post('/sendingchallenge', function (req, res) {
userID = req.body.userID;
battleformat = req.body.battleformat;
customTeam = req.body.customTeam;
//console.log(req.body);
console.log('Sending Challenge Request');
bot.setID(ID.userID, ID.password, battleformat);
setTimeout(function() {
bot.sendingChallenge(userID, battleformat, customTeam);
}, 5000)
});
app.get('/startbattle', function(req,res){
console.log('Initiating Battle');
bot.startRandomBattle();
});