Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. #!/usr/bin/nodejs
  2. // Minecraft server > Scratch Status
  3. // by hiccup01
  4. // hiccup01.com
  5. // Copyright (c) 2016 hiccup01 <hiccup@hiccup01.com>
  6.  
  7. //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:
  8.  
  9. //The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  10.  
  11. //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.
  12.  
  13. // Load the scratch-api, argv and minecraft-ping
  14. var Scratch = require('scratch-api');
  15. var argv = require('yargs').argv;
  16. var boing = require('boing');
  17.  
  18. // Minecraft credentials (For boing)
  19. var username = "";
  20. var password = "";
  21.  
  22. //Scratch credentials
  23. var susername = "";
  24. var spassword = "";
  25.  
  26. // Project ID
  27. var projectid = "";
  28.  
  29. // Packet - Info to send
  30. var packet = "The ping may have failed... ";
  31.  
  32. //The server to use
  33. var server = "";
  34.  
  35. // Check if the command specifies a different packet
  36. if (argv.packet != null || undefined) {
  37. packet = argv.packet;
  38. };
  39.  
  40. //Encoding function
  41. function encode(text) {
  42. // Encoding chart
  43. var characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789.%/\"'!@#$&()[]";
  44. var chars = [];
  45. for (var i = characters.length - 1; i >= 0; i--) {
  46. chars.splice(0, 0, characters[i]); // Prepend the character
  47. };
  48. // Variable inting for encoding
  49. var out = "";
  50. var encodelength = (text.length);
  51. var padder= "";
  52. var length =padder.length;
  53. for (var i = 0; i < encodelength; i++) {
  54. padder = chars.indexOf(text.charAt(i)); // Find index for char
  55. padder++ // Normanilize for scratch because scratch counts from one
  56. padder = padder.toString(); // Convert padder to string to avoid errors
  57. length = padder.length;
  58. if (length == 1) { // If the index is a single digit number then,
  59. padder = "0" + padder; // Add a zero on the front
  60. };
  61. out = out.concat(padder); // Add the index to the string to be sent
  62.  
  63. }
  64. return out // Return the number for the scratch-api to use
  65. }
  66.  
  67. boing({
  68. ip: server,
  69. username: username,
  70. password: password
  71. }, function(err, response) {
  72. if (err) {
  73. console.log(err);
  74. } else {
  75. console.log(response);
  76. packet = "Running version " + "1.8.9" + " with " + (response.players.online) + "/" + (response.players.max) + " " + "players online.";
  77. Scratch.UserSession.create(susername, spassword, function(err, user) { // Load the UserSession
  78. if (err == "null") { // If there is an error log it, if there is not don't
  79. console.log(err);
  80. } else {
  81. console.log("UserSession loaded with no errors.");
  82. }
  83.  
  84. user.cloudSession(projectid, function(err, cloudSession) { // Load the cloudSession
  85. if (err == "null") { // If there is an error log it, if there is not don't
  86. console.log(err);
  87. } else {
  88. console.log("cloudSession loaded with no errors.");
  89. }
  90. var enocodedpacket = encode(packet); // Enocode packet into a sendable state
  91. console.log(enocodedpacket); // Log it
  92. cloudSession.set("☁ status", enocodedpacket); //Set the var
  93. console.log("Set cloud variable \"☁ status\" to " + packet); // Say about it
  94. setTimeout(function(){ cloudSession.end(); }, 500);
  95. });
  96. });
  97.  
  98.  
  99. };
  100. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement