int PushThePainting(){ send_messages("push", "$agent_name $agent_verb the painting on the wall.", this_player(), 0, environment(this_player())); if(hidden == 1) { OpenSesame(); } return 1; }
mixed eventClose(object who){ if( !SetClosed(1) ){ return 0; } send_messages("close", "$agent_name $agent_verb $target_name.", who, this_object(), environment(who)); return 1; }
int openDoor(object who) { object car; send_messages("press", "$agent_name $agent_verb the button.", who, 0, environment(who)); car=load_object("/domains/town/room/elevator"); car->SetDoor(1); car->CallMe(2); }
void GDNetHost::thread_loop() { while (_running) { acquireMutex(); send_messages(); poll_events(); releaseMutex(); } }
void datalink_module::loop(void) { boost::posix_time::time_duration interval_10Hz(boost::posix_time::milliseconds(1000 / 10)); boost::posix_time::ptime timer = boost::posix_time::microsec_clock::local_time() + interval_10Hz; while(thread_running) { send_messages(); boost::this_thread::sleep(timer - boost::posix_time::microsec_clock::local_time()); timer += interval_10Hz; // update timer } }
int eventSuffer(object who) { if( !random(100) ) { Destruct(); return 1; } switch(random(3)) { case 0: send_messages("cough", "$agent_name $agent_verb miserably.", who, 0, environment(who)); break; case 1: send_messages("", "$agent_possessive_noun red nose runs all over " "$agent_possessive face.", who, 0, environment(who)); break; case 2: send_messages("look", "$agent_name $agent_verb miserable.", who, 0, environment(who)); break; } who->eventReceiveDamage(0, COLD, random(3) + 1, 1); return 1; }
int execute_command(int sd, char* command, int* seq_no){ FILE *fp; fp = popen(command,"r"); printf("Executing command \n"); if(fp == NULL){ printf("Bad output \n"); close(sd); exit(1); } if(command[0]=='c' && command[1] == 'd'){ pclose(fp); return 0; } send_messages(sd, fp, seq_no); pclose(fp); return 0; }
mixed eventFall(){ string rvoid = ROOMS_D->GetVoid(this_object()); object env = environment(); mixed rumbo = 0; mixed tmprumbo = 0; string name = this_object()->GetName(); if(!living(this_object())) name = this_object()->GetShort(); if(!env || !(rumbo = env->GetExit("down"))){ if(!sizeof((rumbo = env->GetSinkRoom()))){ return 0; } } if(env == rumbo){ return 0; } if(env->GetMedium() != MEDIUM_AIR){ send_messages("crash", "$agent_name $agent_verb down!", this_object(), 0, env); if(living(this_object())) this_object()->SetPosition(POSITION_LYING); return 1; } else { mixed err; if(!rumbo){ return 0; } tmprumbo = rumbo; if(stringp(rumbo)){ if(grepp(rumbo, "#")) err = "Let's not load a clone."; else err = catch(rumbo = load_object(rumbo)); } if(err || !rumbo){ log_file("runtime","\n"+timestamp()+" "+identify(this_object())+ " could not load "+identify(rumbo)+" to fall into.\n"); err = catch(rumbo = load_object(rvoid)); } if(err || !rumbo){ this_object()->eventMove(ROOM_START); return 0; } tell_object(this_object(),"You plummet downward!"); if(err = this_object()->eventMove(rumbo)){ tell_room(rumbo,capitalize(name)+" plummets in from above.", ({ this_object() }));
int hitCallback(object who, object agent, int x, class MagicProtection cl) { string str; object Caster = cl->caster; if( (int)agent->GetUndead() ) return 0; str = (string)agent->GetName() || (string)agent->GetShort(); if( who == Caster ) { who->eventTrainSkill("magic defense",cl->args,x,1); } else if( Caster && playerp(who) && Caster != who ) { Caster->eventTrainSkill("magic defense",cl->args,0,1); } send_messages("", "The %^YELLOW%^magical shield%^RESET%^ around " "$agent_name wavers as $target_name strikes it.", who, agent, environment(who), 0); return x; }
/* * Receives requests and places the messages in a queue. */ static void run(int fd) { char buf[MAX_LENGTH], method[MAX_LENGTH], uri[MAX_LENGTH], version[MAX_LENGTH], error[MAX_LENGTH]; char * args = NULL; //clear variables to prevent corruption memset(error, '\0', MAX_LENGTH); memset(uri, '\0', MAX_LENGTH); memset(buf, '\0', MAX_LENGTH); memset(version, '\0', MAX_LENGTH); memset(method, '\0', MAX_LENGTH); // Parse and perform requests if we haven't hit timeout and if the headers are still valid while (read(fd, buf, MAX_LENGTH) > 0) { sscanf(buf, "%s %s %s", method, uri, version); //Check for non GET method call if (strncasecmp(method, "GET", 3)) { snprintf(error, sizeof(error), "501 error: %s not supported The server does not support the method provided %s", method, version); write(fd, error, sizeof(error)); Close(fd); return; } //check if version is HTTP 1.0, if so, break. if (strcmp(version, "HTTP/1.0") == 0) { fprintf(stderr, "NON HTTP 1.0 MESSAGE RECEIVED\n"); break; } if ((args = strstr(uri, "/get_messages"))) send_messages(fd, version); //clear variables to prevent corruption memset(error, '\0', MAX_LENGTH); memset(uri, '\0', MAX_LENGTH); memset(buf, '\0', MAX_LENGTH); memset(version, '\0', MAX_LENGTH); memset(method, '\0', MAX_LENGTH); } Close(fd); }
void RedChannel::on_event() { if (_outgoing_message) { RedPeer::OutMessage& peer_message = _outgoing_message->peer_message(); _outgoing_pos += do_send(peer_message, _outgoing_pos); if (_outgoing_pos == peer_message.message_size()) { _outgoing_message->release(); _outgoing_message = NULL; } } send_messages(); if (_incomming_header_pos) { _incomming_header_pos += RedPeer::recive(((uint8_t*)&_incomming_header) + _incomming_header_pos, sizeof(SpiceDataHeader) - _incomming_header_pos); if (_incomming_header_pos != sizeof(SpiceDataHeader)) { return; } _incomming_header_pos = 0; _incomming_message = new CompoundInMessage(_incomming_header.serial, _incomming_header.type, _incomming_header.size, _incomming_header.sub_list); _incomming_message_pos = 0; } if (_incomming_message) { _incomming_message_pos += RedPeer::recive(_incomming_message->data() + _incomming_message_pos, _incomming_message->compound_size() - _incomming_message_pos); if (_incomming_message_pos != _incomming_message->compound_size()) { return; } AutoRef<CompoundInMessage> message(_incomming_message); _incomming_message = NULL; on_message_recived(); _message_handler->handle_message(*(*message)); on_message_complition((*message)->serial()); } recive_messages(); }
static GLOBAL_FUNC(cmd_messages) { long mask = MESSAGE_RECIPIENT_AUTHED | MESSAGE_RECIPIENT_LUSERS | MESSAGE_RECIPIENT_CHANNELS | MESSAGE_RECIPIENT_RCHANNELS; unsigned int count; if(IsOper(user)) mask |= MESSAGE_RECIPIENT_OPERS; if(IsHelper(user)) mask |= MESSAGE_RECIPIENT_HELPERS; count = send_messages(user, mask, 0); if(count) global_notice(user, "GMSG_MESSAGE_COUNT", count); else global_notice(user, "GMSG_NO_MESSAGES"); return 1; }
int main(int argc, char * argv[]) { int socket_id, e; char *hostname, *username; int sending = 0; if (argc < 3) { printf("Usage: client <hostname> <username>\n"); exit(1); } else { hostname = argv[1]; username = argv[2]; if (argc >= 4) { sending = 1; }; } struct user me = new_user(username); setup_sig_handler(); e = socket_id = connect_to_server(hostname, PORT); if (e < 0) check_errors("Error connecting to server", e); e = handshake(socket_id, me); if (e < 0) { printf("Username already taken\n"); running = 0; } else { printf("Handshake succesfull!\n"); } while (running) { if (sending) { e = send_messages(socket_id, me); } else { e = receive_messages(socket_id); } if (e < 0) running = 0; } cleanup(socket_id); }
void serverlist_query(unsigned short msg) { int contactsock; if (!initial && explicit_host != NULL) { /* already did the work, no point doing it again */ return; } contactsock = socket(SOCK_FAMILY, SOCK_DGRAM, 0); if (contactsock < 0) { leave(1, "socket system call failed"); } send_messages(contactsock, msg); get_responses(contactsock); (void) close(contactsock); }
bool background_work() { connection_list connections; { std::unique_lock<mutex_type> l(connections_mtx_, std::try_to_lock); if(l && !connections_.empty()) { connections.push_back(connections_.front()); connections_.pop_front(); } } bool has_work = false; if(!connections.empty()) { send_messages(std::move(connections)); has_work = true; } next_free_tag(); return has_work; }
static int global_process_user(struct userNode *user, UNUSED_ARG(void *extra)) { if(IsLocal(user) || self->uplink->burst || user->uplink->burst) return 0; send_messages(user, MESSAGE_RECIPIENT_LUSERS, 1); /* only alert on new usercount if the record was broken in the last * 30 seconds, and no alert had been sent in that time. */ if((now - max_clients_time) <= 30 && (now - last_max_alert) > 30) { char *message; message = alloca(36); sprintf(message, "New user count record: %d", max_clients); global_message(MESSAGE_RECIPIENT_OPERS, message); last_max_alert = now; } return 0; }
int main() { static const unsigned int repeations = 10; distributor_type& inst = distributor_type::instance(); observer_type* obs1 = new observer_type(); inst.append_observer(obs1); time_vector.clear(); for( unsigned int i=0; i < repeations; ++i ) { send_messages();} print_time_vector("send_messages"); time_vector.clear(); for( unsigned int i=0; i < repeations; ++i ) { send_messages_mt(); } print_time_vector("send_messages_mt"); inst.remove_observer(obs1); delete obs1; return 0; }
// Adds the message to the queue and sends the queued messages if // the queue becomes full. static void send_message(msgpack_sbuffer *buffer) { queue_message(buffer); if(queued_message_count() == MESSAGE_BATCH_SIZE) send_messages(); }
int cmd_cure(string str) { string whom, limb, clas; int amount, cost, healing, i; object tp, ob; string * limbs; if (!spell()) { notify_fail("What?\n"); return 0; } if(!str) { notify_fail("Cure whom?\n"); return 0; } tp = this_player(); if(tp->query_disable()) { notify_fail("You are in the middle of something else.\n"); return 0; } if(!alignment_ok(this_player())) { notify_fail("You have betrayed the source of your powers.\n"); return 0; } healing = (int)tp->query_skill("healing"); clas = (string)tp->query_subclass(); if(str == "me" || str == "myself") ob = tp; else ob = present(str, environment(tp)); if(!ob) { if(sscanf(str, "%s %s", whom, limb) != 2) { notify_fail("Correct syntax: <cure [who] [(limb)]\n"); return 0; } if(whom == "me" || whom == "myself") ob = tp; else ob = present(whom, environment(tp)); } if(!ob) { notify_fail("Cure whom?\n"); return 0; } if(!limb) cost = healing*2/3; else if(limb == "all") cost = healing; else if(member_array(limb, (string *)ob->query_limbs()) == -1) { notify_fail("That limb is missing!\n"); return 0; } else cost = healing/3; if(ob != tp) cost = random(cost); if((int)tp->query_mp() < cost) { notify_fail("Too low on magic power.\n"); return 0; } tp->add_mp(-cost); amount = (healing*((int)ob->query_level()))/10; if(amount > 400) { log_file("hmmm", this_player()->query_name()+" healing "+ob->query_short()+" "+amount+"\n"); amount = 400; } if(clas == "paladin"){ amount = amount/2; } this_player()->set_magic_round(2); if(tp == ob) tp->add_skill_points("healing", amount/6); else { tp->add_skill_points("healing", amount/2); tp->add_alignment("healing", amount/5); } if(!limb) { if (tp->query_hp() < 1) { ob->set_hp(1); send_messages(tp, ob, clas, 0);} else{ ob->add_hp(amount); send_messages(tp, ob, clas, 0);} } else if(limb == "all") { limbs = (string *)ob->query_limbs(); for(i=0; i<sizeof(limbs); i++) { ob->heal_limb(limbs[i], (amount/2)); } if (tp->query_hp() < 1) { ob->set_hp(1); send_messages(tp, ob, clas, 0);} else{ ob->add_hp(amount); send_messages(tp, ob, clas, 0);} } else { ob->add_hp(amount/4); if (tp->query_hp() < 1) { ob->set_hp(1); send_messages(tp, ob, clas, 0);} else{ ob->add_hp(amount); send_messages(tp, ob, clas, 0);} } tp->set_disable(); return 1; }
int cmd_heal(string str) { string whom, limb, clas; int amount, cost, healing, i, wisdom; object tp, ob; string * limbs; if (!spell()) { return 0; } if(!str) { notify_fail("Heal whom?\n"); return 0; } tp = this_player(); if(tp->query_disable()) { notify_fail("You are in the middle of something else.\n"); return 0; } if(!alignment_ok(this_player())) { notify_fail("You have betrayed the source of your powers.\n"); return 0; } if(this_player()->query_ghost()) return notify_fail("You cannot speak without a body.\n"); healing = (int)tp->query_skill("healing")/2; healing += (int)tp->query_level()/3; healing += (int)tp->query_skill("faith")/4; healing += tp->query_skill("belief")/4; clas = (string)tp->query_subclass(); if(str == "me" || str == "myself") ob = tp; else ob = present(str, environment(tp)); if(!ob) { if(sscanf(str, "%s %s", whom, limb) != 2) { notify_fail("Heal whom?\n"); return 0; } if(whom == "me" || whom == "myself") ob = tp; else ob = present(whom, environment(tp)); } if(!ob) { notify_fail("Heal whom?\n"); return 0; } if(!limb) cost = healing/2; else if(limb == "all") cost = healing*3/4; else if(member_array(limb, (string *)ob->query_limbs()) == -1) { notify_fail("That limb is missing!\n"); return 0; } else cost = healing/3; if(ob != tp) cost = random(cost); if((int)tp->query_mp() < cost) { notify_fail("Too low on magic power.\n"); return 0; } tp->add_mp(-cost); amount = (healing); if(amount > 800) { log_file("hmmm", this_player()->query_name()+" healing "+ob->query_short()+" "+amount+"\n"); amount = 800; } this_player()->set_magic_round(2); if(tp == ob) tp->add_skill_points("healing", amount/3); else { tp->add_skill_points("healing", amount/2); tp->add_alignment(amount/5); tp->add_exp(amount/4); } if(!limb) { ob->add_hp(amount); } else if(limb == "all") { limbs = (string *)ob->query_limbs(); for(i=0; i<sizeof(limbs); i++) { ob->heal_limb(limbs[i], (amount/2)); } ob->add_hp(amount/2); } else { ob->heal_limb(limb, amount); ob->add_hp(amount/3); } send_messages(tp, ob, clas, limb); return 1; }
int main(int argc, char** argv) { boost::program_options::options_description desc("options"); desc.add_options() ("help", "produce help message") ("topic", boost::program_options::value<std::string>(), "topic") ("broker", boost::program_options::value<std::string>(), "broker") ("schema_registry", boost::program_options::value<std::string>(), "schema_registry") ("schema_registry_port", boost::program_options::value<int>()->default_value(8081), "schema_registry_port") ; boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); boost::program_options::notify(vm); boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info); if (vm.count("help")) { std::cout << desc << std::endl; return 0; } std::string topic; if (vm.count("topic")) { topic = vm["topic"].as<std::string>(); } else { std::cout << "--topic must be specified" << std::endl; return 0; } int32_t kafka_port = 9092; std::vector<csi::kafka::broker_address> kafka_brokers; if (vm.count("broker")) { std::string s = vm["broker"].as<std::string>(); size_t last_colon = s.find_last_of(':'); if (last_colon != std::string::npos) kafka_port = atoi(s.substr(last_colon + 1).c_str()); s = s.substr(0, last_colon); // now find the brokers... size_t last_separator = s.find_last_of(','); while (last_separator != std::string::npos) { std::string host = s.substr(last_separator + 1); kafka_brokers.push_back(csi::kafka::broker_address(host, kafka_port)); s = s.substr(0, last_separator); last_separator = s.find_last_of(','); } kafka_brokers.push_back(csi::kafka::broker_address(s, kafka_port)); } else { std::cout << "--broker must be specified" << std::endl; return 0; } int32_t schema_registry_port = 8081; std::vector<csi::kafka::broker_address> schema_registrys; std::string used_schema_registry; if (vm.count("schema_registry_port")) { schema_registry_port = vm["schema_registry_port"].as<int>(); } if (vm.count("schema_registry")) { std::string s = vm["schema_registry"].as<std::string>(); size_t last_colon = s.find_last_of(':'); if (last_colon != std::string::npos) schema_registry_port = atoi(s.substr(last_colon + 1).c_str()); s = s.substr(0, last_colon); // now find the brokers... size_t last_separator = s.find_last_of(','); while (last_separator != std::string::npos) { std::string host = s.substr(last_separator + 1); schema_registrys.push_back(csi::kafka::broker_address(host, schema_registry_port)); s = s.substr(0, last_separator); last_separator = s.find_last_of(','); } schema_registrys.push_back(csi::kafka::broker_address(s, schema_registry_port)); } else { // default - assume registry is running on all kafka brokers for (std::vector<csi::kafka::broker_address>::const_iterator i = kafka_brokers.begin(); i != kafka_brokers.end(); ++i) { schema_registrys.push_back(csi::kafka::broker_address(i->host_name, schema_registry_port)); } } // right now the schema registry class cannot handle severel hosts so just stick to the first one. used_schema_registry = schema_registrys[0].host_name + ":" + std::to_string(schema_registrys[0].port); std::string kafka_broker_str = ""; for (std::vector<csi::kafka::broker_address>::const_iterator i = kafka_brokers.begin(); i != kafka_brokers.end(); ++i) { kafka_broker_str += i->host_name + ":" + std::to_string(i->port); if (i != kafka_brokers.end() - 1) kafka_broker_str += ", "; } BOOST_LOG_TRIVIAL(info) << "kafka broker(s): " << kafka_broker_str; BOOST_LOG_TRIVIAL(info) << "topic : " << topic; std::string schema_registrys_info; for (std::vector<csi::kafka::broker_address>::const_iterator i = schema_registrys.begin(); i != schema_registrys.end(); ++i) { schema_registrys_info += i->host_name + ":" + std::to_string(i->port); if (i != schema_registrys.end() - 1) schema_registrys_info += ", "; } BOOST_LOG_TRIVIAL(info) << "schema_registry(s) : " << schema_registrys_info; BOOST_LOG_TRIVIAL(info) << "used schema registry: " << used_schema_registry; int64_t total = 0; boost::asio::io_service fg_ios; std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(fg_ios)); boost::thread fg(boost::bind(&boost::asio::io_service::run, &fg_ios)); csi::kafka::highlevel_producer producer(fg_ios, topic, -1, 200, 1000000); confluent::registry registry(fg_ios, used_schema_registry); confluent::codec avro_codec(registry); producer.connect(kafka_brokers); BOOST_LOG_TRIVIAL(info) << "connected to kafka"; producer.connect_forever(kafka_brokers); boost::thread do_log([&producer] { while (true) { boost::this_thread::sleep(boost::posix_time::seconds(1)); std::vector<csi::kafka::highlevel_producer::metrics> metrics = producer.get_metrics(); size_t total_queue = 0; uint32_t tx_msg_sec_total = 0; uint32_t tx_kb_sec_total = 0; for (std::vector<csi::kafka::highlevel_producer::metrics>::const_iterator i = metrics.begin(); i != metrics.end(); ++i) { total_queue += (*i).msg_in_queue; tx_msg_sec_total += (*i).tx_msg_sec; tx_kb_sec_total += (*i).tx_kb_sec; } BOOST_LOG_TRIVIAL(info) << "\t \tqueue:" << total_queue << "\t" << tx_msg_sec_total << " msg/s \t" << (tx_kb_sec_total / 1024) << "MB/s"; } }); std::cerr << "registring schemas" << std::endl; auto key_res = avro_codec.put_schema("sample.contact_info_key", sample::contact_info_key::valid_schema()); if (key_res.first!=0) { BOOST_LOG_TRIVIAL(error) << "registring sample.contact_info_key failed"; return -1; } auto val_res = avro_codec.put_schema("sample.contact_info", sample::contact_info::valid_schema()); if (val_res.first!=0) { BOOST_LOG_TRIVIAL(error) << "registring sample.contact_info failed"; return -1; } BOOST_LOG_TRIVIAL(info) << "registring schemas done"; //produce messages std::vector<boost::thread*> threads; for (int i = 0; i != 10; ++i) { threads.emplace_back(new boost::thread([&avro_codec, key_res, val_res, &producer, i] { send_messages(avro_codec, key_res.second, val_res.second, producer, i); })); } while (true) { boost::this_thread::sleep(boost::posix_time::seconds(1)); } work.reset(); fg_ios.stop(); return EXIT_SUCCESS; }
int cmd_heal(string str) { string whom, limb, clas; int amount, cost, healing, i, wisdom; object tp, ob; string * limbs; if (!spell()) { write("What?\n"); return 1; } if(!str) { notify_fail("Heal whom?\n"); return 0; } tp = this_player(); if(tp->query_casting()) { notify_fail("You are in the middle of another spell!\n"); return 0; } if(!alignment_ok(this_player())) { notify_fail("You have betrayed the source of your powers.\n"); return 0; } healing = (int)tp->query_skill("healing"); wisdom = (int)tp->query_stats("wisdom"); clas = (string)tp->query_subclass(); if(str == "me" || str == "myself") ob = tp; else ob = present(str, environment(tp)); if(!ob) { if(sscanf(str, "%s %s", whom, limb) != 2) { notify_fail("Correct syntax: <heal [who] [(limb)]\n"); return 0; } if(whom == "me" || whom == "myself") ob = tp; else ob = present(whom, environment(tp)); } if(!ob) { notify_fail("Heal whom?\n"); return 0; } if(!limb) cost = 22; else if(limb == "all") cost = 44; else if(member_array(limb, (string *)tp->query_limbs()) == -1) { notify_fail("You do not have a "+limb+".\n"); return 0; } else cost = 14; if(ob != tp) cost = random(cost); if((int)tp->query_mp() < cost) { notify_fail("Too low on magic power.\n"); tp->add_mp(-cost); return 0; } this_player()->set_magic_round(1); tp->add_mp(-cost); if(healing < 5) amount = 0; else amount = random(wisdom + (healing/10)); if(!amount) { write("You do not have the skill to do that."); return 1; } if(tp == ob) tp->add_skill_points("healing", amount); else { tp->add_skill_points("healing", amount * 2); tp->add_alignment(amount); tp->add_exp(random((amount/2)+2)); } if(!limb) { ob->add_hp(amount); send_messages(tp, ob, clas, 0); } else if(limb == "all") { limbs = (string *)ob->query_limbs(); for(i=0; i<sizeof(limbs); i++) { ob->heal_limb(limbs[i], (amount / 2)); } ob->add_hp(amount / 2); send_messages(tp, ob, clas, limb); } else { ob->heal_limb(limb, amount); send_messages(tp, ob, clas, limb); } return 1; }
int main() { int sfd, cfd; socklen_t len; struct sockaddr_in saddr, caddr; sfd= socket(AF_INET, SOCK_STREAM, 0); saddr.sin_family=AF_INET; saddr.sin_addr.s_addr=htonl(INADDR_ANY); saddr.sin_port=htons(SERVER_PORT); bind(sfd, (struct sockaddr *)&saddr, sizeof(saddr)); listen(sfd, 5); //listen upto 5 connections simultaneously signal(SIGCHLD, SIG_IGN); while(1) { printf("Server waiting\n"); len=sizeof(caddr); cfd=accept(sfd, (struct sockaddr *)&caddr, &len); //Returns descriptor if( fork() == 0) { close(sfd); // In the child process close this. Parent closes cfd char msg[MAX_COMMAND_SIZE]; struct Message* buff = (struct Message*)malloc(sizeof(struct Message)); int started = 0; int seq_no = 0; int rc; printf("Came into first connection"); while(1){ while((rc = recv(cfd, buff, sizeof(struct Message), MSG_DONTWAIT))<=0); memcpy(msg, buff->content, buff->size); if(msg[strlen(msg)-1]=='\n'){ msg[strlen(msg)-1]='\0'; } printf("Received %s with rc = %d and started = %d\n",msg, rc, started); if(!started){ if(strcmp(msg,"open") == 0){ if(chdir("/")==-1){ exit(1); }else{ send_message(cfd, "HOME\0", 5, seq_no ++); printf("Opened... "); started = 1; } } } //ls command else if(msg[0] == 'l' && msg[1] == 's'){ execute_command(cfd, msg, &seq_no); }else if(msg[0] == 'c' && msg[1] == 'd'){ if(msg[2] == '\0'){ //A simple cd. if(chdir("/")==-1){ send_message(cfd, "Cannot move to home directory.\n\0", 32, seq_no ++); }else{ execute_command(cfd, msg, &seq_no); send_message(cfd, "Moved to home directory\n\0", 25, seq_no ++); } } else{ int i; int k = strlen(msg); for(i = 0; i <= k - 3; i++){ msg[i] = msg[i+3]; } msg[k - 3] = '\0'; if(chdir(msg)==-1){ send_message(cfd, "Cannot move to specified location.\n\0", 32, seq_no ++); }else{ send_message(cfd, "Successfully moved to specified location.\n\0", 41, seq_no ++); } } }else if(msg[0] == 'p' && msg[1] == 'w' && msg[2] == 'd'){ execute_command(cfd, "pwd", &seq_no); }else if(msg[0] == 'g' && msg[1] == 'e' && msg[2] == 't'){ int i; int k = strlen(msg); for(i = 0; i <= k - 4; i++){ msg[i] = msg[i+4]; } msg[k - 4] = '\0'; FILE *fp; fp = fopen(msg, "rb"); if(fp == NULL){ printf("Unable to open file.\n"); } else{ printf("Beginning file transfer.\n"); send_messages(cfd, fp, &seq_no); fclose(fp); } }else{ send_message(cfd, "Invalid command.\n\0", 19, seq_no ++); } } free(buff); close(cfd); return 0; } close(cfd); // Parent has closed this. // As there is a bound on the number of fd's you can have. } }
static void global_process_auth(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle), UNUSED_ARG(void *extra)) { if(IsHelper(user)) send_messages(user, MESSAGE_RECIPIENT_HELPERS, 0); }
int PushBed(){ send_messages("move", "$agent_name $agent_verb the bed.", this_player(), 0, environment(this_player())); environment(this_object())->OpenPassage(); return 1; }
void RedChannel::on_send_trigger() { send_messages(); }
int PushRug() { send_messages("move", "$agent_name $agent_verb the Persian rug.", this_player(), 0, environment(this_player())); environment(this_object())->RevealDoor(); return 1; }
void endCallback(object who) { if( who ) { send_messages("", "The %^BOLD%^CYAN%^magical shield%^RESET%^ around " "$agent_name shatters into nothingness.", who, 0, environment(who), 0); } }