int main(int argc, char* argv[]) { schd = create_scheduler(); initialize_scheduler(schd, NULL); session_1 = create_session(); initialize_session(session_1, "222.214.218.237", 6601, "1299880", 0); set_session_index(session_1, 0); add_session(schd, session_1); session_2 = create_session(); initialize_session(session_2, "222.214.218.237", 6601, "1299880", 1); set_session_index(session_2, 1); add_session(schd, session_2); set_surface_mode(schd->surface, mode_2); scheduler_start(schd); session_start(session_1); session_start(session_2); scheduler_wait(schd); session_stop(session_1); session_stop(session_2); destroy_session(session_1); destroy_session(session_2); return 0; }
/** * Creates a Authorization Session. */ AAASession* AAACreateAuthSession(void *generic_data,int is_client,int is_statefull,AAASessionCallback_f *cb,void *param) { AAASession *s; str id; cdp_session_type_t type; generate_session_id(&id,0); if (is_client){ if (is_statefull) type = AUTH_CLIENT_STATEFULL; else type = AUTH_CLIENT_STATELESS; }else{ if (is_statefull) type = AUTH_SERVER_STATEFULL; else type = AUTH_SERVER_STATELESS; } s = new_session(id,type); if (s) { s->u.auth.generic_data = generic_data; s->cb = cb; s->cb_param = param; s->u.auth.timeout=time(0)+config->tc*30; s->u.auth.lifetime=time(0)+config->tc*32; s->u.auth.grace_period=config->tc*2; LOG(L_DBG,"id is %.*s",s->id.len,s->id.s); LOG(L_DBG,"hash is %u",s->hash); add_session(s); } return s; }
/* * Handle a signal from the login manager by recording login/logout pairs. Make * the aggressive assumption that all sessions end when the PrepareForShutdown * signal is sent with parameter TRUE. This isn't necessarily a valid assumption * because the shutdown can be cancelled, but in practice we don't get the * SessionRemoved signal in time if the user shuts down without first logging * out. * * Recording of logins must be 1:1 with recording of logouts, so each time * we record a login we add the session ID to the humanity_by_session_id set, * and each time we record a logout we remove the session ID from the * humanity_by_session_id set. */ static void record_login (GDBusProxy *dbus_proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { if (strcmp ("SessionRemoved", signal_name) == 0) { const gchar *session_id; g_variant_get (parameters, "(&s&o)", &session_id, NULL); remove_session (session_id); } else if (strcmp ("SessionNew", signal_name) == 0) { const gchar *session_id, *session_path; g_variant_get (parameters, "(&s&o)", &session_id, &session_path); guint32 user_id; if (!get_user_id (session_path, &user_id)) return; add_session (session_id, user_id); } }
ani_request_t *ani_create_request(const char *raw_request) { ani_request_t *request = (ani_request_t *)xmalloc(sizeof(ani_request_t)); assert(NULL != raw_request); (void)xstrncpy(request->msg, raw_request, RAW_LEN); add_space(request); add_tag(request); add_session(request); return request; }
static GDBusProxy * login_dbus_proxy_new (void) { GError *error = NULL; GDBusProxy *dbus_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL /* GDBusInterfaceInfo */, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL /* GCancellable */, &error); if (error) { g_warning ("Error creating GDBusProxy: %s.", error->message); g_error_free (error); return NULL; } g_signal_connect (dbus_proxy, "g-signal", G_CALLBACK (record_login), NULL /* data */); GVariant *sessions = g_dbus_proxy_call_sync (dbus_proxy, "ListSessions", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error) { g_warning ("Error calling ListSessions: %s.", error->message); g_error_free (error); return NULL; } GVariantIter *session_iter; g_variant_get (sessions, "(a(susso))", &session_iter); const gchar *session_id; guint32 user_id; while (g_variant_iter_loop (session_iter, "(&suss&o)", &session_id, &user_id, NULL, NULL, NULL)) { add_session (session_id, user_id); } g_variant_iter_free (session_iter); g_variant_unref (sessions); return dbus_proxy; }
void yf::LoadBalance::Impl::process(mp::Package &package) { bool is_closed_front = false; // checking for closed front end packages if (package.session().is_closed()) { is_closed_front = true; } Z_GDU *gdu_req = package.request().get(); // passing anything but z3950 packages if (gdu_req && gdu_req->which == Z_GDU_Z3950) { // target selecting only on Z39.50 init request if (gdu_req->u.z3950->which == Z_APDU_initRequest) { yazpp_1::GDU base_req(gdu_req); Z_APDU *apdu = base_req.get()->u.z3950; Z_InitRequest *org_init = base_req.get()->u.z3950->u.initRequest; mp::odr odr_en(ODR_ENCODE); std::list<std::string> vhosts; mp::util::remove_vhost_otherinfo(&(org_init->otherInfo), vhosts); // get lowest of all vhosts.. Remove them if individually if // they turn out to be bad.. while (1) { std::list<std::string>::iterator ivh = vhosts.begin(); std::list<std::string>::iterator ivh_pick = vhosts.end(); Package init_pkg(package.session(), package.origin()); init_pkg.copy_filter(package); unsigned int cost_i = std::numeric_limits<unsigned int>::max(); { boost::mutex::scoped_lock scoped_lock(m_mutex); for (; ivh != vhosts.end(); ivh++) { if ((*ivh).size() != 0) { unsigned int cost = yf::LoadBalance::Impl::cost(*ivh); std::ostringstream os; os << "LB" << " " << package << " " << "0.000000" << " " << "Consider " << *ivh << " cost=" << cost; yaz_log(YLOG_LOG, "%s", os.str().c_str()); if (cost_i > cost) { ivh_pick = ivh; cost_i = cost; } } } } if (ivh_pick == vhosts.end()) break; std::string target = *ivh_pick; vhosts.erase(ivh_pick); // copying new target into init package yazpp_1::GDU init_gdu(base_req); Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest; mp::util::set_vhost_otherinfo(&(init_req->otherInfo), odr_en, target, 1); init_pkg.request() = init_gdu; // moving all package types init_pkg.move(); // checking for closed back end packages if (!init_pkg.session().is_closed()) { add_session(package.session().id(), target); package.response() = init_pkg.response(); return; } std::ostringstream os; os << "LB" << " " << package << " " << "0.000000" << " " << "Failed " << target; yaz_log(YLOG_LOG, "%s", os.str().c_str()); } mp::odr odr; package.response() = odr.create_initResponse( apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "load_balance: no available targets"); package.session().close(); return; } // frontend Z39.50 close request is added to statistics and marked else if (gdu_req->u.z3950->which == Z_APDU_close) { is_closed_front = true; boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); } // any other Z39.50 package is added to statistics else { boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); } } // moving all package types package.move(); bool is_closed_back = false; // checking for closed back end packages if (package.session().is_closed()) is_closed_back = true; Z_GDU *gdu_res = package.response().get(); // passing anything but z3950 packages if (gdu_res && gdu_res->which == Z_GDU_Z3950) { // session closing only on Z39.50 close response if (gdu_res->u.z3950->which == Z_APDU_close) { is_closed_back = true; boost::mutex::scoped_lock scoped_lock(m_mutex); remove_package(package.session().id()); } // any other Z39.50 package is removed from statistics else { boost::mutex::scoped_lock scoped_lock(m_mutex); remove_package(package.session().id()); } } // finally removing sessions and marking deads if (is_closed_back || is_closed_front) { boost::mutex::scoped_lock scoped_lock(m_mutex); // marking backend dead if backend closed without fronted close if (is_closed_front == false) add_dead(package.session().id()); remove_session(package.session().id()); // making sure that package is closed package.session().close(); } }
/** * Adds a new user to anopes internal userlist. * * If the SVID passed is 2, the user will not be marked registered or requested to ID. * This is an addition to accomodate IRCds where we cannot determine this based on the NICK * or UID command. Some IRCd's keep +r on when changing nicks and do not use SVID (ex. InspIRCd 1.2). * Instead we get a METADATA command containing the accountname the user was last identified to. * Since this is received after the user is introduced to us we should not yet mark the user * as identified or ask him to identify. We will mark him as recognized for the time being and let * him keep his +r if he has it. * It is the responsibility of the protocol module to make sure that this is either invalidated, * or changed to identified. ~ Viper **/ User *do_nick(const char *source, char *nick, char *username, char *host, char *server, char *realname, time_t ts, uint32 svid, uint32 ip, char *vhost, char *uid) { User *user = NULL; char *tmp = NULL; NickAlias *old_na; /* Old nick rec */ int nc_changed = 1; /* Did nick core change? */ int status = 0; /* Status to apply */ char mask[USERMAX + HOSTMAX + 2]; char *logrealname; char *oldnick; if (!*source) { char ipbuf[16]; struct in_addr addr; if (ircd->nickvhost) { if (vhost) { if (!strcmp(vhost, "*")) { vhost = NULL; if (debug) alog("debug: new user�with no vhost in NICK command: %s", nick); } } } /* This is a new user; create a User structure for it. */ if (debug) alog("debug: new user: %s", nick); if (ircd->nickip) { addr.s_addr = htonl(ip); ntoa(addr, ipbuf, sizeof(ipbuf)); } if (LogUsers) { /** * Ugly swap routine for Flop's bug :) **/ if (realname) { tmp = strchr(realname, '%'); while (tmp) { *tmp = '-'; tmp = strchr(realname, '%'); } } logrealname = normalizeBuffer(realname); /** * End of ugly swap **/ if (ircd->nickvhost) { if (ircd->nickip) { alog("LOGUSERS: %s (%s@%s => %s) (%s) [%s] connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, ipbuf, server); } else { alog("LOGUSERS: %s (%s@%s => %s) (%s) connected to the network (%s).", nick, username, host, (vhost ? vhost : "none"), logrealname, server); } } else { if (ircd->nickip) { alog("LOGUSERS: %s (%s@%s) (%s) [%s] connected to the network (%s).", nick, username, host, logrealname, ipbuf, server); } else { alog("LOGUSERS: %s (%s@%s) (%s) connected to the network (%s).", nick, username, host, logrealname, server); } } Anope_Free(logrealname); } /* We used to ignore the ~ which a lot of ircd's use to indicate no * identd response. That caused channel bans to break, so now we * just take what the server gives us. People are still encouraged * to read the RFCs and stop doing anything to usernames depending * on the result of an identd lookup. */ /* First check for AKILLs. */ /* DONT just return null if its an akill match anymore - yes its more efficent to, however, now that ircd's are * starting to use things like E/F lines, we cant be 100% sure the client will be removed from the network :/ * as such, create a user_struct, and if the client is removed, we'll delete it again when the QUIT notice * comes in from the ircd. **/ if (check_akill(nick, username, host, vhost, ipbuf)) { /* return NULL; */ } /** * DefCon AKILL system, if we want to akill all connecting user's here's where to do it * then force check_akill again on them... **/ /* don't akill on netmerges -Certus */ /* don't akill clients introduced by ulines. -Viper */ if (is_sync(findserver(servlist, server)) && checkDefCon(DEFCON_AKILL_NEW_CLIENTS) && !is_ulined(server)) { strncpy(mask, "*@", 3); strncat(mask, host, HOSTMAX); alog("DEFCON: adding akill for %s", mask); add_akill(NULL, mask, s_OperServ, time(NULL) + dotime(DefConAKILL), DefConAkillReason ? DefConAkillReason : "DEFCON AKILL"); if (check_akill(nick, username, host, vhost, ipbuf)) { /* return NULL; */ } } /* SGLINE */ if (ircd->sgline) { if (check_sgline(nick, realname)) return NULL; } /* SQLINE */ if (ircd->sqline) { if (check_sqline(nick, 0)) return NULL; } /* SZLINE */ if (ircd->szline && ircd->nickip) { if (check_szline(nick, ipbuf)) return NULL; } /* Now check for session limits */ if (LimitSessions && !is_ulined(server) && !add_session(nick, host, ipbuf)) return NULL; /* Allocate User structure and fill it in. */ user = new_user(nick); user->username = sstrdup(username); user->host = sstrdup(host); user->server = findserver(servlist, server); user->realname = sstrdup(realname); user->timestamp = ts; user->my_signon = time(NULL); user->chost = vhost ? sstrdup(vhost) : sstrdup(host); user->vhost = vhost ? sstrdup(vhost) : sstrdup(host); if (uid) { user->uid = sstrdup(uid); /* p10/ts6 stuff */ } else { user->uid = NULL; } user->vident = sstrdup(username); /* We now store the user's ip in the user_ struct, * because we will use it in serveral places -- DrStein */ if (ircd->nickip) { user->hostip = sstrdup(ipbuf); } else { user->hostip = NULL; } if (svid == 0) { display_news(user, NEWS_LOGON); display_news(user, NEWS_RANDOM); } if (svid == 2 && user->na) { /* We do not yet know if the user should be identified or not. * mark him as recognized for now. * It s up to the protocol module to make sure this either becomes ID'd or * is invalidated. ~ Viper */ if (debug) alog("debug: Marking %s as recognized..", user->nick); user->svid = 1; user->na->status |= NS_RECOGNIZED; nc_changed = 0; } else if (svid == ts && user->na) { /* Timestamp and svid match, and nick is registered; automagically identify the nick */ user->svid = svid; user->na->status |= NS_IDENTIFIED; check_memos(user); nc_changed = 0; /* Start nick tracking if available */ if (NSNickTracking) nsStartNickTracking(user); } else if (svid != 1) { /* Resets the svid because it doesn't match */ user->svid = 1; anope_cmd_svid_umode(user->nick, user->timestamp); } else { user->svid = 1; } send_event(EVENT_NEWNICK, 1, nick); } else { /* An old user changing nicks. */ if (UseTS6 && ircd->ts6) user = find_byuid(source); if (!user) user = finduser(source); if (!user) { alog("user: NICK from nonexistent nick %s", source); return NULL; } user->isSuperAdmin = 0; /* Dont let people nick change and stay SuperAdmins */ if (debug) alog("debug: %s changes nick to %s", source, nick); if (LogUsers) { logrealname = normalizeBuffer(user->realname); if (ircd->vhost) { alog("LOGUSERS: %s (%s@%s => %s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, (user->vhost ? user->vhost : "(none)"), logrealname, nick, user->server->name); } else { alog("LOGUSERS: %s (%s@%s) (%s) changed nick to %s (%s).", user->nick, user->username, user->host, logrealname, nick, user->server->name); } if (logrealname) { free(logrealname); } } user->timestamp = ts; if (stricmp(nick, user->nick) == 0) { /* No need to redo things */ change_user_nick(user, nick); nc_changed = 0; } else { /* Update this only if nicks aren't the same */ user->my_signon = time(NULL); old_na = user->na; if (old_na) { if (nick_recognized(user)) user->na->last_seen = time(NULL); status = old_na->status & NS_TRANSGROUP; cancel_user(user); } oldnick = sstrdup(user->nick); change_user_nick(user, nick); if ((old_na ? old_na->nc : NULL) == (user->na ? user->na->nc : NULL)) nc_changed = 0; if (!nc_changed && (user->na)) user->na->status |= status; else { anope_cmd_nc_change(user); } send_event(EVENT_CHANGE_NICK, 2, nick, oldnick); free(oldnick); } if (ircd->sqline) { if (!is_oper(user) && check_sqline(user->nick, 1)) return NULL; } } /* if (!*source) */ /* Check for nick tracking to bypass identification */ if (NSNickTracking && nsCheckNickTracking(user)) { user->na->status |= NS_IDENTIFIED; nc_changed = 0; } if (nc_changed || !nick_recognized(user)) { if (validate_user(user)) check_memos(user); } else { if (nick_identified(user)) { char tsbuf[16]; user->na->last_seen = time(NULL); if (user->na->last_usermask) free(user->na->last_usermask); user->na->last_usermask = smalloc(strlen(common_get_vident(user)) + strlen(common_get_vhost(user)) + 2); sprintf(user->na->last_usermask, "%s@%s", common_get_vident(user), common_get_vhost(user)); snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) user->timestamp); anope_cmd_svid_umode2(user, tsbuf); alog("%s: %s!%s@%s automatically identified for nick %s", s_NickServ, user->nick, user->username, user->host, user->nick); } } /* Bahamut sets -r on every nick changes, so we must test it even if nc_changed == 0 */ if (ircd->check_nick_id) { if (nick_identified(user)) { char tsbuf[16]; snprintf(tsbuf, sizeof(tsbuf), "%lu", (unsigned long int) user->timestamp); anope_cmd_svid_umode3(user, tsbuf); } } return user; }
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct iscsi_target *target = NULL; long err; u32 id; if ((err = get_user(id, (u32 *) arg)) != 0) goto done; if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (cmd == ADD_TARGET) if (target) { err = -EEXIST; eprintk("Target %u already exist!\n", id); goto done; } switch (cmd) { case ADD_TARGET: assert(!target); err = add_target(arg); goto done; } if (!target) { eprintk("can't find the target %u\n", id); err = -EINVAL; goto done; } if ((err = target_lock(target, 1)) < 0) { eprintk("interrupted %ld %d\n", err, cmd); goto done; } switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; } if (target) target_unlock(target); done: return err; }
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct iscsi_target *target = NULL; long err; u32 id; err = down_interruptible(&ioctl_sem); if (err < 0) return err; if (cmd == GET_MODULE_INFO) { err = get_module_info(arg); goto done; } if (cmd == ADD_TARGET) { err = add_target(arg); goto done; } err = get_user(id, (u32 *) arg); if (err < 0) goto done; /* locking handled in target_del */ if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (!target) { err = -ENOENT; goto done; } err = target_lock(target, 1); if (err < 0) goto done; switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; default: eprintk("invalid ioctl cmd %x\n", cmd); err = -EINVAL; } target_unlock(target); done: up(&ioctl_sem); return err; }
int iet_ioctl(struct cdev *dev, unsigned long cmd, caddr_t iarg, int fflag, struct thread *td) #endif { struct iscsi_target *target = NULL; long err; u32 id; #ifdef FREEBSD unsigned long arg = (unsigned long)(iarg); /* Avoid make warnings */ #endif err = mutex_lock_interruptible(&ioctl_mutex); if (err != 0) return err; if (cmd == GET_MODULE_INFO) { err = get_module_info(arg); goto done; } if (cmd == ADD_TARGET) { err = add_target(arg); goto done; } err = copy_from_user(&id, (u32 *) (unsigned long)arg, sizeof(u32)); if (err < 0) goto done; /* locking handled in target_del */ if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (!target) { err = -ENOENT; goto done; } err = target_lock(target, 1); if (err < 0) goto done; switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; default: eprintk("invalid ioctl cmd %lx\n", (unsigned long)cmd); err = -EINVAL; } target_unlock(target); done: mutex_unlock(&ioctl_mutex); #ifdef FREEBSD if (err < 0) err = -(err); #endif return err; }
void compile_multi_session_list (session_list_data_type **list) { #if !DEMO_VERSION int session_number = 0; session_table_type *this_session; connection_data_type *this_connection; char text [128]; this_connection = direct_play_get_connection_data (); if ( ( this_connection ) && ( this_connection->is_initialised ) ) { int number_of_sessions; int currentServer; // Jabberwock 040201 Session filter if (command_line_session_filter) { if ((strcmp(session_filter_value, "root") == 0) || (strcmp(session_filter_value, "-Multiplayer-") == 0)) { add_session ("-Multiplayer-", SESSION_LIST_TYPE_FILTER, 1, NULL, "-Multiplayer-", NULL, NULL, "-Multiplayer-", list, NULL, SESSION_SEASON_INVALID); } } if ( !this_connection->one_way_hosting_setup ) { number_of_sessions = direct_play_enumerate_sessions (); } else { validate_modem_connection (); if ( this_connection->is_initialised ) { number_of_sessions = direct_play_refresh_modem_session (); } } if ( number_of_sessions ) { this_session = direct_play_get_session_table (); while (this_session) { //if (this_session->session->dwUser1 == get_game_type ()) // Jabberwock 031118 MP - campaigns shows in skirmishes and vice versa { if ((!command_line_session_filter) || (strcmp ("-Multiplayer-", session_filter_value) == 0)) // Jabberwock 031210 Session filter { sprintf (text, "%s", this_session->session->lpszSessionNameA); session_number ++; add_session (text, SESSION_LIST_TYPE_JOIN, session_number, this_session, NULL, NULL, NULL, "-Multiplayer-", list, NULL, SESSION_SEASON_INVALID); // Jabberwock 031210 Session filter } } this_session = this_session->next_session; } } //Werewolf 14 May 2003 //Fetch active servers from masterserver net_getServerList(); for (currentServer=0; currentServer<numServers; currentServer++) { if ((!command_line_session_filter) || (strcmp ("-Multiplayer-", session_filter_value) == 0)) // Jabberwock 031210 Session filter { sprintf (text, "%s (%i/%i) %s", Servers[currentServer].Name, Servers[currentServer].CurClients, Servers[currentServer].MaxClients, Servers[currentServer].Version); session_number ++; add_session (text, SESSION_LIST_TYPE_MASTER, session_number, NULL, NULL, NULL, NULL, "-Multiplayer-", list, Servers[currentServer].Adress, SESSION_SEASON_INVALID); // Jabberwock 031210 Session filter } } } #endif }
void recursive_check_campaign_files (const char *directory, session_list_data_type **list, const char *extension) { session_list_types session_type; directory_file_list *warzone_file, *directory_listing; unsigned int i, upper; int value, valid_file, season; static char operator_ [64], variable [64], temp_warzone_name [128], *warzone_name, warzone_path [1024], directory_search_path [1024]; // // First, go through any files in this directory. // sprintf (directory_search_path, "%s\\*.%s", directory, extension); // Jabberwock 0400201 Session filter revised //VJ 050123 small bug fix: check for lowercase AND uppercase if ((strstr(directory, "CAMP01") || strstr(directory, "camp01")) && command_line_session_filter) { sprintf(warzone_path, "%s\\*.chc", directory); warzone_file = get_first_directory_file(warzone_path); sprintf(temp_warzone_name, "%s", get_directory_file_filename (warzone_file)); // Vadim 051120, if chc filename has spaces, capitalize every word for (upper=1, i = 0; i < (strlen (temp_warzone_name) - 4); i++) { if (upper) { temp_warzone_name[i] = toupper (temp_warzone_name[i]); upper=0; } else if (isspace(temp_warzone_name[i])) { upper=1; } else { temp_warzone_name[i] = tolower (temp_warzone_name[i]); } } temp_warzone_name[i] = '\0'; for (i = 0; i < (strlen (directory) - 7); i++) { warzone_path[i] = directory[i]; } warzone_path[i] = '\0'; add_session (temp_warzone_name, SESSION_LIST_TYPE_FILTER, 1, NULL, warzone_path, NULL, NULL, temp_warzone_name, list, NULL, SESSION_SEASON_INVALID); } directory_listing = get_first_directory_file (directory_search_path); // JB 030313 Enable running out of separate directories if (!directory_listing) { char fn[1024]; fn[0] = 0; strcpy(fn, comanche_hokum_installation_path); strcat(fn, "\\common\\"); strcat(fn, directory_search_path); directory_listing = get_first_directory_file ( fn ); } if (directory_listing) { valid_file = TRUE; while (valid_file) { session_type = SESSION_LIST_TYPE_HOST; if (get_directory_file_type (directory_listing) == DIRECTORY_FILE_TYPE_FILE) { FILE *file_ptr; file_tags tag; int end_flag; static char *ptr, *last_ptr, path [1024], full_filename [1024], campaign_title [1024], campaign_directory [32], campaign_filename [1024]; // // Add campaign file to list // sprintf (full_filename, "%s\\%s", directory, get_directory_file_filename (directory_listing)); file_ptr = safe_fopen (full_filename, "r"); end_flag = FALSE; warzone_name = NULL; season = SESSION_SEASON_INVALID; while (!end_flag) { tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); switch (tag) { case FILE_TAG_WARZONE_NAME: { get_next_file_string (file_ptr, temp_warzone_name, sizeof (temp_warzone_name)); warzone_name = temp_warzone_name; break; } case FILE_TAG_TITLE: { get_next_file_string (file_ptr, campaign_title, sizeof (campaign_title)); // // Create data path, ie strip off the last directory name // N.B. valid data directories are in any directory below 'MAPS'. // strcpy (path, directory); ptr = strstr (path, "\\maps\\"); ptr += strlen ("\\maps\\"); while (ptr = strstr (ptr, "\\")) { ptr += strlen ("\\"); last_ptr = ptr; } sprintf (campaign_directory, "%s", last_ptr); sprintf (campaign_filename, "%s", get_directory_file_filename (directory_listing)); last_ptr -= strlen ("\\"); *last_ptr = '\0'; break; } case FILE_TAG_LANGUAGE_TEXT_START: { // skip script till correct language while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG)) { #if (LANGUAGE == LANGUAGE_FRENCH) if (tag == FILE_TAG_LANGUAGE_FRENCH) { break; } #elif (LANGUAGE == LANGUAGE_GERMAN) if (tag == FILE_TAG_LANGUAGE_GERMAN) { break; } #elif (LANGUAGE == LANGUAGE_ITALIAN) if (tag == FILE_TAG_LANGUAGE_ITALIAN) { break; } #elif (LANGUAGE == LANGUAGE_SPANISH) if (tag == FILE_TAG_LANGUAGE_SPANISH) { break; } #else //LANGUAGE_ENGLISH if (tag == FILE_TAG_LANGUAGE_ENGLISH) { break; } #endif if (tag == FILE_TAG_LANGUAGE_TEXT_STOP) { break; } } break; } case FILE_TAG_LANGUAGE_TEXT_END: { // skip script till end of languages while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG)) { if (tag == FILE_TAG_LANGUAGE_TEXT_STOP) { break; } } break; } case FILE_TAG_CAMPAIGN_DATA: { while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG)) { if (tag == FILE_TAG_END) { break; } } break; } case FILE_TAG_SAVED_CAMPAIGN: { session_type = SESSION_LIST_TYPE_RESTORE; break; } case FILE_TAG_IF: { ASSERT (get_current_player_log ()); get_next_file_word (file_ptr, variable, sizeof (variable)); get_next_file_word (file_ptr, operator_, sizeof (operator_)); value = get_next_file_int (file_ptr); if (!if_file_tag_variable (variable, operator_, value)) { // skip script till endif while (tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG)) { if ((tag == FILE_TAG_ENDIF) || (tag == FILE_TAG_END)) { break; } } } break; } case FILE_TAG_ENDIF: { break; } case FILE_TAG_SEASON: { // 15JUN09 Casm retrieving season earlier season = get_next_file_int (file_ptr); break; } case FILE_TAG_CAMPAIGN_REQUIRES_APACHE_HAVOC: { debug_log("session filter: campaign_title %s", campaign_title); // VJ 050123 aphavoc install hack, do not close map if it exists but EEAH is not offcially installed if (!global_aphavoc_maps) { if (!get_global_apache_havoc_installed ()) { end_flag = TRUE; debug_log ("SESSION: Campaign %s required Apache-Havoc to be installed", campaign_title); break; } } } case FILE_TAG_END: case FILE_TAG_UNKNOWN: { end_flag = TRUE; if ((!command_line_session_filter) || (strcmp(session_filter_value, "root") != 0)) { // 15JUN09 Casm retrieving season earlier const char *title; // if host get the Translated campaign name // not hosted game so just use the name title = session_type == SESSION_LIST_TYPE_HOST ? get_trans (campaign_title) : campaign_title; if (session_type == SESSION_LIST_TYPE_HOST || (session_type == SESSION_LIST_TYPE_MASTER) || (session_type == SESSION_LIST_TYPE_RESTORE)) { add_session (title, session_type, 1, NULL, path, campaign_directory, campaign_filename, warzone_name, list, NULL, season); } } // Jabberwock 0400201 ends break; } } } fclose (file_ptr); } valid_file = get_next_directory_file (directory_listing); } destroy_directory_file_list (directory_listing); } // // Next, go through any directories, recursing into them. // sprintf (directory_search_path, "%s\\*", directory); directory_listing = get_first_directory_file (directory_search_path); // JB 030313 Enable running out of separate directories if (!directory_listing) { char fn[1024]; fn[0] = 0; strcpy(fn, comanche_hokum_installation_path); strcat(fn, "\\common\\"); strcat(fn, directory_search_path); directory_listing = get_first_directory_file ( fn ); } if (directory_listing) { valid_file = TRUE; while (valid_file) { if (get_directory_file_type (directory_listing) == DIRECTORY_FILE_TYPE_DIRECTORY) { if ((strcmp (get_directory_file_filename (directory_listing), ".") != 0) && (strcmp (get_directory_file_filename (directory_listing), "..") != 0)) { char full_directory [1024]; // // Create the full directory name // sprintf (full_directory, "%s\\%s", directory, get_directory_file_filename (directory_listing)); // // Recurse into this directory // recursive_check_campaign_files (full_directory, list, extension); } } valid_file = get_next_directory_file (directory_listing); } destroy_directory_file_list (directory_listing); } }