Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: pass upload date to OpenTTD client #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bananas_server/application/bananas_server.py
Expand Up @@ -48,6 +48,7 @@ async def _send_content_entry(self, source, content_entry):
md5sum=content_entry.md5sum,
dependencies=content_entry.dependencies,
tags=content_entry.tags,
upload_date=content_entry.upload_date,
)

def get_by_content_id(self, content_id):
Expand Down
4 changes: 4 additions & 0 deletions bananas_server/index/local.py
Expand Up @@ -95,6 +95,8 @@ def _read_content_entry_version(self, content_type, unique_id, data, md5sum_mapp
md5sum_partial = bytes.fromhex(data["md5sum-partial"])
md5sum = md5sum_mapping[content_type][unique_id][md5sum_partial]

upload_date = int(data["upload-date"].timestamp())

dependencies = []
for dependency in data.get("dependencies", []):
dep_content_type = get_content_type_from_name(dependency["content-type"])
Expand Down Expand Up @@ -130,6 +132,7 @@ def _read_content_entry_version(self, content_type, unique_id, data, md5sum_mapp
"url": data.get("url", ""),
"description": data.get("description", ""),
"unique-id": unique_id,
"upload-date": upload_date,
"md5sum": md5sum,
"min-version": min_version,
"max-version": max_version,
Expand All @@ -151,6 +154,7 @@ def _read_content_entry_version(self, content_type, unique_id, data, md5sum_mapp
size += 1
for tag in data.get("tags", []):
size += len(tag) + 2
size += 4 # upload_date

if size > 1400:
raise Exception("Entry would exceed OpenTTD packet size.")
Expand Down
1 change: 1 addition & 0 deletions bananas_server/index/schema.py
Expand Up @@ -23,6 +23,7 @@ class Meta:
description = fields.String(validate=validate.Length(max=511))
tags = fields.List(fields.String(validate=validate.Length(max=31)))
md5sum = fields.Raw(validate=validate.Length(min=16, max=16))
upload_date = fields.Integer(data_key="upload-date")
min_version = fields.List(fields.Integer(), data_key="min-version", missing=None)
max_version = fields.List(fields.Integer(), data_key="max-version", missing=None)
raw_dependencies = fields.List(
Expand Down
16 changes: 15 additions & 1 deletion bananas_server/openttd/send.py
Expand Up @@ -16,7 +16,19 @@

class OpenTTDProtocolSend:
async def send_PACKET_CONTENT_SERVER_INFO(
self, content_type, content_id, filesize, name, version, url, description, unique_id, md5sum, dependencies, tags
self,
content_type,
content_id,
filesize,
name,
version,
url,
description,
unique_id,
md5sum,
dependencies,
tags,
upload_date,
):
data = write_init(PacketTCPContentType.PACKET_CONTENT_SERVER_INFO)

Expand Down Expand Up @@ -53,6 +65,8 @@ async def send_PACKET_CONTENT_SERVER_INFO(
for tag in tags:
data = write_string(data, tag)

data = write_uint32(data, int(upload_date.timestamp()))

data = write_presend(data)
await self.send_packet(data)

Expand Down