Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * ArcusNode Service
- *
- * Copyright 2011 OpenRTMFP
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License received along this program for more
- * details (or else see http://www.gnu.org/licenses/).
- *
- * Author: arcusdev <arcus.node@gmail.com>
- *
- * This file is a part of ArcusNode.
- */
- var util = require('util');
- var ArcusNode = require('./lib/arcus_node.js');
- //Take command line arguments
- var settings = {};
- process.argv.forEach(function (val, index, array) {
- if(index < 2)
- return;
- var valArr = val.split('=');
- switch(valArr[0]){
- case 'logLevel':
- settings.logLevel = valArr[1];
- util.print('Setting logLevel to ' + valArr[1] + '\n');
- break;
- case 'logFile':
- settings.logFile = valArr[1];
- util.print('Setting logFile to ' + valArr[1] + '\n');
- break;
- case '-h':
- case '-help':
- util.print(
- '### USAGE ###\n\n' +
- 'node service.js [argument1 argument2 ...]\n\n' +
- 'Arguments:\n' +
- 'logLevel=[level] [level] can be one of: fatal, error, warn, info, debug' +
- 'logFile=[path] [path] The path to a file to log output to' +
- '\n\n'
- );
- process.exit();
- break;
- default:
- util.print('Argument unknown or malformed: ' + val + '\nStopping process.');
- process.exit();
- }
- });
- //Startup
- util.print(
- 'Starting up ArcusNode RTMFP Service.\nCopyright (C) 2011 OpenRTMFP \n' +
- 'This program comes with ABSOLUTELY NO WARRANTY.\n' +
- 'This is free software, and you are welcome to redistribute it under certain conditions.\n' +
- '(For usage help type "node service.js -h")\n'
- );
- var usercount = 0;
- var messages = [];
- var usernames = [];
- /*
- settings.manageInterval = 24 * 60 * 60;
- settings.connectionTimeout = (24 * 60 * 60)*1000;
- settings.clientKeepalive = 1000;
- settings.serverKeepalive = 1000;
- settings.maxKeepalives = 30000;
- */
- var arc = new ArcusNode(settings);
- arc.on('connect', function(nc, obj){
- usercount++;
- usernames.push({
- id : nc.__p.id,
- name : 'Guest ' + usercount
- });
- messages.push('Guest ' + usercount + ' joined!');
- nc.accept();
- });
- function getUsername(nc) {
- var username = '';
- for (var i = usernames.length - 1; i >= 0; i--) {
- if(nc.__p.id == usernames[i].id)
- {
- username = usernames[i].name;
- }
- };
- return username;
- }
- arc.on('disconnect', function(){
- usercount--;
- });
- util.print(util.inspect(arc, false, null));
- arc.onCommand('getWelcomeMessage', function(nc, obj){
- var message = 'Welcome to this testroom, there are currently '+usercount+' user online';
- messages.push(message);
- var username = getUsername(nc);
- util.print('client connected:'+nc.__p.id+"\n");
- //util.print(util.inspect(nc, false, null));
- return { what: message, name : username };
- });
- arc.onCommand('sendMessage', function(nc, obj){
- var username = getUsername(nc);
- messages.push(username + ' : ' + obj.message);
- return { what: messages.join("\n") };
- });
- arc.onCommand('getMessages', function(nc, obj){
- return { what: messages.join("\n") };
- });
- arc.run();
- process.on('SIGINT', function () {
- util.print('\033[36mArcusNode shutting down...\033[0m\n');
- arc.stop();
- });
- process.on('exit', function(){
- util.print('\033[36mArcusNode stopped.\033[0m\n');
- });
- util.print('ArcusNode RTMFP Service running at ' + arc.address.address + ((arc.address.port != '') ? ':' + arc.address.port : '') + '\n');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement