mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 22:52:42 +01:00
change: consolidate proxy model methods
This commit is contained in:
1 parent
4535a19020
commit
75459515ea
4 files changed
+21
-22
No files matched your search
+14
-7
@@ -436,13 +436,6 @@ def get_rules(record: Record) -> list[int]:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def response_to_fq_ip(res: dict) -> str:
|
|
||||||
ip = res["addr"].split(":")[0]
|
|
||||||
gameport = res["gameport"]
|
|
||||||
qport = res["addr"].split(":")[1]
|
|
||||||
return f"{ip}:{gameport}:{qport}"
|
|
||||||
|
|
||||||
|
|
||||||
def query_by_id(addr: str, key: str) -> Optional[dict]:
|
def query_by_id(addr: str, key: str) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
Used with numeric Battlemetrics IDs
|
Used with numeric Battlemetrics IDs
|
||||||
@@ -495,3 +488,17 @@ def fqip_to_record(addr: str) -> Optional[Record]:
|
|||||||
if len(r) != 3:
|
if len(r) != 3:
|
||||||
return None
|
return None
|
||||||
return Record(r[0], int(r[1]), int(r[2]))
|
return Record(r[0], int(r[1]), int(r[2]))
|
||||||
|
|
||||||
|
|
||||||
|
def response_to_fqip(res: dict) -> str:
|
||||||
|
ip = res["addr"].split(":")[0]
|
||||||
|
gameport = res["gameport"]
|
||||||
|
qport = res["addr"].split(":")[1]
|
||||||
|
return f"{ip}:{gameport}:{qport}"
|
||||||
|
|
||||||
|
|
||||||
|
def response_to_record(res: dict) -> Record:
|
||||||
|
ip = res["addr"].split(":")[0]
|
||||||
|
gameport = res["gameport"]
|
||||||
|
qport = res["addr"].split(":")[1]
|
||||||
|
return Record(ip, gameport, qport)
|
||||||
@@ -48,14 +48,6 @@ class ProxyModelManager:
|
|||||||
self.control_model.append(row)
|
self.control_model.append(row)
|
||||||
self.filter(FilterMode.INITIAL, skip_cache=True)
|
self.filter(FilterMode.INITIAL, skip_cache=True)
|
||||||
|
|
||||||
def remove_row_from_control(self, row: list) -> None:
|
|
||||||
for record in self.control_model:
|
|
||||||
if row[7] == record[7] and row[8] == record[8]:
|
|
||||||
self.control_model.remove(record)
|
|
||||||
break
|
|
||||||
self.wipe_cache()
|
|
||||||
self.filter(FilterMode.INITIAL, skip_cache=True)
|
|
||||||
|
|
||||||
def update_playercount(self, playercount: "NewPlayerCount") -> None:
|
def update_playercount(self, playercount: "NewPlayerCount") -> None:
|
||||||
treeiter = playercount.treeiter
|
treeiter = playercount.treeiter
|
||||||
self.proxy_model[treeiter][4] = playercount.players
|
self.proxy_model[treeiter][4] = playercount.players
|
||||||
@@ -66,8 +58,7 @@ class ProxyModelManager:
|
|||||||
# del self.control_model[0]
|
# del self.control_model[0]
|
||||||
# self.control_model.append(row)
|
# self.control_model.append(row)
|
||||||
|
|
||||||
# TODO: consolidate with remove_row_from_control()
|
def remove_row_from_control(self, record: "Record") -> None:
|
||||||
def remove_from_history(self, record: "Record") -> None:
|
|
||||||
addr = f"{record.ip}:{record.gameport}"
|
addr = f"{record.ip}:{record.gameport}"
|
||||||
qport = record.qport
|
qport = record.qport
|
||||||
for record in self.control_model:
|
for record in self.control_model:
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ class ServerModelManager:
|
|||||||
def remove_from_history(self, record: Servers.Record) -> None:
|
def remove_from_history(self, record: Servers.Record) -> None:
|
||||||
"""Fully unthreaded, just removes a row"""
|
"""Fully unthreaded, just removes a row"""
|
||||||
proxy_man = self._get_proxy_man()
|
proxy_man = self._get_proxy_man()
|
||||||
proxy_man.remove_from_history(record)
|
proxy_man.remove_row_from_control(record)
|
||||||
control_model = proxy_man.get_control()
|
control_model = proxy_man.get_control()
|
||||||
|
|
||||||
config_man = self.controller.get_config_man()
|
config_man = self.controller.get_config_man()
|
||||||
@@ -259,10 +259,12 @@ class ServerModelManager:
|
|||||||
|
|
||||||
# NOTE: expected to only contain one item
|
# NOTE: expected to only contain one item
|
||||||
records = Servers.parse_json([response])
|
records = Servers.parse_json([response])
|
||||||
record = records[0]
|
server = records[0]
|
||||||
|
|
||||||
proxy_man = self._get_proxy_man()
|
proxy_man = self._get_proxy_man()
|
||||||
fqip = Servers.response_to_fq_ip(response)
|
fqip = Servers.response_to_fqip(response)
|
||||||
|
record = Servers.response_to_record(response)
|
||||||
|
|
||||||
config_man = self.controller.get_config_man()
|
config_man = self.controller.get_config_man()
|
||||||
|
|
||||||
# TODO: less convoluted
|
# TODO: less convoluted
|
||||||
@@ -283,7 +285,7 @@ class ServerModelManager:
|
|||||||
if proxy_man.has_control_model() is False:
|
if proxy_man.has_control_model() is False:
|
||||||
self._get_proxy_man().push(records)
|
self._get_proxy_man().push(records)
|
||||||
else:
|
else:
|
||||||
proxy_man.append_row_to_control(record)
|
proxy_man.append_row_to_control(server)
|
||||||
|
|
||||||
control_model = proxy_man.get_control()
|
control_model = proxy_man.get_control()
|
||||||
self._sort_unique_maps(control_model)
|
self._sort_unique_maps(control_model)
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class LogTreeView(ContextMixin, TreeView):
|
|||||||
self.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
|
self.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
|
||||||
|
|
||||||
self.set_model(None)
|
self.set_model(None)
|
||||||
# self.filter: Gtk.TreeModelFilter
|
|
||||||
|
|
||||||
# TODO: strings
|
# TODO: strings
|
||||||
# NOTE: default filters that should be shown on startup
|
# NOTE: default filters that should be shown on startup
|
||||||
|
|||||||
Reference in new issue
Block a user