void ServerEventPusher_i::addNewClient(STI::Pusher::ServerEventHandler_ptr handler, const STI::Pusher::TStatusEvent& initialState) { //First remove all inactive updaters. //Check if a reference to this handler already exists; //if it does, delete the old and use the new. updatersMutex->lock(); { ClientUpdaterVector::iterator current = clientUpdaters.begin(); ClientUpdaterVector::iterator next = current; while(current != clientUpdaters.end()) { next++; if( !current->isActive() || current->isEquivalent(handler) ) { current = clientUpdaters.erase(current); next = current; } else { current = next; } } clientUpdaters.push_back( new ClientUpdater(handler, ServerEvent(initialState), orbManager) ); } updatersMutex->unlock(); }
PingusDemo::PingusDemo(const Pathname& pathname) : m_levelname(), m_checksum(), m_events() { std::vector<FileReader> lines = FileReader::parse_many(pathname); if (lines.empty()) { raise_exception(std::runtime_error, "'" << pathname.str() << "', demo file is empty"); } else { if (lines.front().get_name() == "level") { const FileReader& reader = lines.front(); if (!reader.read_string("name", m_levelname)) { raise_exception(std::runtime_error, "(level (name ...)) entry missing in demo file '" << pathname.str() << "'"); } reader.read_string("checksum", m_checksum); } for(std::vector<FileReader>::iterator i = lines.begin()+1; i != lines.end(); ++i) { if (i->get_name() != "checksum") // workaround for old incorrectly recorded demo files { m_events.push_back(ServerEvent(*i)); } } } }
void Client::event_data(const Connection *c, data_len_t len, void *data) throw (Exception) { if (len) { char *p = new char[len]; memcpy(p, data, len); server_events.push(ServerEvent(EventTypeData, c, p, len)); } }
void Client::event_login(const Connection *c, data_len_t len, void *data) throw (Exception) { logged_in = true; conn = c; const char *msg = "you logged in"; size_t sz = strlen(msg); char *p = new char[sz]; memcpy(p, msg, sz); server_events.push(ServerEvent(EventTypeLogin, c, p, sz)); }
void Client::event_status(hostaddr_t host, hostport_t port, const std::string& name, int max_clients, int cur_clients, ms_t ping_time, bool secured, int protocol_version) throw (Exception) { sprintf(buffer, "%ld", ping_time); std::string msg = "connecting to " + name + ", ping = "; msg += buffer; if (secured) { msg += ", needs password"; } sprintf(buffer, " (clients: %d/%d)", cur_clients, max_clients); msg += buffer; size_t sz = msg.length(); char *p = new char[sz]; memcpy(p, msg.c_str(), sz); server_events.push(ServerEvent(EventTypeStatus, 0, p, sz)); }
void Client::event_access_denied(MessageSequencer::RefusalReason reason) throw (Exception) { const char *msg = 0; switch (reason) { case MessageSequencer::RefusalReasonServerFull: msg = "Login failed: server is full."; break; case MessageSequencer::RefusalReasonWrongPassword: msg = "Login failed: wrong password."; break; } if (msg) { size_t sz = strlen(msg); char *p = new char[sz]; memcpy(p, msg, sz); server_events.push(ServerEvent(EventTypeAccessDenied, 0, p, sz)); } throw_exception = true; }
void Client::event_logout(const Connection *c, LogoutReason reason) throw (Exception) { std::string msg("You logged out."); switch (reason) { case LogoutReasonRegular: break; case LogoutReasonPingTimeout: msg += " (ping timeout)"; break; case LogoutReasonTooManyResends: msg += " (too many resends)"; break; case LogoutApplicationQuit: msg += " (application layer quit)"; break; } size_t sz = msg.length(); char *p = new char[sz]; memcpy(p, msg.c_str(), sz); server_events.push(ServerEvent(EventTypeLogout, c, p, sz)); }
void ServerEventPusher_i::pushStatusEvent(const STI::Pusher::TStatusEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushPingEvent(const STI::Pusher::TPingEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushDeviceDataEvent(const STI::Pusher::TDeviceDataEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushControllerEvent(const STI::Pusher::TControllerEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushFileEvent(const STI::Pusher::TFileEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushMessageEvent(const STI::Pusher::TMessageEvent& event) { pushEvent(ServerEvent(event)); }
void ServerEventPusher_i::pushSequenceEvent(const STI::Pusher::TSequenceEvent& event) { pushEvent(ServerEvent(event)); }