Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var Winston = require('winston');
- var Logger = new(Winston['Logger'])({ transports: [new(Winston['transports']['Console'])({ colorize: true, timestamp: true, level: 'debug', label: 'BOT' }), new(Winston['transports']['File'])({ level: 'info', label: 'BOT', createDirectory: true, timestamp: true, filename: 'bot.log', json: false })] });
- var scribe = require('scribe-js')(),
- console = process.console,
- config = require('./config.js'),
- app = require('express')(),
- server = require('http').Server(app),
- io = require('socket.io')(server),
- redis = require('redis'),
- requestify = require('requestify'),
- mysql = require('mysql'),
- bot = require('./bot.js');
- server.listen(config.serverPort);
- app.get('/', function (req, res) {
- res.json({
- message: 'Please, fuck yourself, asshole!',
- });
- });
- var redisClient = redis.createClient({host: config.redis.host, port: config.redis.port}),
- client = redis.createClient({host: config.redis.host, port: config.redis.port});
- Logger.info('Domain ' + config.domain );
- Logger.info('Port ' + config.serverPort);
- bot.init(redis, io, requestify);
- var pool = mysql.createPool({
- connectionLimit : 1000,
- database: config.db.database,
- host: 'localhost',
- user: 'root',
- password: config.db.password
- });
- redisClient.subscribe('show.winners');
- redisClient.subscribe('message');
- redisClient.subscribe('updateBalance');
- redisClient.subscribe('queue');
- redisClient.subscribe('newDeposit');
- redisClient.subscribe('depositDecline');
- redisClient.subscribe('new.msg');
- redisClient.subscribe('del.msg');
- redisClient.subscribe('dbl_p');
- redisClient.subscribe('msgChannel');
- redisClient.setMaxListeners(0);
- redisClient.on("message", function (channel, message) {
- if (channel == 'depositDecline' || channel == 'queue' || channel == 'dbl_p') {
- io.sockets.emit(channel, message);
- }
- if (channel == 'message') {
- io.sockets.emit('message', message);
- }
- if (channel == 'updateBalance') {
- io.sockets.emit('updateBalance', message);
- }
- if (channel == 'show.winners') {
- clearInterval(timer);
- timerStatus = false;
- console.log('Force Stop');
- game.status = 3;
- showSliderWinners();
- }
- if (channel == 'newDeposit') {
- io.sockets.emit(channel, message);
- message = JSON.parse(message);
- if (!timerStatus && message.gameStatus == 1) {
- game.status = 1;
- startTimer(io.sockets);
- }
- }
- if (channel == 'new.msg') {
- io.sockets.emit('chat', message);
- }
- if (channel == 'del.msg') {
- io.sockets.emit('chatdel', message);
- }
- });
- /* USERS ONLINE SITE */
- io.sockets.on('connection', function(socket) {
- updateOnline();
- socket.on('disconnect', function(){
- updateOnline();
- })
- });
- function updateOnline(){
- io.sockets.emit('online', Object.keys(io.sockets.adapter.rooms).length );
- }
- /* USERS ONLINE SITE END */
- var steamStatus = [],
- game,
- timer,
- ngtimer,
- timerStatus = false,
- timerTime = 90,
- preFinishingTime = 2;
- getPriceItems();
- getCurrentGame();
- checkSteamInventoryStatus();
- var preFinish = false;
- function checkInventor() {
- setInterval(function () {
- requestify.post(config.domain + '/viplatitj', {
- secretKey: config.secretKey
- })
- .then(function(response) {
- console.tag('INVESTOR').log('Checked investors!');
- }, function(response) {
- console.tag('INVESTOR').log('Something wrong [checkInvestor]');
- });
- }, 420000);
- }
- function startTimer() {
- var time = timerTime;
- timerStatus = true;
- clearInterval(timer);
- console.tag('Игра').log('Игра началась.');
- timer = setInterval(function () {
- //console.tag('Game').log('Timer:' + time);
- io.sockets.emit('timer', time--);
- if ((game.status == 1) && (time <= preFinishingTime)) {
- if (!preFinish) {
- preFinish = true;
- setGameStatus(2);
- }
- }
- if (time <= 0) {
- clearInterval(timer);
- timerStatus = false;
- console.tag('Игра').log('Игра окончена!');
- showSliderWinners();
- }
- }, 1000);
- }
- function startNGTimer(winners) {
- var time = 15;
- data = JSON.parse(winners);
- data.showSlider = true;
- clearInterval(ngtimer);
- ngtimer = setInterval(function () {
- if (time <= 12) data.showSlider = false;
- //console.tag('Game').log('NewGame Timer:' + time);
- data.time = time--;
- io.sockets.emit('slider', data);
- if (time <= 0) {
- clearInterval(ngtimer);
- newGame();
- }
- }, 1000);
- }
- function getPriceItems() {
- requestify.post(config.domain + '/api/getPriceItems', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- Logger.info('Prices for items added');
- }, function (response) {
- Logger.info('Something wrong [getPriceItems]');
- });
- }
- function getCurrentGame() {
- requestify.post(config.domain + '/api/getCurrentGame', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- game = JSON.parse(response.body);
- Logger.info('Current Game #' + game.id);
- if (game.status == 1) startTimer();
- if (game.status == 2) startTimer();
- if (game.status == 3) newGame();
- }, function (response) {
- console.tag('Game').log('Something wrong [getCurrentGame]');
- setTimeout(getCurrentGame, 1000);
- });
- }
- function bonus_bot(){
- requestify.post(config.domain+'/api/bonus_bot', {
- secretKey: config.secretKey
- })
- }
- function newGame() {
- requestify.post(config.domain + '/api/newGame', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- preFinish = false;
- game = JSON.parse(response.body);
- console.tag('Game').log('New game! #' + game.id);
- io.sockets.emit('newGame', game);
- updateMaxPrice();
- updateUsersToday();
- updateGamesToday();
- bonus_bot();
- }, function (response) {
- console.log(response);
- console.tag('Game').error('Something wrong [newGame]');
- setTimeout(newGame, 1000);
- });
- }
- function showSliderWinners() {
- requestify.post(config.domain + '/api/getWinners', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- var winners = response.body;
- console.tag('Game').log('Show slider!');
- startNGTimer(winners);
- setGameStatus(3);
- //io.sockets.emit('slider', winners)
- }, function (response) {
- console.tag('Game').error('Something wrong [showSlider]');
- setTimeout(showSliderWinners, 1000);
- });
- }
- function setGameStatus(status) {
- requestify.post(config.domain + '/api/setGameStatus', {
- status: status,
- secretKey: config.secretKey
- })
- .then(function (response) {
- game = JSON.parse(response.body);
- console.tag('Game').log('Set game to a prefinishing status. Bets are redirected to a new game.');
- }, function (response) {
- console.tag('Game').error('Something wrong [setGameStatus]');
- setTimeout(setGameStatus, 1000);
- });
- }
- function updateMaxPrice() {
- requestify.post(config.domain + '/api/maxprice', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- console.tag('Статистика', logTime()).log('Макс. Выигрыш - Обновлено');
- data = JSON.parse(response.body);
- io.sockets.emit('updateMaxPrice', data);
- }
- );
- }
- function updateUsersToday() {
- requestify.post(config.domain + '/api/userstoday', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- console.tag('Статистика', logTime()).log('Игроков Сегодня - Обновлено');
- data = JSON.parse(response.body);
- io.sockets.emit('updateUsersToday', data);
- }
- );
- }
- function updateGamesToday() {
- requestify.post(config.domain + '/api/gamestoday', {
- secretKey: config.secretKey
- })
- .then(function (response) {
- console.tag('Статистика', logTime()).log('Игр Сегодня - Обновлено');
- data = JSON.parse(response.body);
- io.sockets.emit('updateGamesToday', data);
- }
- );
- }
- function checkSteamInventoryStatus() {
- requestify.get('https://api.steampowered.com/ICSGOServers_730/GetGameServersStatus/v1/?key=' + config.apiKey)
- .then(function (response) {
- var answer = JSON.parse(response.body);
- steamStatus = answer.result.services;
- client.set('steam.community.status', steamStatus.SteamCommunity);
- client.set('steam.inventory.status', steamStatus.IEconItems);
- }, function (response) {
- console.log('Something wrong [5]');
- });
- }
- setInterval(checkSteamInventoryStatus, 12000);
Advertisement
Add Comment
Please, Sign In to add comment