Repository navigation
Expand file tree
/
Copy pathdev_fake_server.py
More file actions
70 lines (59 loc) · 1.88 KB
/
Copy pathdev_fake_server.py
File metadata and controls
70 lines (59 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import random
import time
from datetime import UTC, datetime
from pathlib import Path
EVENTS = [
"{player} joined the game",
"{player} left the game",
"<{player}> {message}",
"{player} has made the advancement [{advancement}]",
]
PLAYERS = ["Steve", "Alex"]
MESSAGES = [
"Test 1",
"Test 2",
"Test 3",
]
ADVANCEMENTS = [
"Stone Age",
"Getting an Upgrade",
"Acquire Hardware",
"Suit Up",
"Diamonds!",
]
def generate_line():
now = datetime.now(UTC).strftime("%H:%M:%S")
event = random.choice(EVENTS)
player = random.choice(PLAYERS)
message = random.choice(MESSAGES)
adv = random.choice(ADVANCEMENTS)
msg = event.format(player=player, message=message, advancement=adv)
return f"[{now}] [Server thread/INFO]: {msg}\n"
def main():
log_dir = Path("logs")
log_dir.mkdir(exist_ok=True)
log_file = log_dir / "latest.log"
print(f"Fake server started. Writing to {log_file.resolve()}")
try:
with log_file.open("a", encoding="utf-8") as f:
now = datetime.now(UTC).strftime("%H:%M:%S")
start_line = f"[{now}] [Server thread/INFO]: Starting minecraft server version 1.20.1\n"
f.write(start_line)
f.flush()
print(f"Wrote: {start_line.strip()}")
while True:
line = generate_line()
f.write(line)
f.flush()
print(f"Wrote: {line.strip()}")
time.sleep(random.uniform(1.0, 5.0))
except KeyboardInterrupt:
with log_file.open("a", encoding="utf-8") as f:
now = datetime.now(UTC).strftime("%H:%M:%S")
stop_line = f"[{now}] [Server thread/INFO]: Stopping the server\n"
f.write(stop_line)
f.flush()
print(f"Wrote: {stop_line.strip()}")
print("\nFake server stopped.")
if __name__ == "__main__":
main()