-
Notifications
You must be signed in to change notification settings - Fork 0
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
ANDREI12333
committed
Jan 22, 2023
1 parent
03393b0
commit 323e492
Showing
8 changed files
with
140 additions
and
21 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
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
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
This file was deleted.
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,11 @@ | ||
# Examples | ||
All of these examples have been written by me (ANDREI12333) includes the downtime one. | ||
|
||
# Vanilla Reimplementation | ||
A non production-ready vanilla reimplementation of a Minecraft Server. | ||
|
||
# Chat Room | ||
A Simple chat room. | ||
|
||
# Downtime | ||
Simply kicks the player with the motd on join. |
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
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,25 @@ | ||
""" | ||
For a downtime server i'd recommand directly using quarry. | ||
BeeMineAPI is not supposed to be used for a down time server. | ||
This is a quarry example. | ||
""" | ||
from twisted.internet import reactor | ||
from quarry.net.server import ServerFactory, ServerProtocol | ||
from quarry.types.uuid import UUID | ||
from quarry.data.data_packs import data_packs, dimension_types | ||
true, false = True, False | ||
c = "§" | ||
|
||
class DowntimeProtocol(ServerProtocol): | ||
def player_joined(self): | ||
ServerProtocol.player_joined(self) | ||
self.close(self.factory.motd) | ||
|
||
class DowntimeFactory(ServerFactory): | ||
protocol = DowntimeProtocol | ||
motd = f'{c}4Maintenance' | ||
online_mode = false | ||
|
||
factory = DowntimeFactory() | ||
factory.listen("", 25565) | ||
reactor.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,66 @@ | ||
""" | ||
A vanilla reimplementation made using BeeMineAPI. | ||
This should NOT be used in Production. | ||
It is not complete. | ||
""" | ||
from beemineapi import BeeProtocol, BeeFactory, BeeAPI, reactor | ||
import time, sys | ||
true, false = True, False | ||
c = '§' | ||
cmd_prefix = '.' | ||
beeapi = BeeAPI() | ||
|
||
def exit(exit_code: int=0): | ||
try: | ||
sys.exit(exit_code) | ||
except: | ||
quit() | ||
|
||
def packet_chat_message(self, buff): | ||
p_text = buff.unpack_string() | ||
fmt = f"<{self.display_name}> {p_text}" | ||
print(f'[CHAT] {fmt}') | ||
beeapi.sendMessage(fmt) | ||
buff.discard() | ||
|
||
def getHelpMsg(): | ||
return f"""{c}cThis is a placeholder.""" | ||
|
||
def packet_chat_command(self, buff): | ||
command = buff.unpack_string() | ||
commands = command.split() | ||
cmd = commands[0] | ||
args = commands | ||
args.remove(cmd) | ||
print(f'{self.display_name} sent command: {command}') | ||
if cmd == "help": | ||
beeapi.sendMessage(getHelpMsg(), self) | ||
elif cmd == "eval": | ||
beeapi.sendMessage(f'{c}7Executing...', self) | ||
executes = '' | ||
for arg in args: | ||
executes += f' {arg}' | ||
try: | ||
got = eval(executes) | ||
except Exception as e: | ||
exname = str(type(e)).replace(' ', '').replace('<', '>').replace('>', '').replace('class', '').replace('\'', '') | ||
beeapi.sendMessage(f'{c}c{exname}: {e}', self) | ||
else: | ||
beeapi.sendMessage(f'{c}cInvalid Command! Use /help for help.', self) | ||
buff.discard() | ||
|
||
class VanillaFactory(BeeFactory): | ||
protocol = BeeProtocol | ||
motd = 'A Minecraft Server\nBeeMineAPI Vanilla Reimplementation' | ||
protocol.packet_chat_message = packet_chat_message | ||
protocol.packet_chat_command = packet_chat_command | ||
|
||
try: | ||
factory = VanillaFactory() | ||
host, port="", 25565 | ||
addr=(host, port) | ||
beeapi = BeeAPI(factory) | ||
factory.listen(*addr) | ||
reactor.run() | ||
except Exception as e: | ||
exit() |