# RBattle: a simple networked game in Rust

**URL:** <https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769>\
**Category:** announcements\
**Created:** [May 12, 2017, 8:38pm UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769 "2017-05-12T20:38:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimb](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jimb/32/1497_2.png) [@jimb](https://users.rust-lang.org/u/jimb)\
**Post date:** [May 12, 2017, 8:38pm UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/1 "2017-05-12T20:38:28Z")

</div>

I wrote a simple multiplayer networked real-time strategy game in Rust for my presentation at OSCON this year. The game is called RBattle, and it looks like this:

 ![](https://us1.discourse-cdn.com/flex019/uploads/rust_lang/original/2X/e/e66c862070565e0bbd2d6700ff822cea16f85d0e.png)

It requires Rust 1.17, and the sources are on [GitHub](https://github.com/jimblandy/rbattle). Please give it a try!

From `README.md`:

# RBattle

RBattle is a resurrection of the '90s-era X Windows game XBattle, written in Rust.  
It uses the Glium OpenGL bindings for graphics, and Tokio for some of its networking.

To play, make sure the players' computers can connect to each other via TCP/IP.  
(Many wifi networks don't permit associated hosts to communicate with each other  
directly, only with the outside world.)

On one computer, run the command:

```
$ cargo run server 0.0.0.0:12345

```

where `0.0.0.0:12345` give the IP address and TCP port the server should listen  
for client connections on. Then, on up to three other computers, run:

```
$ cargo run client ADDR:PORT

```

where `ADDR` is the IP address of the computer running the server, and `PORT` is  
the same port number given to the server. The clients simply join the game in  
progress, with each incoming client assigned to a different color.

When the game is started, each player owns a goop source. Click within squares  
to toggle outflow pumps. Equal amounts of goop of different colors cancel each  
other when they come in contact. Win by destroying all of your opponents' goop.

RBattle was written in haste. There are many, many improvements possible, and  
the code is not great in some parts. There are surely plenty of bugs as well.  
Pull requests are welcome!

# License

RBattle is copyright 2017, the RBattle developers. RBattle is distributed under  
the terms of both the MIT license and the Apache License (Version 2.0), with  
portions covered by various BSD-like licenses.

See LICENSE-APACHE and LICENSE-MIT.

---

<div class="post-metadata">

**Author:** ![hunterlester](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/hunterlester/32/2078_2.png) [@hunterlester](https://users.rust-lang.org/u/hunterlester)\
**Post date:** [September 20, 2018, 12:07am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/2 "2018-09-20T00:07:01Z")

</div>

Hi Jim,

I'm using this game to experiment with a peer-to-peer solution.

Should I be seeing the goop fill up an empty square in the direction chosen?  
I see the action being logged but no goop.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/rust_lang/original/2X/4/411485d163f4ff5ffc03b650fefb937df27813ac.png)

---

<div class="post-metadata">

**Author:** ![jimb](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jimb/32/1497_2.png) [@jimb](https://users.rust-lang.org/u/jimb)\
**Post date:** [September 20, 2018, 12:45am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/3 "2018-09-20T00:45:27Z")

</div>

Yes. The user interface is terrible, but when you click within a square but close to its N, S, E, or W side, it toggles a pump sending stuff in that direction. But you should only be able to control your own color, and there's no indication of which one is yours, so you have to try all of them. But it seems like you were able to create a pipe, so I'm not sure why it isn't flowing for you.

I tried a recent build, and it's crashing in xcb trying to open the display. So I can't try to reproduce this...

---

<div class="post-metadata">

**Author:** ![hunterlester](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/hunterlester/32/2078_2.png) [@hunterlester](https://users.rust-lang.org/u/hunterlester)\
**Post date:** [September 20, 2018, 1:32am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/4 "2018-09-20T01:32:00Z")

</div>

Thanks Jim! I just wasn't clicking around enough.  
I don't think the UI is terrible.  
Thank you for creating it.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/rust_lang/original/2X/2/2aa6c0f7598e4adde722eb018977fd396de003a0.png)

---

<div class="post-metadata">

**Author:** ![jimb](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jimb/32/1497_2.png) [@jimb](https://users.rust-lang.org/u/jimb)\
**Post date:** [September 20, 2018, 2:01am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/5 "2018-09-20T02:01:09Z")

</div>

Oh, great!

What sort of peer-to-peer stuff are you doing with it?

---

<div class="post-metadata">

**Author:** ![jimb](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jimb/32/1497_2.png) [@jimb](https://users.rust-lang.org/u/jimb)\
**Post date:** [September 20, 2018, 3:28am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/6 "2018-09-20T03:28:07Z")

</div>

BTW, I just updated to the latest versions of all the dependencies and pushed the fixed version. The prior version was crashing on startup in libxcb when I rebuilt it today.

---

<div class="post-metadata">

**Author:** ![hunterlester](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/hunterlester/32/2078_2.png) [@hunterlester](https://users.rust-lang.org/u/hunterlester)\
**Post date:** [September 20, 2018, 4:49am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/7 "2018-09-20T04:49:23Z")

</div>

> [@jimb](#):
>
> What sort of peer-to-peer stuff are you doing with it?

Reading quite a bit about BFT consensus and gossip protocols and wondering if there is some load that could be taken off of game servers, still using them but perhaps serving a greater number of players or for the same number but just a smoother experience.

I've been trying to play in Star Citizen's persistent universe but the server lag is unbearable.

I'm starting simple just to learn how to implement in a game then I want to test the upper bounds of achieving consensus among peers on game state containing a very high number of dynamic polygons.

---

<div class="post-metadata">

**Author:** ![mtckmeek](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mtckmeek/32/20540_2.png) [@mtckmeek](https://users.rust-lang.org/u/mtckmeek)\
**Post date:** [April 24, 2021, 3:58am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/8 "2021-04-24T03:58:28Z")

</div>

This looks pretty cool. Wonder if it would work on mobile ☎

---

<div class="post-metadata">

**Author:** ![mbrubeck](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mbrubeck/32/648_2.png) [@mbrubeck](https://users.rust-lang.org/u/mbrubeck)\
**Post date:** [May 24, 2021, 3:59am UTC](https://users.rust-lang.org/t/rbattle-a-simple-networked-game-in-rust/10769/9 "2021-05-24T03:59:00Z")

</div>

Closed on May 24, 2021, 3:59am UTC

This topic was automatically closed 30 days after the last reply. We invite you to open a new topic if you have further questions or comments.
