My steps, successes and mistakes in the gamedev world on the example of a game bot in Telegram

Hello! My name is Maxim and I want to tell you the story of the creation of the project Wasteland Wars. I hope you will be interested, and perhaps some of this can help you avoid my mistakes.

Platform Selection


Telegram is a very non-standard platform for creating online games. Especially when it comes to MMORPG. I wondered if it was possible to create a high-quality product on this platform at all, and if so, whether there would be demand for it at all. So, in June of 2017, I began developing Wasteland Wars.

Virality


In the early days of development, it was decided to assemble a focus group from friends to test the game. After all, when dealing with MMOs, testing alone was problematic. So I launched the closed beta test of the game, having made access to the bot using one-time keys. Having generated such 10 pieces, I sent them to my friends in TG. The referral system has already been added to this point, although it did not work after the fact of closure testing. Its essence is that for each person registered in the game of your ref. Link, the player gets +1 to the maximum endurance and some caps (local currency) for spending money. This led to the fact that after 2 weeks from the beginning of the PTA, 50 people took part in it, and my personal messages were filled with requests from people to give them another 1-2-10 keys for their friends. Instead of constantly generating new keys, I decided to focus on fixing the bugs found in testing and launching an open beta test, canceling registration by keys. During the first day of the MBT, 120 people registered in the game. A month later, the daily online was 200-250 people per day, and the total number of registered players was close to 800. And all this, without any movement on my part in promoting the game, the game became known only through word of mouth and referral system.

Features of the project, the players liked


During testing, players noted an extremely unusual game genre for this format, full-fledged PVP battles and a player's leveling system without classic skill points and level-ups. But what came as a surprise to me - most of all, people praised gaming texts, especially noting the quality of humor, references to popular culture and atmospheric situations that contrasted with black humor with its drama.

Technical nuances


The first difficulties associated with the Bot API platform arose in the very first days of development. Telegram has 2 main systems for connecting their bots with your server: the so-called Long Polling and Webhooks. The first implies that your server will, at a certain interval, constantly poll Telegram for new requests, and if there are any, process it, returning a Bot API response. The second is a bit more complicated to implement - it lies in the fact that your server, as it were, tells the Telegram "if you have any requests, throw them here at this address." Accordingly, to implement a bot on the Webhooks technology, a permanent IP address is required and an SSL certificate, at least self-signed, is required. Having started development on the basis of Long Polling, I did not notice at the beginning any problems associated with this method. However, after a day of continuous operation, the bot unexpectedly fell. Telegram began to return an error when a request was received. As it turned out, this problem haunts absolutely all bots based on Long Polling - the telegram closes the processing of requests from the bot after a while, because of which it is necessary to constantly reboot it. At first, I decided to try to automate the process of “resuscitation” of the bot, writing a cron script to check the pulse of the process and restart if the patient did not respond to stick poking. However, this process of constant restarts caused inconvenience to players, since took some time, and also reset the current timers in the game. As a result, the project was moved to Webhooks, and this problem immediately disappeared.

Further, in terms of complexity from the Bot API itself, everything was calm. Until one moment.

The project gained momentum, increased its audience and constantly developed. At one point, the bot suddenly began to "blunt" when it received a request. Or rather, there was a delay in the response of the bot to the player. First of all, I climbed to the server, thinking that he had stopped coping with the growing number of requests. But no, the server load did not exceed 30% at peak times, there were no problems with free memory, there were no errors and warnings in the system log. But the brakes continued to grow. As it turned out, the bot began to rest on the Bot API limit on the number of simultaneous requests to it. At first, I successfully reduced and optimized the work of the bot to reduce this number. However, as the game spreads to the masses, it became obvious: very soon the bot will hit the ceiling and no optimizations on my part will help. Then it was decided to write in support of Telegram with a request to increase the limits specifically for my bot. And to my great surprise, they responded the very next day, and the limit was increased, even though they did not name the new threshold. In addition, they told me that the bot rests on the limit on a specific type of request - Callback on the so-called. Inline buttons. This is the Telegram Keyboard, which is displayed under a specific message. For text requests (including from ordinary buttons) the limit is much higher, and there is also no limit of 15 seconds to the response from the server. The problem was that 70% of the game interface was built on inline buttons. I had to almost completely recycle it to get rid of this evil, so convenient and beautiful.

The next problem the project encountered was already covered in my development environment and code. Specifically, in Python 3 and how it works with threads. Each new thread in Python 3 is created along with environment variables, taking up a large amount of memory. The game is full of timers (2 minutes to switch between locations, waiting for a battle, etc.), and starting them in separate streams, a memory leak was created. As the online game grows, the leak has reached some crazy scale, devouring all the possible random access memory and pumping up the remaining memory of the SSD server. Of course, the problem was solved by creating queues of timers that are processed in one thread for each type.

The visual part of the text game


The introduction of the visual part is one of the key features of Wasteland Wars regarding other similar games in Telegram. An interactive character avatar was added to the game, as well as a visual display of each item of equipment in the game. As in full-size RPGs on gaming platforms, a player can dress his character in different armor, give him different weapons, and then see all changes visually. A little later, I developed this idea, and now when another player encounters a game, his avatar is also displayed — this is how, without knowing the enemy’s pumping, it is possible to evaluate his danger in appearance. In addition to equipment, “Masks” are also displayed on the avatar - they can be bought for donation, they do not give any advantage to the player, but change his appearance in the avatar. In addition, the game has a full interactive map. As far as finding any location, it is added to the player on the map.

All images are displayed in a fairly low resolution, sufficient for understanding their content. This is due to the fact that avatars and maps are assembled from many different elements for each player, and with a large number of simultaneous requests, their assembly in high resolution can significantly load the game server.

Project Development Plans


At the moment, the game is being rewritten to Go - this language, as it turned out, is much better suited for developing such a project. Having my own web server in Go and its speed allowed me to start creating my own API for the project in order to unlink it from a single platform in Telegram. The API will allow receiving and processing requests from any client, and all logic will be processed only on the server.

Thus, the development of a client for any platform will be as simple as possible, as the client himself, this will avoid many of the limitations of Telegram, difficulties with its blocking, as well as attract a large number of new audiences to the game.

Source: https://habr.com/ru/post/412805/


All Articles