-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f45893
commit 9be47f7
Showing
32 changed files
with
1,600 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
test/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-p src | ||
-m Main | ||
-L uuid | ||
--cpp ./build/ | ||
--cmd ./test.sh |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Cuttlefish | ||
A Minecraft server written in Haxe. | ||
|
||
## Currently Supported Features | ||
- Server List Pinging | ||
- can show any data, including text, online/max player count, protocol version, and sample of online players. | ||
- thats literally it for now | ||
|
||
## Features Being Worked On | ||
- login success packet (to login to the server) | ||
- protocol encryption | ||
- some other background stuff |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package; | ||
|
||
import entity.Entity; | ||
|
||
/*enum abstract LegacyColor(Int) { | ||
var Black = 0x000000; // &0 | ||
var DarkBlue = 0x0000aa; // &1 | ||
var DarkGreen = 0x00aa00; // &2 | ||
var DarkCyan = 0x00aaaa; // &3 | ||
var DarkRed = 0xaa0000; // &4 | ||
var DarkPurple = 0xaa00aa; // &5 | ||
var Gold = 0xffaa00; // &6 | ||
var LightGray = 0xaaaaaa; // &7 | ||
var DarkGray = 0x555555; // &8 | ||
var LightBlue; // &9 | ||
var LightGreen; // &a | ||
var LightCyan; // &b | ||
var LightRed; // &c | ||
var LightPurple; // &d | ||
var Yellow; // &e | ||
var White; // &f | ||
}*/ | ||
|
||
enum Color { | ||
Black; | ||
DarkBlue; | ||
DarkGreen; | ||
DarkCyan; | ||
DarkRed; | ||
DarkPurple; | ||
Gold; | ||
LightGray; | ||
DarkGray; | ||
LightBlue; | ||
LightGreen; | ||
LightCyan; | ||
LightRed; | ||
LightPurple; | ||
Yellow; | ||
White; | ||
Hex(code:String); | ||
Legacy(code:String); | ||
Reset; | ||
} | ||
|
||
enum ClickEvent { | ||
OpenURL(url:String); | ||
RunCommand(command:String); | ||
SuggestCommand(command:String); | ||
ChangePage(to:Int); | ||
CopyToClipboard(str:String); | ||
|
||
// not usable: | ||
// OpenFile(path:String); | ||
// TwitchUserInfo(???); | ||
} | ||
|
||
enum HoverEvent { | ||
ShowText(text:ChatComponent); | ||
ShowItem(item:Dynamic); | ||
ShowEntity(entity:Entity); | ||
} | ||
|
||
class ChatComponent { | ||
public static final LEGACY_COLOR_CHARACTER = '§'; | ||
public var isBold:Bool = false; | ||
public var isItalic:Bool = false; | ||
public var isUnderlined:Bool = false; | ||
public var isStrikethrough:Bool = false; | ||
public var isObfuscated:Bool = false; | ||
public var usedFont:Identifier = new Identifier('minecraft', 'default'); | ||
public var usedColor:Color; | ||
public var onInsertion:Null<String>; | ||
public var clickEvent:Null<ClickEvent>; | ||
public var hoverEvent:Null<HoverEvent>; | ||
|
||
public function new() { | ||
|
||
} | ||
|
||
public static function buildText(text:String):ChatComponent { | ||
var ret = new StringComponent(); | ||
ret.text = text; | ||
return ret; | ||
} | ||
|
||
public function bold(val:Bool):ChatComponent { | ||
this.isBold = val; | ||
return this; | ||
} | ||
|
||
public function italic(val:Bool):ChatComponent { | ||
this.isItalic = val; | ||
return this; | ||
} | ||
|
||
public function underline(val:Bool):ChatComponent { | ||
this.isUnderlined = val; | ||
return this; | ||
} | ||
|
||
public function strike(val:Bool):ChatComponent { | ||
this.isStrikethrough = val; | ||
return this; | ||
} | ||
|
||
public function obfuscate(val:Bool):ChatComponent { | ||
this.isObfuscated = val; | ||
return this; | ||
} | ||
|
||
public function font(fnt:Identifier):ChatComponent { | ||
this.usedFont = fnt; | ||
return this; | ||
} | ||
|
||
public function color(col:Color):ChatComponent { | ||
this.usedColor = col; | ||
return this; | ||
} | ||
} | ||
|
||
class StringComponent extends ChatComponent { | ||
public var text:String; | ||
} | ||
|
||
class TranslationComponent extends ChatComponent { | ||
public var translation:String; | ||
public var with:Array<ChatComponent>; | ||
} | ||
|
||
class KeybindComponent extends ChatComponent { | ||
public var keybind:String; | ||
} | ||
|
||
typedef ScoreComponentData = { | ||
var name:String; | ||
var objective:String; | ||
var value:String; | ||
} | ||
|
||
class ScoreComponent extends ChatComponent { | ||
public var score:ScoreComponentData; | ||
} | ||
|
||
class SelectorComponent extends ChatComponent { | ||
var selector:String; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package; | ||
|
||
class Identifier { | ||
public static final DEFAULT_NAMESPACE = 'minecraft'; | ||
|
||
public var namespace:String; | ||
public var key:String; | ||
|
||
public function new(namespace:String, key:String) { | ||
this.namespace = namespace; | ||
this.key = key; | ||
} | ||
|
||
public static function fromString(str:String) { | ||
var colonPos = str.indexOf(':'); | ||
var namespace:String = Identifier.DEFAULT_NAMESPACE; | ||
|
||
if (colonPos != -1) { | ||
namespace = str.substr(0, colonPos); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package; | ||
|
||
import game.GameServer; | ||
|
||
using VarIntLong; | ||
|
||
class Main { | ||
public static var server:GameServer; | ||
|
||
public static function main() { | ||
trace('starting game server'); | ||
|
||
Main.server = new GameServer(25565); | ||
Main.server.run(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package; | ||
|
||
import haxe.io.Input; | ||
import haxe.io.Bytes; | ||
import haxe.Int64; | ||
|
||
using VarIntLong; | ||
using StringTools; | ||
|
||
enum Tag { | ||
TAG_End; | ||
TAG_Byte(name:String, data:Int); | ||
TAG_Short(name:String, data:Int); | ||
TAG_Int(name:String, data:Int); | ||
TAG_Long(name:String, data:Int64); | ||
TAG_Float(name:String, data:Float); | ||
TAG_Double(name:String, data:Float); | ||
TAG_Byte_Array(name:String, data:Bytes); | ||
TAG_String(name:String, data:String); | ||
TAG_List(name:String, data:Array<Tag>, type:Int); | ||
TAG_Compound(name:String, data:Array<Tag>); | ||
TAG_Int_Array(name:String, data:Array<Int>); | ||
TAG_Long_Array(name:String, data:Array<Int64>); | ||
} | ||
|
||
class NBT { | ||
public static function readFromStream(input:Input, inList=false, ?type:Int):Tag { | ||
var tagType = input.readByte(); | ||
var tagName; | ||
if (!inList && tagType != 0) { | ||
var nameLen = input.readInt8(); | ||
tagName = input.readString(nameLen); | ||
} | ||
|
||
switch tagType { | ||
case 0: | ||
return TAG_End; | ||
case 1: | ||
return TAG_Byte(tagName, input.readByte()); | ||
case 2: | ||
return TAG_Short(tagName, input.readInt16()); | ||
case 3: | ||
return TAG_Int(tagName, input.readInt32()); | ||
case 4: | ||
return TAG_Long(tagName, input.readInt64()); | ||
case 5: | ||
return TAG_Float(tagName, input.readFloat()); | ||
case 6: | ||
return TAG_Double(tagName, input.readDouble()); | ||
case 7: | ||
return TAG_Byte_Array(tagName, input.read(input.readInt32())); | ||
case 8: | ||
return TAG_String(tagName, input.readString(input.readUInt16())); | ||
case 9: | ||
var arrayType = input.readByte(); | ||
var arrayLength = input.readInt32(); | ||
if (arrayLength > 0 && arrayType == 0) throw 'array with len>0 cannot have type TAG_End'; | ||
|
||
if (arrayLength <= 0) | ||
return TAG_List(tagName, [], arrayType); | ||
|
||
var array:Array<Tag> = []; | ||
for (i in 0...arrayLength) { | ||
array.push(NBT.readFromStream(input, true)); | ||
} | ||
return TAG_List(tagName, array, arrayType); | ||
case 10: | ||
var tags:Array<Tag> = []; | ||
while (true) { | ||
var next = NBT.readFromStream(input); | ||
if (next.match(TAG_End)) | ||
break; | ||
tags.push(next); | ||
} | ||
return TAG_Compound(tagName, tags); | ||
case 11: | ||
var length = input.readInt32(); | ||
var array:Array<Int> = []; | ||
for (i in 0...length) { | ||
array.push(input.readInt32()); | ||
} | ||
return TAG_Int_Array(tagName, array); | ||
case 12: | ||
var length = input.readInt32(); | ||
var array:Array<Int64> = []; | ||
for (i in 0...length) { | ||
array.push(input.readInt64()); | ||
} | ||
return TAG_Long_Array(tagName, array); | ||
default: | ||
throw 'invalid type id `${tagType.hex}` while reading nbt tag'; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package; | ||
|
||
import NBT.Tag; | ||
|
||
class SlotData { | ||
var present:Bool; | ||
var itemId:Null<Int>; | ||
var itemCount:Null<Int>; | ||
var nbt:Null<Tag>; | ||
|
||
public function new() { | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package; | ||
|
||
import uuid.Uuid; | ||
import haxe.io.Bytes; | ||
import haxe.io.Output; | ||
import haxe.io.Input; | ||
import haxe.Int64; | ||
|
||
using StringTools; | ||
|
||
class UUID { | ||
var lower:Int64; | ||
var upper:Int64; | ||
|
||
public function new(upper:Int64, lower:Int64) { | ||
this.upper = upper; | ||
this.lower = lower; | ||
} | ||
|
||
public function compare(other:UUID) { | ||
if (other.upper != this.upper) return false; | ||
if (other.lower != this.lower) return false; | ||
return true; | ||
} | ||
|
||
public static function readFromStream(stream:Input):UUID { | ||
var bytes = stream.read(16); | ||
var upper = bytes.getInt64(0); | ||
var lower = bytes.getInt64(8); | ||
return new UUID(upper, lower); | ||
} | ||
|
||
public function writeToStream(stream:Output) { | ||
var bytes = Bytes.alloc(16); | ||
bytes.setInt64(0, this.upper); | ||
bytes.setInt64(8, this.lower); | ||
stream.write(bytes); | ||
} | ||
|
||
public function toString():String { | ||
return Uuid.hexToUuid('${lower.low.hex}${lower.high.hex}${upper.low.hex}${upper.high.hex}', ''); | ||
} | ||
|
||
public static function fromString(str:String) { | ||
var bytes = Uuid.parse(str, ''); | ||
var upper = bytes.getInt64(0); | ||
var lower = bytes.getInt64(64); | ||
trace(upper.high.hex, upper.low.hex); | ||
return new UUID(upper, lower); | ||
} | ||
} |
Oops, something went wrong.