Handle connections

This commit is contained in:
AlexKvazos
2015-04-28 02:01:29 -05:00
parent a867668582
commit bc5b1ed90d
9 changed files with 128 additions and 20 deletions
Executable
+37
View File
@@ -0,0 +1,37 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/iojs', '/usr/local/bin/npm', 'start' ]
2 info using npm@2.8.3
3 info using node@v1.8.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart Chat@1.0.0
6 info start Chat@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info Chat@1.0.0 Failed to exec start script
9 verbose stack Error: Chat@1.0.0 start: `node server/index.js`
9 verbose stack Exit status 1
9 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at EventEmitter.emit (events.js:169:7)
9 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at ChildProcess.emit (events.js:169:7)
9 verbose stack at maybeClose (child_process.js:953:16)
9 verbose stack at Process.ChildProcess._handle.onexit (child_process.js:1020:5)
10 verbose pkgid Chat@1.0.0
11 verbose cwd /Library/WebServer/Documents/MCBoard/Chat
12 error Darwin 14.3.0
13 error argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "start"
14 error node v1.8.1
15 error npm v2.8.3
16 error code ELIFECYCLE
17 error Chat@1.0.0 start: `node server/index.js`
17 error Exit status 1
18 error Failed at the Chat@1.0.0 start script 'node server/index.js'.
18 error This is most likely a problem with the Chat package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error node server/index.js
18 error You can get their info via:
18 error npm owner ls Chat
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
Regular → Executable
+2 -2
View File
@@ -2,7 +2,7 @@
"name": "Chat",
"version": "1.0.0",
"description": "Minecraft chat client",
"main": "app.js",
"main": "server/index.js",
"dependencies": {
"debug": "^2.1.3",
"express": "^4.12.3",
@@ -12,7 +12,7 @@
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
"start": "node server/index.js"
},
"repository": {
"type": "git",
Regular → Executable
View File
Regular → Executable
+48 -6
View File
@@ -1,8 +1,50 @@
// initialize angular application
var app = angular.module('chat', []);
$('#buffer').append('<br>');
$('#buffer').append('Welcome to AlexKvazos\'s Minecraft Chat App');
$('#buffer').append('<br>');
$('#buffer').append('&gt; Press connect to connect to a Minecraft server and start chatting!');
$('#buffer').append('<br><br>');
$('#buffer').append('<i>Note: This application only works with 1.8 Minecraft servers.</i>');
// socket service
app.factory('socket', function() {
var socket = io(window.location.host);
return socket;
});
// connect controller
app.controller('connectController', function($scope, socket) {
// connect handler
$scope.connect = function() {
if (socket.connected) {
socket.emit('server:connect', {
username: $scope.username,
password: $scope.password,
hostname: $scope.ip,
port: $scope.port || 25565
}, function(response) {
});
} else {
alert('Server unreachable, please try again later...');
}
}
});
// buffer controller
app.controller('bufferController', function($scope, socket) {
// initial console buffer
$('#buffer').append('<br>');
$('#buffer').append('Welcome to AlexKvazos\'s Minecraft Chat App');
$('#buffer').append('<br>');
$('#buffer').append('&gt; Press connect to connect to a Minecraft server and start chatting!');
$('#buffer').append('<br><br>');
$('#buffer').append('<i>Note: This application only works with 1.8 Minecraft servers.</i>');
$('#buffer').append('<br>-<br><br>');
socket.on('bot:error', function(error) {
console.log(error);
$('#buffer').append('<span style="color:#D62D18;">' + error.errorMessage + '</span><br>');
});
});
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
+7 -5
View File
@@ -8,22 +8,24 @@
// create new express application
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var path = require('path');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
// handle root requests
app.get('/', function(req, res, next) {
res.sendFile(__dirname + '/views/index.html');
res.sendFile(path.join(__dirname, '/../views/index.html'));
});
// public folder serves static content
app.use('/static', express.static('public'));
// configure socket.io
require('./sockets')(io);
// initialize http and socket servers
app.listen(3000, function() {
server.listen(3000, function() {
console.log('> Server running on port 3000')
});
+27
View File
@@ -0,0 +1,27 @@
var mineflayer = require('mineflayer');
module.exports = function(io) {
io.on('connection', function(socket) {
socket.on('server:connect', function(data, response) {
socket.mcbot = mineflayer.createBot({
host: data.hostname,
port: data.port,
username: data.username,
password: data.password
});
socket.mcbot.on('error', function(error) {
console.log(error);
socket.emit('bot:error', error);
});
});
socket.on('disconnect', function() {
socket.mcbot = null;
});
});
};
Regular → Executable
+7 -7
View File
@@ -18,7 +18,7 @@
</ul>
</nav>
<div id="buffer">
<div id="buffer" ng-controller="bufferController">
</div>
@@ -33,7 +33,7 @@
</form>
<!-- Modal -->
<div class="modal fade" id="connectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="connectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" ng-controller="connectController">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
@@ -45,24 +45,24 @@
<form>
<div class="form-group">
<label>Minecraft Username</label>
<input type="text" ng-model="username" class="form-control" placeholder="Steve">
<input type="text" ng-model="username" class="form-control" placeholder="Steve" required>
</div>
<div class="form-group">
<label>Minecraft Password</label>
<input type="password" ng-model="password" class="form-control" placeholder="">
<input type="password" ng-model="password" class="form-control" placeholder="" required>
</div>
<div class="form-group">
<label>Server IP</label>
<input type="password" ng-model="ip" class="form-control" placeholder="mc.server.com">
<input type="text" ng-model="ip" class="form-control" placeholder="mc.server.com" required>
</div>
<div class="form-group">
<label>Server Port (Leave empty if unknown)</label>
<input type="password" ng-model="port" class="form-control" placeholder="25565">
<input type="number" ng-model="port" class="form-control" placeholder="25565">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Connect</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="connect()">Connect</button>
</div>
</div>
</div>