Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Node JS
- var discord = require('discord-bot-webhook');
- var mysql = require('mysql');
- var io = require('socket.io')(8000);
- var connection = mysql.createConnection({
- host : 'localhost',
- user : 'root',
- password : '',
- database : 'rollgg'
- });
- connection.connect();
- discord.hookId = '';
- discord.hookToken = '';
- var users = [];
- var timer = 20;
- var currentBets = [];
- var currentRollInfo = [];
- var rolling = false;
- var usersOnline = 0;
- io.on('connection', function(socket) {
- usersOnline += 1
- io.sockets.emit("users", usersOnline);
- socket.on('authenticate', function(identifier) {
- getAccountInfo(identifier,function(account){
- //discord.sendMessage('new connection with the steamid: ' + account.steamid);
- console.log('new connection with the steamid: ' + account.steamid);
- users[socket.id] = {steamid: account.steamid, identifier: identifier, avatar: account.avatar, name: account.nickname};
- });
- });
- socket.on('disconnect', function () {
- //discord.sendMessage(users[socket.id].steamid + ' disconnected');
- console.log(users[socket.id].steamid + ' disconnected');
- usersOnline -= 1;
- io.sockets.emit("users", usersOnline);
- //delete users[socket.id];
- });
- });
- setInterval(function() {
- if(timer.toFixed(2) >= -0.00)
- {
- io.sockets.emit("updateTime", timer);
- }
- timer-= 0.010;
- if(timer.toFixed(2) == -1.00)
- {
- var rolledNumber = (Math.floor(Math.random() * 14));
- var colour;
- if (rolledNumber == 0)
- {
- colour = "green";
- }
- else if (rolledNumber <= 7)
- {
- colour = "red";
- }
- else
- {
- colour = "black";
- }
- currentRollInfo.push({roll: rolledNumber, colour: colour, time: Math.round((new Date()).getTime() / 1000)});
- console.log("Rolled " + colour);
- io.sockets.emit("roll", rolledNumber);
- connection.query('INSERT INTO rolls SET ?', currentRollInfo);
- rolling = true;
- setInterval(function() {
- rolling = false;
- }, 3250);
- }
- if(timer.toFixed(2) == -4.20)
- {
- currentBets.forEach(function(bet) {
- if(bet.colour == currentRollInfo[0].colour)
- {
- console.log(bet.steamid + " Has won " + bet.amount*2);
- connection.query('UPDATE `users` SET `balance` = `balance` + '+bet.amount*2+' WHERE `steamid` = '+bet.steamid);
- }
- });
- currentBets = [];
- currentRollInfo = [];
- timer = 20;
- }
- }, 10);
- function getAccountInfo(identifier, callback)
- {
- connection.query("SELECT * from users WHERE identifier = " + connection.escape(identifier), function(err, row) {
- if (err)
- {
- console.log('Error while performing Query.');
- //io.sockets.emit('notification', { message: "Error obtaining user details. Please try again later.", identifier: identifier, type: "error" });
- return;
- }
- callback(row[0]);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement