Skip to content

Instantly share code, notes, and snippets.

@samyok
Created October 6, 2017 23:24
Show Gist options
  • Save samyok/9bec5afc5ce7964661219abd75efb140 to your computer and use it in GitHub Desktop.
Save samyok/9bec5afc5ce7964661219abd75efb140 to your computer and use it in GitHub Desktop.
Samyok.us Server Code
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
var usersOnline = 0;
io.on('connection', function(socket){
usersOnline++;
io.emit("usersUpdate", usersOnline);
console.log('>> Connected! Online:' + usersOnline + "");
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
var chars = 00;
var id = 0;
var totalIDS = 22; // MAKE SURE YOU CHANGE THIS
setInterval(function(){
if(chars <= que.problems[id].question.length && !pauseQuestion && usersOnline > 0){
chars++;
io.emit('chars', chars);
io.emit('question', que.problems[id].question.substr(0,chars));
console.log(chars);
}
}, 75 ); /////////////////////////////
/*W__WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW*/
var text = '{"problems":[' +
'{"question":"This collective, informal name referred to a group of people in a religious faith that followed the strictest form. These people think that pleasure is a sin. For 10 points, restate what Miss Maudie called Mr. Radley. ","answer":"Foot Washing Baptist" },' +
'{"question":"For 10 points, name the character that said this quote: \'\'Ain\'t no snot-nosed ---- of a schoolteacher ever born c\'n make me do nothin! You ain\'t makin\' me go nowhere, missus.\'\' ","answer":"Burris Ewell" },' +
'{"question":"Who was the man who learned something from Scout around Christmas time? He \'\'didn\'t hear both sides of the story\'\' and thought Scout was holding Francis hostage in the kitchen. When he finally does hear both sides of the story, he wants to punish Francis, and possibly his sister, Aunt Alexandra. Name this uncle of Francis, Jem, and Scout.","answer":"Uncle Jack Finch" },' +
'{"question":"If this woman had her way, Calpurnia would have been long gone and Scout would be the \'\'female Finche\'\' she was. She normally lives in Finch\'s Landing, but came to Atticus\' place for Tom Robinson\'s trial. Name Atticus\' sister.","answer":"Aunt Alexandra" },' +
'{"question":"This man, one of Atticus\' clients, came to lynch Tom Robinson. However, Scout, brave as she is, recognized nim--so he called the mob off. Name the person who is the father of one of the poorest people in Maycomb, (and also Scout\'s friend) Walter Cunningham Jr.","answer":"Walter Cunningham Sr." },' +
'{"question":"At the (almost) lynching of Tom Robinson, this man had both Atticus\'s and Tom Robinson\'s back. Even though he doesn\'t like blacks, he defends their right to a fair trial in the newspaper that he owns, edits, and publishes: The Maycomb Tribune.","answer":"Mr. Braxton Bragg Underwood" },' +
'{"question":"This man appears thoughout the whole book, yet he only has one line. He very rarely steps foot outside his yard, and is quite isolated. In the beginning of the book, he is more part of a game they play, rather than a life-saver, as he was at the end of the book. This man is quite literally the \'\'urban legend\'\' of this town. Name the character with the nickname Boo. ","answer":"Boo (Arthur) Radley" },' +
'{"question":"Even though this title is never said in the book, father is one job this man has. This book would have been called this man\'s name. This man also defended Tom Robinson, a job looked down upon by many, with all his might. For 10 points, name Scout\'s father. ","answer":"Atticus Finch" },' +
'{"question":"This father of many children lived in a place that was only seen at Christmas. This man, who lived in a filthy landfill, beat up Mayella Ewell. For 10 points, name this character that is the father of the very amoral family--the Ewells. ","answer":"Bob Ewell" },' +
'{"question":"For 10 points, name the character that said this quote: \'\'And you--what are you doing in those overalls? You should be in a dress and a camisole, young lady!...Not only a Finch waiting on tables but one in a courthouse lawing for -------!...Yes indeed, what has this world come to when a Finch goes against his raising!","answer":"Miss Dubose" },' +
'{"question":"What name is missing from this quote by Scout? \'\'Neighbors bring food with death and flowers with sickness and little things in between. XXXXXXXX was our neighbor. He gave us two soap dolls, a broken watch and chain, a pair of good-luck pennies, and our lives. But neighbors give in return. We never put back into the tree what we took out of it: we had given him nothing, and it made me sad.\'\'", "answer":"Boo (Arthur) Radley" },' +
'{"question":"Who said this? \'\'We know all men are not created equal in the sense some people would have us believe- some people are smarter than others, some people have more opportunity because they\'re born with it, some men make more money than others, some ladies make better cakes than others- some people are born gifted beyond the normal scope of men. <br /> But there is one way in this country in which all men are created equal- there is one human institution that makes a pauper the equal of a Rockefeller, the stupid man the equal of an Einstein, and the ignorant man the equal of any college president. That institution, gentlemen, is a court.\'\'", "answer":"Atticus Finch" },' +
'{"question":"Who said the only quote in this paragraph? Gone was the terror in my mind of stale whiskey and barnyard smells, of sleepy-eyed sullen men, of a husky voice calling in the night, \'\'Mr. Finch? They gone?\'\' Our nightmare had gone with daylight, everything would come out all right. ", "answer":"Tom Robinson" },' +
'{"question":"This wealthy white man is married to a negro woman and has \'\'mixed\'\' children. He pretends to be drunk so the other whites in town will all have an excuse. In reality, he prefers living among blacks. This person drank Coco-Cola from a bag. ", "answer":"Dolphus Raymond" },' +
'{"question":"These two people were mostly deaf and had huge ear horns. On Halloween, the children sneaked in and moved all the furniture into the cellar. A hound had to be summoned to find it. This prank led to the Halloween party in the school gym. Who were these two people?", "answer":"The Barber Sisters (The Barber Sisters (Miss Tutti and Frutti)" },' +
'{"question":"This Doctor is a friend of Scout\'s because he \'\'had brought Jem and me into the world, had lead us through every childhood disease known to man including the time Jem fell out of the tree house, and he had never lost our friendship....\'\' Who fixed Jem up to the best of his ability?", "answer":"Dr. Scott Reynolds" },' +
'{"question":"Who said this? \'\'I wanted you to see what real courage is, instead of getting the idea that courage is a man with a gun in his hand. It\'s when you know you\'re licked before you begin, but you begin anyway and see it through no matter what\'\'", "answer":"Atticus Finch" },' +
'{"question":"This person\'s role in a community is to protect law and order. When he was called to the Finch\'s to kill a mad dog, he gave the gun to Atticus rather than risk a shot going into the Radley place. This man also arrested Tom Robinson without evidence, but still warned Atticus that he may not be able to protect him the night of the trial. Who ended up being a witness for the Ewells in the trial of Tom Robinson? ", "answer":"Mr. Heck Tate" },' +
'{"question":"This person respected Dill, Jem, and Scout, and really helped Scout understand Atticus. She is a garderner and spends time talking to the children and baking cakes. In Chapter 8, her house caught on fire. Whp lives across the street from the Finches?", "answer":"Miss Maudie Atkinson" },' +
'{"question":"This literate and educate character is older than Atticus. One day, she takes the children to her church, which makes LuLa extremly unhappy. This person is like a mother to the children. Who is the Finch\'s cook?", "answer":"Calpurnia" },' + /*
'{"question":"On Scout\'s first day of school, this person messed up. She is unaware of her surroundings and doesn\'t know what to do. She gave a Cunningham money and tried to make an Ewell do something. Who is Scout\'s first teacher?", "answer: "Miss Caroline Fisher" },' +*/
'{"question":"This narrator of the story is what, according to some people, made the story so hard to write and so easy to read. THis person lives with Jem and Atticus. What is Scout\'s real name?", "answer":"Jean Louise Finch" },' +
'{"question":"This literate boy is named in the book at least 280 times. He is known for being a \'\'third person\'\' to act out their plays. While he is a person that turns statements into hyperboles, he was a great \'\'villian\'s villian\'\'. For 10 points, what is Dill\'s real name?","answer":"Charles Baker Harris" }]}';
var scores = '{}';
que = JSON.parse(text);
// que.problems[0].question;
// que.problems[0].answer;
var pauseQuestion = false;
io.on('connection', function(socket){
socket.on('disconnect', function() {
usersOnline--;
if(usersOnline == "0"){
chars=0;
id=0;
scores = '{}';
console.log(" ");
console.log("XXXXX==== reset!!! ====XXXXX");
console.log(" ");
pauseQuestion === false;
}
io.emit("usersUpdate", usersOnline);
console.log('>> Disconnect :( Now:' + usersOnline + "");
});
socket.on("question", function(msg){
// live stream question here
});
socket.on("chars", function(msg){
// live stream question chars here
if(chars <= que.problems[id].question.length && !pauseQuestion){
chars++;
}
io.emit('chars', chars);
io.emit('question', que.problems[id].question.substr(0,chars));
});
socket.on("buzz", function(msg){
// let everyone know whos buzzing
io.emit("buzz", msg);
console.log(msg + " buzzed in!");
pauseQuestion = true;
});
socket.on("answer", function(msg){
// let enable peoples buzz button again
console.log(msg.split(/\s*\-\s*/g)[0] +" anawered with " + msg.split(/\s*\-\s*/g)[1]);
io.emit("answer", msg.split(/\s*\-\s*/g)[1]);
var answer = msg.split(/\s*\-\s*/g)[1];
var username = msg.split(/\s*\-\s*/g)[0];
if(answer === que.problems[id].answer){
io.emit("correct", answer +"-"+ username);
console.log("--correct");
chars = que.problems[id].question.length;
scores = JSON.parse(scores);
if(scores[username]){
scores[username] =scores[username] + 10;
} else {
scores[username] = 10;
}
scores = JSON.stringify(scores);
io.emit("scoresUpdate", scores);
console.log(scores);
setTimeout(function () { pauseQuestion = false; chars=0;
id++; id = id%(totalIDS)}, 3000);
} else {
console.log("--incorrect");
io.emit("incorrect", answer+"-"+username);
scores = JSON.parse(scores);
pauseQuestion=false;
if(scores[username]){
scores[username] =scores[username] -5;
} else {
scores[username] = -5;
}
scores = JSON.stringify(scores);
io.emit("scoresUpdate", scores);
console.log(scores);
}
});
socket.on("correct", function(msg){
console.log("\n \n something is wrong code correct \n \n");
});
socket.on("incorrect", function(msg){
console.log("\n \n something is wrong code incorrect \n \n");
});
socket.on("score", function(msg){
io.emit("scoresUpdate", scores);
});
socket.on("resetScores", function(msg){
scores = '{}';
io.emit("scoresUpdate", scores);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment