123456789101112131415161718192021222324252627282930313233343536373839 |
- #include <iostream>
- #include <array>
- #include <unistd.h>
- #include "Socket.h"
- #include "Client.h"
- #include "Game.h"
- int main() {
- Socket socket;
- if(socket.start(4456)) {
- return 0;
- }
- std::array<Client, 20> clients;
- while(true) {
- int clientId = socket.waitForClients(100);
- if(clientId != -1) {
- for(Client& client : clients) {
- if(client.isFree()) {
- client.start(clientId);
- clientId = -1;
- std::cout << "client added" << "\n";
- break;
- }
- }
- if(clientId != -1) {
- std::cout << "client disconnected - full server" << "\n";
- close(clientId);
- }
- }
- char buffer[256];
- if(socket.readConsole(buffer, 256, 100)) {
- break;
- }
- }
- return 0;
- }
|