123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "client/GameClient.h"
- #include "client/Game.h"
- #include "client/packets/WorldPackets.h"
- #include "common/network/Packets.h"
- #include "utils/Logger.h"
- static Client client;
- struct Receiver {
- void onConnect() {
- }
- void onDisconnect() {
- }
- void onPacket(InPacket& in) {
- uint16 id;
- if(in.readU16(id)) {
- return;
- }
- switch(id) {
- case S_CHAT:
- {
- StringBuffer<256> s;
- in.readString(s);
- puts(s);
- break;
- }
- case S_WORLD_SEGMENT:
- WorldPackets::receiveChunk(Game::world, in);
- break;
- }
- }
- };
- bool GameClient::init() {
- Error error = client.start();
- if(error.has()) {
- LOG_ERROR(error.message);
- }
- return error.has();
- }
- Error GameClient::connect(const char* address, Client::Port port, int timeout) {
- return client.connect(address, port, timeout);
- }
- void GameClient::consumeEvents() {
- Receiver r;
- client.consumeEvents(r);
- }
|