12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #include <iostream>
- #include "server/GameServer.h"
- #include "server/commands/CommandManager.h"
- GameServer::GameServer(const Clock& tps) : tps(tps) {
- }
- void GameServer::tick() {
- }
- void GameServer::handleCommands(CommandEditor& editor, ServerCommands& serverCommands) {
- while(editor.hasCommand()) {
- String s = editor.readCommand();
- commandManager.execute(serverCommands, s);
- }
- }
- void GameServer::onFullServerClientConnect(int socket) {
- Stream answer;
- answer.write("Sorry, the server is full");
- answer.sendToSocket(socket);
- }
- void GameServer::onClientConnect(int socket) {
- std::cout << socket << " has connected\n";
- Stream answer;
- answer.write("Welcome to the server.");
- answer.sendToSocket(socket);
- }
- void GameServer::onClientPackage(int socket, Stream& in) {
- String s = "";
- while(in.hasData()) {
- char c;
- in.read(&c, 1);
- s.append(c);
- }
- Stream answer;
- answer.write(s, s.getLength());
- answer.sendToSocket(socket);
- }
- void GameServer::onClientDisconnect(int socket) {
- std::cout << socket << " has disconnected\n";
- Stream answer;
- answer.write("Bye.");
- answer.sendToSocket(socket);
- }
|