Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latest merge #4

Open
wants to merge 128 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
a4e9a63
mini-simulation on char info page - prototype
ash7594 Feb 7, 2016
0c713dd
Merge branch 'docs'
ash7594 Feb 7, 2016
33e915e
Add Gitter badge
gitter-badger Feb 11, 2016
dbb5f3f
Merge pull request #1 from gitter-badger/gitter-badge
tushar-rishav Feb 11, 2016
37a9b0b
Revert "Add a Gitter chat badge to README.md"
tushar-rishav Feb 12, 2016
eb98b65
Merge pull request #2 from ash7594/revert-1-gitter-badge
tushar-rishav Feb 12, 2016
a72a8b7
bug fix with mapgen
ash7594 Feb 15, 2016
19ee0bc
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 15, 2016
3b9486a
Finished linting
sathiyavrs Feb 16, 2016
877acad
simple stuff
sathiyavrs Feb 17, 2016
8b50b9d
Tentative fix for globals
sathiyavrs Feb 17, 2016
72eebaf
edit_build.js: Minor UI change
tushar-rishav Feb 15, 2016
ccf55bf
models.js: Change the Char Schema
tushar-rishav Feb 17, 2016
4ebb061
edit_char.ejs: Fix code display bug
tushar-rishav Feb 17, 2016
37d74f9
lint.js: Export attack and defend code
tushar-rishav Feb 17, 2016
c84159d
runner.js Separate attack and defend code
tushar-rishav Feb 18, 2016
dc7076c
runner.js Change Runner function
tushar-rishav Feb 18, 2016
46456a4
Map gen altered
ash7594 Feb 20, 2016
11e6720
map gen in serverjs
ash7594 Feb 20, 2016
ce86c63
2 simulations defend attack
ash7594 Feb 20, 2016
892e5db
runner.js: First working prototype with successful attack and defense…
tushar-rishav Feb 20, 2016
7806d08
docs.ejs: Remove login from docs
tushar-rishav Feb 20, 2016
fd05f5b
info_char page mini-simulation overlay effect
ash7594 Feb 20, 2016
cd96c3b
docs login fixed
ash7594 Feb 20, 2016
2207d10
docs login fixed
ash7594 Feb 20, 2016
bc214b9
lint.js: Fix error in lint
tushar-rishav Feb 21, 2016
7d9baff
lint.js: Stick to only two globals(defend,attack) in user's code
tushar-rishav Feb 21, 2016
c6d3f90
defense attack added for BattleLevel
ash7594 Feb 23, 2016
f2e035e
Defender shall not Attack
sathiyavrs Feb 23, 2016
1b146a3
prototype 2 after bug fixes with battle
ash7594 Feb 23, 2016
12fd514
info_char.ejs: Remove map options
tushar-rishav Feb 22, 2016
457ab19
I'll be back. Client side done
tushar-rishav Feb 23, 2016
55a0217
bug fix with scoring
ash7594 Feb 23, 2016
befe46c
Sending match initiator information to client
ash7594 Feb 23, 2016
a1706e2
cleaner styled match page
Feb 23, 2016
0323409
server.js: Add the option to challenge user's own characters done
tushar-rishav Feb 23, 2016
b28327b
Add challenge self characters
tushar-rishav Feb 23, 2016
112736c
signin page
ash7594 Feb 23, 2016
6f480db
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 23, 2016
a375501
bug fix with opp challenge form
ash7594 Feb 23, 2016
e0ee3d6
bug fix with nologin charPage
ash7594 Feb 23, 2016
d92d5cb
Bomb simulation
sathiyavrs Feb 23, 2016
ba0799b
attacking on left and defend on right
Feb 23, 2016
1898715
Fixed bomb
sathiyavrs Feb 23, 2016
35ae72b
Added render
sathiyavrs Feb 23, 2016
4ef9eb0
docs/*: Add docs
tushar-rishav Feb 23, 2016
f5b76e5
attacking on left and defend on right
Feb 23, 2016
075517f
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 23, 2016
cabf8e9
Merge branch 'master' of https://github.com/ash7594/code-control
Feb 23, 2016
94fa58f
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 23, 2016
429e523
template code indendation fix
Feb 23, 2016
8f9c8a1
Damage Event merged with Bomb Event
sathiyavrs Feb 24, 2016
27c70ac
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 24, 2016
2e02225
Merge branch 'bomb' of https://github.com/ash7594/code-control into l…
sathiyavrs Feb 24, 2016
5ce3f64
constant explosion
sathiyavrs Feb 24, 2016
f678e6e
Explosions complete
sathiyavrs Feb 24, 2016
f21bf29
Removed logs
sathiyavrs Feb 24, 2016
c17f9a3
Support for throwing explosions added
sathiyavrs Feb 24, 2016
0245ebd
auth complete
ash7594 Feb 24, 2016
551f6c0
some bugs fixed
ash7594 Feb 24, 2016
78f6f0e
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 24, 2016
d9779c6
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 24, 2016
ff1f7fa
bug fix: self challenge wont increment exp
ash7594 Feb 24, 2016
ed88edb
additional styling to match page and draw display bug fix
Feb 24, 2016
9b76539
Merge branch 'master' of https://github.com/ash7594/code-control
Feb 24, 2016
1349f14
No exp increment displayed if challenging own character
Feb 24, 2016
4bd9b33
mini-simulation of both attack defend
ash7594 Feb 24, 2016
9df074c
changed attack val to match health - kill in one blow
ash7594 Feb 24, 2016
011b9e4
Numerous bug fixes
sathiyavrs Feb 24, 2016
690165d
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 24, 2016
55c40ca
docs/* : Add docs for game
tushar-rishav Feb 24, 2016
401f8fe
some shit
ash7594 Feb 24, 2016
3578961
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 24, 2016
8466571
docs/* : Update who defend first info
tushar-rishav Feb 24, 2016
57e7691
Major bug fix with match
ash7594 Feb 24, 2016
c7f92b9
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 24, 2016
dcb226e
match page minor edit
ash7594 Feb 24, 2016
985fa27
Merge branch 'master' into explosion
ash7594 Feb 24, 2016
f35e2a8
Merge branch 'master' of https://github.com/ash7594/code-control into…
sathiyavrs Feb 24, 2016
3ce6ba3
mini-simulation info_char page done
ash7594 Feb 24, 2016
1e87cef
default code fixed
ash7594 Feb 24, 2016
2e9e0a2
bug with code editing
ash7594 Feb 24, 2016
292f59a
lint.js: Fix err code but still save to db bug
tushar-rishav Feb 24, 2016
10dc837
return check
ash7594 Feb 24, 2016
3b7801c
Logout added to header nav-bar
ash7594 Feb 24, 2016
327e470
Merge branch 'explosions' of https://github.com/ash7594/code-control …
ash7594 Feb 25, 2016
56d9c66
Merge branch 'master' into explosion
ash7594 Feb 25, 2016
579e504
push action:plant bomb, action:explosive ring
ash7594 Feb 25, 2016
c953359
bug fix with match template avoid exp display on selfversus
ash7594 Feb 25, 2016
fb73896
bug fix with match template avoid exp display on selfversus
ash7594 Feb 25, 2016
45c6881
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 25, 2016
4dcbd3a
server.js: Add exp check for battle only
tushar-rishav Feb 25, 2016
71b22b6
fixed res-simulation
sathiyavrs Feb 25, 2016
5aadf44
match.ejs: Improve match controls UI
tushar-rishav Feb 25, 2016
091ff9b
Merge branch 'master' of https://github.com/ash7594/code-control
tushar-rishav Feb 25, 2016
8650c32
mini-simulation reverse showing matches
ash7594 Feb 25, 2016
fa51d5a
Merge branch 'master' of https://github.com/ash7594/code-control
tushar-rishav Feb 25, 2016
e93b4f7
auth done to verify event registered pids
ash7594 Feb 25, 2016
8783b76
updated docs for specials
sathiyavrs Feb 25, 2016
13bfee7
Updated 4 API and corresponding docs
sathiyavrs Feb 25, 2016
402e521
Template mods
ash7594 Feb 25, 2016
4fc22bb
pragyan logos added
ash7594 Feb 25, 2016
2cab459
docs: Add docs imgs
tushar-rishav Feb 25, 2016
864d04e
Merge branch 'master' of https://github.com/ash7594/code-control
tushar-rishav Feb 25, 2016
77ec043
leaderboard differentiation
ash7594 Feb 25, 2016
5575409
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 25, 2016
cb67155
Revert SwarmLevel
sathiyavrs Feb 25, 2016
b7daee0
leaderboard.ejs: Fix url ref bug
tushar-rishav Feb 25, 2016
7f2d2f4
docs bug fix
ash7594 Feb 25, 2016
2dce532
Added examples
sathiyavrs Feb 25, 2016
775f771
Merge branch 'master' of https://github.com/ash7594/code-control
sathiyavrs Feb 25, 2016
f116563
exp algo modified
ash7594 Feb 25, 2016
ed4df84
swarm-code update
sathiyavrs Feb 25, 2016
4631d00
exp algo modified
ash7594 Feb 25, 2016
df6c7d0
fix
ash7594 Feb 25, 2016
c3910d4
showing losers exp dec
ash7594 Feb 25, 2016
42980f9
docs: Add neagtive points
tushar-rishav Feb 25, 2016
7e874da
Merge branch 'master' of https://github.com/ash7594/code-control
ash7594 Feb 25, 2016
c5d0beb
docs: Add neagtive points
tushar-rishav Feb 25, 2016
bc67607
Merge branch 'master' of https://github.com/ash7594/code-control
tushar-rishav Feb 25, 2016
fc2f364
docs: Add negatives and peace podu
tushar-rishav Feb 25, 2016
4dd1025
Corrected docs
sathiyavrs Feb 25, 2016
c17bd3f
IRC added
ash7594 Feb 25, 2016
0e27f33
reg date modified
ash7594 Feb 26, 2016
4dcc8d4
leaderboard template changes
ash7594 Feb 26, 2016
1c9f600
template leaderboard edit
ash7594 Feb 26, 2016
a683d7a
api.md: coord fix
tushar-rishav Feb 26, 2016
9e21917
api corrections
sathiyavrs Feb 27, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
89 changes: 65 additions & 24 deletions auth/verify.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,69 @@
var req = require('request');
var request = require('request');

function cbackWrapper(cback) {
return function(err, msg, resp) {
if(err) {
return cback(err);
}
try {
var r_code = parseInt(resp);
} catch(e) {
cback(e);
}
if(r_code == -1) {
cback(null, false);
} else {
cback(null, { pid: r_code });
}
}
}
var customUserPass = {
usernameField: 'email',
passwordField: 'pass'
};

const PRAGYAN_EVENT_ID = 17;
const USER_AUTH_URL = 'https://api.pragyan.org/user/getDetails';
const EVENT_AUTH_URL = 'https://api.pragyan.org/user/eventauth';

const VERIFY_URL = 'http://pragyan.org/14/cms/codecharacter.php?kookie='
function verifyCookie(kookie, cback) {
/* DEBUG */
/* END DEBUG */
var get = req.get(VERIFY_URL + kookie, cbackWrapper(cback));
function verifyCreds(email, password, done) {
function registered() {
request.post(
USER_AUTH_URL, {
form: {
'user_email' : email,
'user_pass' : password
}
}, function (err, res, body) {
body = JSON.parse(body);
if (err) {
return done(err);
}
if (res.statusCode != 200) {
return done(err);
}
if (body.status == 0) {
return done(null, false, { message: 'Incorrect username or password' });
}
if (body.status == 3) {
return done(null, false, { message: 'Register on www.pragyan.org' });
}
if (body.status == 2) {
return done(null, { pid: body.data.user_id });
}
done(null, false);
});
}
request.post(
EVENT_AUTH_URL, {
form: {
'user_email' : email,
'user_pass' : password,
'event_id' : PRAGYAN_EVENT_ID
}
}, function (err, res, body) {
body = JSON.parse(body);
if (err) {
return done(err);
}
if (res.statusCode != 200) {
return done(err);
}
if (body.status == 0) {
return done(null, false, { message: 'Incorrect username or password' });
}
if (body.status == 3) {
return done(null, false, { message: 'Register on www.pragyan.org' });
}
if (body.status == 1) {
return registered();
}
done(null, false);
});
}

module.exports.verifyCookie = verifyCookie;
module.exports.verifyCreds = verifyCreds;
module.exports.customUserPass = customUserPass;
207 changes: 204 additions & 3 deletions common/lint.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const DEFAULT_ATTACK_CODE = "function attack(params) {\n // TODO: insert attack code here\n return {action: 'rest'};}";
const DEFAULT_DEFEND_CODE = "function defend(params) {\n // TODO: insert defend code here\n return {action: 'rest'};}";

var options = {
undef: true,
noarg: true,
freeze: true,
latedef: true
}
var attack_and_defend_code = [ DEFAULT_DEFEND_CODE, DEFAULT_ATTACK_CODE]
const ATTACK_FUNCTION = 'attack',
DEFEND_FUNCTION = 'defend';

function makeMap(x) {
var m = {}, i;
Expand All @@ -23,9 +29,200 @@ function truthize(x) {
return res;
}

function getFunctionCode(code, name, lineInfo) {
var codeLines = code.split('\n'),
functionCode = '';

// Assume lineInfo is just as needed.
/*
* lineInfo = {
* line: ,
* character: ,
* last: ,
* lastcharacter: ,
* };
*/

if (lineInfo.last === lineInfo.line) {
var line = codeLines[lineInfo.line - 1];
var functionString = line.substring(lineInfo.character, lineInfo.lastcharacter - 1);

for (var i = lineInfo.character - 2; i >= 0; i--) {
if (line.charAt(i) === '(')
break;
}

functionString = line.substring(i, lineInfo.character) + functionString;
functionString = 'function ' + name + functionString;
return functionString;
}

var line = codeLines[lineInfo.line - 1];
var firstLine = line.substring(lineInfo.character, line.length);

var i = 0;
for (i = lineInfo.character - 2; i >= 0; i--)
if (line.charAt(i) === '(')
break;

firstLine = 'function ' + name + line.substring(i, lineInfo.character) + firstLine;
functionCode = firstLine + '\n';

for (i = lineInfo.line; i < lineInfo.last - 1; i++) {
line = codeLines[i];
functionCode = functionCode + line + '\n';
}

// Now for the last line;
i = lineInfo.last - 1;
line = codeLines[i];
functionCode = functionCode + line.substring(0, lineInfo.lastcharacter - 1);

return functionCode;
}

// Returns object if function is present. Else returns 0.
function getLineData(functionArray, name) {
var lineInfo = {},
funcPresent = false;

functionArray.forEach(function(func){
if (func.name === name) {
funcPresent = true;
lineInfo.line = func.line;
lineInfo.character = func.character;
lineInfo.last = func.last;
lineInfo.lastcharacter = func.lastcharacter;
}
});
if (funcPresent)
return lineInfo;
else
return 0;
}

// This function returns 'empty' if the code isn't there. Else, it returns the code.
// name is the name of the function
// code is the overall code
// globals is the 'common + defend + attack' api file
function getCode(code, globals, name) {
var jsHintExport = require('jshint').JSHINT,
res = jsHintExport(code, options, truthize(globals));

var functionData = jsHintExport.data().functions;

var lineInfo = getLineData(functionData, name);
if (lineInfo === 0) {
return 'empty';
}

var functionCode = getFunctionCode(code, name, lineInfo);
return functionCode;
}
function array_to_bool_dict(array){
var dict = {}
array.forEach(function(el){
dict[el] = true;
});
return dict;
}
const EraseGlobals = true;
const ValidGlobalsList = ['Array', 'Math', 'Function', 'Object', 'String', 'Infinity', 'NaN', 'undefined', 'null', 'Boolean', 'Symbol', 'Error', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'Number', 'Math', 'Date', 'RegExp', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'Map', 'Set', 'WeakMap', 'WeakSet', 'ArrayBuffer', 'SharedArrayBuffer', 'Atomics', 'DataView', 'JSON', 'Promise', 'Generator', 'GeneratorFunction', 'Reflect', 'Proxy', 'arguments' ];
var validGlobalsDict = array_to_bool_dict(ValidGlobalsList); // Too lazy to modify ValidGlobalsList

function versusProcess(code, globalsArr, req_func) {
/*
Allows only required functions as global variables, nothing more.
params code :User's code. A single string of
attack and defend code actually
params globalsArr [api, attack_api, defend_api]
params req_func :['attack','defend']

*/
if (globalsArr.length < 3)
throw new Error('Globals doesn\'t have enough elements!');

var warn = process(code, globalsArr[0], req_func);
var globals = truthize(globalsArr[0]);
var jsHintExport = require('jshint').JSHINT,
res = jsHintExport(code, options, globals);
var functionData = jsHintExport.data().functions;
var jsHintData = jsHintExport.data();

// discard all the invalid global functions
var req_func_dict = array_to_bool_dict(req_func);
jsHintData.globals.forEach(function(glob){
if(!(globals[glob] || (glob in req_func_dict) || (glob in validGlobalsDict))){
warn.push({
row: 0,
text: glob + ' can not be used',
column: 1,
type: 'warning',
raw: 'Invalid access to function'
});
}
});

var warnIndex = warn.length;
for (var j = 0; j < req_func.length; j++) {
var lineInfo = getLineData(functionData, req_func[j]);
if (lineInfo === 0) {
continue;
warn.push({
row: 0,
text: 'Function ' + req_func[j] + ' is not defined',
column: 1,
type: 'warning',
raw: 'Required function not defined'
});
}

var childCode = getFunctionCode(code, req_func[j], lineInfo);
var childWarn = process(childCode, globalsArr[j + 1], [req_func[j]]);
attack_and_defend_code[j] = childCode; // 0->defend, 1-> attack
warn = warn.concat(childWarn);

if (warn.length > warnIndex) {
for (var i = warnIndex; i < warn.length; i++) {
var warnMessage = warn[i];
warnMessage.row += lineInfo.line - 1;
}
warnIndex = warn.length;
}
}
return warn;
}

function process(code, globals, req_func) {
var j = require('jshint').JSHINT, i,
res = j(code, options, truthize(globals)), warn = [], errors, f;
globals = truthize(globals);
var j = require('jshint').JSHINT, i,
res = j(code, options, globals), warn = [], errors, f;

var def = 0, att = 0
j.data().functions.forEach(function(func){
if(func.name == "defend")
++def;
else if(func.name == "attack")
++att;
});
if (def>1){
warn.push({
row: 0,
text: 'There can be only one defend function defined in code',
column: 1,
type: 'error',
raw: 'Invalid declaration of function'
});
}else if (att>1){
warn.push({
row: 0,
text: 'There can be only one attack function defined in code',
column: 1,
type: 'error',
raw: 'Invalid declaration of function'
});
}

if(!res) {
var errors = j.data().errors, e;
for(i = 0; i < errors.length; i++) {
Expand All @@ -42,7 +239,8 @@ function process(code, globals, req_func) {
if(req_func) {
var f = makeMap(j.data().functions);
for(i = 0; i < req_func.length; i++) {
if(!(req_func[i] in f)) {
// attack and defend must be present in player's code
if(!(req_func[i] in f)){
warn.push({
row: 0,
text: 'Function ' + req_func[i] + ' is not defined',
Expand All @@ -57,3 +255,6 @@ function process(code, globals, req_func) {
return warn;
}
module.exports.process = process;
module.exports.versusProcess = versusProcess;
module.exports.getFunctionCode = getCode;
module.exports.adCode = attack_and_defend_code
Loading