-
Notifications
You must be signed in to change notification settings - Fork 2
/
mobinfooutput.py
74 lines (61 loc) · 2.39 KB
/
mobinfooutput.py
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
71
72
73
74
from collections import deque # type: ignore
import dill # type: ignore
from multiprocessing.connection import Listener
from os import getuid
from threading import Timer
from typing import cast, Tuple
from utils import Color, colorize, GREEN, RED, YELLOW, WHITE
MOBINFO_SOCKET_FILE = "/var/run/user/{0}/bcproxy-tf-scripts-mobinfo".format(getuid())
from mobinfotypes import Monster, State
def receiveMessage(msg: Tuple[int, Monster]):
global state
(index, monster) = msg
if state.latestMonster != monster:
mobnameColor = WHITE
if (
monster.shortname is None
or monster.race is None
or monster.gender is None
# or monster.align is None
):
mobnameColor = Color(0xFF, 0xFF, 0xA0)
print(colorize("{0} {1}".format(index + 1, monster.name[:35]), mobnameColor))
exp = "?"
if monster.exp is not None:
expColor = GREEN
if monster.exp is not None and monster.exp >= 50 and monster.exp < 150:
expColor = YELLOW
elif monster.exp is not None and monster.exp >= 150:
expColor = RED
exp = colorize(str(monster.exp), expColor)
elif monster.wikiexp is not None:
exp = monster.wikiexp
print(
"{0}/{1} {2} {3} {4} {5}".format(
exp,
monster.killcount,
monster.shortname,
monster.race,
monster.gender,
monster.align,
)
)
spells = list(monster.spells) if monster.spells is not None else []
skills = list(monster.skills) if monster.skills is not None else []
spellsskills = spells + skills
if len(spellsskills) > 0:
print(" " + ", ".join(spellsskills))
state = state._replace(latestMonster=monster)
state = State(None)
with Listener(MOBINFO_SOCKET_FILE, "AF_UNIX") as listener:
print("listening to connections on {0}".format(MOBINFO_SOCKET_FILE))
while True:
with listener.accept() as conn:
print("connection opened", listener.last_accepted)
while True:
try:
msg = cast(Tuple[int, Monster], dill.loads(conn.recv_bytes()))
receiveMessage(msg)
except EOFError:
print("connection closed")
break