5 * Free a session's march list
7 void free_march_list(wcsession *wcf)
11 while (wcf->march != NULL) {
12 mptr = wcf->march->next;
21 * remove a room from the march list
23 void remove_march(const StrBuf *aaa)
25 struct march *mptr, *mptr2;
27 if (WC->march == NULL)
30 if (!strcasecmp(WC->march->march_name, ChrPtr(aaa))) {
31 mptr = WC->march->next;
37 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
38 if (!strcasecmp(mptr->march_name, ChrPtr(aaa))) {
39 mptr2->next = mptr->next;
51 * \brief Locate the room on the march list which we most want to go to.
53 * is measured given a "weight" of preference based on various factors.
54 * \param desired_floor the room number on the citadel server
55 * \return the roomname
57 char *pop_march(int desired_floor)
59 static char TheRoom[128];
62 struct march *mptr = NULL;
64 strcpy(TheRoom, "_BASEROOM_");
65 if (WC->march == NULL)
68 for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
70 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
71 weight = weight + 10000;
72 if (mptr->march_floor == desired_floor)
73 weight = weight + 5000;
75 weight = weight + ((128 - (mptr->march_floor)) * 128);
76 weight = weight + (128 - (mptr->march_order));
78 if (weight > TheWeight) {
80 strcpy(TheRoom, mptr->march_name);
82 TheFloor = mptr->march_floor;
83 TheOrder = mptr->march_order;
93 * Goto next room having unread messages.
95 * We want to skip over rooms that the user has already been to, and take the
96 * user back to the lobby when done. The room we end up in is placed in
97 * newroom - which is set to 0 (the lobby) initially.
98 * We start the search in the current room rather than the beginning to prevent
99 * two or more concurrent users from dragging each other back to the same room.
104 struct march *mptr = NULL;
105 struct march *mptr2 = NULL;
111 * First check to see if the march-mode list is already allocated.
112 * If it is, pop the first room off the list and go there.
114 if (havebstr("startmsg")) {
115 readloop(readnew, eUseDefault);
119 if (WC->march == NULL) {
121 serv_getln(buf, sizeof buf);
123 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
124 if (IsEmptyStr(buf)) {
127 if (ELoop % 100 == 0)
132 extract_token(room_name, buf, 0, '|', sizeof room_name);
133 if (strcasecmp(room_name, ChrPtr(WC->CurRoom.name))) {
134 mptr = (struct march *) malloc(sizeof(struct march));
136 safestrncpy(mptr->march_name, room_name, sizeof mptr->march_name);
137 mptr->march_floor = extract_int(buf, 2);
138 mptr->march_order = extract_int(buf, 3);
139 if (WC->march == NULL)
148 * add _BASEROOM_ to the end of the march list, so the user will end up
149 * in the system base room (usually the Lobby>) at the end of the loop
151 mptr = (struct march *) malloc(sizeof(struct march));
153 mptr->march_order = 0;
154 mptr->march_floor = 0;
155 strcpy(mptr->march_name, "_BASEROOM_");
156 if (WC->march == NULL) {
160 while (mptr2->next != NULL)
165 * ...and remove the room we're currently in, so a <G>oto doesn't make us
166 * walk around in circles
168 remove_march(WC->CurRoom.name);
170 if (WC->march != NULL) {
171 next_room = NewStrBufPlain(pop_march(-1), -1);/*TODO: migrate march to strbuf */
173 next_room = NewStrBufPlain(HKEY("_BASEROOM_"));
177 smart_goto(next_room);
178 FreeStrBuf(&next_room);
182 * un-goto the previous room
188 if (havebstr("startmsg")) {
189 readloop(readnew, eUseDefault);
193 if (!strcmp(WC->ugname, "")) {
194 smart_goto(WC->CurRoom.name);
197 serv_printf("GOTO %s", WC->ugname);
199 StrBuf_ServGetln(Buf);
200 if (GetServerStatus(Buf, NULL) != 2) {
201 smart_goto(WC->CurRoom.name);
205 if (WC->uglsn >= 0L) {
206 serv_printf("SLRP %ld", WC->uglsn);
207 StrBuf_ServGetln(Buf);
210 StrBufAppendBufPlain(Buf, WC->ugname, -1, 0);
211 strcpy(WC->ugname, "");
218 void tmplput_ungoto(StrBuf *Target, WCTemplputParams *TP)
223 (!IsEmptyStr(WCC->ugname)))
224 StrBufAppendBufPlain(Target, WCC->ugname, -1, 0);
227 void _gotonext(void) {
235 int ConditionalHaveUngoto(StrBuf *Target, WCTemplputParams *TP)
239 return ((WCC!=NULL) &&
240 (!IsEmptyStr(WCC->ugname)) &&
241 (strcasecmp(WCC->ugname, ChrPtr(WCC->CurRoom.name)) == 0));
249 RegisterConditional("COND:UNGOTO", 0, ConditionalHaveUngoto, CTX_NONE);
250 RegisterNamespace("ROOM:UNGOTO", 0, 0, tmplput_ungoto, NULL, CTX_NONE);
252 WebcitAddUrlHandler(HKEY("gotonext"), "", 0, _gotonext, NEED_URL);
253 WebcitAddUrlHandler(HKEY("skip"), "", 0, gotonext, NEED_URL);
254 WebcitAddUrlHandler(HKEY("ungoto"), "", 0, ungoto, NEED_URL);