Last active
December 7, 2021 05:00
-
-
Save rdebath/734110f764d585d550b1981e2f7b3026 to your computer and use it in GitHub Desktop.
Classicube API reader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MCGalaxy; | |
namespace Core { | |
public class Announce: Plugin { | |
public override string MCGalaxy_Version { get { return "1.8.0.0"; } } | |
public override string name { get { return "Announce"; } } | |
public override void Load(bool startup) { | |
Command.Register(new CmdAnnounce()); | |
} | |
public override void Unload(bool shutdown) { | |
Command.Unregister(Command.Find("Announce")); | |
} | |
} | |
public class CmdAnnounce : Command2 { | |
public override string name { get { return "Announce"; } } | |
public override string shortcut { get { return "an"; } } | |
public override string type { get { return "other"; } } | |
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } | |
public override void Use(Player p, string message) | |
{ | |
Player[] online = PlayerInfo.Online.Items; | |
foreach (Player pl in online) { | |
pl.SendCpeMessage(CpeMessageType.Announcement, message); | |
} | |
} | |
public override void Help(Player p) | |
{ | |
p.Message("%T/Announce - Send really important message to everyone."); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh - | |
COOKIES="$HOME/.curl_cookies" | |
VERBOSE=no | |
CCARGS=no | |
case "$1" in | |
-v ) VERBOSE=yes; shift ;; | |
-c ) CCARGS=yes; shift ;; | |
esac | |
[ "$(echo '"+"'|jq -r .)" != + ] && { echo>&2 "Please install 'jq'"; exit 1; } | |
[ "$1" = '' ] && { | |
echo>&2 "Usage: $0 [-v] [-c] [ServerName_ipport_or_hash] [UserName] [Password] [MFACode]" | |
echo>&2 "The Password and Code are usually optional " | |
echo>&2 "Omitting the username just lists matching hosts" | |
echo>&2 "The host can be a regex to match against the server name or" | |
echo>&2 "the ip address and port (127.0.0.1:25565) or the hash of the" | |
echo>&2 "server (ie: of it's ip and port)." | |
echo>&2 "" | |
echo>&2 "Authentication cookies are stored in $COOKIES" | |
exit 1 | |
} | |
SEARCH="$1" | |
NICK="$2" | |
PASS="$3" | |
CODE="$4" | |
[ "$NICK" != '' ] && { | |
mkdir -p -m 0700 "$COOKIES" | |
JSON1=$(curl -sS \ | |
--cookie "$COOKIES"/.cookie.$NICK \ | |
--cookie-jar "$COOKIES"/.cookie.$NICK \ | |
https://www.classicube.net/api/login/) | |
AUTHD=$(echo "$JSON1" | jq -r .authenticated) | |
TOKEN=$(echo "$JSON1" | jq -r .token) | |
[ "$AUTHD" = false ] && { | |
if [ "$PASS" != '' ] | |
then | |
JSON2=$( | |
curl -sS https://www.classicube.net/api/login \ | |
--cookie "$COOKIES"/.cookie.$NICK \ | |
--cookie-jar "$COOKIES"/.cookie.$NICK \ | |
--data username="$NICK" \ | |
--data password="$PASS" \ | |
--data token="$TOKEN" \ | |
${CODE:+ --data login_code="$CODE"} ) | |
echo >&2 "$JSON2" | |
AUTHD=$(echo "$JSON2" | jq -r .authenticated) | |
else JSON2="No password" | |
fi | |
[ "$AUTHD" = false ] && { | |
echo >&2 "Login failed ... $JSON2" | |
exit 1 | |
} | |
} | |
} | |
TMP=/tmp/_tmp$$.txt | |
HASH= | |
[ "$NICK" != '' ] && { | |
case "$SEARCH" in | |
[0-9]*.*.*.*:*[0-9] ) | |
HASH="$(echo -n "$SEARCH" | md5sum - | awk '{print $1;}')" ;; | |
esac | |
} | |
if [ "$HASH" != '' ] | |
then echo>&2 "Using $HASH generated from $SEARCH" | |
elif [ "${#SEARCH}" = 32 ] | |
then HASH="$SEARCH" | |
echo>&2 "Using $HASH directly" | |
else | |
curl -sS ${NICK:+--cookie "$COOKIES"/.cookie."$NICK"} https://www.classicube.net/api/servers > "$TMP" | |
NAME=$(jq<"$TMP" -r '.servers[] | [.name,.ip+":"+(.port|tostring)] | @tsv' | grep -i "$SEARCH" ) | |
[ "$(echo "$NAME" | wc -l)" -ne 1 ] && { | |
echo >&2 "Found records..." | |
echo "$NAME" | expand -64 >&2 | |
exit 1 | |
} | |
NAME=$(echo "$NAME" | awk -F'\t' 'NR==1{print $1;}') | |
if [ "$VERBOSE" = yes ]||[ "$NICK" = '' ] | |
then echo >&2 "Found record: $NAME" | |
fi | |
[ "$NICK" = '' ] && { | |
rm -f "$TMP" | |
exit 0 | |
} | |
[ "$NAME" = '' ]&&[ "${#SEARCH}" = 32 ]&& HASH="$SEARCH" | |
if [ "$NAME" = '' ]&&[ "$HASH" = '' ] | |
then | |
echo >&2 "Server not found: $SEARCH" | |
rm -f "$TMP" | |
exit 1 | |
fi | |
[ "$NICK" != '' ] && | |
echo >&2 "Using \"$NAME$HASH\"" | |
[ "$HASH" = '' ] && | |
HASH=$( jq < "$TMP" -r '.servers[] | select(.name=="'"$NAME"'").hash') | |
fi | |
fetch_j3() { | |
JSON3=$(curl -sS ${NICK:+--cookie "$COOKIES"/.cookie."$NICK"} \ | |
"https://www.classicube.net/api/server/$HASH") | |
} | |
fetch_j3 | |
case "$JSON3" in | |
*429* ) sleep 2 ; fetch_j3 ;; | |
esac | |
[ "$NICK" != '' ] && { | |
if [ "$CCARGS" != yes ] | |
then | |
echo "$JSON3" | jq -r '.servers[] | ["mc://"+.ip+":"+(.port|tostring)+"/'"$NICK"'/"+.mppass] | @tsv ' | |
else | |
echo "$JSON3" | jq -r '.servers[] | ["'"$NICK"' "+.mppass+" "+.ip+" "+(.port|tostring)] | @tsv ' | |
fi | |
} | |
[ "$VERBOSE" = yes ] && { | |
echo "$JSON3" | jq '.servers[0]' >&2 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MCGalaxy; | |
using MCGalaxy.Events; | |
using MCGalaxy.Events.PlayerEvents; | |
// TODO: Save properties in file? | |
// TODO: Add timer; "Classic hour" | |
namespace Core { | |
public class ClassicMode: Plugin { | |
public override string MCGalaxy_Version { get { return "1.8.0.0"; } } | |
public override string name { get { return "ClassicMode"; } } | |
public static bool Enabled = false; | |
public static string ClassicMap = "Classic"; | |
public override void Load(bool startup) { | |
Command.Register(new CmdClassicMode()); | |
OnPlayerFinishConnectingEvent.Register(CheckForEnhanced, Priority.High); | |
if (ClassicMap != "") { | |
Level lvl = LevelActions.Load(Player.Console, ClassicMap, false); | |
if (lvl == null) | |
lvl = Matcher.FindLevels(Player.Console, ClassicMap); | |
if (lvl == null) | |
ClassicMap = ""; | |
else | |
lvl.Config.AutoUnload = false; | |
} | |
} | |
public override void Unload(bool shutdown) { | |
Command.Unregister(Command.Find("ClassicMode")); | |
OnPlayerFinishConnectingEvent.Unregister(CheckForEnhanced); | |
} | |
void CheckForEnhanced(Player p) { | |
string failreason = ""; | |
if (Enabled) return; | |
if (!p.hasCpe) | |
failreason = "enhanced mode."; | |
else if (!p.Supports(CpeExt.CustomBlocks)) | |
failreason = "custom blocks"; | |
else if (!p.Supports(CpeExt.BlockDefinitions)) | |
failreason = "block definitions"; | |
#if false // Beware MaxRaw is defined at compile time not load time. | |
else if (Block.MaxRaw > 255 && !p.Supports(CpeExt.ExtBlocks)) | |
failreason = "ten bit block numbers"; | |
#endif | |
else if (!p.Supports(CpeExt.FullCP437) || !p.Supports(CpeExt.EmoteFix)) | |
failreason = "working chat"; | |
if (failreason != "") { | |
if (ClassicMap == "") { | |
p.Leave("Please use a client supporting " + failreason, true); | |
p.cancelconnecting = true; | |
} else { | |
Level lvl = Matcher.FindLevels(p, ClassicMap); | |
if (lvl != null) | |
p.level = lvl; | |
} | |
} | |
} | |
} | |
public class CmdClassicMode : Command2 { | |
public override string name { get { return "ClassicMode"; } } | |
public override string shortcut { get { return "cm"; } } | |
public override string type { get { return "other"; } } | |
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } | |
public override void Use(Player p, string message) | |
{ | |
Player[] online = PlayerInfo.Online.Items; | |
switch(message) { | |
case "": ClassicMode.Enabled = !ClassicMode.Enabled; break; | |
case "allow": case "enable": ClassicMode.Enabled = true; break; | |
case "deny": case "disable": | |
ClassicMode.Enabled = false; | |
ClassicMode.ClassicMap = ""; | |
break; | |
default: | |
string[] parts = message.SplitSpaces(2); | |
string NewMap = message; | |
if (parts.Length == 2 && parts[0] == "map") | |
NewMap = parts[1]; | |
Level lvl = LevelActions.Load(p, NewMap, false); | |
if (lvl == null) { | |
p.Message("Level \"{0}\" not found.", NewMap); | |
return; | |
} | |
lvl.Config.AutoUnload = false; | |
ClassicMode.Enabled = true; | |
ClassicMode.ClassicMap = NewMap; | |
break; | |
} | |
if (ClassicMode.Enabled || ClassicMode.ClassicMap == "") | |
p.Message("Classic clients are {0}", ClassicMode.Enabled?"allowed":"denied"); | |
else | |
p.Message("Connecting classic clients are redirected to map \"{0}\"", ClassicMode.ClassicMap); | |
} | |
public override void Help(Player p) | |
{ | |
p.Message("%T/ClassicMode - Allow or disallow classic clients."); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if !Supernova | |
#define MCGalaxy | |
#endif | |
using System; | |
#if MCGalaxy | |
using MCGalaxy; | |
using MCGalaxy.Network; | |
#endif | |
#if Supernova | |
using Supernova; | |
#endif | |
namespace Core { | |
public class GetMPPass : Plugin { | |
#if MCGalaxy | |
public override string MCGalaxy_Version { get { return "1.9.3.5"; } } | |
#endif | |
#if Supernova | |
public override string Supernova_Version { get { return "1.0.0.0"; } } | |
#endif | |
public override string name { get { return "MPPass"; } } | |
public override void Load(bool startup) { | |
Command.Register(new CmdMPPass()); | |
} | |
public override void Unload(bool shutdown) { | |
Command.Unregister(Command.Find("MPPass")); | |
} | |
} | |
public class CmdMPPass : Command2 { | |
public override string name { get { return "MPPass"; } } | |
public override string type { get { return "other"; } } | |
public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } | |
public override bool LogUsage { get { return false; } } | |
public override bool UpdatesLastCmd { get { return false; } } | |
public override bool MessageBlockRestricted { get { return true; } } | |
public override void Use(Player p, string message) { | |
if (message == "") { | |
Help(p); | |
return; | |
} | |
#if MCGalaxy | |
if (message == "-salt") { | |
foreach (Heartbeat hb in Heartbeat.Heartbeats) { | |
p.Message("The current salt is {0} for {1}", hb.Salt, hb.URL); | |
} | |
} else { | |
foreach (Heartbeat hb in Heartbeat.Heartbeats) { | |
p.Message("MPPass for {0} is {1} on {2}", | |
message, | |
Server.CalcMppass(message, hb.Salt), | |
hb.URL); | |
} | |
#endif | |
#if Supernova | |
p.Message("Classicube MPPass for {0} is {1}", | |
message, | |
Server.CalcMppass(message, Server.salt)); | |
p.Message("Betacraft MPPass for {0} is {1}", | |
message, | |
Server.CalcMppass(message, Server.betacraftSalt)); | |
#endif | |
#if MCGalaxy | |
} | |
#endif | |
} | |
public override void Help(Player p) { | |
p.Message("%T/MPPass -- Calculate current mppass for ID"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment