Exploring Nostrawars: An Investigation Using Iris and Snort Clients
In this blog post, I will share updates on my project for nostrHack. Previously, I shared some of my ideas for the hackathon on this post. I decided to develop a multiplayer game based on Nostr and started learning more about the protocol. Along the way, I also developed small projects and code snippets, such as nip19 encoder/decoder, a simple feed app filtering tags, and nip04 e2ee simple chat app.
Now, I am excited to share with you the progress I have made on my project called "Nostrawars". It is a multiplayer space shooting game based on Nostr! In this post, I will take an investigative approach to help you understand what's happening behind the scenes.
To try out the game, head over to "https://nostrawars.netlify.app/". You will see a loading screen with a silly UFO animation. After the loading screen, you will see two buttons: "Create Room" and "Join Room" (the latter is yet to be developed).
Click on "Create Room" button to generate the keys for the room and to connect to the relay.
For now, the relay URL is hardcoded, but I have plans to use the Nostr Client plugin introduced by lnbits in the announcement of 3 Nostr extension videos here: https://www.youtube.com/watch?v=lqV0XkOlcCs&t=2159s.
Next, click on the "Keys" button located in the top right corner. It will display a dialog box with your npub and nsec keys:
Copy the nsec key and keep it locally with you.
Next, copy the npub and head over to your favorite Nostr client. Paste the npub into the search bar of the client to find the user:
Once you find the user, click on "Send Message" button on your client and send a message like "SYN:12345":
After sending that message, the "SYN" and "SYN-ACK" will turn green on the Nostrawars screen. On your client, you will receive the SYN-ACK message.
Now, copy the ACK message and send it as follows:
Once the message is successfully sent, the game will start!
So here I created a custom three-way handshake algorithm for the game before starting it. This ensures that both players are connected to the same relays and that their connection is secure and safe to pass the game stats messages further.
Why is a three-way handshake important in a multiplayer game like Nostrawars? A three-way handshake is a method used in network communication to establish a connection between two devices. In Nostrawars, the three-way handshake ensures that both players are connected to the same relay and that their connection is secure and reliable. This is crucial for a multiplayer game as it ensures that the players receive the same game state and that there are no inconsistencies or discrepancies between the players. Without a secure and reliable connection, the game would not be playable, and there would be no way to ensure that both players have a fair and equal chance of winning.
Now Play the game, and you will most likely lose because the opponent is just a dummy client, and the health value does not change:
Remember the nsec/priv key you copied and kept with you earlier? Now, head over to your favorite client and log in with that key. I logged in on snort and went to the chats to see what's happening in Nostrawars:
First, the three-way handshake takes place. Once it is completed, we start playing the game, and the values of the player and the opponent pass through Nostr as {x:xxx,y:xxxx,health:xxxx}. The x and y values represent the position, and the health value represents the player's current health.
Now there are only three days left until the submission deadline on the 24th, and I have many ideas for improvements, but I may not be able to implement them all. Some of the things on my to-do list include Nostr nip46 integration, caching the keys, connecting with Nos2x, sats depositing and winning, and more. I will try to implement the "Join Room" screen and depositing sats to win, but let's see how things go.
If you have any questions or comments about Nostrawars, the Nostr protocol, or anything else related to this blog post, feel free to add them in the comments section below. I would be happy to answer your questions and hear your feedback.
Thank you for reading!