1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "server/GameServer.h"
- #include "common/network/Packets.h"
- #include "server/Game.h"
- static Server* server = nullptr;
- struct Receiver {
- void onConnect(Server::Client& client) {
- std::cout << "connected\n";
- World& w = Game::getTestWorld();
- OutPacket out = OutPacket::reliable(
- w.getHeight() * w.getSize() * w.getSize() * sizeof(BlockId) + 2);
- out.writeU16(ServerPacket::WORLD);
- for(int x = 0; x < w.getSize(); x++) {
- for(int y = 0; y < w.getHeight(); y++) {
- for(int z = 0; z < w.getSize(); z++) {
- out.writeU16(w.getBlock(x, y, z).getId());
- }
- }
- }
- client.send(out);
- }
- void onDisconnect(Server::Client& client) {
- (void)client;
- std::cout << "disconnected\n";
- }
- void onPacket(Server::Client& client, InPacket& in) {
- (void)client;
- StringBuffer<256> s;
- int8 c;
- while(in.readS8(c)) {
- s.append(c);
- }
- std::cout << "Packet: " << s << "\n";
- }
- };
- void GameServer::init(Server* s) {
- server = s;
- }
- void GameServer::tick() {
- Receiver r;
- server->consumeEvents(r);
- }
- void GameServer::sendToAll(OutPacket& out) {
- server->send(out);
- }
|