-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the entire mojang.minecraft package
- Loading branch information
Showing
14 changed files
with
395 additions
and
309 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List, Tuple | ||
from typing import List, NamedTuple, Tuple | ||
|
||
@dataclass(frozen=True) | ||
class ServerStats: | ||
motd: str = field() | ||
game_type: str = field() | ||
game_id: str = field() | ||
version: str = field() | ||
map: str = field() | ||
host: Tuple[str, int] = field() | ||
plugins: List[str] = field(repr=False) | ||
players: Tuple[int, int] = field() | ||
player_list: List[str] = field() | ||
|
||
class ServerStats(NamedTuple): | ||
motd: str | ||
game_type: str | ||
game_id: str | ||
version: str | ||
map: str | ||
host: Tuple[str, int] | ||
plugins: List[str] | ||
players: Tuple[int, int] | ||
player_list: List[str] |
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,20 @@ | ||
import socket | ||
import struct | ||
from typing import Tuple | ||
|
||
|
||
class Packets: | ||
|
||
def __init__(self, sock: socket.socket): | ||
self.__sock = sock | ||
|
||
def send(self, _type: int, sess_id: int, data: bytes = b'') -> int: | ||
packet = struct.pack(f'>Hbi{len(data)}s', 0xFEFd, _type, sess_id, data) | ||
return self.__sock.send(packet) | ||
|
||
def recv(self) -> Tuple[int, int, bytes]: | ||
with self.__sock.makefile('rb') as buffer: | ||
data = buffer.read1() | ||
|
||
_type, sess_id = struct.unpack('>bi', data[:5]) | ||
return _type, sess_id, data[5:] |
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
Oops, something went wrong.