New build.

This commit is contained in:
barant committed 2020-04-13 09:40:58 -07:00
1 parent a5a51f8aae
commit b4ab5fb86a
835 files changed
+26499 -3119

No files matched your search

+18 -21
View File
@@ -5,8 +5,6 @@
namespace core {
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server) : TCPSocket(ePoll), server(server) {}
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {}
TCPSession::~TCPSession() {
@@ -17,45 +15,44 @@ namespace core {
data << "|" << ipAddress.getClientAddressAndPort();
}
void TCPSession::protocol(std::stringstream &out, std::string data = "") {
void TCPSession::protocol(std::string data = "") {
if(data.length() > 0) {
if(!server.commands.processRequest(data, this, out))
server.sessionErrorHandler("Invalid data received.", out);
}
else {
onConnected(out);
}
}
}
void TCPSession::onRegister() {
std::stringstream out;
protocol(out);
send(out.str());
void TCPSession::onRegistered() {
onConnected();
protocol();
send();
}
void TCPSession::onConnected(std::stringstream &out) {}
void TCPSession::onConnected() {}
void TCPSession::onDataReceived(std::string data) {
std::stringstream out;
protocol(out, data);
send(out.str());
protocol(data);
send();
}
void TCPSession::sendToAll(std::string data) {
void TCPSession::sendToAll() {
for(auto session : server.sessions)
if(session != this)
session->write(data);
session->write(out.str());
out.str("");
}
void TCPSession::sendToAll(SessionFilter filter, std::string data) {
void TCPSession::sendToAll(SessionFilter filter) {
for(auto session : server.sessions)
if(filter.test(*session))
if(session != this)
session->write(data);
session->write(out.str());
out.str("");
}
void TCPSession::send(std::string data) {
write(data);
void TCPSession::send() {
write(out.str());
out.str("");
}
}