GameServer.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <iostream>
  2. #include "server/GameServer.h"
  3. #include "server/commands/CommandManager.h"
  4. #include "server/commands/CommandTypes.h"
  5. #include "server/world/WorldGenerator.h"
  6. GameServer::GameServer(Server& server) : state(server), reader(0, "> ") {
  7. worlds.add(new World(blocks));
  8. WorldGenerator wg(blocks, *(worlds[0]));
  9. }
  10. void GameServer::tick() {
  11. tps.update();
  12. handleCommands();
  13. }
  14. void GameServer::handleCommands() {
  15. if(!reader.canRead()) {
  16. return;
  17. }
  18. const char* s = reader.readLine();
  19. if(s == nullptr) {
  20. return;
  21. }
  22. RawCommand rawCommand(s);
  23. commandManager.execute(state, rawCommand);
  24. }
  25. void GameServer::onConnect(Server::Client& client) {
  26. (void)client;
  27. std::cout << "connected\n";
  28. }
  29. void GameServer::onDisconnect(Server::Client& client) {
  30. (void)client;
  31. std::cout << "disconnected\n";
  32. }
  33. void GameServer::onPacket(Server::Client& client, InPacket& in) {
  34. (void)client;
  35. StringBuffer<256> s;
  36. int8 c;
  37. while(in.readS8(c)) {
  38. s.append(c);
  39. }
  40. std::cout << "Packet: " << s << "\n";
  41. }
  42. bool GameServer::isRunning() const {
  43. return state.running;
  44. }