Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/nodejs
- // Minecraft server > Scratch Status
- // by hiccup01
- // hiccup01.com
- // Copyright (c) 2016 hiccup01 <hiccup@hiccup01.com>
- //Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- //The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- // Load the scratch-api, argv and minecraft-ping
- var Scratch = require('scratch-api');
- var argv = require('yargs').argv;
- var boing = require('boing');
- // Minecraft credentials (For boing)
- var username = "";
- var password = "";
- //Scratch credentials
- var susername = "";
- var spassword = "";
- // Project ID
- var projectid = "";
- // Packet - Info to send
- var packet = "The ping may have failed... ";
- //The server to use
- var server = "";
- // Check if the command specifies a different packet
- if (argv.packet != null || undefined) {
- packet = argv.packet;
- };
- //Encoding function
- function encode(text) {
- // Encoding chart
- var characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.%/\"'!@#$&()[]";
- var chars = [];
- for (var i = characters.length - 1; i >= 0; i--) {
- chars.splice(0, 0, characters[i]); // Prepend the character
- };
- // Variable inting for encoding
- var out = "";
- var encodelength = (text.length);
- var padder= "";
- var length =padder.length;
- for (var i = 0; i < encodelength; i++) {
- padder = chars.indexOf(text.charAt(i)); // Find index for char
- padder++ // Normanilize for scratch because scratch counts from one
- padder = padder.toString(); // Convert padder to string to avoid errors
- length = padder.length;
- if (length == 1) { // If the index is a single digit number then,
- padder = "0" + padder; // Add a zero on the front
- };
- out = out.concat(padder); // Add the index to the string to be sent
- }
- return out // Return the number for the scratch-api to use
- }
- boing({
- ip: server,
- username: username,
- password: password
- }, function(err, response) {
- if (err) {
- console.log(err);
- } else {
- console.log(response);
- packet = "Running version " + "1.8.9" + " with " + (response.players.online) + "/" + (response.players.max) + " " + "players online.";
- Scratch.UserSession.create(susername, spassword, function(err, user) { // Load the UserSession
- if (err == "null") { // If there is an error log it, if there is not don't
- console.log(err);
- } else {
- console.log("UserSession loaded with no errors.");
- }
- user.cloudSession(projectid, function(err, cloudSession) { // Load the cloudSession
- if (err == "null") { // If there is an error log it, if there is not don't
- console.log(err);
- } else {
- console.log("cloudSession loaded with no errors.");
- }
- var enocodedpacket = encode(packet); // Enocode packet into a sendable state
- console.log(enocodedpacket); // Log it
- cloudSession.set("☁ status", enocodedpacket); //Set the var
- console.log("Set cloud variable \"☁ status\" to " + packet); // Say about it
- setTimeout(function(){ cloudSession.end(); }, 500);
- });
- });
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement