Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Initalizing packages
- */
- var fs = require('fs');
- var request = require('request');
- var config = require('./config.json');
- var CryptoJS = require("crypto-js");
- var log4js = require('log4js');
- var express = require('express');
- var sha256 = require('sha256');
- var math = require('mathjs');
- var app = express();
- var server = require('http').createServer();
- var io = require('socket.io')(server);
- server.listen(8880);
- updateLog(time());
- function updateLog(time) {
- log4js.configure({
- appenders: [
- { type: 'console' },
- { type: 'file', filename: 'logs/site_'+time+'.log' }
- ]
- });
- }
- var logger = log4js.getLogger();
- var mysql = require('mysql');
- var db_config = {
- //debug: true,
- host: config.options.sql['host'],
- user: config.options.sql['username'],
- password: config.options.sql['password'],
- database: config.options.sql['database'],
- supportBigNumbers: true
- };
- var pool;
- handleDisconnect();
- process.on('uncaughtException', function (err) {
- logger.error('Strange error');
- logger.error(err);
- });
- //GAME INFO
- var AppID = 730;
- var ContextID = 2;
- var minDep = config.options.minDeposit;
- //ROULETTE
- var currentMode = 'NONE';
- var currentColors = {};
- var betTimes = {};
- var usersBalance = {};
- var currentSums = {
- 'red': 0,
- 'blue': 0,
- 'green': 0,
- 'black': 0
- };
- var currentBets = [];
- var currentTimer = 30;
- var currentLastNumber = -1;
- var currentLastWooble = -1;
- var currentHash = "";
- var currentSecret = "";
- var currentLottery = "";
- var lastRolls = [];
- var withdrawItems = [];
- var proxies = config.proxies;
- var inventoryTimer = {};
- var socketBySteam = {};
- var antiFlood = {};
- var timesFlooding = {};
- var inventoryUser = {};
- //CHAT FUNCTIONS
- var chatMessages = [];
- var usersOnline = {};
- var antiSpamChat = {};
- //CHAT FUNCTIONS
- startRoulette();
- io.on('connection', function(socket) {
- socket.on('hash', function(m) {
- var address = socket.handshake.address;
- addHistory(socket);
- if(!usersOnline[address])
- {
- usersOnline[address] = 1;
- }
- if(m.hash)
- {
- pool.query('SELECT steamid, refmoney, tlink FROM users WHERE hash = ' + pool.escape(m.hash), function(err, row) {
- if(err) throw err;
- if(row.length == 0) return;
- usersBalance[row[0].steamid] = {
- 'balance': row[0].refmoney
- }
- if(socketBySteam.hasOwnProperty(row[0].steamid))
- {
- delete socketBySteam[row[0].steamid];
- socketBySteam[row[0].steamid] = {
- 'info': socket.id
- };
- }
- else
- {
- socketBySteam[row[0].steamid] = {
- 'info': socket.id
- };
- }
- currentBets.forEach(function(item) {
- socket.emit('roulette_newbet', item.bet, item.color, item.user, item.avatar, item.name);
- });
- var emitRolls = lastRolls.join('/');
- socket.emit('roulette_addroll', emitRolls);
- io.sockets.emit('connections', Object.keys(usersOnline).length);
- socket.emit('roulette_hash', currentHash);
- socket.emit('roulette_bets', currentSums);
- socket.emit('connected', row[0].refmoney, row[0].steamid, row[0].tlink, currentLastNumber, currentLastWooble);
- socket.emit('roulette_start', currentTimer);
- });
- }
- else
- {
- currentBets.forEach(function(item) {
- socket.emit('roulette_newbet', item.bet, item.color, item.user, item.avatar, item.name);
- });
- var emitRolls = lastRolls.join('/');
- socket.emit('roulette_addroll', emitRolls);
- io.sockets.emit('connections', Object.keys(usersOnline).length);
- socket.emit('roulette_hash', currentHash);
- socket.emit('roulette_bets', currentSums);
- socket.emit('connected', 0, 'not logged in', 'not logged in', currentLastNumber, currentLastWooble);
- socket.emit('roulette_start', currentTimer);
- }
- });
- socket.on('roulette_addbet', function(value, bet, hash) {
- logger.trace(value + ' ' + bet);
- if(currentMode == 'WAITING')
- {
- pool.query('SELECT name, avatar, steamid, refmoney FROM users WHERE hash = ' + pool.escape(hash), function(err, row) {
- if(err) throw err;
- if(row.length == 0) return;
- if(value > row[0].refmoney)
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You do not have enough money!'
- });
- return;
- }
- if(value <= 0 || value >= 500000)
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You can bet more than $0.01 and less than $500 coins!'
- });
- return;
- }
- if(!currentColors.hasOwnProperty(row[0].steamid))
- {
- currentColors[row[0].steamid] = {
- 'red': 0,
- 'blue': 0,
- 'green': 0,
- 'black': 0
- };
- }
- if(currentColors[row[0].steamid]['red'] == 1 && bet == 'red')
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You can\'t bet on same color twice!'
- });
- return;
- }
- else if(currentColors[row[0].steamid]['blue'] == 1 && bet == 'blue')
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You can\'t bet on same color twice!'
- });
- return;
- }
- else if(currentColors[row[0].steamid]['green'] == 1 && bet == 'green')
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You can\'t bet on same color twice!'
- });
- return;
- }
- else if(currentColors[row[0].steamid]['black'] == 1 && bet == 'black')
- {
- socket.emit('msg', {
- tip: 'error',
- msg: 'You can\'t bet on same color twice!'
- });
- return;
- }
- else
- {
- pool.query('UPDATE users SET refmoney = refmoney - ' + pool.escape(value) + ' WHERE steamid = ' + pool.escape(row[0].steamid), function(er, ro) {
- if(er) throw er;
- if(ro.length == 0) return;
- pool.query('INSERT INTO bets SET user = ' + pool.escape(row[0].steamid) + ', bettime=UNIX_TIMESTAMP(), color = ' + pool.escape(bet) + ', amount = ' + pool.escape(value) + ', won = 0', function(e, r) {
- if(e) throw e;
- if(r.length == 0) return;
- getBalance(socket, row[0].steamid);
- currentBets.push({
- "id": r.insertId,
- "bet": value,
- "color": bet,
- "user": row[0].steamid,
- "avatar": row[0].avatar,
- "name": row[0].name
- });
- if(!betTimes.hasOwnProperty(row[0].steamid))
- {
- betTimes[row[0].steamid] = 0;
- betTimes[row[0].steamid] += 1;
- }
- else
- {
- betTimes[row[0].steamid] += 1;
- }
- currentSums[bet] += value;
- currentColors[row[0].steamid][bet] = 1;
- io.sockets.emit('roulette_newbet', value, bet, row[0].steamid, row[0].avatar, row[0].name);
- socket.emit('msg', {
- tip: 'alert',
- msg: 'You successfully placed bet #' + r.insertId + ' (' + betTimes[row[0].steamid] +'/3)'
- });
- io.sockets.emit('roulette_bets', currentSums);
- });
- });
- }
- });
- }
- });
- //CHAT FUNCTIONS
- socket.on('nMsg', function(m) {
- var mesaj = m.message;
- var utilizator = m.user;
- var hide = 0;
- var address = socket.client.request.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
- pool.query('SELECT `name`,`avatar`,`steamid`,`admin`,`mute` FROM `users` WHERE `hash` = ' + pool.escape(utilizator), function(err, res) {
- if (err) throw err;
- var row = res;
- if (!res[0]) return err;
- if (mesaj.length > 128 || mesaj.length < 6 && res[0].admin != 1) {
- socket.emit('msg', {
- tip: 'alert',
- msg: 'Error: Minimum length 6 and maximum length 128 to send a message.'
- });
- return;
- } else {
- if (antiSpamChat[res[0].steamid] + 2 >= time() && res[0].admin != 1) {
- socket.emit('msg', {
- tip: 'alert',
- msg: 'Error: You need to wait before sending another message.'
- });
- return;
- } else {
- antiSpamChat[res[0].steamid] = time();
- }
- var caca = null;
- if (caca = /^\/clear/.exec(mesaj)) {
- if (row[0].admin == 1 || row[0].admin == 92) {
- io.sockets.emit('addMessage', {
- tip: 'clear',
- name: 'Alert',
- rank: '0',
- avatar: 'http://services.imobbr.com/galeria/78/avatar.png',
- msg: 'Chat was cleared by Admin ' + row[0].name + '.'
- });
- chatMessages = [];
- logger.trace('Chat: Cleared by Admin ' + row[0].name + '.');
- }
- } else if (caca = /^\/mute ([0-9]*) ([0-9]*)/.exec(mesaj)) {
- if (row[0].admin == 1 || row[0].admin == 92) {
- var t = time();
- pool.query('UPDATE `users` SET `mute` = ' + pool.escape(parseInt(t) + parseInt(caca[2])) + ' WHERE `steamid` = ' + pool.escape(caca[1]), function(err2, row2) {
- if (err2) throw err2;
- if (row2.affectedRows == 0) {
- socket.emit('msg', {
- tip: 'alert',
- msg: 'Steamid not found in database.'
- });
- logger.trace('Mute: Steamid not found in database (' + caca[1] + ').');
- return;
- }
- socket.emit('msg', {
- tip: 'alert',
- msg: 'You have muted user for ' + caca[2] + ' seconds.'
- });
- logger.trace('Mute: Steamid ' + caca[1] + ' has been muted for ' + caca[2] + ' seconds by ' + row[0].name + ' (' + row[0].steamid + ').');
- });
- }
- } else if (caca = /^\/wload/.exec(mesaj)) {
- if (row[0].admin == 1) {
- }
- } else {
- if (row[0].mute > time() && row[0].mute != 0) {
- socket.emit('msg', {
- tip: 'alert',
- msg: 'You are muted (seconds remaining: ' + parseInt(row[0].mute - time()) + ').'
- });
- logger.trace('Mute: ' + row[0].name + ' (' + row[0].steamid + ') tried to speak (' + mesaj + ') while muted (seconds remaining: ' + parseInt(row[0].mute - time()) + ').');
- return;
- }
- if (chatMessages.length > 20) {
- chatMessages.shift();
- }
- chatMessages.push({
- name: res[0].name,
- avatar: res[0].avatar,
- steamid: res[0].steamid,
- rank: res[0].admin,
- message: mesaj
- });
- io.sockets.emit('addMessage', {
- msg: mesaj,
- avatar: res[0].avatar,
- steamid: res[0].steamid,
- rank: res[0].admin,
- name: res[0].name
- });
- logger.trace('Chat: Message from ' + row[0].name + ' (SID: ' + row[0].steamid + ', IP: ' + address + ', hide: ' + hide + ') --> ' + mesaj);
- }
- }
- });
- });
- socket.on('disconnect', function(m) {
- var address = socket.handshake.address;
- delete usersOnline[address];
- io.sockets.emit('connections', Object.keys(usersOnline).length);
- });
- });
- function startRoulette()
- {
- if(currentMode == 'NONE')
- {
- currentHash = sha256('CSGO7-' + time() + '-' + Math.floor(Math.random() * (690 - 1 + 1)) + 1);
- currentLottery = time();
- currentSecret = makeCode();
- logger.trace('[Roulette] nextRoll --> Round hash: ' + currentHash + ', Lottery: ' + currentLottery + ', Secret: ' + currentSecret + ', Cifra: ' + getCifra(currentHash, currentSecret, currentLottery));
- pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(getCifra(currentHash, currentSecret, currentLottery)) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
- io.sockets.emit('roulette_hash', currentHash);
- currentMode = 'WAITING';
- var rolls = setInterval(function() {
- currentTimer = currentTimer - 1;
- if(currentTimer == 0)
- {
- clearInterval(rolls);
- currentMode = 'ROLLING';
- setTimeout(function() {
- startRolling();
- }, 600);
- }
- }, 1000);
- }
- else if(currentMode == 'ENDED')
- {
- currentHash = sha256('CSGO7-' + time() + '-' + Math.floor(Math.random() * (690 - 1 + 1)) + 1);
- currentLottery = time();
- currentSecret = makeCode();
- logger.trace('[Roulette] nextRoll --> Round hash: ' + currentHash + ', Lottery: ' + currentLottery + ', Secret: ' + currentSecret + ', Cifra: ' + getCifra(currentHash, currentSecret, currentLottery));
- pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(getCifra(currentHash, currentSecret, currentLottery)) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
- io.sockets.emit('roulette_hash', currentHash);
- currentTimer = 30;
- currentMode = 'WAITING';
- var rolls = setInterval(function() {
- currentTimer = currentTimer - 1;
- if(currentTimer == 0)
- {
- clearInterval(rolls);
- currentMode = 'ROLLING';
- setTimeout(function() {
- startRolling();
- }, 600);
- }
- }, 1000);
- io.sockets.emit('roulette_start', currentTimer);
- }
- }
- function startRolling()
- {
- pool.query('SELECT * FROM rolls WHERE lottery = ' + pool.escape(currentLottery), function(err, row) {
- var cifra = row[0].cifra;
- var wooble = Math.random() * (1 - 0.1) + 0.1;
- io.sockets.emit('roulette_roll', cifra, wooble);
- setTimeout(function() {
- io.sockets.emit('roulette_secret', currentSecret);
- setTimeout(function() {
- currentLastNumber = cifra;
- currentLastWooble = wooble;
- // pool.query('INSERT INTO rolls SET cifra = ' + pool.escape(cifra) + ', hash = ' + pool.escape(currentHash) + ', lottery = ' + pool.escape(currentLottery) + ', secret = ' + pool.escape(currentSecret));
- if(lastRolls.length >= 10)
- {
- lastRolls.shift();
- }
- lastRolls.push(cifra);
- winnerRoulette(cifra);
- }, 2500);
- }, 7000);
- });
- }
- function winnerRoulette(cifra)
- {
- pool.query('SELECT * FROM rolls WHERE lottery = ' + pool.escape(currentLottery), function(err, row) {
- var number = row[0].cifra;
- currentMode = 'ENDED';
- currentBets.forEach(function(i) {
- if(i.color == 'red' && (number == 1))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number >= 3 && number <= 4))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number >= 6 && number <= 7))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number >= 9 && number <= 10))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number >= 12 && number <= 13))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number >= 15 && number <= 16))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'red' && (number == 18))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*3) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*3;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 2))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 5))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 8))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 11))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 14))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }else if(i.color == 'green' && (number == 17))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*5) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*5;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }
- else if(i.color == 'black' && (number >= 19 && number <= 36))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*2) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*2;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }
- else if(i.color == 'blue' && (number == 0))
- {
- pool.query('UPDATE users SET refmoney = refmoney + ' + pool.escape(i.bet*30) + ' WHERE steamid = ' + pool.escape(i.user));
- pool.query('UPDATE bets SET won = 1 WHERE id = ' + pool.escape(i.id));
- usersBalance[i.user]['refmoney'] += i.bet*30;
- if(io.sockets.connected[socketBySteam[i.user]['info']])
- {
- io.sockets.connected[socketBySteam[i.user]['info']].emit('roulette_balance', usersBalance[i.user]['refmoney']);
- }
- }
- });
- startRoulette();
- currentColors = {};
- currentBets = [];
- betTimes = {};
- currentSums = {
- 'red': 0,
- 'blue': 0,
- 'green': 0,
- 'black': 0
- };
- });
- }
- function getCifra(hash, secret, lottery)
- {
- var cifra = sha256(hash+'-'+secret+'-'+lottery);
- cifra = hexdec(cifra.substr(0, 16)) % 37;
- return cifra;
- }
- function hexdec(hexString) {
- hexString = (hexString + '').replace(/[^a-f0-9]/gi, '')
- return parseInt(hexString, 16)
- }
- function getBalance(socket, steamid)
- {
- pool.query('SELECT refmoney FROM users WHERE steamid = ' + pool.escape(steamid), function(err, row) {
- if(err) throw err;
- if(row.length == 0) return;
- var balanta = row[0].refmoney;
- usersBalance[steamid]['refmoney'] = row[0].refmoney;
- socket.emit('roulette_balance', balanta);
- });
- }
- function isInArray(value, array) {
- return array.indexOf(value) > -1;
- }
- function time()
- {
- return parseInt(new Date().getTime()/1000);
- }
- function addHistory(socket)
- {
- chatMessages.forEach(function(itm) {
- socket.emit('addMessage', {
- msg: itm.message,
- avatar: itm.avatar,
- steamid: itm.steamid,
- rank: itm.rank,
- name: itm.name
- });
- })
- }
- function makeCode() {
- var text = "";
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for(var i=0; i < 12; i++)
- text += possible.charAt(Math.floor(Math.random() * possible.length));
- return text;
- }
- function getProxy()
- {
- return "http://" + proxies[random(0,proxies.length-1)];
- }
- function random(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function getRandomFloat(min, max) {
- return (Math.random() * (max - min) + min).toFixed(10);
- }
- function handleDisconnect() {
- pool = mysql.createConnection(db_config);
- pool.connect(function(err) {
- if(err) {
- logger.trace('Error: Connecting to database: ', err);
- setTimeout(handleDisconnect, 2000);
- }
- });
- pool.on('error', function(err) {
- logger.trace('Error: Database error: ', err);
- if(err.code === 'PROTOCOL_CONNECTION_LOST') {
- handleDisconnect();
- } else {
- throw err;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement