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

Saving & loading game state on bot restart #13

Open
artyom-poptsov opened this issue Apr 2, 2020 · 3 comments
Open

Saving & loading game state on bot restart #13

artyom-poptsov opened this issue Apr 2, 2020 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@artyom-poptsov
Copy link
Collaborator

When bot is restarted and a user tries to interact with it, the bot produces the following error:

14:20:08.851 [cadropod_bot Telegram Executor] FATAL org.telegram.telegrambots.updatesreceivers.DefaultBotSession - null
java.lang.NullPointerException: null
	at rpgram.RPGram.onUpdateReceived(RPGram.java:131) ~[classes/:?]
	at java.util.ArrayList.forEach(ArrayList.java:1540) ~[?:?]
	at org.telegram.telegrambots.meta.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27) ~[telegrambots-meta-4.4.0.1.jar:?]
	at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:307) [telegrambots-4.4.0.1.jar:?]

If the user issues /start command after restart, the error does not occur.

@artyom-poptsov artyom-poptsov added the bug Something isn't working label Apr 2, 2020
@F1uctus
Copy link
Collaborator

F1uctus commented Apr 2, 2020

There is a break statement on that line

case "back": {
answer = curPlayer.getMap().viewMapArea(curPlayer.getPos(), curPlayer.getFieldOfView());
keyboard = getKeyBoardOfArrows(curPlayer);
break;
}
case "getWood": {
answer = curPlayer.getResource("дерево");

Edit: OK. In #12 there is that line:
answer = curPlayer.getMap().viewMapArea(curPlayer.getPos(), curPlayer.getFieldOfView());

I think, when bot is restarted, curPlayer becomes null, so we need to save players list somewhere, or even implement registration system?

@artyom-poptsov
Copy link
Collaborator Author

We should save game state somewhere (e.g. to a database) periodically or keep the actual state here altogether.

A more fast solution could be that we should notify the player that the bot was restarted and ask his/her to re-start game by issuing /start command again.

@F1uctus
Copy link
Collaborator

F1uctus commented Aug 22, 2020

Saving a game state using a manually written logic is a hell of a job. After each addition to the game (e.g. new player property, new thing, etc) manual serialization logic should be updated too.

Recently I looked at https://github.com/EsotericSoftware/kryo, but was not able to integrate it to my branch yet. Seems like Map is a too complex object to be processed by Kryo without many modifications, and I have a little experience with Java serialization libraries.

The https://github.com/kostaskougios/cloning library is powerful enough to clone the entire game state automagically, but it is not purposed for serialization, only for cloning.

I will continue the investigation, but later. If no serialization library will be found, manual serializing may be considered as a last resort...

@F1uctus F1uctus changed the title rpgram.RPGram.onUpdateReceived: Null pointer exception Saving & loading game state on bot restart Aug 22, 2020
@F1uctus F1uctus added the enhancement New feature or request label Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants