Comment by LandOfMightDev

Open in a window
Comment

Comment by LandOfMightDev

You can look at the Repo and the actual game to see how it works in real time. https://landofmight.alwaysdata.net/

Before, there was no way to track the the state of the world after all player's logged off. Since i am using peer to peer (master - peer), there is no dedicated server, thus, no way to keep the game's state after the players leave. So i had this idea Friday evening. Basically, all i really needed was to record the NPCs stats (level, might, health), and their location. then every so many seconds, i needed to update it. When the first player joins, they will be the master client, and they will be the one keeping the server up to date & loading the world's state initially.

For example, player 1 joins, they are the master client now. Then, they play for a while, every 5 seconds the game does inventory and gives back all of the NPC's and their stats as a 2d text string array. This string array is encoded into a text file and sent to the github repo. 10 other players join (then due to other syncing I set up), they do not need to reload the world from the file, nor do they need to keep it updated (only one client needs to handle this).

Github allows 50,000 actions per hour, given that in order to update a file, you need to first pull the repo to see if a file exists & then get the file's sha. Essentially, you can have about 7.5 commits per second or about 133ms latency. Since only one client in the game is doing all of this, (updating the world's state, loading the world), there is no chance of exceeding the limit. Also, the latency for actually putting the file is normally around 400-800ms...

Yeah, also, the CDN will try to have give you the cashed version of the file, so make sure you force a new request each time you upload or the sha will mismatch. Also, when pulling the file, you may think that you can just use the raw url (atleast since it is a public repo), however, the CDN will just give you a shit copy of an older cached version.

So apart from all this, the hardest part is integrating it with webgl and unity. Unity is a piece of shit when it comes to networking, it does not support Asyn, so you need to use enumerators for everything.. Also, you cannot use any non-native networking modules. So everything must be done using UnityEngine.Networking. Lastly, headers are a joke in webgl, do not even try to use any headers other than Authorization and Content-Type or CORS will fuck you.

Now, the fact that you can do this is pretty cool. There are a ton of services that offer the same functions, yet charge alot. Even more, if you were developing a game that isn't super high-paced / a strategy game etc. Or you dont care about having potentially terrible latency (50,000 requests (2 requests per put), 133ms minimum delay, more users, less requests etc.etc.), so if your users can go with a 5000ms latency, this could be used for other multiplayer scenarios.

Replies LandOfMightDev · 2025-04-20
Open on HN
Loading the discussion…

Domain filters

Stories from these domains are hidden from every list. Subdomains match too: blocking substack.com also hides danluu.substack.com. The list is kept in this browser only.

Help

Keyboard

j / k
Move down and up the story list. The arrow keys scroll whatever has focus.
Enter
Read the marked story in the article reader.
]
Read the next story in the same article-reader applet. Back returns to the previous story.
p
Pin or unpin the marked story, which keeps it in Pinned.
n / N
Move to the next or previous top-level comment in the window in front.
c
Collapse or expand that comment.
f
Hide or show the story list.
Esc
Close a menu or this help.
Access key m
Go to the menu bar. Most browsers take it with Alt on Windows and Linux, and Safari with Control and Option.
?
Show this help.

Windows

Each story opens in a window holding its article above its discussion; drag the bar between them to share the room differently. A window can be moved by its title bar, resized from any edge, snapped to a half or a corner by dragging it there, maximised, or minimised to the bar at the foot of the page. Use Window > New reader window to open an empty reader, or a story row's Open in new reader window button to compare articles. Docked readers keep their articles when you select another story from the sidebar. Minimized readers can be restored and reused for their site. A window's Next story link reads on down the list in the same window.

A link in a comment or an article to another Hacker News or Lobsters thread opens that thread in a window too. A link to a single HN comment opens the comment above its replies.

While a story's window is in front, the Story and Discussion menus in the menu bar hold its commands: pinning, Next story, sorting, collapsing every thread, jumping to the first new comment. Each window also remembers where you were in its article and discussion, so a reload, or Back to a story that Next took you past, finds your place again. Closing a window forgets it.

The whole arrangement lives in the address, so a bookmark or a shared link brings it back, and Back undoes the last change. Moving between Hacker News, Lobsters, their lists, Pinned and Find changes only the list, and leaves the windows open.

The list

The pin at the start of a row keeps the story in Pinned, and the cross at its end hides it. Pinned can be narrowed by words in the title, site or author, by source, and to the stories you haven't opened yet, and ordered by when you pinned them, by points or by comments; the filters are part of the address, so a filtered view can be bookmarked. Scroll past the end of the list to load more. Domain filters, in the View menu, hide every story from a site.

Applets

The Applets menu in the menu bar holds three tools, each a window of its own. Replies to me takes your Hacker News user name and lists the replies to your last thirty comments and stories, checking again every three minutes while it is open, and marking what is new since you last marked them read. Look up a user opens a profile on Hacker News or Lobsters, with their submissions and recent comments, as a commenter's name in any discussion does; the bar at the top of a profile looks up someone else in the same window, and Back returns to the one before. Who is hiring? filters the posts of HN's monthly hiring threads by the words you type.

They read only what the sites publish to everyone, so none of them asks for a login, and your user name stays in this browser.

Find

Find takes any link and lists every time it was submitted to Hacker News and Lobsters, so you can read each discussion of it.

About

YAVCHN never sees your Hacker News or Lobsters login. The discussion is fetched from each site's public API; to vote or reply, follow the link above the discussion, or the arrow beside a comment, to the source's own site. Pins, hidden stories, filters and layout are kept in this browser only.

Open source: github.com/paulmooreparks/yavchn. Built with PUDL.