-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·210 lines (166 loc) · 4.45 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
var http = require('http');
var express = require('express');
var app = express();
//var app = require('./service/rest.serv');
var server = http.createServer(app);
var io = require('socket.io');
var url = require('url');
var fs = require('fs');
var path = require('path');
var bodyParser =require('body-parser');
var methodOverride = require('method-override');
var util = require('util');
var game = require('./game');
app.use(express.static(__dirname + '/www'));
process.env.NODE_PATH = __dirname;
console.log("Directory name is:"+__dirname);
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST,PUT');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
// get all data/stuff of the body (POST) parameters
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(bodyParser.urlencoded({ extended: true })); // parse application/x-www-form-urlencoded
app.use(methodOverride('X-HTTP-Method-Override')); // override with the X-HTTP-Method-Override header in the request. simulate DELETE/PUT
//var server_port = process.env.port || 2222
var server_port = 2001
var server_ip_address = 'localhost';
server.listen( server_port,server_ip_address, function(){
var addr = server.address();
console.info("APP server listening at", addr.address + ":" + addr.port);
});
var listener = io.listen(server);
//The basic structure of different types of hackers
/*
id:
,typeName:
,Description:
,accessMove:{
diagonal:
,any:{
numberOfActions:
}
}
,canCrossMissingProduct:
,canMoveOtherHackers:{
numberOfAdjacentProducts:
}
,canShareObjCard:{}
,canInstallMalwareAnywhere:{
diagonal:
,numberOfActionsAndProducts:{
actions:
products:
}
}
*/
var hackerTypes = [
{
id:0
,typeName:"Black Hat Hacker"
,Description:"Can access products and install malware diagonally"
,accessMove:{
diagonal:1
,any:null
}
,canCrossMissingProduct:null
,canMoveOtherHackers:null
,canShareObjCardAnyWhere:null
,canInstallMalware:{
diagonal:1
,numberOfActionsAndProducts:{
actions:4
,products:1
}
}
}
,{
id:1
,typeName:"Script Kiddie"
,Description:"Can move through one or more secured and missing positions"
,accessMove:{
diagonal:1
,any:{
numberOfActions:4
}
}
,canCrossMissingProduct:1
,canMoveOtherHackers:null
,canShareObjCardAnyWhere:null
,canInstallMalwareAnyWhere:null
}
,{
id:2
,typeName:"Hacktivist"
,Description:"Give objectives to Hackers anywhere"
,accessMove:null
,canCrossMissingProduct:null
,canMoveOtherHackers:null
,canShareObjCardAnyWhere:1
,canInstallMalwareAnywhere:null
}
,{
id:3
,typeName:"State Sponsored Hacker"
,Description:"Can access any product for one action and once per turn"
,accessMove:{
diagonal:null
,any:{
numberOfActions:1
}
}
,canCrossMissingProduct:null
,canMoveOtherHackers:null
,canShareObjCardAnyWhere:null
,canInstallMalwareAnywhere:null
}
,{
id:4
,typeName:"Cyber Terrorist"
,Description:"Can move other hackers upto two adjacent positions for one action"
,accessMove:null
,canCrossMissingProduct:null
,canMoveOtherHackers:{
maxNumberOfAdjacentProducts:2
}
,canShareObjCardAnywhere:null
,canInstallMalwareAnywhere:null
}
,{
id:5
,typeName:"Spy Hacker"
,Description:"Install Malware on 2 products in one action"
,accessMove:null
,canCrossMissingProduct:null
,canMoveOtherHackers:null
,canShareObjCard:null
,canInstallMalwareAnywhere:{
diagonal:1
,numberOfActionsAndProducts:{
actions:4
,products:2
}
}
}];
var availableHackerIDs = [0,1,2,3,4,5];
var positionOfHackers = [0,8,10,15,24,18];
var pathName = __dirname+'/www/index.html'
app.get('/', function (req, res) {
console.log("Got a request!!");
res.sendFile(pathName);
});
app.get('/hackerTypes*',function(req,res){
console.log("Got a request to choose hackers");
res.jsonp(hackerTypes);
});
app.get('/availableHackers*',function(req,res){
console.log("Got a request to return available hackers");
res.jsonp(availableHackerIDs);
});
listener.sockets.on('connection',function(socket){
console.log("Socket.io is GO");
game.initGame(listener,socket);
});