Main.cpp 907 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <iostream>
  2. #include <array>
  3. #include <unistd.h>
  4. #include "Socket.h"
  5. #include "Client.h"
  6. #include "Game.h"
  7. int main() {
  8. Socket socket;
  9. if(socket.start(4455)) {
  10. return 0;
  11. }
  12. std::array<Client, 1> clients;
  13. while(true) {
  14. int clientId = socket.waitForClients(100);
  15. if(clientId != -1) {
  16. for(Client& client : clients) {
  17. if(client.isFree()) {
  18. client.start(clientId);
  19. clientId = -1;
  20. std::cout << "client added" << "\n";
  21. break;
  22. }
  23. }
  24. if(clientId != -1) {
  25. std::cout << "client disconnected - full server" << "\n";
  26. close(clientId);
  27. }
  28. }
  29. char buffer[256];
  30. if(socket.readConsole(buffer, 256, 100)) {
  31. break;
  32. }
  33. }
  34. return 0;
  35. }