GameClient.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "client/GameClient.h"
  2. #include "client/Game.h"
  3. #include "client/packets/WorldPackets.h"
  4. #include "common/network/Packets.h"
  5. #include "utils/Logger.h"
  6. static Client client;
  7. struct Receiver {
  8. void onConnect() {
  9. }
  10. void onDisconnect() {
  11. }
  12. void onPacket(InPacket& in) {
  13. uint16 id;
  14. if(in.readU16(id)) {
  15. return;
  16. }
  17. switch(id) {
  18. case S_CHAT:
  19. {
  20. StringBuffer<256> s;
  21. in.readString(s);
  22. puts(s);
  23. break;
  24. }
  25. case S_WORLD_SEGMENT:
  26. WorldPackets::receiveChunk(Game::world, in);
  27. break;
  28. }
  29. }
  30. };
  31. bool GameClient::init() {
  32. Error error = client.start();
  33. if(error.has()) {
  34. LOG_ERROR(error.message);
  35. }
  36. return error.has();
  37. }
  38. Error GameClient::connect(const char* address, Client::Port port, int timeout) {
  39. return client.connect(address, port, timeout);
  40. }
  41. void GameClient::consumeEvents() {
  42. Receiver r;
  43. client.consumeEvents(r);
  44. }